KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > jboss > axis > handlers > EchoHandler


1 /*
2  * The Apache Software License, Version 1.1
3  *
4  *
5  * Copyright (c) 2001-2003 The Apache Software Foundation. All rights
6  * reserved.
7  *
8  * Redistribution and use in source and binary forms, with or without
9  * modification, are permitted provided that the following conditions
10  * are met:
11  *
12  * 1. Redistributions of source code must retain the above copyright
13  * notice, this list of conditions and the following disclaimer.
14  *
15  * 2. Redistributions in binary form must reproduce the above copyright
16  * notice, this list of conditions and the following disclaimer in
17  * the documentation and/or other materials provided with the
18  * distribution.
19  *
20  * 3. The end-user documentation included with the redistribution,
21  * if any, must include the following acknowledgment:
22  * "This product includes software developed by the
23  * Apache Software Foundation (http://www.apache.org/)."
24  * Alternately, this acknowledgment may appear in the software itself,
25  * if and wherever such third-party acknowledgments normally appear.
26  *
27  * 4. The names "Axis" and "Apache Software Foundation" must
28  * not be used to endorse or promote products derived from this
29  * software without prior written permission. For written
30  * permission, please contact apache@apache.org.
31  *
32  * 5. Products derived from this software may not be called "Apache",
33  * nor may "Apache" appear in their name, without prior written
34  * permission of the Apache Software Foundation.
35  *
36  * THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED OR IMPLIED
37  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
38  * OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
39  * DISCLAIMED. IN NO EVENT SHALL THE APACHE SOFTWARE FOUNDATION OR
40  * ITS CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL,
41  * SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT
42  * LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF
43  * USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND
44  * ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
45  * OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT
46  * OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
47  * SUCH DAMAGE.
48  * ====================================================================
49  *
50  * This software consists of voluntary contributions made by many
51  * individuals on behalf of the Apache Software Foundation. For more
52  * information on the Apache Software Foundation, please see
53  * <http://www.apache.org/>.
54  */

55
56 package org.jboss.axis.handlers;
57
58 import org.jboss.axis.AxisFault;
59 import org.jboss.axis.Message;
60 import org.jboss.axis.MessageContext;
61 import org.jboss.axis.message.SOAPEnvelopeAxisImpl;
62 import org.jboss.axis.utils.Messages;
63 import org.jboss.axis.utils.XMLUtils;
64 import org.jboss.logging.Logger;
65 import org.w3c.dom.Document JavaDoc;
66
67 import java.io.StringBufferInputStream JavaDoc;
68
69 /**
70  * @author Doug Davis (dug@us.ibm.com)
71  */

72 public class EchoHandler extends BasicHandler
73 {
74    private static Logger log = Logger.getLogger(EchoHandler.class.getName());
75
76    public void invoke(MessageContext msgContext) throws AxisFault
77    {
78       log.debug("Enter: EchoHandler::invoke");
79       try
80       {
81          Message msg = msgContext.getRequestMessage();
82          SOAPEnvelopeAxisImpl env = (SOAPEnvelopeAxisImpl)msg.getSOAPEnvelope();
83          msgContext.setResponseMessage(new Message(env));
84       }
85       catch (Exception JavaDoc e)
86       {
87          log.error(Messages.getMessage("exception00"), e);
88          throw AxisFault.makeFault(e);
89       }
90       log.debug("Exit: EchoHandler::invoke");
91    }
92
93    public String JavaDoc wsdlStart1 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
94            "<definitions xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n" +
95            "xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" \n" +
96            "xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\" \n" +
97            "xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" \n" +
98            "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" \n" +
99            "xmlns:s0=\"http://tempuri.org/EchoService\" \n" +
100            "targetNamespace=\"http://tempuri.org/EchoService\" \n" +
101            "xmlns=\"http://schemas.xmlsoap.org/wsdl/\">" +
102            "<message name=\"request\">" +
103            "<part name=\"content\" type=\"xsd:anyType\" />" +
104            "</message>" +
105            "<message name=\"response\">" +
106            "<part name=\"content\" element=\"xsd:anyType\" />" +
107            "</message>" +
108            "<portType name=\"EchoSoap\">" +
109            "<operation name=\"doIt\">" +
110            "<input message=\"s0:request\" /> " +
111            "<output message=\"s0:response\" /> " +
112            "</operation>" +
113            "</portType>" +
114            "<binding name=\"EchoSoap\" type=\"s0:EchoSoap\">" +
115            "<soap:binding transport=\"http://schemas.xmlsoap.org/soap/http\" style=\"document\" />" +
116            "<operation name=\"doIt\">" +
117            "<soap:operation soapAction=\"http://tempuri.org/Echo\" style=\"document\" />" +
118            "<input>" +
119            "<soap:body use=\"literal\" />" +
120            "</input>" +
121            "<output>" +
122            "<soap:body use=\"literal\" />" +
123            "</output>" +
124            "</operation>" +
125            "</binding>" +
126            "<service name=\"Echo\">" +
127            "<port name=\"EchoSoap\" binding=\"s0:EchoSoap\">" +
128            "<soap:address location=\"http://";
129
130
131    public String JavaDoc wsdlStart =
132            "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n" +
133            "<wsdl:definitions targetNamespace=\"http://handlers.apache.org/EchoService\" \n" +
134            "xmlns=\"http://schemas.xmlsoap.org/wsdl/\" \n" +
135            "xmlns:apachesoap=\"http://xml.apache.org/xml-soap\" \n" +
136            "xmlns:impl=\"http://handlers.apache.org/EchoService\" \n" +
137            "xmlns:intf=\"http://handlers.apache.org/EchoService\" \n" +
138            "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" \n" +
139            "xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" \n" +
140            "xmlns:wsdlsoap=\"http://schemas.xmlsoap.org/wsdl/soap/\" \n" +
141            "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> \n" +
142            "<wsdl:types> \n" +
143            "<schema targetNamespace=\"http://handlers.apache.org/EchoService\" \n" +
144            "xmlns=\"http://www.w3.org/2001/XMLSchema\"> \n" +
145            "<xsd:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\"/> \n" +
146            "<xsd:complexType name=\"echoElements\"> \n" +
147            " <xsd:sequence> \n" +
148            " <xsd:element name=\"content\" type=\"xsd:anyType\"/> \n" +
149            " </xsd:sequence>\n" +
150            "</xsd:complexType> \n" +
151            "<xsd:complexType name=\"echoElementsReturn\"> \n" +
152            " <xsd:sequence> \n" +
153            " <xsd:element name=\"content\" type=\"xsd:anyType\"/> \n" +
154            " </xsd:sequence> \n" +
155            "</xsd:complexType> \n" +
156            "</schema> \n" +
157            "</wsdl:types> \n" +
158            " <wsdl:message name=\"echoElementsResponse\"> \n" +
159            " <wsdl:part type=\"impl:echoElementsReturn\" name=\"echoElementsReturn\"/> \n" +
160            " </wsdl:message> \n" +
161            " <wsdl:message name=\"echoElementsRequest\"> \n" +
162            " <wsdl:part type=\"impl:echoElements\" name=\"part\"/> \n" +
163            " </wsdl:message> \n" +
164            " <wsdl:portType name=\"EchoService\"> \n" +
165            " <wsdl:operation name=\"doIt\"> \n" +
166            " <wsdl:input message=\"impl:echoElementsRequest\" name=\"echoElementsRequest\"/> \n" +
167            " <wsdl:output message=\"impl:echoElementsResponse\" name=\"echoElementsResponse\"/> \n" +
168            " </wsdl:operation> \n" +
169            " </wsdl:portType> \n" +
170            " <wsdl:binding name=\"EchoServiceSoapBinding\" type=\"impl:EchoService\"> \n" +
171            " <wsdlsoap:binding style=\"document\" transport=\"http://schemas.xmlsoap.org/soap/http\"/> \n" +
172            " <wsdl:operation name=\"doIt\"> \n" +
173            " <wsdlsoap:operation soapAction=\"\"/> \n" +
174            " <wsdl:input name=\"echoElementsRequest\"> \n" +
175            " <wsdlsoap:body namespace=\"http://handlers.apache.org/EchoService\" use=\"literal\"/> \n" +
176            " </wsdl:input> \n" +
177            " <wsdl:output name=\"echoElementsResponse\"> \n" +
178            " <wsdlsoap:body namespace=\"http://handlers.apache.org/EchoService\" use=\"literal\"/> \n" +
179            " </wsdl:output> \n" +
180            " </wsdl:operation> \n" +
181            " </wsdl:binding> \n" +
182            " <wsdl:service name=\"EchoService\"> \n" +
183            " <wsdl:port binding=\"impl:EchoServiceSoapBinding\" name=\"EchoService\"> \n" +
184            " <wsdlsoap:address location=\"";
185
186    String JavaDoc wsdlEnd = " \"/></wsdl:port>\n" +
187            "</wsdl:service>\n" +
188            "</wsdl:definitions>\n";
189
190
191    public void generateWSDL(MessageContext msgContext) throws AxisFault
192    {
193       try
194       {
195          String JavaDoc url = msgContext.getStrProp(MessageContext.TRANS_URL);
196          String JavaDoc wsdlString = wsdlStart + url + wsdlEnd;
197          Document JavaDoc doc = XMLUtils.newDocument(new StringBufferInputStream JavaDoc(wsdlString));
198          msgContext.setProperty("WSDL", doc);
199       }
200       catch (Exception JavaDoc e)
201       {
202          throw AxisFault.makeFault(e);
203       }
204    }
205 }
206
207 ;
208
Popular Tags