KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > apache > geronimo > axis > AxisWebServiceContainerTest


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

17 package org.apache.geronimo.axis;
18
19 import java.io.IOException JavaDoc;
20 import java.io.InputStream JavaDoc;
21 import java.io.ByteArrayOutputStream JavaDoc;
22
23 import java.net.URI JavaDoc;
24
25 import java.util.Collections JavaDoc;
26 import java.util.HashMap JavaDoc;
27 import java.util.Map JavaDoc;
28
29 import javax.xml.namespace.QName JavaDoc;
30
31 import org.apache.axis.constants.Style;
32 import org.apache.axis.constants.Use;
33 import org.apache.axis.description.JavaServiceDesc;
34 import org.apache.axis.description.OperationDesc;
35 import org.apache.axis.description.ParameterDesc;
36 import org.apache.axis.encoding.TypeMapping;
37 import org.apache.axis.encoding.TypeMappingRegistryImpl;
38 import org.apache.axis.handlers.soap.SOAPService;
39 import org.apache.axis.providers.java.RPCProvider;
40
41 import org.apache.geronimo.axis.server.AxisWebServiceContainer;
42 import org.apache.geronimo.axis.server.POJOProvider;
43 import org.apache.geronimo.axis.server.ReadOnlyServiceDesc;
44 import org.apache.geronimo.axis.testData.echosample.EchoBean;
45 import org.apache.geronimo.webservices.WebServiceContainer;
46
47 /**
48  *
49  * @version $Rev: 476049 $ $Date: 2006-11-16 23:35:17 -0500 (Thu, 16 Nov 2006) $
50  */

51 public class AxisWebServiceContainerTest extends AbstractTestCase {
52     public AxisWebServiceContainerTest(String JavaDoc testName) {
53         super(testName);
54     }
55
56     public void testInvokeSOAP() throws Exception JavaDoc {
57
58         ClassLoader JavaDoc cl = Thread.currentThread().getContextClassLoader();
59         JavaServiceDesc serviceDesc = new JavaServiceDesc();
60         serviceDesc.setEndpointURL("http://127.0.0.1:8080/axis/services/echo");
61         //serviceDesc.setWSDLFile(portInfo.getWsdlURL().toExternalForm());
62
serviceDesc.setStyle(Style.RPC);
63         serviceDesc.setUse(Use.ENCODED);
64
65         TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();
66         tmr.doRegisterFromVersion("1.3");
67         TypeMapping typeMapping = tmr.getOrMakeTypeMapping(serviceDesc.getUse().getEncoding());
68
69         serviceDesc.setTypeMappingRegistry(tmr);
70         serviceDesc.setTypeMapping(typeMapping);
71
72         OperationDesc op = new OperationDesc();
73         op.setName("echoString");
74         op.setStyle(Style.RPC);
75         op.setUse(Use.ENCODED);
76         Class JavaDoc beanClass = EchoBean.class;
77         op.setMethod(beanClass.getMethod("echoString", new Class JavaDoc[] { String JavaDoc.class }));
78         ParameterDesc parameter =
79             new ParameterDesc(
80                 new QName JavaDoc("http://ws.apache.org/echosample", "in0"),
81                 ParameterDesc.IN,
82                 typeMapping.getTypeQName(String JavaDoc.class),
83                 String JavaDoc.class,
84                 false,
85                 false);
86         op.addParameter(parameter);
87         serviceDesc.addOperationDesc(op);
88
89         serviceDesc.getOperations();
90         ReadOnlyServiceDesc sd = new ReadOnlyServiceDesc(serviceDesc, Collections.EMPTY_LIST);
91
92         Class JavaDoc pojoClass = cl.loadClass("org.apache.geronimo.axis.testData.echosample.EchoBean");
93
94         RPCProvider provider = new POJOProvider();
95         SOAPService service = new SOAPService(null, provider, null);
96         service.setServiceDescription(sd);
97         service.setOption("className","org.apache.geronimo.axis.testData.echosample.EchoBean");
98         URI JavaDoc wsdlURL = new URI JavaDoc("echo.wsdl");
99         URI JavaDoc location = new URI JavaDoc(serviceDesc.getEndpointURL());
100         Map JavaDoc wsdlMap = new HashMap JavaDoc();
101
102         AxisWebServiceContainer container =
103             new AxisWebServiceContainer(location, wsdlURL, service, wsdlMap, cl);
104
105         InputStream JavaDoc in = cl.getResourceAsStream("echoString-req.txt");
106
107         try {
108             AxisRequest req =
109                 new AxisRequest(
110                     504,
111                     "text/xml; charset=utf-8",
112                     in,
113                     0,
114                     new HashMap JavaDoc(),
115                     location,
116                     new HashMap JavaDoc());
117             
118             ByteArrayOutputStream JavaDoc out = new ByteArrayOutputStream JavaDoc();
119             AxisResponse res = new AxisResponse("text/xml; charset=utf-8", "127.0.0.1", null, null, 8080, out);
120             req.setAttribute(WebServiceContainer.POJO_INSTANCE, pojoClass.newInstance());
121             container.invoke(req, res);
122             
123             out.flush();
124             log.debug(new String JavaDoc(out.toByteArray()));
125         } finally {
126             if (in != null) {
127                 try {
128                     in.close();
129                 } catch (IOException JavaDoc ignore) {
130                     // ignore
131
}
132             }
133         }
134     }
135
136     protected void setUp() throws Exception JavaDoc {
137     }
138
139     protected void tearDown() throws Exception JavaDoc {
140     }
141
142 }
143
Popular Tags