KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > com > caucho > jws > NullCallServlet


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.jws;
30
31 import javax.servlet.ServletException JavaDoc;
32 import javax.servlet.http.HttpServlet JavaDoc;
33 import javax.servlet.http.HttpServletRequest JavaDoc;
34 import javax.servlet.http.HttpServletResponse JavaDoc;
35 import java.io.IOException JavaDoc;
36 import java.io.PrintWriter JavaDoc;
37
38 /**
39  * A bogus SOAP null-call for testing purposes
40  */

41 public class NullCallServlet extends HttpServlet JavaDoc {
42
43   public void doPost(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp)
44     throws ServletException JavaDoc, IOException JavaDoc {
45     doIt(req, resp);
46   }
47
48   public void doGet(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp)
49     throws ServletException JavaDoc, IOException JavaDoc {
50     doIt(req, resp);
51   }
52
53   public void doIt(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp)
54     throws ServletException JavaDoc, IOException JavaDoc {
55
56     if (req.getParameter("wsdl")==null)
57       sendResponse(req, resp);
58     else
59       sendWsdl(req, resp);
60   }
61
62   public void sendResponse(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp)
63     throws ServletException JavaDoc, IOException JavaDoc {
64
65     PrintWriter JavaDoc out = resp.getWriter();
66     resp.setContentType("text/xml;charset=utf-8");
67     out.println("<?xml version=\"1.0\" ?>");
68     out.println(" <Envelope");
69     out.println(" xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\"");
70     out.println(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"");
71     out.println(" xmlns:ns1=\"http://endpoint.nullservice/\">");
72     out.println(" <soapenv:Body>");
73     out.println(" <ns1:nullCallResponse>");
74     out.println(" </ns1:nullCallResponse>");
75     out.println(" </soapenv:Body>");
76     out.println(" </Envelope>");
77     out.flush();
78     out.close();
79   }
80
81   public void sendWsdl(HttpServletRequest JavaDoc req, HttpServletResponse JavaDoc resp)
82     throws ServletException JavaDoc, IOException JavaDoc {
83
84     PrintWriter JavaDoc out = resp.getWriter();
85     resp.setContentType("text/xml");
86     out.println("<?xml version=\"1.0\" encoding=\"UTF-8\"?>");
87     out.println("<definitions xmlns=\"http://schemas.xmlsoap.org/wsdl/\"");
88     out.println(" xmlns:tns=\"http://endpoint.nullservice/\"");
89     out.println(" xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"");
90     out.println(" xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\"");
91     out.println(" targetNamespace=\"http://endpoint.nullservice/\"");
92     out.println(" name=\"NullService\">");
93     out.println("<types>");
94     out.println(" <xsd:schema>");
95     out.println(" <xsd:import namespace=\"http://endpoint.nullservice/\"");
96
97     String JavaDoc xsd = "http://127.0.0.1:49106/nullservice/NullService/" +
98       "__container$publishing$subctx/WEB-INF/wsdl/NullService_schema1.xsd";
99     out.println(" schemaLocation=\""+xsd+"\"");
100     out.println(" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" ");
101     out.println(" xmlns:soap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\"/>");
102     out.println(" </xsd:schema>");
103     out.println("</types>");
104     out.println("<message name=\"nullCall\">");
105     out.println(" <part name=\"parameters\" element=\"tns:nullCall\"/>");
106     out.println("</message>");
107     out.println("<message name=\"nullCallResponse\">");
108     out.println("<part name=\"parameters\" element=\"tns:nullCallResponse\"/>");
109     out.println("</message>");
110     out.println("<portType name=\"Null\">");
111     out.println(" <operation name=\"nullCall\">");
112     out.println(" <input message=\"tns:nullCall\"/>");
113     out.println(" <output message=\"tns:nullCallResponse\"/>");
114     out.println(" </operation>");
115     out.println("</portType>");
116     out.println("<binding name=\"NullPortBinding\" type=\"tns:Null\">");
117     out.println(" <soap:binding ");
118     out.println(" transport=\"http://schemas.xmlsoap.org/soap/http\" ");
119     out.println(" style=\"document\"/>");
120     out.println(" <operation name=\"nullCall\">");
121     out.println(" <soap:operation soapAction=\"\"/>");
122     out.println(" <input>");
123     out.println(" <soap:body use=\"literal\"/>");
124     out.println(" </input>");
125     out.println(" <output>");
126     out.println(" <soap:body use=\"literal\"/>");
127     out.println(" </output>");
128     out.println(" </operation>");
129     out.println("</binding>");
130     out.println("<service name=\"NullService\">");
131     out.println(" <port name=\"NullPort\" binding=\"tns:NullPortBinding\">");
132
133     String JavaDoc service = "http://127.0.0.1:49106/nullservice/NullService";
134     out.println(" <soap:address location=\""+service+"\" ");
135     out.println(" xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\"");
136     out.println(" xmlns:soap12=\"http://schemas.xmlsoap.org/wsdl/soap12/\"/>");
137     out.println(" </port>");
138     out.println("</service>");
139     out.println("</definitions>");
140     out.flush();
141     out.close();
142   }
143 }
144
Popular Tags