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.jws;
030:
031: import javax.servlet.ServletException;
032: import javax.servlet.http.HttpServlet;
033: import javax.servlet.http.HttpServletRequest;
034: import javax.servlet.http.HttpServletResponse;
035: import java.io.IOException;
036: import java.io.PrintWriter;
037:
038: /**
039: * A bogus SOAP null-call for testing purposes
040: */
041: public class NullCallServlet extends HttpServlet {
042:
043: public void doPost(HttpServletRequest req, HttpServletResponse resp)
044: throws ServletException, IOException {
045: doIt(req, resp);
046: }
047:
048: public void doGet(HttpServletRequest req, HttpServletResponse resp)
049: throws ServletException, IOException {
050: doIt(req, resp);
051: }
052:
053: public void doIt(HttpServletRequest req, HttpServletResponse resp)
054: throws ServletException, IOException {
055:
056: if (req.getParameter("wsdl") == null)
057: sendResponse(req, resp);
058: else
059: sendWsdl(req, resp);
060: }
061:
062: public void sendResponse(HttpServletRequest req,
063: HttpServletResponse resp) throws ServletException,
064: IOException {
065:
066: PrintWriter out = resp.getWriter();
067: resp.setContentType("text/xml;charset=utf-8");
068: out.println("<?xml version=\"1.0\" ?>");
069: out.println(" <Envelope");
070: out
071: .println(" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"");
072: out.println(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"");
073: out.println(" xmlns:ns1=\"http://endpoint.nullservice/\">");
074: out.println(" <soapenv:Body>");
075: out.println(" <ns1:nullCallResponse>");
076: out.println(" </ns1:nullCallResponse>");
077: out.println(" </soapenv:Body>");
078: out.println(" </Envelope>");
079: out.flush();
080: out.close();
081: }
082:
083: public void sendWsdl(HttpServletRequest req,
084: HttpServletResponse resp) throws ServletException,
085: IOException {
086:
087: PrintWriter out = resp.getWriter();
088: resp.setContentType("text/xml");
089: out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
090: out
091: .println("<definitions xmlns=\"http://schemas.xmlsoap.org/wsdl/\"");
092: out
093: .println(" xmlns:tns=\"http://endpoint.nullservice/\"");
094: out
095: .println(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"");
096: out
097: .println(" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\"");
098: out
099: .println(" targetNamespace=\"http://endpoint.nullservice/\"");
100: out.println(" name=\"NullService\">");
101: out.println("<types>");
102: out.println(" <xsd:schema>");
103: out
104: .println(" <xsd:import namespace=\"http://endpoint.nullservice/\"");
105:
106: String xsd = "http://127.0.0.1:49106/nullservice/NullService/"
107: + "__container$publishing$subctx/WEB-INF/wsdl/NullService_schema1.xsd";
108: out.println(" schemaLocation=\"" + xsd + "\"");
109: out
110: .println(" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" ");
111: out
112: .println(" xmlns:soap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\"/>");
113: out.println(" </xsd:schema>");
114: out.println("</types>");
115: out.println("<message name=\"nullCall\">");
116: out
117: .println(" <part name=\"parameters\" element=\"tns:nullCall\"/>");
118: out.println("</message>");
119: out.println("<message name=\"nullCallResponse\">");
120: out
121: .println("<part name=\"parameters\" element=\"tns:nullCallResponse\"/>");
122: out.println("</message>");
123: out.println("<portType name=\"Null\">");
124: out.println(" <operation name=\"nullCall\">");
125: out.println(" <input message=\"tns:nullCall\"/>");
126: out.println(" <output message=\"tns:nullCallResponse\"/>");
127: out.println(" </operation>");
128: out.println("</portType>");
129: out
130: .println("<binding name=\"NullPortBinding\" type=\"tns:Null\">");
131: out.println(" <soap:binding ");
132: out
133: .println(" transport=\"http://schemas.xmlsoap.org/soap/http\" ");
134: out.println(" style=\"document\"/>");
135: out.println(" <operation name=\"nullCall\">");
136: out.println(" <soap:operation soapAction=\"\"/>");
137: out.println(" <input>");
138: out.println(" <soap:body use=\"literal\"/>");
139: out.println(" </input>");
140: out.println(" <output>");
141: out.println(" <soap:body use=\"literal\"/>");
142: out.println(" </output>");
143: out.println(" </operation>");
144: out.println("</binding>");
145: out.println("<service name=\"NullService\">");
146: out
147: .println(" <port name=\"NullPort\" binding=\"tns:NullPortBinding\">");
148:
149: String service = "http://127.0.0.1:49106/nullservice/NullService";
150: out.println(" <soap:address location=\"" + service + "\" ");
151: out
152: .println(" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\"");
153: out
154: .println(" xmlns:soap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\"/>");
155: out.println(" </port>");
156: out.println("</service>");
157: out.println("</definitions>");
158: out.flush();
159: out.close();
160: }
161: }
|