[jboss-cvs] jboss-seam/src/main/org/jboss/seam/servlet ...
Gavin King
gavin.king at jboss.com
Sat Feb 3 20:13:20 EST 2007
User: gavin
Date: 07/02/03 20:13:20
Modified: src/main/org/jboss/seam/servlet SeamExceptionFilter.java
Log:
redesigned exception handling
Revision Changes Path
1.22 +51 -20 jboss-seam/src/main/org/jboss/seam/servlet/SeamExceptionFilter.java
(In the diff below, changes in quantity of whitespace are not shown.)
Index: SeamExceptionFilter.java
===================================================================
RCS file: /cvsroot/jboss/jboss-seam/src/main/org/jboss/seam/servlet/SeamExceptionFilter.java,v
retrieving revision 1.21
retrieving revision 1.22
diff -u -b -r1.21 -r1.22
--- SeamExceptionFilter.java 16 Dec 2006 02:58:12 -0000 1.21
+++ SeamExceptionFilter.java 4 Feb 2007 01:13:20 -0000 1.22
@@ -16,10 +16,15 @@
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.jboss.seam.contexts.Lifecycle;
+import org.jboss.seam.core.Exceptions;
import org.jboss.seam.log.LogProvider;
import org.jboss.seam.log.Logging;
-import org.jboss.seam.contexts.Lifecycle;
+import org.jboss.seam.mock.MockApplication;
+import org.jboss.seam.mock.MockExternalContext;
+import org.jboss.seam.mock.MockFacesContext;
import org.jboss.seam.util.Transactions;
/**
@@ -34,7 +39,8 @@
private static final LogProvider log = Logging.getLogProvider(SeamExceptionFilter.class);
private ServletContext context;
- public void init(FilterConfig cfg) throws ServletException {
+ public void init(FilterConfig cfg) throws ServletException
+ {
context = cfg.getServletContext();
}
@@ -53,45 +59,70 @@
}
catch (Exception e)
{
- rollbackTransactionIfNecessary();
- endWebRequestAfterException(request);
- if ( !isExceptionHandled(request) )
+ log.error("uncaught exception", e);
+ if (e instanceof ServletException)
{
- log.error("uncaught exception handled by Seam", e);
- throw new ServletException(e);
+ log.error("exception root cause", ( (ServletException) e ).getRootCause() );
}
+ rollbackTransactionIfNecessary();
+ endWebRequestAfterException( (HttpServletRequest) request, (HttpServletResponse) response, e);
}
finally
{
Lifecycle.setPhaseId(null);
- log.debug("ended request");
}
}
- private boolean isExceptionHandled(ServletRequest request)
+ private void endWebRequestAfterException(HttpServletRequest request, HttpServletResponse response, Exception e)
+ throws ServletException, IOException
{
- return request.getAttribute("org.jboss.seam.exceptionHandled")!=null;
+ log.debug("ending request");
+ //the FacesContext is gone - create a fake one for Redirect and HttpError to call
+ MockFacesContext facesContext = createFacesContext(request, response);
+ facesContext.setCurrent();
+ Lifecycle.beginExceptionRecovery(context, request); //the faces ExternalContext is useless to us at this point
+ try
+ {
+ Exceptions.instance().handle(e);
}
-
- private void endWebRequestAfterException(ServletRequest request)
+ catch (ServletException se)
+ {
+ throw se;
+ }
+ catch (IOException ioe)
+ {
+ throw ioe;
+ }
+ catch (Exception ehe)
+ {
+ throw new ServletException(ehe);
+ }
+ finally
{
try
{
- Lifecycle.beginExceptionRecovery( context, (HttpServletRequest) request ); //the faces ExternalContext is useless to us at this point
Lifecycle.endRequest();
+ facesContext.release();
+ log.debug("ended request");
}
- catch (Exception e)
+ catch (Exception ere)
{
log.error("could not destroy contexts", e);
}
}
+ }
+
+ private MockFacesContext createFacesContext(HttpServletRequest request, HttpServletResponse response)
+ {
+ return new MockFacesContext( new MockExternalContext(context, request, response), new MockApplication() );
+ }
private void rollbackTransactionIfNecessary()
{
try {
if ( Transactions.isTransactionActiveOrMarkedRollback() )
{
- log.info("killing transaction");
+ log.debug("killing transaction");
Transactions.getUserTransaction().rollback();
}
}
More information about the jboss-cvs-commits
mailing list