[jboss-cvs] jboss-seam/src/main/org/jboss/seam/core ...

Gavin King gavin.king at jboss.com
Fri Nov 3 17:47:24 EST 2006


  User: gavin   
  Date: 06/11/03 17:47:24

  Modified:    src/main/org/jboss/seam/core   Exceptions.java Manager.java
  Log:
  decoupled the endRequest() processing in Manager from storing stuff in the ViewRoot
  
  Revision  Changes    Path
  1.7       +19 -19    jboss-seam/src/main/org/jboss/seam/core/Exceptions.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Exceptions.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Exceptions.java,v
  retrieving revision 1.6
  retrieving revision 1.7
  diff -u -b -r1.6 -r1.7
  --- Exceptions.java	3 Nov 2006 02:32:38 -0000	1.6
  +++ Exceptions.java	3 Nov 2006 22:47:24 -0000	1.7
  @@ -27,7 +27,6 @@
   import org.jboss.seam.contexts.Contexts;
   import org.jboss.seam.contexts.Lifecycle;
   import org.jboss.seam.interceptors.ExceptionInterceptor;
  -import org.jboss.seam.jsf.AbstractSeamPhaseListener;
   import org.jboss.seam.util.Reflections;
   import org.jboss.seam.util.Resources;
   import org.jboss.seam.util.Strings;
  @@ -213,8 +212,7 @@
            addFacesMessage( e, getMessage(e) );
            if ( isEnd(e) ) Conversation.instance().end();
            redirect( getViewId(e) );
  -         handled(e);
  -         throw e;
  +         return rethrow(e);
         }
   
         public boolean isHandler(Exception e)
  @@ -279,8 +277,7 @@
            String message = getMessage(e);
            addFacesMessage(e, message);
            error( getCode(e), Interpolator.instance().interpolate( getDisplayMessage(e, message) ) );
  -         handled(e);
  -         throw e;
  +         return rethrow(e);
         }  
   
         public boolean isHandler(Exception e)
  @@ -312,17 +309,13 @@
            log.error("redirecting to debug page", e);
            Contexts.getConversationContext().set("org.jboss.seam.debug.lastException", e);
            Contexts.getConversationContext().set("org.jboss.seam.debug.phaseId", Lifecycle.getPhaseId().toString());
  -         FacesContext facesContext = FacesContext.getCurrentInstance();
            org.jboss.seam.core.Redirect redirect = org.jboss.seam.core.Redirect.instance();
            redirect.setViewId("/debug.xhtml");
            Manager manager = Manager.instance();
            manager.beforeRedirect();
            redirect.setParameter( manager.getConversationIdParameter(), manager.getCurrentConversationId() );
            redirect.execute();
  -         FacesMessages.afterPhase();
  -         AbstractSeamPhaseListener.storeAnyConversationContext(facesContext);
  -         handled(e);
  -         throw e;
  +         return rethrow(e);
         }
   
         public boolean isHandler(Exception e)
  @@ -356,7 +349,6 @@
      protected static void error(int code, String message)
      {
         if ( log.isDebugEnabled() ) log.debug("sending error: " + code);
  -      FacesContext facesContext = FacesContext.getCurrentInstance();
         org.jboss.seam.core.HttpError httpError = org.jboss.seam.core.HttpError.instance();
         if (message==null)
         {
  @@ -366,23 +358,18 @@
         {
            httpError.send(code, message);
         }
  -      FacesMessages.afterPhase();
  -      AbstractSeamPhaseListener.storeAnyConversationContext(facesContext);
      }
   
      protected static void redirect(String viewId)
      {
  -      FacesContext facesContext = FacesContext.getCurrentInstance();
         if ( Strings.isEmpty(viewId) )
         {
  -         viewId = facesContext.getViewRoot().getViewId();
  +         viewId = FacesContext.getCurrentInstance().getViewRoot().getViewId();
         }
         if ( log.isDebugEnabled() ) log.debug("redirecting to: " + viewId);
         org.jboss.seam.core.Redirect redirect = org.jboss.seam.core.Redirect.instance();
         redirect.setViewId(viewId);
         redirect.execute();
  -      FacesMessages.afterPhase();
  -      AbstractSeamPhaseListener.storeAnyConversationContext(facesContext);
      }
      
      protected static void render(String viewId)
  @@ -402,9 +389,22 @@
         facesContext.renderResponse();
      }
   
  -   protected static void handled(Exception e)
  +   private static Object rethrow(Exception e) throws Exception
  +   {
  +      //SeamExceptionFilter does *not* do these things, which 
  +      //would normally happen in the phase listener after a 
  +      //responseComplete() call, but because we are rethrowing,
  +      //the phase listener might not get called (due to a bug!)
  +      /*FacesMessages.afterPhase();
  +      if ( Contexts.isConversationContextActive() )
      {
  -      FacesContext.getCurrentInstance().getExternalContext().getRequestMap().put("org.jboss.seam.exceptionHandled", e);
  +         Manager.instance().endRequest( ContextAdaptor.getSession( externalContext, true ) );
  +      }*/
  +      
  +      FacesContext facesContext = FacesContext.getCurrentInstance();
  +      facesContext.responseComplete();
  +      facesContext.getExternalContext().getRequestMap().put("org.jboss.seam.exceptionHandled", e);
  +      throw e;
      }
   
      public static Exceptions instance()
  
  
  
  1.110     +50 -68    jboss-seam/src/main/org/jboss/seam/core/Manager.java
  
  (In the diff below, changes in quantity of whitespace are not shown.)
  
  Index: Manager.java
  ===================================================================
  RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/core/Manager.java,v
  retrieving revision 1.109
  retrieving revision 1.110
  diff -u -b -r1.109 -r1.110
  --- Manager.java	3 Nov 2006 16:49:17 -0000	1.109
  +++ Manager.java	3 Nov 2006 22:47:24 -0000	1.110
  @@ -20,7 +20,6 @@
   import javax.faces.context.ExternalContext;
   import javax.faces.context.FacesContext;
   import javax.faces.event.PhaseEvent;
  -import javax.faces.event.PhaseId;
   import javax.portlet.ActionResponse;
   import javax.servlet.http.HttpServletResponse;
   
  @@ -34,7 +33,6 @@
   import org.jboss.seam.annotations.Scope;
   import org.jboss.seam.contexts.ContextAdaptor;
   import org.jboss.seam.contexts.Contexts;
  -import org.jboss.seam.contexts.Lifecycle;
   import org.jboss.seam.contexts.ServerConversationContext;
   import org.jboss.seam.util.Id;
   
  @@ -43,7 +41,7 @@
    *
    * @author Gavin King
    * @author <a href="mailto:theute at jboss.org">Thomas Heute</a>
  - * @version $Revision: 1.109 $
  + * @version $Revision: 1.110 $
    */
   @Scope(ScopeType.EVENT)
   @Name("org.jboss.seam.core.manager")
  @@ -71,8 +69,6 @@
      private String conversationIdParameter = "conversationId";
      private String conversationIsLongRunningParameter = "conversationIsLongRunning";
   
  -   private boolean conversationAlreadyStored;
  -
      public String getCurrentConversationId()
      {
         return currentConversationId;
  @@ -245,7 +241,7 @@
      /**
       * Clean up timed-out conversations
       */
  -   public void conversationTimeout(ExternalContext externalContext)
  +   public void conversationTimeout(ContextAdaptor session)
      {
         long currentTime = System.currentTimeMillis();
         List<ConversationEntry> entries = new ArrayList<ConversationEntry>( ConversationEntries.instance().getConversationEntries() );
  @@ -278,7 +274,6 @@
                     //      unlock() the CE
                     log.info("destroying conversation with garbage lock: " + conversationEntry.getId());
                  }
  -               ContextAdaptor session = ContextAdaptor.getSession(externalContext, true);
                  destroyConversation( conversationEntry.getId(), session );
               }
            }
  @@ -302,87 +297,80 @@
      }
      
      /**
  -    * Flush the server-side conversation context to the session and
  -    * write the conversation id and pageflow info to the response
  -    * if we have a long running conversation, or discard the state
  -    * of a temporary conversation.
  +    * Touch the conversation stack and flush some state to the 
  +    * conversation context, destroy ended conversations, and
  +    * timeout inactive conversations.
       */
  -   public void storeConversation(ContextAdaptor session, Object response)
  +   public void endRequest(ContextAdaptor session)
      {
         if ( isLongRunningConversation() )
         {
  -         touchConversationStack( getCurrentConversationIdStack() );
  -         if ( !Seam.isSessionInvalid() ) 
  +         if ( log.isDebugEnabled() )
            {
  -            storeLongRunningConversation(response);
  +            log.debug("Storing conversation state: " + getCurrentConversationId());
            }
  +         touchConversationStack( getCurrentConversationIdStack() );
  +         Conversation.instance().flush();
         }
         else
         {
  -         discardTemporaryConversation(session, response);
  +         if ( log.isDebugEnabled() )
  +         {
  +            log.debug("Discarding conversation state: " + getCurrentConversationId());
         }
  -      conversationAlreadyStored = true;
  +         //now safe to remove the entry
  +         removeCurrentConversationAndDestroyNestedContexts(session);
      }
      
  -   public void unlockConversation()
  -   {
  -      ConversationEntry ce = getCurrentConversationEntry();
  -      if (ce!=null) 
  +      if ( !Init.instance().isClientSideConversations() ) 
         {
  -         ce.unlock();
  -      }
  -      else if ( isNestedConversation() )
  -      {
  -         ConversationEntries.instance().getConversationEntry( getParentConversationId() ).unlock();
  +         // difficult question: is it really safe to do this here?
  +         // right now we do have to do it after committing the Seam
  +         // transaction because we can't close EMs inside a txn
  +         // (this might be a bug in HEM)
  +         Manager.instance().conversationTimeout(session);
         }
      }
   
  -   private void storeLongRunningConversation(Object response)
  +   /**
  +    * Write the conversation id and pageflow info to the response
  +    * if we have a long running conversation.
  +    */
  +   public void writeValuesToViewRoot(ContextAdaptor session, Object response)
      {
  -      if ( log.isDebugEnabled() )
  +      //we only need to execute this code when we are in the 
  +      //RENDER_RESPONSE phase, ie. not before redirects
  +      if ( isLongRunningConversation() )
  +      {
  +         if ( !Seam.isSessionInvalid() ) 
         {
  -         log.debug("Storing conversation state: " + getCurrentConversationId());
  -      }
  -      Conversation.instance().flush();
         //if the session is invalid, don't put the conversation id
         //in the view, 'cos we are expecting the conversation to
         //be destroyed by the servlet session listener
  -      if ( Contexts.isPageContextActive() && Lifecycle.getPhaseId()==PhaseId.RENDER_RESPONSE ) 
  -      {
  -         //TODO: we really only need to execute this code when we are in the 
  -         //      RENDER_RESPONSE phase, ie. not before redirects
            org.jboss.seam.core.FacesPage.instance().storeConversation();
         }
  -      writeConversationIdToResponse( response, getCurrentConversationId() );
      }
  -
  -   private void discardTemporaryConversation(ContextAdaptor session, Object response)
  -   {
  -      if (log.isDebugEnabled())
  +      else if ( isNestedConversation() )
         {
  -         log.debug("Discarding conversation state: " + getCurrentConversationId());
  +         org.jboss.seam.core.FacesPage.instance().discardNestedConversation( getParentConversationId() );
         }
  -         
  -      List<String> stack = getCurrentConversationIdStack();
  -      if ( stack.size()>1 )
  -      {
  -         String outerConversationId = stack.get(1);
  -         if ( Contexts.isPageContextActive() && Lifecycle.getPhaseId()==PhaseId.RENDER_RESPONSE  )
  +      else
            {
  -            org.jboss.seam.core.FacesPage.instance().discardNestedConversation(outerConversationId);
  +         org.jboss.seam.core.FacesPage.instance().discardTemporaryConversation();
            }
  -         writeConversationIdToResponse(response, outerConversationId);
         }
  -      else
  +   
  +   public void unlockConversation()
         {
  -         if ( Contexts.isPageContextActive() && Lifecycle.getPhaseId()==PhaseId.RENDER_RESPONSE  )
  +      ConversationEntry ce = getCurrentConversationEntry();
  +      if (ce!=null) 
            {
  -            org.jboss.seam.core.FacesPage.instance().discardTemporaryConversation();
  +         ce.unlock();
            }
  +      else if ( isNestedConversation() )
  +      {
  +         ConversationEntries.instance().getConversationEntry( getParentConversationId() ).unlock();
         }
  -
  -      //now safe to remove the entry
  -      removeCurrentConversationAndDestroyNestedContexts(session);
      }
   
      /**
  @@ -1028,11 +1016,6 @@
            );
      }
   
  -   public boolean isConversationAlreadyStored()
  -   {
  -      return conversationAlreadyStored;
  -   }
  -
      public boolean isUpdateModelValuesCalled()
      {
         return updateModelValuesCalled;
  @@ -1059,5 +1042,4 @@
         return "Manager(" + currentConversationIdStack + ")";
      }
   
  -
   }
  
  
  



More information about the jboss-cvs-commits mailing list