Wildfly 8.2.0:不抛出ViewExpiredException

时间:2015-03-15 17:48:53

标签: jsf primefaces wildfly-8 viewexpiredexception

Wildfly 8.2.0 上运行的我的JSF应用程序(Primefaces 5)在我的页面在security-constraint 下时无法捕获viewExpiredException。似乎服务器在会话超时后不会抛出javax.faces.application.ViewExpiredException。

我的web.xml:

<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
     xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
     xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
     version="3.1">
<context-param>
    <param-name>javax.faces.PROJECT_STAGE</param-name>
    <param-value>Development</param-value>
</context-param>

<context-param>
    <param-name>javax.faces.STATE_SAVING_METHOD</param-name>
    <param-value>server</param-value>
</context-param>

<!-- JSF Servlet is defined to container -->
<servlet>
    <servlet-name>Faces Servlet</servlet-name>
    <servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
    <load-on-startup>1</load-on-startup>
</servlet>
<!-- Mapping with servlet and url for the http requests. -->
<servlet-mapping>
    <servlet-name>Faces Servlet</servlet-name>
    <url-pattern>*.xhtml</url-pattern>
</servlet-mapping>

<error-page>
    <exception-type>javax.faces.application.ViewExpiredException</exception-type>
    <location>/WEB-INF/errorpages/viewExpired.xhtml</location>
</error-page>
<session-config>
    <session-timeout>
        1 //For testing purpose
    </session-timeout>
</session-config>
<welcome-file-list>
    <welcome-file>secure/index.xhtml</welcome-file>
</welcome-file-list>
<!--Security Constraints-->
<login-config>
    <auth-method>FORM</auth-method>

    <realm-name>BusinessLabRealm</realm-name>
    <form-login-config>
        <form-login-page>/login.xhtml</form-login-page>
        <form-error-page>/loginError.xhtml</form-error-page>
    </form-login-config>
</login-config>
<security-constraint>
    <display-name>secured Modules</display-name>
    <web-resource-collection>
        <web-resource-name>protected</web-resource-name>
        <url-pattern>/secure/*</url-pattern>
        <http-method>PUT</http-method>
        <http-method>DELETE</http-method>
        <http-method>GET</http-method>
        <http-method>POST</http-method>
    </web-resource-collection>
    <auth-constraint>
        <role-name>ADMIN</role-name>
        <role-name>EMPLOYEE</role-name>
        <role-name>MANAGER</role-name>
    </auth-constraint>
</security-constraint>

我的CustomExceptionHandler:

public class CustomExceptionHandler extends ExceptionHandlerWrapper{
@Override
public void handle() throws FacesException {
    final Iterator<ExceptionQueuedEvent> i = getUnhandledExceptionQueuedEvents().iterator();
    while (i.hasNext()) {
        ExceptionQueuedEvent event = i.next();
        ExceptionQueuedEventContext context = (ExceptionQueuedEventContext) event.getSource();
        Throwable t = context.getException();

        FacesContext fc = FacesContext.getCurrentInstance();
        HttpServletRequest request = (HttpServletRequest) fc.getExternalContext().getRequest();
        String message;
        String errorPageLocation = "/WEB-INF/errorpages/error.xhtml";
        try {

            //Examine the root cause
            Throwable causingEx = ExceptionUtils.getRootCause(t);
            if (causingEx == null) {
                causingEx = t;
            }
//The server doesn't throw ViewExpiredException so I cannot redirect to my error page
            if (causingEx instanceof ViewExpiredException) {
                message = createErrorCode(VIEW_EXPIRED);
                errorPageLocation = "/WEB-INF/errorpages/viewExpired.xhtml";
            } else if (causingEx instanceof FileNotFoundException) {
                message = createErrorCode(FILE_NOT_FOUND);
                errorPageLocation = "/WEB-INF/errorpages/fileNotFound.xhtml";
            } else if (causingEx instanceof ContextedRuntimeException) {
                ContextedRuntimeException bue = (ContextedRuntimeException) causingEx;
                message = bue.getMessage();
                errorPageLocation = "/WEB-INF/errorpages/process.xhtml";
            } else if (causingEx instanceof EJBAccessException) {
                message = createErrorCode(EJB_ACCESS);
                errorPageLocation = "/WEB-INF/errorpages/process.xhtml";
            } else {
                message = createErrorCode(UNEXPECTED_EXCEPTION);
                logger.error(message, t);
            }

            request.setAttribute(ERROR_MESSAGE, message);
            request.setAttribute(ERROR_REQUEST_URI, request.getRequestURI());


            renderErrorPageView(fc, request, errorPageLocation);

        } catch (IOException e) {
            throw new FacesException(e);
        } finally {
            i.remove();
        }
    }

    //parent handle
    getWrapped().handle();
}}

它是野萤虫吗?在glassfish下,我对上面的代码和配置没有任何问题!

感谢您的帮助

0 个答案:

没有答案