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>
Related
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
I am having issues with the Omnifaces FullAjaxExceptionHandler (http://showcase.omnifaces.org/exceptionhandlers/FullAjaxExceptionHandler). It does not redirect to the specified error page after the session is invalidated.
I have the following in my faces-config:
<factory>
<exception-handler-factory>org.omnifaces.exceptionhandler.FullAjaxExceptionHandlerFactory</exception-handler-factory>
</factory>
And the following in my web.xml:
<error-page>
<exception-type>javax.faces.application.ViewExpiredException</exception-type>
<location>/pages/error/viewExpired.html</location>
</error-page>
After I invalidate the session, from a user's perspective nothing seems to happen. The application is just 'dead'. In my console I see the following Ajax request:
A POST to the original facelet page with a response code of 302
a GET to the login page with a code 200 (but nothing happens because it's requested via Ajax)
I am running MyFaces 2.1.10, Primefaces 3.5, Primefaces Extension 0.6.3 & Omnifaces 1.4.1 on WebLogic 12c
Could anyone help me in the right direction? How do I get the FullAjaxExeptionHandler to work properly?
Thanks
A POST to the original facelet page with a response code of 302
This is not right. A redirect on a JSF ajax request must have a response code of 200 with a special XML response with a <redirect> element with target URL in its url attribute.
This thus indicates that you manually used HttpServletResponse#sendRedirect() somewhere long before JSF has the chance to deal with ViewExpiredException.
Perhaps you've somewhere a servlet filter which checks some session attribute and sends a redirect based on its presence/state? That filter should then be manipulated based on the following answer: JSF Filter not redirecting After Initial Redirect in order to recognize JSF ajax requests and return a special XML response instead of a 302 response.
E.g.
if ("partial/ajax".equals(request.getHeader("Faces-Request"))) {
response.setContentType("text/xml");
response.getWriter()
.append("<?xml version=\"1.0\" encoding=\"UTF-8\"?>")
.printf("<partial-response><redirect url=\"%s\"></redirect></partial-response>", loginURL);
} else {
response.sendRedirect(loginURL);
}
This all is completely unrelated to the FullAjaxExceptionHandler. JSF didn't have any chance to throw a ViewExpiredException because you're already sending a redirect yourself beforehand.
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.
I am planning to use Cometd library in my application that runs on JBoss AS 6. Therefore I downloaded cometd 2.4.0 and tried to deploy example war (from cometd-demo/target) to my AS. I was aware that this was not possible without modifications, so I did the changes in web.xml:
Changed to servlet 3.0 in web-app tag (it is originally 2.5). Used complete tag from CometD faq answer. Also uncommented continuation filter that was already in web.xml, based on this description
Based on faq answer, added async-supported tag. However, this causes problems: if I just uncomment it, web.xml can't be parsed. I found out that this is due to order of tags in XML, so moved async-supported tag down the order, just after load-on-startup tag. However, Jboss still throws exceptions:
ERROR
[org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/cometd-demo-2.4.0].[cometd]]
Servlet.service() for servlet cometd threw exception:
java.lang.IllegalStateException: The servlet or filters that are being
used by this request do not support async operation
ERROR
[org.apache.catalina.core.ContainerBase.[jboss.web].[localhost].[/cometd-demo-2.4.0].[cometd]]
Servlet.service() for servlet cometd threw exception:
java.lang.ClassNotFoundException:
org.eclipse.jetty.server.AbstractHttpConnection from
BaseClassLoader#12a54b
Complete web.xml file that I use is here.
Example runs no my Jboss despite all errors reported, but by watching firebug, I can see that it does quick pooling instead of long pool. It seems that server thinks that browser has multiple connections open, which is not the case (see JSON below):
[{"id":"137","successful":true,"advice":{"interval":2000,"reconnect":"retry","multiple-clients":true,"timeout":20000},"channel":"/meta/connect"}]
Did anyone managed to make examples work with JBoss as6 and how? What I did wrong here?
remove:
<!-- Portability Filter, needed only to run on non Jetty or non Servlet-3.0 containers -->
<filter>
<filter-name>continuation</filter-name>
<filter-class>org.eclipse.jetty.continuation.ContinuationFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>continuation</filter-name>
<url-pattern>/cometd/*</url-pattern>
</filter-mapping>
from web.xml
I have the same setup and the same problem even if I remove continuation filter from web.xml.
I've found a thread on cometd-users group complaining about multiple-client issue on Tomcat 7 and the cause seems to be a Tomcat bug around Content-Type that is not set to "application/json".
However I've inspected packets and on JBossAS6 the content-type is correctly set on server responses.
UPDATE
I've give a try using Jetty 7 and the problem disappeared. The "multiple-clients" issue affects Tomcat as well as JBoss6 AS
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.");