Requirement:
I want to show an error page when ever we get any exception(i.e.,NullPointer,IndexOutofBoundsException etc) in Server Console.
System Requirement:
We are using apache tomcat 7.0.61,maven 3.2.3,Spring and Vaadin 7 (For UI Framework).
Ours WEB.XML file:
<context-param>
..............
</context-param>
<context-param>
<param-name>contextClass</param-name>
<param-value>
org.springframework.web.context.support.AnnotationConfigWebApplicationContext
</param-value>
</context-param>
.....
<listener>
<listener-class>
org.springframework.web.context.ContextLoaderListener
</listener-class>
</listener>
<servlet>
<servlet-name>Vaadin Application Servlet</servlet-name>
<servlet-class>com.vaadin.server.VaadinServlet</servlet-class>
<init-param>
<description>Vaadin UI to display</description>
<param-name>UI</param-name>
<param-value>com.lone.ui.LoneUI</param-value>
</init-param>
<init-param>
<description>Application widgetset</description>
<param-name>widgetset</param-name>
<param-value>com.lone.ui.AppWidgetSet</param-value>
</init-param>
</servlet>
<servlet-mapping>
<servlet-name>Vaadin Application Servlet</servlet-name>
<url-pattern>/*</url-pattern>
</servlet-mapping>
So i browsed and tried with some of the scenarios:
Scenario 1)
First i have configured
<error-page>
<exception-type>java.lang.Throwable</exception-type>
<location>/error</location>
</error-page>
(or)
<error-page>
<exception-type>java.lang.Exception</exception-type>
<location>/error</location>
</error-page>
in web.xml file and then i have written the Controller class by using the @RequestMapping("/error") in the method level but this scenario not worked.
Scenario 2)
Same with the above web.xml file i have written the Servlet class as
@WebServlet(value = {"/error"},asyncSupported = true)
public class ExceptionHandling extends VaadinServlet{
@Override
protected VaadinServletService getService() {
System.out.println("First if i display the sout message then i can Navigate to the Error Page....");
return super.getService();
}
}
But this is also not at worked.
Scenario 3)
Same with the above web.xml file i have written the Servlet class by extending the HTTPServlet but still unable to display the sout message.
Scenario 4) I have tried with Spring @ControllerAdvice and @Exception handler Annotation still i am unable to display the Error Page
Main Requirement:
I need to configure the Exceptions in the Web.xml file,so that when we get any exceptions in the server console it should hit the web.xml file and should navigate to the error page.
Could you please suggest me to complete the requirement because i have been working on this requirement from past 2 days.
Thanks in advance.
Vaadin 7 allows you to create extra error handler. So in case when you get any error/exception on the UI, Vaadin calls ErrorHandler. If your idea redirect to error page in case of any error, you can do the next:
UI.getCurrent().setErrorHandler(new ErrorHandler() {
@Override
public void error(com.vaadin.server.ErrorEvent event) {
Page.getCurrent().setLocation("error");
// Do the default error handling (optional)
DefaultErrorHandler.doDefault(event);
}
});
Also you can extend this with any other error handler methods.