KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > webapp > ErrorPageFilter


1 /*
2  * Copyright (c) 1998-2006 Caucho Technology -- all rights reserved
3  *
4  * This file is part of Resin(R) Open Source
5  *
6  * Each copy or derived work must preserve the copyright notice and this
7  * notice unmodified.
8  *
9  * Resin Open Source is free software; you can redistribute it and/or modify
10  * it under the terms of the GNU General Public License as published by
11  * the Free Software Foundation; either version 2 of the License, or
12  * (at your option) any later version.
13  *
14  * Resin Open Source is distributed in the hope that it will be useful,
15  * but WITHOUT ANY WARRANTY; without even the implied warranty of
16  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
17  * of NON-INFRINGEMENT. See the GNU General Public License for more
18  * details.
19  *
20  * You should have received a copy of the GNU General Public License
21  * along with Resin Open Source; if not, write to the
22  * Free SoftwareFoundation, Inc.
23  * 59 Temple Place, Suite 330
24  * Boston, MA 02111-1307 USA
25  *
26  * @author Scott Ferguson
27  */

28
29 package com.caucho.server.webapp;
30
31 import com.caucho.log.Log;
32
33 import javax.servlet.Filter JavaDoc;
34 import javax.servlet.FilterChain JavaDoc;
35 import javax.servlet.FilterConfig JavaDoc;
36 import javax.servlet.ServletException JavaDoc;
37 import javax.servlet.ServletRequest JavaDoc;
38 import javax.servlet.ServletResponse JavaDoc;
39 import java.io.IOException JavaDoc;
40 import java.util.logging.Logger JavaDoc;
41
42 /**
43  * Represents the final servlet in a filter chain.
44  */

45 public class ErrorPageFilter implements Filter JavaDoc {
46   private static final Logger JavaDoc log = Log.open(ErrorPageFilter.class);
47   
48   public static String JavaDoc REQUEST_URI = "javax.servlet.include.request_uri";
49   public static String JavaDoc CONTEXT_PATH = "javax.servlet.include.context_path";
50   public static String JavaDoc SERVLET_PATH = "javax.servlet.include.servlet_path";
51   public static String JavaDoc PATH_INFO = "javax.servlet.include.path_info";
52   public static String JavaDoc QUERY_STRING = "javax.servlet.include.query_string";
53   
54   public static String JavaDoc STATUS_CODE = "javax.servlet.error.status_code";
55   public static String JavaDoc EXCEPTION_TYPE = "javax.servlet.error.exception_type";
56   public static String JavaDoc MESSAGE = "javax.servlet.error.message";
57   public static String JavaDoc EXCEPTION = "javax.servlet.error.exception";
58   public static String JavaDoc ERROR_URI = "javax.servlet.error.request_uri";
59   public static String JavaDoc SERVLET_NAME = "javax.servlet.error.servlet_name";
60   
61   public static String JavaDoc JSP_EXCEPTION = "javax.servlet.jsp.jspException";
62   
63   public static String JavaDoc SHUTDOWN = "com.caucho.shutdown";
64   
65   private FilterConfig JavaDoc _config;
66   private Application _app;
67   private ErrorPageManager _errorPageManager;
68
69   /**
70    * Create error page filter.
71    */

72   public ErrorPageFilter()
73   {
74   }
75
76   /**
77    * Create error page filter.
78    */

79   public ErrorPageFilter(ErrorPageManager manager)
80   {
81     _errorPageManager = manager;
82   }
83
84   /**
85    * Dummy init.
86    */

87   public void init(FilterConfig JavaDoc config)
88   {
89     _config = config;
90     _app = (Application) config.getServletContext();
91   }
92   
93   /**
94    * Invokes the final servlet at the end of the chain.
95    *
96    * @param request the servlet request
97    * @param response the servlet response
98    */

99   public void doFilter(ServletRequest JavaDoc request,
100                        ServletResponse JavaDoc response,
101                        FilterChain JavaDoc next)
102     throws ServletException JavaDoc, IOException JavaDoc
103   {
104     try {
105       next.doFilter(request, response);
106     } catch (Throwable JavaDoc e) {
107       _errorPageManager.sendServletError(e, request, response);
108     }
109   }
110
111   /**
112    * Dummy destroy
113    */

114   public void destroy()
115   {
116   }
117 }
118
Popular Tags