001: /*
002: * Copyright (c) 1998-2007 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: *
023: * Free Software Foundation, Inc.
024: * 59 Temple Place, Suite 330
025: * Boston, MA 02111-1307 USA
026: *
027: * @author Scott Ferguson
028: */
029:
030: package com.caucho.soa.servlet;
031:
032: import com.caucho.soa.encoding.SoapEncoding;
033:
034: import javax.servlet.GenericServlet;
035: import javax.servlet.ServletException;
036: import javax.servlet.ServletRequest;
037: import javax.servlet.ServletResponse;
038: import javax.servlet.http.HttpServletRequest;
039: import javax.servlet.http.HttpServletResponse;
040: import java.io.IOException;
041: import java.util.logging.Logger;
042:
043: /**
044: * Invokes a service based on a Soap-encoded request.
045: */
046: public class SoapProtocolServlet extends GenericServlet implements
047: ProtocolServlet {
048: protected static Logger log = Logger
049: .getLogger(SoapProtocolServlet.class.getName());
050:
051: private final SoapEncoding _soap = new SoapEncoding();
052:
053: /**
054: * Sets the service class.
055: */
056: public void setService(Object service) {
057: _soap.setService(service);
058: }
059:
060: public void setSeparateSchema(boolean separateSchema)
061: throws Throwable {
062: _soap.setSeparateSchema(separateSchema);
063: }
064:
065: public void init() throws ServletException {
066: try {
067: _soap.init();
068: } catch (RuntimeException e) {
069: throw e;
070: } catch (Exception e) {
071: throw new ServletException(e);
072: }
073: }
074:
075: public void service(ServletRequest request, ServletResponse response)
076: throws IOException, ServletException {
077: try {
078: if (request instanceof HttpServletRequest) {
079: HttpServletRequest httpRequest = (HttpServletRequest) request;
080:
081: if ("wsdl".equalsIgnoreCase(httpRequest
082: .getQueryString())) {
083: _soap.dumpWSDL(response.getOutputStream());
084: return;
085: }
086: }
087:
088: _soap.invoke((HttpServletRequest) request,
089: (HttpServletResponse) response);
090: } catch (IOException e) {
091: throw e;
092: } catch (ServletException e) {
093: throw e;
094: } catch (RuntimeException e) {
095: throw e;
096: } catch (Throwable e) {
097: throw new ServletException(e);
098: }
099: }
100: }
|