Processed pages simply remain blank halfway on errors / exceptions, and are not sent to the error page specified in web.xml

In web.xml, I have the following configurations for the global error page.

<error-page> <error-code>401</error-code> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> <error-page> <error-code>403</error-code> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> <error-page> <error-code>404</error-code> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> <error-page> <error-code>500</error-code> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> <error-page> <error-code>503</error-code> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> 

If any exception occurs (this leads to an error of 500 internal servers), it is expected that the request will be sent to the specified error page, but when the exception occurs, the processed page is simply left halfway. It does not forward the error page.

Configuring java.lang.Throwable or java.lang.Exception as follows:

 <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> 

also did not help anymore.


Full contents of web.xml:

 <?xml version="1.0" encoding="UTF-8"?> <web-app version="3.1" 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"> <context-param> <param-name>javax.faces.FACELETS_LIBRARIES</param-name> <param-value>/WEB-INF/my.taglib.xml</param-value> </context-param> <context-param> <param-name>javax.faces.DATETIMECONVERTER_DEFAULT_TIMEZONE_IS_SYSTEM_TIMEZONE</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>javax.faces.PROJECT_STAGE</param-name> <param-value>Production</param-value> </context-param> <context-param> <param-name>com.sun.faces.enableViewStateIdRendering</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>com.sun.faces.enableRestoreView11Compatibility</param-name> <param-value>true</param-value> </context-param> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>server</param-value> </context-param> <context-param> <param-name>log4jConfigLocation</param-name> <param-value>/WEB-INF/log4j.properties</param-value> </context-param> <context-param> <param-name>log4jExposeWebAppRoot</param-name> <param-value>false</param-value> </context-param> <filter> <filter-name>PrimeFaces FileUpload Filter</filter-name> <filter-class>org.primefaces.webapp.filter.FileUploadFilter</filter-class> </filter> <filter-mapping> <filter-name>PrimeFaces FileUpload Filter</filter-name> <servlet-name>Faces Servlet</servlet-name> </filter-mapping> <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>*.xhtml</url-pattern> </servlet-mapping> <error-page> <error-code>401</error-code> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> <error-page> <error-code>403</error-code> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> <error-page> <error-code>404</error-code> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> <error-page> <error-code>500</error-code> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> <error-page> <error-code>503</error-code> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> <error-page> <exception-type>java.lang.Throwable</exception-type> <location>/WEB-INF/error_pages/GeneralError.xhtml</location> </error-page> <security-constraint> <display-name>AdminConstraint</display-name> <web-resource-collection> <web-resource-name>ROLE_ADMIN</web-resource-name> <description/> <url-pattern>/admin_side/*</url-pattern> </web-resource-collection> <auth-constraint> <description/> <role-name>ROLE_ADMIN</role-name> </auth-constraint> <user-data-constraint> <description/> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint> <security-constraint> <display-name>UserConstraint</display-name> <web-resource-collection> <web-resource-name>ROLE_USER</web-resource-name> <description/> <url-pattern>/user_side/*</url-pattern> </web-resource-collection> <auth-constraint> <description/> <role-name>ROLE_USER</role-name> </auth-constraint> <user-data-constraint> <description/> <transport-guarantee>CONFIDENTIAL</transport-guarantee> </user-data-constraint> </security-constraint> <login-config> <auth-method>FORM</auth-method> <realm-name>projectRealm</realm-name> <form-login-config> <form-login-page>/utility/Login.xhtml</form-login-page> <form-error-page>/utility/ErrorPage.xhtml</form-error-page> </form-login-config> </login-config> <security-role> <description/> <role-name>ROLE_ADMIN</role-name> </security-role> <security-role> <description/> <role-name>ROLE_USER</role-name> </security-role> <!--error-page> <exception-type>javax.faces.application.ViewExpiredException</exception-type> <location>/utility/Login.xhtml</location> </error-page--> <session-config> <session-timeout> 120 </session-timeout> <tracking-mode>COOKIE</tracking-mode> </session-config> <welcome-file-list> <welcome-file>utility/Login.xhtml</welcome-file> </welcome-file-list> </web-app> 

Also tried to use an empty project with a single XHTML page and nothing more than an error page configuration in web.xml. Pages simply remain blank halfway, and are not sent to the page with an error when an exception occurs (only 404 works among other HTTP statuses).

How to send errors to the specified page when any exceptions / errors occur?


Update 1:

In accordance with this question / answer, I added the javax.faces.FACELETS_BUFFER_SIZE context javax.faces.FACELETS_BUFFER_SIZE to web.xml to have a buffer size of 64K, but nothing new happened. It still does not forward the error page if an exception occurs. Pages are only partially processed and remain blank halfway if an error / error occurs. The stacktrace exception is detected only on the server terminal, and not on the web page (in case of an internal server 500 error). I intentionally force the application to throw an exception to see if it goes to the error page.


Update 2:

After setting the size of the buffer, as indicated in Editor 1, I received the following exception at a certain time (when the request was redirected to a protected area after a successful login). So, I removed this option for now.

 Severe: Error Rendering View[/utility/Login.xhtml] java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.setBufferSize(ResponseFacade.java:285) at com.sun.faces.context.ExternalContextImpl.setResponseBufferSize(ExternalContextImpl.java:923) at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1162) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:403) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:72) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at filter.LoginNocacheFilter.doFilter(LoginNocacheFilter.java:39) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545) at java.lang.Thread.run(Thread.java:745) Info: Exception when handling error trying to reset the response. java.lang.IllegalStateException at org.apache.catalina.connector.ResponseFacade.setBufferSize(ResponseFacade.java:285) at com.sun.faces.context.ExternalContextImpl.setResponseBufferSize(ExternalContextImpl.java:923) at com.sun.faces.application.view.FaceletViewHandlingStrategy.createResponseWriter(FaceletViewHandlingStrategy.java:1162) at com.sun.faces.application.view.FaceletViewHandlingStrategy.renderView(FaceletViewHandlingStrategy.java:403) at com.sun.faces.application.view.MultiViewHandler.renderView(MultiViewHandler.java:133) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) at javax.faces.application.ViewHandlerWrapper.renderView(ViewHandlerWrapper.java:337) at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:120) at com.sun.faces.lifecycle.Phase.doPhase(Phase.java:101) at com.sun.faces.lifecycle.LifecycleImpl.render(LifecycleImpl.java:219) at javax.faces.webapp.FacesServlet.service(FacesServlet.java:647) at org.apache.catalina.core.StandardWrapper.service(StandardWrapper.java:1682) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:344) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.primefaces.webapp.filter.FileUploadFilter.doFilter(FileUploadFilter.java:72) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at filter.LoginNocacheFilter.doFilter(LoginNocacheFilter.java:39) at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:256) at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:214) at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:316) at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:160) at org.apache.catalina.core.StandardPipeline.doInvoke(StandardPipeline.java:734) at org.apache.catalina.core.StandardPipeline.invoke(StandardPipeline.java:673) at com.sun.enterprise.web.WebPipeline.invoke(WebPipeline.java:99) at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:174) at org.apache.catalina.connector.CoyoteAdapter.doService(CoyoteAdapter.java:415) at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:282) at com.sun.enterprise.v3.services.impl.ContainerMapper$HttpHandlerCallable.call(ContainerMapper.java:459) at com.sun.enterprise.v3.services.impl.ContainerMapper.service(ContainerMapper.java:167) at org.glassfish.grizzly.http.server.HttpHandler.runService(HttpHandler.java:201) at org.glassfish.grizzly.http.server.HttpHandler.doHandle(HttpHandler.java:175) at org.glassfish.grizzly.http.server.HttpServerFilter.handleRead(HttpServerFilter.java:235) at org.glassfish.grizzly.filterchain.ExecutorResolver$9.execute(ExecutorResolver.java:119) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeFilter(DefaultFilterChain.java:284) at org.glassfish.grizzly.filterchain.DefaultFilterChain.executeChainPart(DefaultFilterChain.java:201) at org.glassfish.grizzly.filterchain.DefaultFilterChain.execute(DefaultFilterChain.java:133) at org.glassfish.grizzly.filterchain.DefaultFilterChain.process(DefaultFilterChain.java:112) at org.glassfish.grizzly.ProcessorExecutor.execute(ProcessorExecutor.java:77) at org.glassfish.grizzly.nio.transport.TCPNIOTransport.fireIOEvent(TCPNIOTransport.java:561) at org.glassfish.grizzly.strategies.AbstractIOStrategy.fireIOEvent(AbstractIOStrategy.java:112) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.run0(WorkerThreadIOStrategy.java:117) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy.access$100(WorkerThreadIOStrategy.java:56) at org.glassfish.grizzly.strategies.WorkerThreadIOStrategy$WorkerThreadRunnable.run(WorkerThreadIOStrategy.java:137) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.doWork(AbstractThreadPool.java:565) at org.glassfish.grizzly.threadpool.AbstractThreadPool$Worker.run(AbstractThreadPool.java:545) at java.lang.Thread.run(Thread.java:745) 

Update 3:

I tried to increase the buffer size ( 100002400 , which is too much) until a java.lang.OutOfMemoryError: Java heap space error is java.lang.OutOfMemoryError: Java heap space . Therefore, the size of the output buffer should not be a problem.

In Ajaxical things, error pages, by the way, display correctly when errors occur during asynchronous requests using OmniFaces - org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory configured in faces-config.xml .

Perhaps it would be possible to see the cause of the problem if I set up the error pages at the beginning - when I started the application, and the application therefore did not have the special additional costs that many XHTML pages currently have, CDI managed beans, EJB session beans, etc., But in any case, I overloaded it.


Update 4:

Now I am launching the same application in the final of WildFly 9.0.2. The problem remains unchanged.

+7
java-ee servlets jsf glassfish
source share
1 answer

Check by increasing the size of your GeneralError.xhtml error page. Sometimes the server does not display the error page if it is smaller in size. those. try adding more than 50-100 lines of text to GeneralError.xhtml and check)

-one
source share

All Articles