001: /*
002: * Copyright (c) 1998-2008 Caucho Technology -- all rights reserved
003: *
004: * This file is part of Resin(R) Open Source
005: *
006: * Each copy or derived work must preserve the copyright notice and this
007: * notice unmodified.
008: *
009: * Resin Open Source is free software; you can redistribute it and/or modify
010: * it under the terms of the GNU General Public License as published by
011: * the Free Software Foundation; either version 2 of the License, or
012: * (at your option) any later version.
013: *
014: * Resin Open Source is distributed in the hope that it will be useful,
015: * but WITHOUT ANY WARRANTY; without even the implied warranty of
016: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE, or any warranty
017: * of NON-INFRINGEMENT. See the GNU General Public License for more
018: * details.
019: *
020: * You should have received a copy of the GNU General Public License
021: * along with Resin Open Source; if not, write to the
022: * Free SoftwareFoundation, Inc.
023: * 59 Temple Place, Suite 330
024: * Boston, MA 02111-1307 USA
025: *
026: * @author Scott Ferguson
027: */
028:
029: package com.caucho.server.dispatch;
030:
031: //import com.caucho.soa.servlet.ProtocolServlet;
032:
033: import javax.servlet.*;
034: import java.io.IOException;
035: import java.util.HashMap;
036: import java.util.logging.*;
037:
038: /**
039: * Represents the final servlet in a filter chain.
040: */
041: public class WebServiceFilterChain implements FilterChain {
042: private static final Logger log = Logger
043: .getLogger(WebServiceFilterChain.class.getName());
044:
045: public static final String SERVLET_NAME = "javax.servlet.error.servlet_name";
046:
047: // servlet config
048: private ServletConfigImpl _config;
049:
050: // protocol skeleton
051: // private ProtocolServlet _skeleton;
052: private Servlet _skeleton;
053:
054: /**
055: * Create the filter chain servlet.
056: *
057: * @param servlet the underlying servlet
058: */
059: public WebServiceFilterChain(ServletConfigImpl config) {
060: if (config == null)
061: throw new NullPointerException();
062:
063: _config = config;
064: }
065:
066: /**
067: * Returns the servlet name.
068: */
069: public String getServletName() {
070: return _config.getServletName();
071: }
072:
073: /**
074: * Returns the role map.
075: */
076: public HashMap<String, String> getRoleMap() {
077: return _config.getRoleMap();
078: }
079:
080: /**
081: * Invokes the final servlet at the end of the chain.
082: *
083: * @param request the servlet request
084: * @param response the servlet response
085: *
086: * @since Servlet 2.3
087: */
088: public void doFilter(ServletRequest request,
089: ServletResponse response) throws ServletException,
090: IOException {
091: if (_skeleton == null) {
092: _skeleton = _config.createProtocolServlet();
093: }
094:
095: try {
096: _skeleton.service(request, response);
097: } catch (UnavailableException e) {
098: _skeleton = null;
099: _config.setInitException(e);
100: _config.killServlet();
101: request
102: .setAttribute(SERVLET_NAME, _config
103: .getServletName());
104: throw e;
105: } catch (ServletException e) {
106: request
107: .setAttribute(SERVLET_NAME, _config
108: .getServletName());
109: throw e;
110: } catch (IOException e) {
111: request
112: .setAttribute(SERVLET_NAME, _config
113: .getServletName());
114: throw e;
115: } catch (RuntimeException e) {
116: request
117: .setAttribute(SERVLET_NAME, _config
118: .getServletName());
119: throw e;
120: } catch (Exception e) {
121: request
122: .setAttribute(SERVLET_NAME, _config
123: .getServletName());
124: throw new ServletException(e);
125: }
126: }
127:
128: public String toString() {
129: return getClass().getSimpleName() + "[" + _skeleton + "]";
130: }
131: }
|