[jboss-cvs] jboss-seam/src/main/org/jboss/seam/interceptors ...
Gavin King
gavin.king at jboss.com
Sat Oct 21 21:47:12 EDT 2006
User: gavin
Date: 06/10/21 21:47:12
Modified: src/main/org/jboss/seam/interceptors
AsynchronousInterceptor.java
ExceptionInterceptor.java
Log:
better exception handling
rolled back change to faces-config
fix bug where destroy() injected closed EM and tried to register in txn
Revision Changes Path
1.4 +2 -5 jboss-seam/src/main/org/jboss/seam/interceptors/AsynchronousInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: AsynchronousInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/AsynchronousInterceptor.java,v
retrieving revision 1.3
retrieving revision 1.4
diff -u -b -r1.3 -r1.4
--- AsynchronousInterceptor.java 10 Oct 2006 06:43:16 -0000 1.3
+++ AsynchronousInterceptor.java 22 Oct 2006 01:47:12 -0000 1.4
@@ -4,16 +4,13 @@
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
+import org.jboss.seam.InterceptorType;
import org.jboss.seam.annotations.Asynchronous;
import org.jboss.seam.annotations.Interceptor;
import org.jboss.seam.contexts.Contexts;
import org.jboss.seam.core.Dispatcher;
- at Interceptor(around={BijectionInterceptor.class, RemoveInterceptor.class,
- ConversationInterceptor.class, EventInterceptor.class,
- RollbackInterceptor.class, TransactionInterceptor.class,
- ExceptionInterceptor.class, BusinessProcessInterceptor.class,
- ManagedEntityIdentityInterceptor.class})
+ at Interceptor(type=InterceptorType.CLIENT)
public class AsynchronousInterceptor extends AbstractInterceptor
{
@AroundInvoke
1.11 +10 -133 jboss-seam/src/main/org/jboss/seam/interceptors/ExceptionInterceptor.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: ExceptionInterceptor.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/interceptors/ExceptionInterceptor.java,v
retrieving revision 1.10
retrieving revision 1.11
diff -u -b -r1.10 -r1.11
--- ExceptionInterceptor.java 11 Oct 2006 21:41:29 -0000 1.10
+++ ExceptionInterceptor.java 22 Oct 2006 01:47:12 -0000 1.11
@@ -1,40 +1,23 @@
-//$Id: ExceptionInterceptor.java,v 1.10 2006/10/11 21:41:29 gavin Exp $
+//$Id: ExceptionInterceptor.java,v 1.11 2006/10/22 01:47:12 gavin Exp $
package org.jboss.seam.interceptors;
-import java.util.Map;
-
-import javax.faces.component.UIViewRoot;
import javax.faces.context.FacesContext;
-import javax.faces.event.PhaseId;
import javax.interceptor.AroundInvoke;
import javax.interceptor.InvocationContext;
-import org.apache.commons.logging.Log;
-import org.apache.commons.logging.LogFactory;
-import org.jboss.seam.annotations.HttpError;
+import org.jboss.seam.InterceptorType;
import org.jboss.seam.annotations.Interceptor;
-import org.jboss.seam.annotations.Redirect;
-import org.jboss.seam.annotations.Render;
-import org.jboss.seam.contexts.Contexts;
-import org.jboss.seam.contexts.Lifecycle;
-import org.jboss.seam.core.FacesMessages;
-import org.jboss.seam.core.Init;
-import org.jboss.seam.core.Interpolator;
-import org.jboss.seam.core.Manager;
-import org.jboss.seam.jsf.AbstractSeamPhaseListener;
+import org.jboss.seam.core.Exceptions;
/**
- * Handle exceptions
+ * Handles exceptions annotation @Redirect, @HttpError or @Render.
*
* @author Gavin King
*/
- at Interceptor(stateless=true,
- around={ConversationalInterceptor.class, RemoveInterceptor.class, BijectionInterceptor.class})
+ at Interceptor(stateless=true, type=InterceptorType.CLIENT)
public class ExceptionInterceptor extends AbstractInterceptor
{
- private static final Log log = LogFactory.getLog(ExceptionInterceptor.class);
-
@AroundInvoke
public Object handleExceptions(InvocationContext invocation) throws Exception
{
@@ -48,120 +31,14 @@
{
if ( outermost && FacesContext.getCurrentInstance()!=null )
{
- if ( e.getClass().isAnnotationPresent(Redirect.class) && Lifecycle.getPhaseId()!=PhaseId.RENDER_RESPONSE )
- {
- Redirect redirect = e.getClass().getAnnotation(Redirect.class);
- addFacesMessage( e, redirect.message() );
- redirect( redirect.viewId() );
- handled(e);
- }
- else if ( e.getClass().isAnnotationPresent(Render.class) && Lifecycle.getPhaseId()==PhaseId.INVOKE_APPLICATION )
- {
- //unfortunately, @Render can only really work during an action invocation
- Render render = e.getClass().getAnnotation(Render.class);
- addFacesMessage( e, render.message() );
- render( render.viewId() );
- return null;
- }
- else if ( e.getClass().isAnnotationPresent(HttpError.class) )
- {
- HttpError httpError = e.getClass().getAnnotation(HttpError.class);
- error( httpError.errorCode(), renderExceptionMessage( e, httpError.message() ) );
- handled(e);
- }
- else if ( Init.instance().isDebug() && Lifecycle.getPhaseId()!=PhaseId.RENDER_RESPONSE )
- {
- redirectToDebugPage(e);
- handled(e);
- }
- }
- throw e;
- }
- }
-
- private void addFacesMessage(Exception e, String message)
- {
- message = renderExceptionMessage(e, message);
- if (message!=null)
- {
- FacesMessages.instance().add(message);
- }
- }
-
- private String renderExceptionMessage(Exception e, String message)
- {
- message = "".equals(message) ? e.getMessage() : message;
- return message==null ? null : Interpolator.instance().interpolate(message);
- }
-
- private 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)
- {
- httpError.send(code);
+ return Exceptions.instance().handle(e);
}
else
{
- httpError.send(code, message);
- }
- FacesMessages.afterPhase();
- AbstractSeamPhaseListener.storeAnyConversationContext(facesContext);
- }
-
- private void redirect(String viewId)
- {
- FacesContext facesContext = FacesContext.getCurrentInstance();
- if ( "".equals(viewId) )
- {
- viewId = facesContext.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);
- }
-
- private void render(String viewId)
- {
- FacesContext context = FacesContext.getCurrentInstance();
- if ( !"".equals(viewId) )
- {
- if ( log.isDebugEnabled() ) log.debug("rendering: " + viewId);
- UIViewRoot viewRoot = context.getApplication().getViewHandler().createView(context, viewId);
- context.setViewRoot(viewRoot);
- }
- context.renderResponse();
+ throw e;
}
-
- private void redirectToDebugPage(Exception e)
- {
- 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);
}
-
- private static void handled(Exception e)
- {
- getRequest().put("org.jboss.seam.exceptionHandled", e);
}
- private static Map getRequest()
- {
- return FacesContext.getCurrentInstance().getExternalContext().getRequestMap();
- }
}
More information about the jboss-cvs-commits
mailing list