从Facelets错误页面引用CDI托管bean

时间:2013-08-30 22:14:11

标签: jsf-2 error-handling weblogic cdi facelets

我很难在一个使用JSF 2,Facelets和CDI的(非常简单的)WAR项目中尝试使用通用错误页面。

我的应用程序服务器是WebLogic 12c,它应支持所有这些开箱即用的功能,但无法显示错误页面。当我将完全相同的WAR部署到Glassfish应用程序服务器时,它可以工作。

我倾向于将WebLogic归咎于CDI部门的错误,但可以使用一些额外的专业知识来判断我的方法是否错误。

以下是我的应用程序试图证明的内容:

可以在执行重定向后从错误页面引用已存在的CDI托管bean

该项目拥有一个@SessionScoped托管bean,用于生成 welcome 页面和错误页面上显示的内容。

欢迎页面显示由@SessionScoped bean生成的内容,并使用@RequestScoped bean只抛出(Runtime)?Exception(它会启动重定向到错误页面)。 / p>

这是我的相关代码:


  • 网络/ WEB-INF / beans.xml中

    <?xml version="1.0" encoding="UTF-8"?>
    <beans xmlns="http://java.sun.com/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/beans_1_0.xsd">
    </beans>
    
  • 网络/ WEB-INF / web.xml中

    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="3.0" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd">
        <context-param>
            <param-name>javax.faces.PROJECT_STAGE</param-name>
            <param-value>Development</param-value>
        </context-param>
        <servlet>
            <servlet-name>Faces Servlet</servlet-name>
            <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
            <load-on-startup>1</load-on-startup>
        </servlet>
        <servlet-mapping>
            <servlet-name>Faces Servlet</servlet-name>
            <url-pattern>/faces/*</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>30</session-timeout>
        </session-config>
        <welcome-file-list>
            <welcome-file>faces/index.xhtml</welcome-file>
        </welcome-file-list>
        <error-page>
            <exception-type>java.lang.Throwable</exception-type>
            <location>/faces/error.xhtml?faces-redirect=true</location>
        </error-page>
        <error-page>
            <error-code>500</error-code>
            <location>/faces/error.xhtml?faces-redirect=true</location>
        </error-page>
    </web-app>
    
  • 网络/ error.xhtml

    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html">
        <h:head>
            <title>Error page</title>
        </h:head>
        <h:body>
            <h1>You are now on the error page</h1>
    
            <h3>Current milliseconds: #{sessionScopedBean.milliseconds}</h3>
        </h:body>
    </html>
    
  • 网络/的index.xhtml

    <?xml version='1.0' encoding='UTF-8' ?>
    <!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
    <html xmlns="http://www.w3.org/1999/xhtml"
          xmlns:h="http://java.sun.com/jsf/html">
        <h:head>
            <title>Generate exception</title>
        </h:head>
        <h:body>
            <h1>Please generate an exception of some sorts</h1>
    
            <h1>Current milliseconds: #{sessionScopedBean.milliseconds}</h1>
    
            <h:form>
                <h:commandButton action="#{exceptionGeneratingBean.generateException()}" value="Exception" />
                <h:commandButton action="#{exceptionGeneratingBean.generateRuntimeException()}" value="RuntimeException" />
            </h:form>
        </h:body>
    </html>
    
  • 的src /爪哇/ NL / rensvanleeuwen /豆腐/ ExceptionGeneratingBean.java

    package nl.rensvanleeuwen.bean;
    
    import javax.enterprise.context.RequestScoped;
    import javax.inject.Named;
    
    @RequestScoped
    @Named
    public class ExceptionGeneratingBean {
    
        public void generateRuntimeExcetion() {
            throw new RuntimeException("Here is the exception!");
        }
    
        public void generateException() throws Exception {
            throw new Exception("Here is the exception!");
        }
    }
    
  • 的src /爪哇/ NL / rensvanleeuwen /豆腐/ SessionScopedBean.java

    package nl.rensvanleeuwen.bean;
    
    import java.io.Serializable;
    import javax.enterprise.context.SessionScoped;
    import javax.inject.Named;
    
    @Named
    @SessionScoped
    public class SessionScopedBean implements Serializable {
    
        public long getMilliseconds() {
            return System.currentTimeMillis();
        }
    }
    

当我将其部署到Glassfish 3.1.2时,按下其中一个按钮时会得到以下输出:


您现在位于错误页面

当前毫秒数:1377897262568


另一方面,在WebLogic上,它会爆炸,并显示以下堆栈跟踪:

####<Aug 30, 2013 11:24:26 PM CEST> <Error> <HTTP> <rens7> <131Server> <[ACTIVE] ExecuteThread: '0' for queue: 'weblogic.kernel.Default (self-tuning)'> <<WLS Kernel>> <> <> <1377897866330> <BEA-101107> <[ServletContext@2045981067[app:_appsdir_ErrorPageTest_war module:ErrorPageTest.war path:null spec-version:3.0]] Problem occurred while serving the error page.
javax.servlet.ServletException: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:606)
  at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
  at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
  at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
  at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:338)
  at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:221)
  at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:564)
  at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:263)
  at weblogic.servlet.internal.ForwardAction.run(ForwardAction.java:22)
  at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
  at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
  at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
  at weblogic.servlet.internal.ErrorManager.handleException(ErrorManager.java:144)
  at weblogic.servlet.internal.WebAppServletContext.handleThrowableFromInvocation(WebAppServletContext.java:2239)
  at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2089)
  at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1514)
  at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
  at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
  at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
Caused By: org.jboss.weld.context.ContextNotActiveException: WELD-001303 No active contexts for scope type javax.enterprise.context.SessionScoped
  at org.jboss.weld.manager.BeanManagerImpl.getContext(BeanManagerImpl.java:612)
  at org.jboss.weld.bean.proxy.ContextBeanInstance.getInstance(ContextBeanInstance.java:71)
  at org.jboss.weld.bean.proxy.ProxyMethodHandler.invoke(ProxyMethodHandler.java:79)
  at nl.rensvanleeuwen.bean.SessionScopedBean$Proxy$_$$_WeldClientProxy.getMilliseconds(SessionScopedBean$Proxy$_$$_WeldClientProxy.java)
  at sun.reflect.GeneratedMethodAccessor58.invoke(Unknown Source)
  at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43)
  at java.lang.reflect.Method.invoke(Method.java:601)
  at javax.el.BeanELResolver.getValue(BeanELResolver.java:305)
  at com.sun.faces.el.DemuxCompositeELResolver._getValue(DemuxCompositeELResolver.java:176)
  at com.sun.faces.el.DemuxCompositeELResolver.getValue(DemuxCompositeELResolver.java:203)
  at com.sun.el.parser.AstValue.getValue(AstValue.java:138)
  at com.sun.el.parser.AstValue.getValue(AstValue.java:184)
  at com.sun.el.ValueExpressionImpl.getValue(ValueExpressionImpl.java:224)
  at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
  at org.jboss.weld.el.WeldValueExpression.getValue(WeldValueExpression.java:50)
  at com.sun.faces.facelets.el.ELText$ELTextVariable.writeText(ELText.java:227)
  at com.sun.faces.facelets.el.ELText$ELTextComposite.writeText(ELText.java:150)
  at com.sun.faces.facelets.compiler.TextInstruction.write(TextInstruction.java:85)
  at com.sun.faces.facelets.compiler.UIInstructions.encodeBegin(UIInstructions.java:82)
  at com.sun.faces.facelets.compiler.UILeaf.encodeAll(UILeaf.java:183)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
  at javax.faces.component.UIComponent.encodeAll(UIComponent.java:1760)
  at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:402)
  at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:131)
  at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:288)
  at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:121)
  at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101)
  at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:139)
  at javax.faces.webapp.FacesServlet.service(FacesServlet.java:594)
  at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:242)
  at weblogic.servlet.internal.StubSecurityHelper$ServletServiceAction.run(StubSecurityHelper.java:216)
  at weblogic.servlet.internal.StubSecurityHelper.invokeServlet(StubSecurityHelper.java:132)
  at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:338)
  at weblogic.servlet.internal.ServletStubImpl.execute(ServletStubImpl.java:221)
  at weblogic.servlet.internal.RequestDispatcherImpl.invokeServlet(RequestDispatcherImpl.java:564)
  at weblogic.servlet.internal.RequestDispatcherImpl.forward(RequestDispatcherImpl.java:263)
  at weblogic.servlet.internal.ForwardAction.run(ForwardAction.java:22)
  at weblogic.security.acl.internal.AuthenticatedSubject.doAs(AuthenticatedSubject.java:321)
  at weblogic.security.service.SecurityManager.runAs(SecurityManager.java:120)
  at weblogic.servlet.provider.WlsSubjectHandle.run(WlsSubjectHandle.java:57)
  at weblogic.servlet.internal.ErrorManager.handleException(ErrorManager.java:144)
  at weblogic.servlet.internal.WebAppServletContext.handleThrowableFromInvocation(WebAppServletContext.java:2239)
  at weblogic.servlet.internal.WebAppServletContext.execute(WebAppServletContext.java:2089)
  at weblogic.servlet.internal.ServletRequestImpl.run(ServletRequestImpl.java:1514)
  at weblogic.servlet.provider.ContainerSupportProviderImpl$WlsRequestExecutor.run(ContainerSupportProviderImpl.java:254)
  at weblogic.work.ExecuteThread.execute(ExecuteThread.java:256)
  at weblogic.work.ExecuteThread.run(ExecuteThread.java:221)
>

我无法使这个构造工作。有没有人指出我可能忽略的东西?

1 个答案:

答案 0 :(得分:1)

球现在在甲骨文的法庭上。针对WebLogic 12.1.1.0报告了错误17410908。