Gracefully handling "View State cannot be reconstructed" error - jsf

My application is on Apache MyFaces V2.0. Application Server is WebSphere V8.0. During security testing using URL like below, application is rendering the error in the browser exposing application server details. I have below entries in web.xml. Please suggest a solution to gracefully handle this scenario.
Web.xml
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/error.xhtml</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/error/error500.xhtml</location>
</error-page>
URL
localhost/app/test.xhtml?emailId=test1#abcd.com&clickSubmit=Save&javax.faces.ViewState=83eNclk%2FbIe05NjdSUOQtQqlm5FVhzOBEHXMRHzqXhuC7fG%2BpJS9xRI%2BxN9tCjZIPg2dA3%2B8Xdor%2Bj40Wjiy%2FxO3J%2Bu0lbQJFHXnGNxYwUUh102oPNugRXQAmHNJsjYDnxwh9w%3D%3D
Error:
Error Page Exception
SRVE0260E: The server cannot use the error page specified for your
application to handle the Original Exception printed below.
Original Exception:
Error Message: javax.servlet.ServletException: /app/test.xhtml No saved
view state could be found for the view identifier: /app/test.xhtml
Error Code: 500 Target Servlet: Faces Servlet Error Stack:
javax.faces.application.ViewExpiredException
org.apache.myfaces.lifecycle.RestoreViewExecutor.execute(RestoreViewExecutor.java:128)
at org.apache.myfaces.lifecycle.LifecycleImpl.executePhase(LifecycleImpl.java:171)
at org.apache.myfaces.lifecycle.LifecycleImpl.execute(LifecycleImpl.java:118)
at javax.faces.webapp.FacesServlet.service(FacesServlet.java:189)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.service(ServletWrapper.java:1224)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:774)
at com.ibm.ws.webcontainer.servlet.ServletWrapper.handleRequest(ServletWrapper.java:456)
at com.ibm.ws.webcontainer.servlet.ServletWrapperImpl.handleRequest(ServletWrapperImpl.java:178)
at com.ibm.ws.webcontainer.filter.WebAppFilterChain.invokeTarget(WebAppFilterChain.

Related

How to replicate 500 server error in hybris

I am facing the problem while bug fixing. I am trying to provide a handler page for 500 server errors. Sometimes it is throwing 500 server error and sometimes it is not. Can anyone please help to replicate the 500 server error in hybris project.
It is an internal server error. You have to check the backend logs for more information. Possible exceptions and stacktraces. It can be anything. If you want to change the 500 error page, you can find configuration about it in your *storefront extension web.xml file. Here is an example:
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/WEB-INF/views/errorPages/serverError.jsp</location>
</error-page>
<error-page>
<error-code>500</error-code>
<location>/WEB-INF/views/errorPages/serverError.jsp</location>
</error-page>
You can replicate so many ways
1)Place a null pointer expection in controller
2)Inproper close of JSP tags

how to print unhandled exception to console instead of browser in JSF

I want unhandled exceptions to be printed to console so that I can just click on exception to go to the line causing exception.
But they are printed to the browser and I couldn't find any setting for that.
I am using JSF 2.2 with myfaces implementation and tomcat as container.
You can use a special page for exceptions instead of showing exceptions. The exception trace will still be written into the log but it will not be displayed to users.
web.xml
<error-page>
<error-code>404</error-code>
<location>/errorpages/404.xhtml</location>
</error-page>
<error-page>
<exception-type>javax.ejb.EJBException</exception-type> // Your exception type
<location>/errorpages/404.xhtml</location>
</error-page>

JSF 1.2 Error handling with IceFaces 1.8

my project is on JSF 1.2 and IceFaces. It works perfectly. I thought of adding error pages, to avoid showing that ugly exceptions page.
This is what I did :
web.xml
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error.xhtml</location>
</error-page>
error.xhml
<html>
<body>
<center>
<h1> HELLO THIS IS AN ERROR</h1>
</center>
</body>
I made a link in the application that generates the exception. But when I click on it, I just get nothing, neither the Hello message, neither the classic exception stack trace message.
Should I add some code to FacesConfig or something?

PrimeFaces Custom Error pages

In my PrimeFaces project, I need to provide some general error pages for general response error status codes such as 401 and 404. Does somebody know how can I figure this out?
It's not handled by JSF, it's handled by the servlet container. You can specify them by <error-page> in web.xml.
<error-page>
<error-code>401</error-code>
<location>/errors/401.xhtml</location>
</error-page>
<error-page>
<error-code>404</error-code>
<location>/errors/404.xhtml</location>
</error-page>
If you'd like to navigate to them from inside JSF action methods, then you can use ExternalContext#responseSendError() for this.
externalContext.responseSendError(401, "You are not authorized.");

JSF Exception: /main.jsp not found in external context as a Resource

I have a User Interface built using "IceFaces". And it's deployed on a portal built using "LifeRay". The UI application is getting undeployed automatically from the portal sometimes.
And the log is showing the following error message :
javax.servlet.ServletException: java.lang.Exception: javax.faces.FacesException: Problem in renderResponse: /main.jsp Not Found in ExternalContext as a Resource
at com.icesoft.faces.webapp.http.servlet.MainServlet.service(MainServlet.java:175)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:717)
-----------------
Caused by: java.lang.Exception: javax.faces.FacesException: Problem in renderResponse: /main.jsp Not Found in ExternalContext as a Resource
at com.icesoft.faces.context.View.servePage(View.java:136)
at com.icesoft.faces.webapp.http.core.MultiViewServer.service(MultiViewServer.java:55)
------------------
Caused by: javax.faces.FacesException: Problem in renderResponse: /main.jsp Not Found in ExternalContext as a Resource
at com.icesoft.faces.facelets.D2DFaceletViewHandler.renderResponse(D2DFaceletViewHandler.java:296)
at com.icesoft.faces.application.D2DViewHandler.renderView(D2DViewHandler.java:153)
at com.sun.faces.lifecycle.RenderResponsePhase.execute(RenderResponsePhase.java:109)
Caused by: java.io.FileNotFoundException: /main.jsp Not Found in ExternalContext as a Resource
at com.sun.facelets.impl.DefaultFaceletFactory.resolveURL(DefaultFaceletFactory.java:121)
at com.sun.facelets.impl.DefaultFaceletFactory.getFacelet(DefaultFaceletFactory.java:91)
at com.icesoft.faces.facelets.D2DFaceletViewHandler.renderResponse(D2DFaceletViewHandler.java:268)
... 171 more
The UI has only .xhtml pages and no jsp page so I have no idea why it's trying to render a main.jsp page.
Also, after it gets deployed again it works fine for some time before the exception resurfaces.
Will be grateful if you can provide any pointer to the root cause or how to fix this problem.
Thanks in advance
Do you have the following in your web.xml?
<context-param>
<param-name>javax.faces.DEFAULT_SUFFIX</param-name>
<param-value>.xhtml</param-value>
</context-param>

Resources