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.openejb.server.axis;
018:
019: import org.apache.axis.constants.Style;
020: import org.apache.axis.constants.Use;
021: import org.apache.axis.description.JavaServiceDesc;
022: import org.apache.axis.description.OperationDesc;
023: import org.apache.axis.description.ParameterDesc;
024: import org.apache.axis.encoding.TypeMapping;
025: import org.apache.axis.encoding.TypeMappingRegistryImpl;
026: import org.apache.axis.handlers.soap.SOAPService;
027: import org.apache.axis.providers.java.RPCProvider;
028: import org.apache.openejb.server.httpd.HttpRequest;
029: import org.apache.openejb.server.webservices.WsConstants;
030:
031: import javax.xml.namespace.QName;
032: import java.io.ByteArrayOutputStream;
033: import java.io.IOException;
034: import java.io.InputStream;
035: import java.net.URI;
036: import java.net.URL;
037: import java.util.HashMap;
038: import java.util.Map;
039:
040: public class AxisWsContainerTest extends AbstractTestCase {
041: public AxisWsContainerTest(String testName) {
042: super (testName);
043: }
044:
045: public void testInvokeSOAP() throws Exception {
046:
047: ClassLoader cl = Thread.currentThread().getContextClassLoader();
048: JavaServiceDesc serviceDesc = new JavaServiceDesc();
049: serviceDesc
050: .setEndpointURL("http://127.0.0.1:8080/axis/services/echo");
051: //serviceDesc.setWSDLFile(portInfo.getWsdlURL().toExternalForm());
052: serviceDesc.setStyle(Style.RPC);
053: serviceDesc.setUse(Use.ENCODED);
054:
055: TypeMappingRegistryImpl tmr = new TypeMappingRegistryImpl();
056: tmr.doRegisterFromVersion("1.3");
057: TypeMapping typeMapping = tmr.getOrMakeTypeMapping(serviceDesc
058: .getUse().getEncoding());
059:
060: serviceDesc.setTypeMappingRegistry(tmr);
061: serviceDesc.setTypeMapping(typeMapping);
062:
063: OperationDesc op = new OperationDesc();
064: op.setName("echoString");
065: op.setStyle(Style.RPC);
066: op.setUse(Use.ENCODED);
067: Class beanClass = EchoBean.class;
068: op.setMethod(beanClass.getMethod("echoString", String.class));
069: ParameterDesc parameter = new ParameterDesc(new QName(
070: "http://ws.apache.org/echosample", "in0"),
071: ParameterDesc.IN, typeMapping
072: .getTypeQName(String.class), String.class,
073: false, false);
074: op.addParameter(parameter);
075: serviceDesc.addOperationDesc(op);
076:
077: serviceDesc.getOperations();
078: ReadOnlyServiceDesc sd = new ReadOnlyServiceDesc(serviceDesc);
079:
080: Class pojoClass = cl
081: .loadClass("org.apache.openejb.server.axis.EchoBean");
082:
083: RPCProvider provider = new PojoProvider();
084: SOAPService service = new SOAPService(null, provider, null);
085: service.setServiceDescription(sd);
086: service.setOption("className",
087: "org.apache.openejb.server.axis.EchoBean");
088: URL wsdlURL = new URL("http://fake/echo.wsdl");
089: URI location = new URI(serviceDesc.getEndpointURL());
090: Map wsdlMap = new HashMap();
091:
092: AxisWsContainer container = new AxisWsContainer(wsdlURL,
093: service, wsdlMap, cl);
094:
095: InputStream in = cl.getResourceAsStream("echoString-req.txt");
096:
097: try {
098: AxisRequest req = new AxisRequest(504,
099: "text/xml; charset=utf-8", in,
100: HttpRequest.Method.GET,
101: new HashMap<String, String>(), location,
102: new HashMap<String, String>(), "127.0.0.1");
103:
104: ByteArrayOutputStream out = new ByteArrayOutputStream();
105: AxisResponse res = new AxisResponse(
106: "text/xml; charset=utf-8", "127.0.0.1", null, null,
107: 8080, out);
108: req.setAttribute(WsConstants.POJO_INSTANCE, pojoClass
109: .newInstance());
110: container.onMessage(req, res);
111:
112: out.flush();
113: // log.debug(new String(out.toByteArray()));
114: } finally {
115: if (in != null) {
116: try {
117: in.close();
118: } catch (IOException ignore) {
119: // ignore
120: }
121: }
122: }
123: }
124: }
|