ItEr07S06ArquitecturaServidorItEr06S04: Adding centralized error pages. One is for errors while processing ajax events and the other is for errors when loading pages.
This commit is contained in:
parent
cced9e9a4a
commit
c25c91a9b4
6 changed files with 187 additions and 81 deletions
|
|
@ -0,0 +1,48 @@
|
|||
package org.navalplanner.web.error;
|
||||
|
||||
import javax.servlet.http.HttpServletRequest;
|
||||
|
||||
import org.apache.commons.logging.Log;
|
||||
import org.apache.commons.logging.LogFactory;
|
||||
import org.zkoss.zk.ui.Component;
|
||||
import org.zkoss.zk.ui.Executions;
|
||||
import org.zkoss.zk.ui.util.GenericForwardComposer;
|
||||
|
||||
public class PageForErrorOnEvent extends GenericForwardComposer {
|
||||
|
||||
private static final Log LOG = LogFactory.getLog(PageForErrorOnEvent.class);
|
||||
|
||||
private Component modalWindow;
|
||||
|
||||
@Override
|
||||
public void doAfterCompose(Component comp) throws Exception {
|
||||
super.doAfterCompose(comp);
|
||||
logError();
|
||||
modalWindow = comp;
|
||||
|
||||
}
|
||||
|
||||
private void logError() {
|
||||
Throwable exception = (Throwable) Executions.getCurrent().getAttribute(
|
||||
"javax.servlet.error.exception");
|
||||
String errorMessage = (String) Executions.getCurrent().getAttribute(
|
||||
"javax.servlet.error.message");
|
||||
LOG.error(errorMessage, exception);
|
||||
}
|
||||
|
||||
public void onClick$continueWorking() {
|
||||
modalWindow.detach();
|
||||
}
|
||||
|
||||
public void onClick$reload() {
|
||||
Executions.sendRedirect(null);
|
||||
}
|
||||
|
||||
public void onClick$quitSession() {
|
||||
HttpServletRequest nativeRequest = (HttpServletRequest) Executions
|
||||
.getCurrent().getNativeRequest();
|
||||
nativeRequest.getSession().invalidate();
|
||||
Executions.sendRedirect("/");
|
||||
}
|
||||
|
||||
}
|
||||
|
|
@ -1,91 +1,103 @@
|
|||
<?xml version="1.0" encoding="UTF-8"?>
|
||||
<web-app id="WebApp_ID" version="2.4"
|
||||
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
|
||||
xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
|
||||
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
|
||||
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
|
||||
<display-name>helloworld</display-name>
|
||||
<display-name>helloworld</display-name>
|
||||
|
||||
<!-- It searches all navalplanner-business-spring-config.xml files, it can found several. There must be at least one.
|
||||
It searches navalplanner-webapp-spring-config.xml. There must be just one.
|
||||
It searches navalplanner-override-spring-config.xml to override some previous definitions. There could be several or none.
|
||||
-->
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath*:/navalplanner-business-spring-config.xml classpath:/navalplanner-webapp-spring-config.xml classpath*:/navalplanner-override-spring-config.xml</param-value>
|
||||
</context-param>
|
||||
<!--
|
||||
It searches all navalplanner-business-spring-config.xml files, it can
|
||||
found several. There must be at least one. It searches
|
||||
navalplanner-webapp-spring-config.xml. There must be just one. It
|
||||
searches navalplanner-override-spring-config.xml to override some
|
||||
previous definitions. There could be several or none.
|
||||
-->
|
||||
<context-param>
|
||||
<param-name>contextConfigLocation</param-name>
|
||||
<param-value>classpath*:/navalplanner-business-spring-config.xml classpath:/navalplanner-webapp-spring-config.xml classpath*:/navalplanner-override-spring-config.xml</param-value>
|
||||
</context-param>
|
||||
|
||||
|
||||
<!-- /// -->
|
||||
<!-- DSP -->
|
||||
<servlet>
|
||||
<description><![CDATA[The servlet loads the DSP pages.]]></description>
|
||||
<servlet-name>dspLoader</servlet-name>
|
||||
<servlet-class>org.zkoss.web.servlet.dsp.InterpreterServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>dspLoader</servlet-name>
|
||||
<url-pattern>*.dsp</url-pattern>
|
||||
</servlet-mapping>
|
||||
<!-- /// -->
|
||||
<!-- /// -->
|
||||
<!-- DSP -->
|
||||
<servlet>
|
||||
<description><![CDATA[The servlet loads the DSP pages.]]></description>
|
||||
<servlet-name>dspLoader</servlet-name>
|
||||
<servlet-class>org.zkoss.web.servlet.dsp.InterpreterServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>dspLoader</servlet-name>
|
||||
<url-pattern>*.dsp</url-pattern>
|
||||
</servlet-mapping>
|
||||
<!-- /// -->
|
||||
|
||||
<!-- //// -->
|
||||
<!-- ZK -->
|
||||
<listener>
|
||||
<description>Used to cleanup when a session is destroyed</description>
|
||||
<display-name>ZK Session Cleaner</display-name>
|
||||
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<!-- Spring listeners -->
|
||||
<!-- //// -->
|
||||
<!-- ZK -->
|
||||
<listener>
|
||||
<description>Used to cleanup when a session is destroyed</description>
|
||||
<display-name>ZK Session Cleaner</display-name>
|
||||
<listener-class>org.zkoss.zk.ui.http.HttpSessionListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<listener>
|
||||
<listener-class>
|
||||
org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
<!-- Spring listeners -->
|
||||
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.request.RequestContextListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<!-- end Spring listeners -->
|
||||
|
||||
<servlet>
|
||||
<description>ZK loader for ZUML pages</description>
|
||||
<servlet-name>zkLoader</servlet-name>
|
||||
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
|
||||
<!--
|
||||
Must. Specifies URI of the update engine
|
||||
(DHtmlUpdateServlet). It must be the same as <url-pattern>
|
||||
for the update engine.
|
||||
-->
|
||||
<init-param>
|
||||
<param-name>update-uri</param-name>
|
||||
<param-value>/zkau</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>zkLoader</servlet-name>
|
||||
<url-pattern>*.zul</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>zkLoader</servlet-name>
|
||||
<url-pattern>*.zhtml</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet>
|
||||
<description>The asynchronous update engine for ZK</description>
|
||||
<servlet-name>auEngine</servlet-name>
|
||||
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>auEngine</servlet-name>
|
||||
<url-pattern>/zkau/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
<!-- //// -->
|
||||
<listener>
|
||||
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<listener>
|
||||
<listener-class>
|
||||
org.springframework.web.context.request.RequestContextListener</listener-class>
|
||||
</listener>
|
||||
|
||||
<!-- end Spring listeners -->
|
||||
|
||||
<servlet>
|
||||
<description>ZK loader for ZUML pages</description>
|
||||
<servlet-name>zkLoader</servlet-name>
|
||||
<servlet-class>org.zkoss.zk.ui.http.DHtmlLayoutServlet</servlet-class>
|
||||
<!--
|
||||
Must. Specifies URI of the update engine (DHtmlUpdateServlet). It
|
||||
must be the same as <url-pattern> for the update engine.
|
||||
-->
|
||||
<init-param>
|
||||
<param-name>update-uri</param-name>
|
||||
<param-value>/zkau</param-value>
|
||||
</init-param>
|
||||
<load-on-startup>1</load-on-startup>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>zkLoader</servlet-name>
|
||||
<url-pattern>*.zul</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet-mapping>
|
||||
<servlet-name>zkLoader</servlet-name>
|
||||
<url-pattern>*.zhtml</url-pattern>
|
||||
</servlet-mapping>
|
||||
<servlet>
|
||||
<description>The asynchronous update engine for ZK</description>
|
||||
<servlet-name>auEngine</servlet-name>
|
||||
<servlet-class>org.zkoss.zk.au.http.DHtmlUpdateServlet</servlet-class>
|
||||
</servlet>
|
||||
<servlet-mapping>
|
||||
<servlet-name>auEngine</servlet-name>
|
||||
<url-pattern>/zkau/*</url-pattern>
|
||||
</servlet-mapping>
|
||||
<!-- //// -->
|
||||
|
||||
|
||||
|
||||
<welcome-file-list>
|
||||
|
||||
<welcome-file>/planner/main.zul</welcome-file>
|
||||
|
||||
</welcome-file-list>
|
||||
|
||||
<error-page>
|
||||
<exception-type>java.lang.Throwable</exception-type>
|
||||
<location>/common/error.zul</location>
|
||||
</error-page>
|
||||
|
||||
<welcome-file-list>
|
||||
|
||||
<welcome-file>/planner/main.zul</welcome-file>
|
||||
|
||||
</welcome-file-list>
|
||||
</web-app>
|
||||
|
|
|
|||
|
|
@ -1,5 +1,11 @@
|
|||
<zk>
|
||||
<log>
|
||||
<log-base></log-base>
|
||||
</log>
|
||||
<log>
|
||||
<log-base></log-base>
|
||||
</log>
|
||||
<error-page>
|
||||
<exception-type>java.lang.Throwable
|
||||
</exception-type>
|
||||
<location>/common/event_error.zul</location>
|
||||
</error-page>
|
||||
|
||||
</zk>
|
||||
|
|
|
|||
12
navalplanner-webapp/src/main/webapp/common/error.jsp
Normal file
12
navalplanner-webapp/src/main/webapp/common/error.jsp
Normal file
|
|
@ -0,0 +1,12 @@
|
|||
<%@ page language="java" contentType="text/html; charset=UTF-8"
|
||||
pageEncoding="UTF-8"%>
|
||||
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
|
||||
<html>
|
||||
<head>
|
||||
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
|
||||
<title>Insert title here</title>
|
||||
</head>
|
||||
<body>
|
||||
|
||||
</body>
|
||||
</html>
|
||||
14
navalplanner-webapp/src/main/webapp/common/error.zul
Normal file
14
navalplanner-webapp/src/main/webapp/common/error.zul
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<zk>
|
||||
<caption>
|
||||
Erro ${requestScope['javax.servlet.error.status_code']}
|
||||
</caption>
|
||||
<vbox apply="org.navalplanner.web.error.PageForErrorOnEvent">
|
||||
Prodúxose un erro na execución:
|
||||
"${requestScope['javax.servlet.error.message']}". O erro
|
||||
gardouse e procurarase arreglalo no menor tempo posible.
|
||||
<hbox style="margin-left:auto; margin-right:auto">
|
||||
<button id="reload" label="Reload" />
|
||||
<button id="quitSession" label="Exit Session"></button>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</zk>
|
||||
14
navalplanner-webapp/src/main/webapp/common/event_error.zul
Normal file
14
navalplanner-webapp/src/main/webapp/common/event_error.zul
Normal file
|
|
@ -0,0 +1,14 @@
|
|||
<window title="Erro ${requestScope['javax.servlet.error.status_code']}"
|
||||
width="400px" border="normal" mode="modal"
|
||||
apply="org.navalplanner.web.error.PageForErrorOnEvent">
|
||||
<vbox>
|
||||
Prodúxose un erro na execución:
|
||||
"${requestScope['javax.servlet.error.message']}". O erro
|
||||
gardouse e procurarase arreglalo no menor tempo posible.
|
||||
<hbox style="margin-left:auto; margin-right:auto">
|
||||
<button id="continueWorking" label="Continue" />
|
||||
<button id="reload" label="Reload" />
|
||||
<button id="quitSession" label="Exit Session"></button>
|
||||
</hbox>
|
||||
</vbox>
|
||||
</window>
|
||||
Loading…
Add table
Reference in a new issue