I need some help in using a OmniFaces Feature.
I am trying to use the FacesExceptionFilter to redirect the user to an error page when an exception is encountered.
I have the following web.xml config
<?xml version="1.0" encoding="UTF-8"?>
<display-name>xxxxx</display-name>
<session-config>
<session-timeout>1</session-timeout>
</session-config>
<welcome-file-list>
<welcome-file>pages/secured/main.xhtml</welcome-file>
</welcome-file-list>
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<context-param>
<param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name>
<param-value>resources.application</param-value>
</context-param>
<context-param>
<param-name>javax.faces.STATE_SAVING_METHOD</param-name>
<param-value>client</param-value>
</context-param>
<context-param>
<param-name>contextConfigLocation</param-name>
<param-value>/WEB-INF/spring-application-context.xml</param-value>
</context-param>
<context-param>
<param-name>facelets.DEVELOPMENT</param-name>
<param-value>true</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>2</param-value>
</context-param>
<context-param>
<param-name>primefaces.THEME</param-name>
<param-value>mytheme</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/springsecurity.taglib.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.SEPARATOR_CHAR</param-name>
<param-value>_</param-value>
</context-param>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<listener>
<listener-class>com.bdo.corpsoa.utilities.security.listeners.impl.CorpSoaSessionListener</listener-class>
</listener>
<filter>
<filter-name>facesExceptionFilter</filter-name>
<filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>facesExceptionFilter</filter-name>
<servlet-name>facesServlet</servlet-name>
</filter-mapping>
<context-param>
<param-name>org.omnifaces.FACES_VIEWS_SCAN_PATH</param-name>
<param-value>/*.xhtml</param-value>
</context-param>
<context-param>
<param-name>org.omnifaces.FACES_VIEWS_PATH_ACTION</param-name>
<param-value>REDIRECT_TO_SCANNED_EXTENSIONLESS</param-value>
</context-param>
<!-- <filter> <filter-name>springSecurityFilterChain</filter-name> <filter-class>org.springframework.web.filter.DelegatingFilterProxy</filter-class>
</filter> <filter-mapping> <filter-name>springSecurityFilterChain</filter-name>
<url-pattern>/*</url-pattern> <dispatcher>REQUEST</dispatcher> <dispatcher>FORWARD</dispatcher>
</filter-mapping> -->
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/WEB-INF/pages/errors/viewExpired.xhtml</location>
</error-page>
<error-page>
<exception-type>java.lang.RuntimeException</exception-type>
<location>/WEB-INF/pages/errors/unHandled.xhtml</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/pages/errors/pageNotFound.xhtml</location>
</error-page>
<error-page>
<exception-type>java.io.FileNotFoundException</exception-type>
<location>/WEB-INF/pages/errors/pageNotFound.xhtml</location>
</error-page>
However when an exception happens the user is just redirected to the default 500 error page.
The redirection will only work if I move error pages out of the WEB-INF folder /WEB-INF/pages/errors/pageNotFound.xhtml --> /pages/errors/pageNotFound.xhtml
But this would mean that the error page can now be accessed directly. But in the Omnifaces showcase this should be possible. I don't know what I am missing please help...
Here is the web.xml of the Omnifaces showcase that shows that error pages in the WEB-INF is possible.
<?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" metadata-complete="false"
<display-name>OmniFaces Showcase</display-name>
<!-- Standard JSF settings. -->
<context-param>
<param-name>javax.faces.FACELETS_BUFFER_SIZE</param-name>
<param-value>65535</param-value> <!-- 64KB. -->
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_REFRESH_PERIOD</param-name>
<param-value>0</param-value> <!-- Should be -1 for production. -->
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_LIBRARIES</param-name>
<param-value>/WEB-INF/showcase.taglib.xml</param-value>
</context-param>
<context-param>
<param-name>javax.faces.FACELETS_SKIP_COMMENTS</param-name>
<param-value>true</param-value>
</context-param>
<!-- Mojarra/RI specific settings. -->
<context-param>
<param-name>com.sun.faces.defaultResourceMaxAge</param-name>
<param-value>3628800000</param-value> <!-- 6 weeks. -->
</context-param>
<!-- MyFaces specific settings. -->
<context-param>
<param-name>org.apache.myfaces.RESOURCE_MAX_TIME_EXPIRES</param-name>
<param-value>3628800000</param-value> <!-- 6 weeks. -->
</context-param>
<context-param>
<!--
MyFaces and Mojarra don't agree on the default setting for actually serializing state
in the session as opposed to just storing a reference. Mojarra's default is false, but
can be switched to true. MyFaces' default is true, and can be switched to false, which
we thus do below. See http://arjan-tijms.omnifaces.org/p/jsf-22.html#1127
-->
<param-name>org.apache.myfaces.SERIALIZE_STATE_IN_SESSION</param-name>
<param-value>false</param-value>
</context-param>
<!-- OmniFaces specific settings. -->
<context-param>
<param-name>org.omnifaces.CACHE_SETTING_SESSION_MAX_CAPACITY</param-name>
<param-value>6</param-value>
</context-param>
<context-param>
<!--
All files in the 3 paths defined below will be scanned and made available
as extensionless JSF views. Since no explicit extension is given for scanning,
these paths should contain ONLY JSF (Facelets) files.
-->
<param-name>org.omnifaces.FACES_VIEWS_SCAN_PATHS</param-name>
<param-value>/showcase,/etc,/demo</param-value>
</context-param>
<context-param>
<!--
Redirects the faces views scanned /showcase/[PAGE].xhtml to /[PAGE].
A 404 would normally be preferred (and this is thus the default), but the showcase app
already has published /showcase/[PAGE].xhtml
-->
<param-name>org.omnifaces.FACES_VIEWS_PATH_ACTION</param-name>
<param-value>REDIRECT_TO_SCANNED_EXTENSIONLESS</param-value>
</context-param>
<!-- Servlets and filters. -->
<servlet>
<servlet-name>facesServlet</servlet-name>
<servlet-class>javax.faces.webapp.FacesServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>facesServlet</servlet-name>
<url-pattern>*.xhtml</url-pattern>
</servlet-mapping>
<filter>
<filter-name>characterEncodingFilter</filter-name>
<filter-class>org.omnifaces.filter.CharacterEncodingFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>characterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
<filter>
<filter-name>facesExceptionFilter</filter-name>
<filter-class>org.omnifaces.filter.FacesExceptionFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>facesExceptionFilter</filter-name>
<servlet-name>facesServlet</servlet-name>
</filter-mapping>
<filter>
<filter-name>gzipResponseFilter</filter-name>
<filter-class>org.omnifaces.filter.GzipResponseFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>gzipResponseFilter</filter-name>
<url-pattern>/*</url-pattern>
<dispatcher>REQUEST</dispatcher>
<dispatcher>ERROR</dispatcher>
</filter-mapping>
<!-- Welcome files, error pages and mime types. -->
<session-config>
<cookie-config>
<http-only>true</http-only>
</cookie-config>
<tracking-mode>COOKIE</tracking-mode>
</session-config>
<welcome-file-list>
<!--
Note that an extension is used here, since the index file resides within the
root which has not been configured for FacesViews scanning.
-->
<welcome-file>index.xhtml</welcome-file>
</welcome-file-list>
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/WEB-INF/errorpages/expired.xhtml</location>
</error-page>
<error-page>
<exception-type>java.sql.SQLException</exception-type>
<location>/WEB-INF/errorpages/database.xhtml</location>
</error-page>
<error-page>
<exception-type>java.lang.RuntimeException</exception-type>
<location>/WEB-INF/errorpages/bug.xhtml</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/errorpages/500.xhtml</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/WEB-INF/errorpages/404.xhtml</location>
</error-page>
<mime-mapping>
<!--
Silence WebLogic's annoying "JSF1091: No mime type could be found for file" warning.
-->
<extension>xhtml</extension>
<mime-type>text/html</mime-type>
</mime-mapping>
Summary
- Redirect to error pages work if outside the WEB-INF.
- Showcase shows that it should be possible.
- I need help....
Thank you for your time
EDIT
It seems that "Redirect to error pages work if outside the WEB-INF." is not always true.
This error page will be displayed if outside of WEB-INF
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<h1>#{"XXXXXXXX"}</h1>
</h:body>
</html>
This error page will not be displayed even if outside of WEB-INF. This Will result in the default 404 Page
<?xml version="1.0" encoding="ISO-8859-1" ?>
<!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:ui="http://java.sun.com/jsf/facelets"
xmlns:h="http://java.sun.com/jsf/html"
xmlns:f="http://java.sun.com/jsf/core"
xmlns:p="http://primefaces.org/ui">
<h:body>
<h1>ZZZZZZZZZ</h1>
</h:body>
</html>
FacesExceptionFilter
solve 2 problems. i want to understand if you want to navigate for all exceptions not only those two specific ones. – erencan