Re: [solved] Exception handling JSF2

Splash Forums PrettyFaces Users [solved] Exception handling JSF2 Re: [solved] Exception handling JSF2

#20135

0swald
Participant

Hi Lincoln. Here are complete test results using latest snapshot

ExceptionHandler:

@Override
public void handle() throws FacesException {
for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) {
ExceptionQueuedEvent event = i.next();
ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
Throwable t = context.getException();
if(t instanceof DynaViewException) {
try {
FacesContext fc = event.getContext().getContext();
NavigationHandler nav = fc.getApplication().getNavigationHandler();
nav.handleNavigation(fc, null, "/faces/pages/test.xhtml");
fc.renderResponse();
} finally {
i.remove();
}
}
}
super.handle();
}

If I throw Exception from DynaView’s url-parsing method it will be root cause for subsequent ELException, so I catch all parsing exceptions and put my own in queue:

FacesContext fc = FacesContext.getCurrentInstance();
//ExceptionQueuedEventContext exceptionQueuedEventContext = new ExceptionQueuedEventContext(fc, e);
ExceptionQueuedEventContext exceptionQueuedEventContext = new ExceptionQueuedEventContext(fc, e, null, PhaseId.RESTORE_VIEW);
ExceptionQueuedEvent redirectEvent = new ExceptionQueuedEvent(exceptionQueuedEventContext);
fc.getExceptionHandler().processEvent(redirectEvent);

My handler catches these events and, no matter which phase I use for ExceptionQueuedEventContext, I get following stacktrace:

java.lang.NullPointerException
at com.ocpsoft.pretty.PrettyContext.getCurrentInstance(PrettyContext.java:68)
at com.ocpsoft.pretty.faces.application.PrettyRedirector.redirect(PrettyRedirector.java:51)
at com.ocpsoft.pretty.faces.application.PrettyNavigationHandler.handleNavigation(PrettyNavigationHandler.java:49)
at com.mycompany.web.faces.CustomErrorExceptionHandler.handle(CustomErrorExceptionHandler.java:44)
at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:119)
at com.sun.faces.lifecycle.RestoreViewPhase.doPhase(RestoreViewPhase.java:110)
at com.sun.faces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:312)
at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1523)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:343)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:113)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.ApplicationDispatcher.doInvoke(ApplicationDispatcher.java:820)
at org.apache.catalina.core.ApplicationDispatcher.invoke(ApplicationDispatcher.java:684)
at org.apache.catalina.core.ApplicationDispatcher.processRequest(ApplicationDispatcher.java:517)
at org.apache.catalina.core.ApplicationDispatcher.doDispatch(ApplicationDispatcher.java:488)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:379)
at org.apache.catalina.core.ApplicationDispatcher.dispatch(ApplicationDispatcher.java:336)
at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:314)
at com.ocpsoft.pretty.PrettyFilter.doFilter(PrettyFilter.java:87)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at com.mycompany.web.multipart.MultipartFilter.doFilter(MultipartFilter.java:73)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:215)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:277)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:188)
at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:641)
at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:97)
at com.sun.enterprise.web.PESessionLockingStandardPipeline.invoke(PESessionLockingStandardPipeline.java:85)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:185)
at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:325)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:226)
at org.apache.jk.server.JkCoyoteHandler.invoke(JkCoyoteHandler.java:229)
at org.apache.jk.common.HandlerRequest.invoke(HandlerRequest.java:334)
at org.apache.jk.common.ChannelSocket.invoke(ChannelSocket.java:814)
at org.apache.jk.common.ChannelSocket.processConnection(ChannelSocket.java:743)
at org.apache.jk.common.ChannelSocket$SocketConnection.runIt(ChannelSocket.java:936)
at org.apache.tomcat.util.threads.ThreadPool$ControlRunnable.run(ThreadPool.java:682)
at java.lang.Thread.run(Thread.java:619)