5 Replies Latest reply on May 24, 2006 5:58 PM by pbrewer_uk

    Migration problem from CR2 to CR3

    pbrewer_uk

      I'm currently trying to upgrade from Seam CR2 to CR3 and have now hit a stumper.

      I have a JSF PhaseListener that requires a user to login before being redirected back to their original page request (which was working fine under CR2). However, the code below now complains about "No active conversation context" when a user first hits a page that requires them to login.

      Any help or ideas on how to solve this would be gratefully received.

      public class LoggedInPhaseListener implements PhaseListener {
      
       private static final Logger log = Logger.getLogger( LoggedInPhaseListener.class );
      
       public void afterPhase ( PhaseEvent event ) {
      
       FacesContext facesContext = FacesContext.getCurrentInstance();
       String viewId = facesContext.getViewRoot().getViewId();
       log.debug( "afterPhase view id: " + viewId );
      
       if ( Contexts.isSessionContextActive() ) {
      
       Context sessionContext = Contexts.getSessionContext();
      
       SecurePages securePages = SecurePages.instance();
       if ( securePages.isSecure( viewId ) ) {
      
       // This is a secure page so check the settings
       User user = null;
       user = ( User ) sessionContext.get( "loggedInUser" );
       SecurePage securePage = securePages.getSecurePage( viewId );
      
       if ( user == null || !securePage.isRoleValid( user.getUserRole() ) ) {
      
       // User is not logged in or does not have privileges for this page
       log.debug( "Redirecting to the login outcome " + securePage.getLoginOutcome() );
      
       // Set the secure page so it can be checked when login completes
       if ( ( securePage.isLoginPage() && sessionContext.get( "destinationPage" ) == null ) || !securePage.isLoginPage() ) {
       log.debug( "Setting destination page to " + securePage );
       sessionContext.remove( "destinationPage" );
       sessionContext.set( "destinationPage", securePage );
       }
      
       // Redirect to the login outcome specified in secure-page.xml
       if ( !securePage.isLoginPage() ) {
       facesContext.getApplication().getNavigationHandler()
       .handleNavigation( facesContext, null, securePage.getLoginOutcome() );
      
       }
      
       }
       } else {
       sessionContext.remove( "destinationPage" );
       log.debug( "Page " + viewId + " does not require authentication." );
       }
      
       } else {
       log.debug( "No Active session context - This should not happen - Error ?" );
       }
      
       }
      
       public void beforePhase ( PhaseEvent event ) {
       // Auto-generated method stub
       }
      
       public PhaseId getPhaseId () {
       // Auto-generated method stub
       return PhaseId.RESTORE_VIEW;
       }
      
      }
      
      


      Produces this stack trace:

      24-05 17:55:00 ERROR [PhaseListenerManager] Exception in PhaseListener RESTORE_VIEW(1) afterPhase
      java.lang.IllegalStateException: No active conversation context
       at org.jboss.seam.core.Pageflow.instance(Pageflow.java:57)
       at org.jboss.seam.jsf.SeamNavigationHandler.handleNavigation(SeamNavigationHandler.java:29)
       at uk.co.iblocks.jsf.LoggedInPhaseListener.afterPhase(LoggedInPhaseListener.java:71)
       at org.apache.myfaces.lifecycle.PhaseListenerManager.informPhaseListenersAfter(PhaseListenerManager.java:89)
       at org.apache.myfaces.lifecycle.LifecycleImpl.restoreView(LifecycleImpl.java:181)
       at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:66)
       at javax.faces.webapp.FacesServlet.service(FacesServlet.java:137)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:252)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.myfaces.webapp.filter.ExtensionsFilter.doFilter(ExtensionsFilter.java:144)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.servlet.SeamRedirectFilter.doFilter(SeamRedirectFilter.java:23)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.jboss.seam.servlet.SeamExceptionFilter.doFilter(SeamExceptionFilter.java:45)
       at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:202)
       at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:173)
       at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:213)
       at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:178)
       at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:126)
       at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:105)
       at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:107)
       at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:148)
       at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:868)
       at org.apache.coyote.http11.Http11BaseProtocol$Http11ConnectionHandler.processConnection(Http11BaseProtocol.java:663)
       at org.apache.tomcat.util.net.PoolTcpEndpoint.processSocket(PoolTcpEndpoint.java:527)
       at org.apache.tomcat.util.net.LeaderFollowerWorkerThread.runIt(LeaderFollowerWorkerThread.java:80)
       at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:684)
       at java.lang.Thread.run(Thread.java:595)
      


        • 1. Re: Migration problem from CR2 to CR3
          gavin.king

          What version of MyFaces is it?

          And what is the setting for

          org.jboss.seam.core.init.myFacesLifecycleBug

          • 2. Re: Migration problem from CR2 to CR3
            pbrewer_uk

            I'm using MyFaces 1.1.3 (with tomahawk 1.1.2) inside the embedded ejb container and tomcat and have set the following in my web.xml:

             <context-param>
             <param-name>org.jboss.seam.core.init.myFacesLifecycleBug</param-name>
             <param-value>false</param-value>
             </context-param>
            


            Is this the correct setting and is it in the right place? I tried setting it to true as well, but that gave the same exception.

            • 3. Re: Migration problem from CR2 to CR3
              gavin.king

              yes, that is all correct.

              The problem is probably to do with PhaseListener ordering. (Which is not really very welldefined in the JSF spec, AFAIK.)

              • 4. Re: Migration problem from CR2 to CR3
                pbrewer_uk

                Ok, cheers Gavin, thanks for the help/ hints. So should the SeamExtendedManagedPersistencePhaseListener be called prior to my phase listener?

                Is there any way to talk to the SEMPPL to enforce such an ordering? If not, I suppose I could extend it to allow such communication?

                • 5. Re: Migration problem from CR2 to CR3
                  pbrewer_uk

                  I've just discovered its not necessary to do anything other than swap the order that the phase listeners are declared in the web.xml (they seem to be invoked in reverse order now).

                  You were spot on about undefined ordering! Cheers Gavin.