KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > server > dispatch > WebServiceFilterChain


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.dispatch;
30
31 import com.caucho.soa.servlet.ProtocolServlet;
32
33 import javax.servlet.FilterChain JavaDoc;
34 import javax.servlet.ServletException JavaDoc;
35 import javax.servlet.ServletRequest JavaDoc;
36 import javax.servlet.ServletResponse JavaDoc;
37 import javax.servlet.UnavailableException JavaDoc;
38 import java.io.IOException JavaDoc;
39 import java.util.HashMap JavaDoc;
40
41 /**
42  * Represents the final servlet in a filter chain.
43  */

44 public class WebServiceFilterChain implements FilterChain JavaDoc {
45   public static final String JavaDoc SERVLET_NAME
46     = "javax.servlet.error.servlet_name";
47   
48   // servlet config
49
private ServletConfigImpl _config;
50   
51   // protocol skeleton
52
private ProtocolServlet _skeleton;
53
54   /**
55    * Create the filter chain servlet.
56    *
57    * @param servlet the underlying servlet
58    */

59   public WebServiceFilterChain(ServletConfigImpl config)
60   {
61     if (config == null)
62       throw new NullPointerException JavaDoc();
63     
64     _config = config;
65   }
66
67   /**
68    * Returns the servlet name.
69    */

70   public String JavaDoc getServletName()
71   {
72     return _config.getServletName();
73   }
74
75   /**
76    * Returns the role map.
77    */

78   public HashMap JavaDoc<String JavaDoc,String JavaDoc> getRoleMap()
79   {
80     return _config.getRoleMap();
81   }
82   
83   /**
84    * Invokes the final servlet at the end of the chain.
85    *
86    * @param request the servlet request
87    * @param response the servlet response
88    *
89    * @since Servlet 2.3
90    */

91   public void doFilter(ServletRequest JavaDoc request,
92                        ServletResponse JavaDoc response)
93     throws ServletException JavaDoc, IOException JavaDoc
94   {
95     if (_skeleton == null) {
96       try {
97         _skeleton = _config.createWebServiceSkeleton();
98       } catch (ServletException JavaDoc e) {
99         throw e;
100       } catch (RuntimeException JavaDoc e) {
101         throw e;
102       } catch (Exception JavaDoc e) {
103         throw new ServletException JavaDoc(e);
104       }
105     }
106     
107     try {
108       _skeleton.service(request, response);
109     } catch (UnavailableException JavaDoc e) {
110       _skeleton = null;
111       _config.setInitException(e);
112       _config.killServlet();
113       request.setAttribute(SERVLET_NAME, _config.getServletName());
114       throw e;
115     } catch (ServletException JavaDoc e) {
116       request.setAttribute(SERVLET_NAME, _config.getServletName());
117       throw e;
118     } catch (IOException JavaDoc e) {
119       request.setAttribute(SERVLET_NAME, _config.getServletName());
120       throw e;
121     } catch (RuntimeException JavaDoc e) {
122       request.setAttribute(SERVLET_NAME, _config.getServletName());
123       throw e;
124     } catch (Throwable JavaDoc e) {
125       request.setAttribute(SERVLET_NAME, _config.getServletName());
126       throw new ServletException JavaDoc(e);
127     }
128   }
129 }
130
Popular Tags