3 Replies Latest reply on Jun 30, 2006 1:30 PM by javidjamae

    Session persistence

    javidjamae

      I'm trying to enable session persistence in jboss-4.0.4GA, but no SESSIONS.ser file is created. I followed the instructions in the global context.xml file in the root of the Tomcat service archive, which says to create a WEB-INF/context.xml file to enable session persistence for an individual app.

      Unfortunately, no SESSIONS.ser file is created where I expected it, in the following directory:

      jboss-4.0.4.GA\server\default\work\jboss.web\localhost\simple

      I'm guessing one of the following:

      1) Session persistence is broken in this release
      2) There is an additional step that I'm missing, which is not mentioned in the global context.xml
      3) My code is not using the session properly
      4) The SESSIONS.ser file is being created somewhere else (but I think I've eliminated this as an option because I've restarted the server and my sessions are recreated from scratch)

      Any suggestions would be greatly appreciated!!



      Here is my code:

      WEB-INF/context.xml

      <Context cookies="true" crossContext="true">
       <Manager pathname="SESSIONS.ser" />
       <InstanceListener>org.jboss.web.tomcat.security.RunAsListener</InstanceListener>
      </Context>


      WEB-INF/web.xml
      <web-app xmlns="http://java.sun.com/xml/ns/j2ee" version="2.4"
       xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http:/java.sun.com/dtd/web-app_2_3.dtd">
      
       <servlet>
       <servlet-name>Hello Servlet</servlet-name>
       <servlet-class>HelloWorldServlet</servlet-class>
       </servlet>
       <servlet-mapping>
       <servlet-name>Hello Servlet</servlet-name>
       <url-pattern>/sayhello</url-pattern>
       </servlet-mapping>
      </web-app>


      HelloWorldServlet
      import java.io.IOException;
      import java.io.PrintWriter;
      
      import javax.servlet.ServletException;
      import javax.servlet.http.HttpServlet;
      import javax.servlet.http.HttpServletRequest;
      import javax.servlet.http.HttpServletResponse;
      import javax.servlet.http.HttpSession;
      
      @SuppressWarnings("serial")
      public class HelloWorldServlet extends HttpServlet
      {
      
       @Override
       public void service( HttpServletRequest request, HttpServletResponse response )
       throws ServletException, IOException
       {
       PrintWriter out = response.getWriter();
       HttpSession session = request.getSession( true );
       Object o = session.getAttribute( "count" );
       int count;
       if ( o == null )
       {
       System.out.println("count was null");
       count = 0;
       session.setAttribute( "count", count );
       }
       else
       {
       count = (Integer) o;
       System.out.println("count was " + count);
       session.setAttribute( "count", ++count );
       }
       out.println( "<html><body>I've said 'Hello World!' "
       + count
       + " times!</body></html>" );
       out.close();
       }
      }


        • 1. Re: Session persistence
          javidjamae

          I'm curious if this is related to:

          http://jira.jboss.com/jira/browse/JBAS-1811

          • 2. Re: Session persistence
            nancy.aggarwal

            Hi,

            I am facing a problem while making my http session persistent (session.ser is created)

            Caused by: java.sql.SQLException: Connection handle is not currently associated with a ManagedConnection
             at org.jboss.resource.adapter.jdbc.WrappedConnection.checkStatus(WrappedConnection.java:539)
             at org.jboss.resource.adapter.jdbc.WrappedConnection.getAutoCommit(WrappedConnection.java:327)
             at org.hibernate.jdbc.ConnectionManager.isAutoCommit(ConnectionManager.java:185)
             at org.hibernate.jdbc.JDBCContext.afterNontransactionalQuery(JDBCContext.java:232)
             ... 35 more


            I am using mysql as backend database with hibernate and done Jndi binding of datasource as well as hibernate session factory and packaged all in har archive file.
            when i try to run my application i get session is closed error!!!!!

            I make temprorarily working of my application by creating new session if i found session closed.

            Now i wanted persistent http sessions and my all objects which i want to put in session are serailizable.When i run my application i got above mentioned error....


            12:15:25,343 ERROR [JDBCExceptionReporter] Connection handle is not currently associated with a ManagedConnection
            12:15:25,343 ERROR [STDERR] org.hibernate.exception.GenericJDBCException: could not inspect JDBC autocommit mode
             at org.hibernate.exception.SQLStateConverter.handledNonSpecificException(SQLStateConverter.java:103)
             at org.hibernate.exception.SQLStateConverter.convert(SQLStateConverter.java:91)
             at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:43)
             at org.hibernate.exception.JDBCExceptionHelper.convert(JDBCExceptionHelper.java:29)
             at org.hibernate.jdbc.JDBCContext.afterNontransactionalQuery(JDBCContext.java:241)
             at org.hibernate.impl.SessionImpl.afterOperation(SessionImpl.java:419)
             at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1119)
             at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)
            
            
            
            12:15:25,218 WARN [TxConnectionManager] Connection error occured: org.jboss.resource.connectionmanager.TxConnectionManager$TxConnectionEventListener@1abac1[state=NORMAL mc=org.jboss.resource.adapter.jdbc.local.LocalManagedConnection@1ddf5ee handles=1 lastUse=1150785668218 permit=true trackByTx=false mcp=org.jboss.resource.connectionmanager.JBossManagedConnectionPool$OnePool@1b9cdfc context=org.jboss.resource.connectionmanager.InternalManagedConnectionPool@1829097 xaResource=org.jboss.resource.connectionmanager.TxConnectionManager$LocalXAResource@13d0953 txSync=null]
            java.lang.NullPointerException
             at org.jboss.mx.loading.RepositoryClassLoader.findClass(RepositoryClassLoader.java:620)
             at java.lang.ClassLoader.loadClass(ClassLoader.java:289)
             at org.jboss.mx.loading.RepositoryClassLoader.loadClassImpl(RepositoryClassLoader.java:464)
             at org.jboss.mx.loading.RepositoryClassLoader.loadClass(RepositoryClassLoader.java:405)
             at java.lang.ClassLoader.loadClass(ClassLoader.java:235)
             at java.lang.ClassLoader.loadClassInternal(ClassLoader.java:302)
             at com.mysql.jdbc.PreparedStatement.<init>(PreparedStatement.java:147)
             at com.mysql.jdbc.Connection.prepareStatement(Connection.java:1283)
             at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.doPrepareStatement(BaseWrapperManagedConnection.java:349)
             at org.jboss.resource.adapter.jdbc.BaseWrapperManagedConnection.prepareStatement(BaseWrapperManagedConnection.java:344)
             at org.jboss.resource.adapter.jdbc.WrappedConnection.prepareStatement(WrappedConnection.java:187)
             at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:497)
             at org.hibernate.jdbc.AbstractBatcher.getPreparedStatement(AbstractBatcher.java:415)
             at org.hibernate.jdbc.AbstractBatcher.prepareQueryStatement(AbstractBatcher.java:139)
             at org.hibernate.loader.Loader.prepareQueryStatement(Loader.java:1561)
             at org.hibernate.loader.Loader.doQuery(Loader.java:661)
             at org.hibernate.loader.Loader.doQueryAndInitializeNonLazyCollections(Loader.java:224)
             at org.hibernate.loader.Loader.doList(Loader.java:2145)
             at org.hibernate.loader.Loader.listIgnoreQueryCache(Loader.java:2029)
             at org.hibernate.loader.Loader.list(Loader.java:2024)
             at org.hibernate.loader.hql.QueryLoader.list(QueryLoader.java:392)
             at org.hibernate.hql.ast.QueryTranslatorImpl.list(QueryTranslatorImpl.java:333)
             at org.hibernate.engine.query.HQLQueryPlan.performList(HQLQueryPlan.java:172)
             at org.hibernate.impl.SessionImpl.list(SessionImpl.java:1114)
             at org.hibernate.impl.QueryImpl.list(QueryImpl.java:79)




            please help

            • 3. Re: Session persistence
              javidjamae

              [Nancy: you should start a separate thread since you are having an unrelated issue]

              I discovered two issues:

              1) The file is only created after you shut down the server manually. This seems like a bug, because the whole reason people would want to do this is to be able to survive a machine crash. I understand that replication is an alternative when you're in a clustered environment, but many people only run a single node and want to have a fault tolerance mechanism for their HTTP sessions. I opened the following JIRA issue:

              http://jira.jboss.com/jira/browse/JBAS-3357

              2) The default output directory (if you don't specify an absolute path) is the configurations work directory. Apparently this directory is wiped out after the server stops. So if you don't specify an absolute directory, your file will always be deleted. I feel like this is a bug. There may be good reasons to wipe out the work directory, but it shouldn't be the default directory for a persistent file then. I'm opened the following JIRA issue for this bug:

              http://jira.jboss.com/jira/browse/JBAS-3358