JSF 全局异常处理程序允许异常冒泡



我的JSF 2.0 Web项目中有一个扩展ExceptionHandlerWrapper的异常处理程序。我遇到的问题是,在调用 handle() 方法之前,异常出现在服务器日志中。

知道为什么会发生这种情况,以及如何解决这个问题吗?

我正在使用jBoss 7.1.2。异常处理程序 handle() 方法如下所示:

  @Override
    public void handle() {
        if (getUnhandledExceptionQueuedEvents() == null || !getUnhandledExceptionQueuedEvents().iterator().hasNext()) {         
            getWrapped().handle();
            return;
        }
        FacesContext fc = FacesContext.getCurrentInstance();
        ExternalContext externalContext = fc.getExternalContext();
        Outcome outcome = Outcome.GENERAL_ERROR;
        for (Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator(); i.hasNext();) {
            ExceptionQueuedEvent event = i.next();
            ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
            Throwable throwable = context.getException();
            logger.warn("Intercepting exception before it bubbles to the UI", throwable);
            outcome = determineOutcome(throwable);
            populateMessageForOutcome(outcome);
            i.remove();
        }
        try {
            logger.warn("GeneralUiExceptionHandler is redirecting to " + outcome.value() + " as a result of an exception");
            externalContext.redirect(outcome.value());
        } catch (IOException e) {
            logger.error("Error while handling exceptions", e);
        }
  //        fc.renderResponse();
  //        getWrapped().handle();
    }

服务器日志中的异常示例

10:00:52,422 SEVERE [javax.enterprise.resource.webcontainer.jsf.application] (http-localhost/127.0.0.1:8080-6) Error Rendering View[/disbursement.xhtml]: javax.faces.FacesException: javax.el.ELException: /disbursement.xhtml @23,97 value="#{disbursementBean.cashValueDisbursement.effectiveDate}": java.lang.ArrayIndexOutOfBoundsException: 3
    at javax.faces.component.UIComponentBase$AttributesMap.get(UIComponentBase.java:2364) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at com.sun.faces.el.CompositeComponentAttributesELResolver$ExpressionEvalMap.get(CompositeComponentAttributesELResolver.java:345) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.el.MapELResolver.getValue(MapELResolver.java:196) [jboss-el-api_2.2_spec-1.0.1.Final.jar:1.0.1.Final]
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at org.apache.el.parser.AstValue.getValue(AstValue.java:169) [jbossweb-7.0.16.Final.jar:]
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189) [jbossweb-7.0.16.Final.jar:]
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at com.sun.faces.facelets.el.ContextualCompositeValueExpression.getValue(ContextualCompositeValueExpression.java:156) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:194) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at javax.faces.component.ComponentStateHelper.eval(ComponentStateHelper.java:182) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at javax.faces.component.UIOutput.getValue(UIOutput.java:169) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at org.primefaces.util.ComponentUtils.getValueToRender(ComponentUtils.java:63) [primefaces-3.4.jar:]
    at org.primefaces.component.inputmask.InputMaskRenderer.encodeMarkup(InputMaskRenderer.java:94) [primefaces-3.4.jar:]
    at org.primefaces.component.inputmask.InputMaskRenderer.encodeEnd(InputMaskRenderer.java:52) [primefaces-3.4.jar:]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.renderkit.html_basic.GroupRenderer.encodeChildren(GroupRenderer.java:105) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at com.sun.faces.renderkit.html_basic.CompositeRenderer.encodeChildren(CompositeRenderer.java:78) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:304) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:55) [primefaces-3.4.jar:]
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43) [primefaces-3.4.jar:]
    at org.primefaces.component.fieldset.FieldsetRenderer.encodeContent(FieldsetRenderer.java:89) [primefaces-3.4.jar:]
    at org.primefaces.component.fieldset.FieldsetRenderer.encodeMarkup(FieldsetRenderer.java:71) [primefaces-3.4.jar:]
    at org.primefaces.component.fieldset.FieldsetRenderer.encodeEnd(FieldsetRenderer.java:45) [primefaces-3.4.jar:]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at com.sun.faces.renderkit.html_basic.HtmlBasicRenderer.encodeRecursive(HtmlBasicRenderer.java:312) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.renderkit.html_basic.GridRenderer.renderRow(GridRenderer.java:185) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.renderkit.html_basic.GridRenderer.encodeChildren(GridRenderer.java:129) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at org.primefaces.renderkit.CoreRenderer.renderChild(CoreRenderer.java:55) [primefaces-3.4.jar:]
    at org.primefaces.renderkit.CoreRenderer.renderChildren(CoreRenderer.java:43) [primefaces-3.4.jar:]
    at org.primefaces.component.panel.PanelRenderer.encodeContent(PanelRenderer.java:198) [primefaces-3.4.jar:]
    at org.primefaces.component.panel.PanelRenderer.encodeMarkup(PanelRenderer.java:115) [primefaces-3.4.jar:]
    at org.primefaces.component.panel.PanelRenderer.encodeEnd(PanelRenderer.java:55) [primefaces-3.4.jar:]
    at javax.faces.component.UIComponentBase.encodeEnd(UIComponentBase.java:875) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1786) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at javax.faces.render.Renderer.encodeChildren(Renderer.java:168) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at javax.faces.component.UIComponentBase.encodeChildren(UIComponentBase.java:845) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1779) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1782) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:125) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.company.dept.cdi.jsf2.impl.listener.phase.CodiLifecycleWrapper.render(CodiLifecycleWrapper.java:127) [cdi-0.1.jar:]
    at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:329) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final.jar:]
    at org.jboss.weld.servlet.ConversationPropagationFilter.doFilter(ConversationPropagationFilter.java:62) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final.jar:]
    at com.company.dept.log.filter.LoggingFilter.doFilter(LoggingFilter.java:74) [com.company.dept.logging.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final.jar:]
    at com.company.dept.security.filter.LoggedInFilter.doFilter(LoggedInFilter.java:135) [security-0.1.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:280) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:248) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:275) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:161) [jbossweb-7.0.16.Final.jar:]
    at org.jboss.as.web.security.SecurityContextAssociationValve.invoke(SecurityContextAssociationValve.java:153) [jboss-as-web-7.1.2.Final.jar:7.1.2.Final]
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:155) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:102) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:109) [jbossweb-7.0.16.Final.jar:]
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:368) [jbossweb-7.0.16.Final.jar:]
    at org.apache.coyote.http11.Http11Processor.process(Http11Processor.java:877) [jbossweb-7.0.16.Final.jar:]
    at org.apache.coyote.http11.Http11Protocol$Http11ConnectionHandler.process(Http11Protocol.java:679) [jbossweb-7.0.16.Final.jar:]
    at org.apache.tomcat.util.net.JIoEndpoint$Worker.run(JIoEndpoint.java:931) [jbossweb-7.0.16.Final.jar:]
    at java.lang.Thread.run(Thread.java:662) [rt.jar:1.6.0_37]
Caused by: javax.el.ELException: /disbursement.xhtml @23,97 value="#{disbursementBean.cashValueDisbursement.effectiveDate}": java.lang.ArrayIndexOutOfBoundsException: 3
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:114) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at javax.faces.component.UIComponentBase$AttributesMap.get(UIComponentBase.java:2362) [jboss-jsf-api_2.1_spec-2.0.2.Final.jar:2.0.2.Final]
    ... 79 more
Caused by: java.lang.ArrayIndexOutOfBoundsException: 3
    at com.company.dept.system.bean.DisbursementBean.initialPageLoad(DisbursementBean.java:129) [com.company.dept.system-beans.jar:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_37]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_37]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_37]
    at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_37]
    at org.jboss.weld.interceptor.proxy.SimpleMethodInvocation.invoke(SimpleMethodInvocation.java:32) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at org.jboss.weld.interceptor.proxy.SimpleInterceptionChain.invokeNextInterceptor(SimpleInterceptionChain.java:70) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.executeInterception(InterceptorMethodHandler.java:112) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at org.jboss.weld.interceptor.proxy.InterceptorMethodHandler.invoke(InterceptorMethodHandler.java:76) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at org.jboss.weld.bean.proxy.CombinedInterceptorAndDecoratorStackMethodHandler.invoke(CombinedInterceptorAndDecoratorStackMethodHandler.java:55) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at com.company.dept.system.bean.DisbursementBean$Proxy$_$$_WeldSubclass.lifecycle_mixin_$$_postConstruct(DisbursementBean$Proxy$_$$_WeldSubclass.java) [com.company.dept.system-beans.jar:]
    at org.jboss.weld.interceptor.util.InterceptionUtils.executePostConstruct(InterceptionUtils.java:56) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at org.jboss.weld.interceptor.util.InterceptionUtils.executePostConstruct(InterceptionUtils.java:68) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at org.jboss.weld.bean.ManagedBean$ManagedBeanInjectionTarget.postConstruct(ManagedBean.java:172) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at org.jboss.weld.bean.ManagedBean.create(ManagedBean.java:294) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at com.company.dept.cdi.core.impl.util.CodiUtils.createNewInstanceOfBean(CodiUtils.java:69) [cdi-0.1.jar:]
    at com.company.dept.cdi.jsf.impl.scope.conversation.AbstractConversationBeanEntry.createNewBeanInstance(AbstractConversationBeanEntry.java:140) [cdi-0.1.jar:]
    at com.company.dept.cdi.jsf.impl.scope.conversation.AbstractConversationBeanEntry.getBeanInstance(AbstractConversationBeanEntry.java:85) [cdi-0.1.jar:]
    at com.company.dept.cdi.core.impl.scope.conversation.AbstractGroupedConversationContext.create(AbstractGroupedConversationContext.java:101) [cdi-0.1.jar:]
    at com.company.dept.cdi.core.impl.scope.conversation.ConversationContextAdapter.get(ConversationContextAdapter.java:83) [cdi-0.1.jar:]
    at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:90) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at com.company.dept.system.bean.DisbursementBean$Proxy$_$$_WeldClientProxy.getCashValueDisbursement(DisbursementBean$Proxy$_$$_WeldClientProxy.java) [com.company.dept.system-beans.jar:]
    at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) [rt.jar:1.6.0_37]
    at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39) [rt.jar:1.6.0_37]
    at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25) [rt.jar:1.6.0_37]
    at java.lang.reflect.Method.invoke(Method.java:597) [rt.jar:1.6.0_37]
    at javax.el.BeanELResolver.getValue(BeanELResolver.java:302) [jboss-el-api_2.2_spec-1.0.1.Final.jar:1.0.1.Final]
    at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203) [jsf-impl-2.1.7-jbossorg-2.jar:]
    at org.apache.el.parser.AstValue.getValue(AstValue.java:169) [jbossweb-7.0.16.Final.jar:]
    at org.apache.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:189) [jbossweb-7.0.16.Final.jar:]
    at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50) [weld-core-1.1.8.Final.jar:2012-04-29 10:45]
    at com.sun.faces.facelets.el.TagValueExpression.getValue(TagValueExpression.java:109) [jsf-impl-2.1.7-jbossorg-2.jar:]
    ... 80 more

这不是由冒泡引起的。它只是由 JSF 实现的内部日志记录引起的。这在异常处理程序被命中之前已经记录下来,因此没有冒泡的方法。在您的特定示例中,它按FaceletViewHandlingStrategy#renderView()方法记录。

在您的特定情况下,使用 java.util.logging 的 Mojarra ,您可以通过在运行时类路径中logging.properties来调整日志记录。若要关闭特定日志,请添加以下条目:

javax.enterprise.resource.webcontainer.jsf.application.level = OFF

它将关闭javax.enterprise.resource.webcontainer.jsf.application记录器的所有日志记录,该记录器由其他FaceletViewHandlingStrategy使用。请注意,您可能会错过出于其他目的而记录的日志。 java.util.logging不允许对日志记录进行细粒度控制。

相关内容

  • 没有找到相关文章

最新更新