PageRenderTime 18ms CodeModel.GetById 13ms app.highlight 3ms RepoModel.GetById 1ms app.codeStats 0ms

/webportal/src/main/java/au/org/emii/portal/servlet/ErrorHandlerServlet.java

http://alageospatialportal.googlecode.com/
Java | 68 lines | 33 code | 13 blank | 22 comment | 0 complexity | f051c7cdec0fa8fbd473dc3e899f421d MD5 | raw file
 1package au.org.emii.portal.servlet;
 2
 3import java.io.IOException;
 4
 5import javax.servlet.RequestDispatcher;
 6import javax.servlet.ServletException;
 7import javax.servlet.http.HttpServlet;
 8import javax.servlet.http.HttpServletRequest;
 9import javax.servlet.http.HttpServletResponse;
10
11import org.apache.log4j.Logger;
12
13/**
14 * Servlet implementation class ErrorHandlerServlet
15 */
16public class ErrorHandlerServlet extends HttpServlet {
17
18    private static final long serialVersionUID = 1L;
19    private static final String ERROR_PAGE = "/WEB-INF/jsp/Error.jsp";
20
21    /**
22     * @see HttpServlet#HttpServlet()
23     */
24    public ErrorHandlerServlet() {
25        super();
26    }
27
28    /**
29     * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
30     */
31    @Override
32    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
33
34        // get the error fields from the request - these should all be null if we've
35        // already handled the error elsewhere
36        Object statusCode = request.getAttribute("javax.servlet.error.status_code");
37        Object message = request.getAttribute("javax.servlet.error.message");
38        //Object errorType = request.getAttribute("javax.servlet.error.exception_type");
39        Throwable exception = (Throwable) request.getAttribute("javax.servlet.error.exception");
40        Object request_uri = request.getAttribute("javax.servlet.error.request_uri");
41
42        // Exceptions are normally raised and logged during application or session init
43        // if something has slipped through the net, log it, otherwise just display the
44        // jsp error page
45        Logger logger = Logger.getLogger(this.getClass());
46        logger.fatal(
47                "UNHANDLED EXCEPTION: HTTP ERROR " + statusCode + " Message: " + message +
48                " URI: " + request_uri + " REASON " +
49                exception.getMessage());
50
51
52        // now we just display a static-ish JSP to the user - we don't use a
53        // ZK page because it could well be problems with ZK that have sent
54        // us here in the first place which would leave us unable to display
55        // the error message
56        RequestDispatcher dispatcher = getServletContext().getRequestDispatcher(ERROR_PAGE);
57        dispatcher.forward(request, response);
58
59    }
60
61    /**
62     * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
63     */
64    @Override
65    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
66        doGet(request, response);
67    }
68}