001: /*
002: * Licensed to the Apache Software Foundation (ASF) under one or more
003: * contributor license agreements. See the NOTICE file distributed with
004: * this work for additional information regarding copyright ownership.
005: * The ASF licenses this file to You under the Apache License, Version 2.0
006: * (the "License"); you may not use this file except in compliance with
007: * the License. You may obtain a copy of the License at
008: *
009: * http://www.apache.org/licenses/LICENSE-2.0
010: *
011: * Unless required by applicable law or agreed to in writing, software
012: * distributed under the License is distributed on an "AS IS" BASIS,
013: * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
014: * See the License for the specific language governing permissions and
015: * limitations under the License.
016: */
017: package org.apache.geronimo.axis;
018:
019: import java.io.IOException;
020: import java.io.InputStream;
021: import java.io.ByteArrayOutputStream;
022:
023: import java.net.URI;
024:
025: import java.util.Collections;
026: import java.util.HashMap;
027: import java.util.Map;
028:
029: import javax.xml.namespace.QName;
030:
031: import org.apache.axis.constants.Style;
032: import org.apache.axis.constants.Use;
033: import org.apache.axis.description.JavaServiceDesc;
034: import org.apache.axis.description.OperationDesc;
035: import org.apache.axis.description.ParameterDesc;
036: import org.apache.axis.encoding.TypeMapping;
037: import org.apache.axis.encoding.TypeMappingRegistryImpl;
038: import org.apache.axis.handlers.soap.SOAPService;
039: import org.apache.axis.providers.java.RPCProvider;
040:
041: import org.apache.geronimo.axis.server.AxisWebServiceContainer;
042: import org.apache.geronimo.axis.server.POJOProvider;
043: import org.apache.geronimo.axis.server.ReadOnlyServiceDesc;
044: import org.apache.geronimo.axis.testData.echosample.EchoBean;
045: import org.apache.geronimo.webservices.WebServiceContainer;
046:
047: /**
048: *
049: * @version $Rev: 496024 $ $Date: 2007-01-13 18:59:40 -0800 (Sat, 13 Jan 2007) $
050: */
051: public class AxisWebServiceContainerTest extends AbstractTestCase {
052: public AxisWebServiceContainerTest(String testName) {
053: super (testName);
054: }
055:
056: public void testInvokeSOAP() throws Exception {
057:
058: ClassLoader cl = Thread.currentThread().getContextClassLoader();
059: JavaServiceDesc serviceDesc = new JavaServiceDesc();
060: serviceDesc
061: .setEndpointURL("http://127.0.0.1:8080/axis/services/echo");
062: //serviceDesc.setWSDLFile(portInfo.getWsdlURL().toExternalForm());
063: serviceDesc.setStyle(Style.RPC);
064: serviceDesc.setUse(Use.ENCODED);
065:
066: TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();
067: tmr.doRegisterFromVersion("1.3");
068: TypeMapping typeMapping = tmr.getOrMakeTypeMapping(serviceDesc
069: .getUse().getEncoding());
070:
071: serviceDesc.setTypeMappingRegistry(tmr);
072: serviceDesc.setTypeMapping(typeMapping);
073:
074: OperationDesc op = new OperationDesc();
075: op.setName("echoString");
076: op.setStyle(Style.RPC);
077: op.setUse(Use.ENCODED);
078: Class beanClass = EchoBean.class;
079: op.setMethod(beanClass.getMethod("echoString",
080: new Class[] { String.class }));
081: ParameterDesc parameter = new ParameterDesc(new QName(
082: "http://ws.apache.org/echosample", "in0"),
083: ParameterDesc.IN, typeMapping
084: .getTypeQName(String.class), String.class,
085: false, false);
086: op.addParameter(parameter);
087: serviceDesc.addOperationDesc(op);
088:
089: serviceDesc.getOperations();
090: ReadOnlyServiceDesc sd = new ReadOnlyServiceDesc(serviceDesc,
091: Collections.EMPTY_LIST);
092:
093: Class pojoClass = cl
094: .loadClass("org.apache.geronimo.axis.testData.echosample.EchoBean");
095:
096: RPCProvider provider = new POJOProvider();
097: SOAPService service = new SOAPService(null, provider, null);
098: service.setServiceDescription(sd);
099: service
100: .setOption("className",
101: "org.apache.geronimo.axis.testData.echosample.EchoBean");
102: URI wsdlURL = new URI("echo.wsdl");
103: URI location = new URI(serviceDesc.getEndpointURL());
104: Map wsdlMap = new HashMap();
105:
106: AxisWebServiceContainer container = new AxisWebServiceContainer(
107: location, wsdlURL, service, wsdlMap, cl);
108:
109: InputStream in = cl.getResourceAsStream("echoString-req.txt");
110:
111: try {
112: AxisRequest req = new AxisRequest(504,
113: "text/xml; charset=utf-8", in, 0, new HashMap(),
114: location, new HashMap(), "127.0.0.1");
115:
116: ByteArrayOutputStream out = new ByteArrayOutputStream();
117: AxisResponse res = new AxisResponse(
118: "text/xml; charset=utf-8", "127.0.0.1", null, null,
119: 8080, out);
120: req.setAttribute(WebServiceContainer.POJO_INSTANCE,
121: pojoClass.newInstance());
122: container.invoke(req, res);
123:
124: out.flush();
125: log.debug(new String(out.toByteArray()));
126: } finally {
127: if (in != null) {
128: try {
129: in.close();
130: } catch (IOException ignore) {
131: // ignore
132: }
133: }
134: }
135: }
136:
137: protected void setUp() throws Exception {
138: }
139:
140: protected void tearDown() throws Exception {
141: }
142:
143: }
|