KickJava   Java API By Example, From Geeks To Geeks.

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


1 /*
2  * Copyright 2001-2004 The Apache Software Foundation.
3  *
4  * Licensed under the Apache License, Version 2.0 (the "License");
5  * you may not use this file except in compliance with the License.
6  * You may obtain a copy of the License at
7  *
8  * http://www.apache.org/licenses/LICENSE-2.0
9  *
10  * Unless required by applicable law or agreed to in writing, software
11  * distributed under the License is distributed on an "AS IS" BASIS,
12  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13  * See the License for the specific language governing permissions and
14  * limitations under the License.
15  */

16
17 package org.apache.axis.handlers ;
18
19 import org.apache.axis.AxisFault;
20 import org.apache.axis.Message;
21 import org.apache.axis.MessageContext;
22 import org.apache.axis.components.logger.LogFactory;
23 import org.apache.axis.message.SOAPEnvelope;
24 import org.apache.axis.utils.Messages;
25 import org.apache.axis.utils.XMLUtils;
26 import org.apache.commons.logging.Log;
27 import org.w3c.dom.Document JavaDoc;
28
29 import java.io.ByteArrayInputStream JavaDoc;
30
31 /**
32  *
33  * @author Doug Davis (dug@us.ibm.com)
34  */

35 public class EchoHandler extends BasicHandler {
36     protected static Log log =
37         LogFactory.getLog(EchoHandler.class.getName());
38
39     public void invoke(MessageContext msgContext) throws AxisFault {
40         log.debug("Enter: EchoHandler::invoke");
41         try {
42             Message msg = msgContext.getRequestMessage();
43             SOAPEnvelope env = (SOAPEnvelope) msg.getSOAPEnvelope();
44             msgContext.setResponseMessage( new Message( env ) );
45         }
46         catch( Exception JavaDoc e ) {
47             log.error( Messages.getMessage("exception00"), e );
48             throw AxisFault.makeFault(e);
49         }
50         log.debug("Exit: EchoHandler::invoke");
51     }
52
53     public String JavaDoc wsdlStart1 = "<?xml version=\"1.0\" encoding=\"utf-8\" ?>" +
54             "<definitions xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" \n" +
55             "xmlns:http=\"http://schemas.xmlsoap.org/wsdl/http/\" \n" +
56             "xmlns:mime=\"http://schemas.xmlsoap.org/wsdl/mime/\" \n" +
57             "xmlns:soap=\"http://schemas.xmlsoap.org/wsdl/soap/\" \n" +
58             "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" \n" +
59             "xmlns:s0=\"http://tempuri.org/EchoService\" \n"+
60             "targetNamespace=\"http://tempuri.org/EchoService\" \n" +
61             "xmlns=\"http://schemas.xmlsoap.org/wsdl/\">" +
62             "<message name=\"request\">" +
63             "<part name=\"content\" type=\"xsd:anyType\" />" +
64             "</message>" +
65             "<message name=\"response\">" +
66             "<part name=\"content\" element=\"xsd:anyType\" />" +
67             "</message>" +
68             "<portType name=\"EchoSoap\">" +
69             "<operation name=\"doIt\">" +
70             "<input message=\"s0:request\" /> " +
71             "<output message=\"s0:response\" /> " +
72             "</operation>" +
73             "</portType>" +
74             "<binding name=\"EchoSoap\" type=\"s0:EchoSoap\">" +
75             "<soap:binding transport=\"http://schemas.xmlsoap.org/soap/http\" style=\"document\" />" +
76             "<operation name=\"doIt\">" +
77             "<soap:operation soapAction=\"http://tempuri.org/Echo\" style=\"document\" />" +
78             "<input>" +
79             "<soap:body use=\"literal\" />" +
80             "</input>" +
81             "<output>" +
82             "<soap:body use=\"literal\" />" +
83             "</output>" +
84             "</operation>" +
85             "</binding>" +
86             "<service name=\"Echo\">" +
87             "<port name=\"EchoSoap\" binding=\"s0:EchoSoap\">" +
88             "<soap:address location=\"http://";
89
90
91     public String JavaDoc wsdlStart =
92     "<?xml version=\"1.0\" encoding=\"UTF-8\"?> \n"+
93     "<wsdl:definitions targetNamespace=\"http://handlers.apache.org/EchoService\" \n"+
94     "xmlns=\"http://schemas.xmlsoap.org/wsdl/\" \n"+
95     "xmlns:apachesoap=\"http://xml.apache.org/xml-soap\" \n"+
96     "xmlns:impl=\"http://handlers.apache.org/EchoService\" \n"+
97     "xmlns:intf=\"http://handlers.apache.org/EchoService\" \n"+
98     "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" \n"+
99     "xmlns:wsdl=\"http://schemas.xmlsoap.org/wsdl/\" \n"+
100     "xmlns:wsdlsoap=\"http://schemas.xmlsoap.org/wsdl/soap/\" \n"+
101     "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\"> \n"+
102     "<wsdl:types> \n"+
103     "<schema targetNamespace=\"http://handlers.apache.org/EchoService\" \n" +
104     "xmlns=\"http://www.w3.org/2001/XMLSchema\"> \n"+
105     "<xsd:import namespace=\"http://schemas.xmlsoap.org/soap/encoding/\"/> \n"+
106     "<xsd:complexType name=\"echoElements\"> \n" +
107     " <xsd:sequence> \n" +
108     " <xsd:element name=\"content\" type=\"xsd:anyType\"/> \n"+
109     " </xsd:sequence>\n"+
110     "</xsd:complexType> \n" +
111     "<xsd:complexType name=\"echoElementsReturn\"> \n" +
112     " <xsd:sequence> \n" +
113     " <xsd:element name=\"content\" type=\"xsd:anyType\"/> \n"+
114     " </xsd:sequence> \n" +
115     "</xsd:complexType> \n" +
116     "</schema> \n"+
117     "</wsdl:types> \n"+
118     " <wsdl:message name=\"echoElementsResponse\"> \n"+
119     " <wsdl:part type=\"impl:echoElementsReturn\" name=\"echoElementsReturn\"/> \n"+
120     " </wsdl:message> \n"+
121     " <wsdl:message name=\"echoElementsRequest\"> \n"+
122     " <wsdl:part type=\"impl:echoElements\" name=\"part\"/> \n"+
123     " </wsdl:message> \n"+
124     " <wsdl:portType name=\"EchoService\"> \n"+
125     " <wsdl:operation name=\"doIt\"> \n"+
126     " <wsdl:input message=\"impl:echoElementsRequest\" name=\"echoElementsRequest\"/> \n"+
127     " <wsdl:output message=\"impl:echoElementsResponse\" name=\"echoElementsResponse\"/> \n"+
128     " </wsdl:operation> \n"+
129     " </wsdl:portType> \n"+
130     " <wsdl:binding name=\"EchoServiceSoapBinding\" type=\"impl:EchoService\"> \n"+
131     " <wsdlsoap:binding style=\"document\" transport=\"http://schemas.xmlsoap.org/soap/http\"/> \n"+
132     " <wsdl:operation name=\"doIt\"> \n"+
133     " <wsdlsoap:operation soapAction=\"\"/> \n"+
134     " <wsdl:input name=\"echoElementsRequest\"> \n"+
135     " <wsdlsoap:body namespace=\"http://handlers.apache.org/EchoService\" use=\"literal\"/> \n"+
136     " </wsdl:input> \n"+
137     " <wsdl:output name=\"echoElementsResponse\"> \n"+
138     " <wsdlsoap:body namespace=\"http://handlers.apache.org/EchoService\" use=\"literal\"/> \n"+
139     " </wsdl:output> \n"+
140     " </wsdl:operation> \n"+
141     " </wsdl:binding> \n"+
142     " <wsdl:service name=\"EchoService\"> \n"+
143     " <wsdl:port binding=\"impl:EchoServiceSoapBinding\" name=\"EchoService\"> \n"+
144     " <wsdlsoap:address location=\"";
145           
146         String JavaDoc wsdlEnd = " \"/></wsdl:port>\n" +
147                           "</wsdl:service>\n" +
148                           "</wsdl:definitions>\n";
149
150
151     public void generateWSDL(MessageContext msgContext) throws AxisFault {
152         try {
153             String JavaDoc url = msgContext.getStrProp(MessageContext.TRANS_URL);
154             String JavaDoc wsdlString = wsdlStart + url + wsdlEnd;
155             Document JavaDoc doc = XMLUtils.newDocument(new ByteArrayInputStream JavaDoc(wsdlString.getBytes("UTF-8")));
156             msgContext.setProperty("WSDL", doc);
157         } catch (Exception JavaDoc e) {
158             throw AxisFault.makeFault(e);
159         }
160     }
161 };
162
Popular Tags