1 17 package org.apache.geronimo.axis; 18 19 import java.io.IOException ; 20 import java.io.InputStream ; 21 import java.io.ByteArrayOutputStream ; 22 23 import java.net.URI ; 24 25 import java.util.Collections ; 26 import java.util.HashMap ; 27 import java.util.Map ; 28 29 import javax.xml.namespace.QName ; 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 51 public class AxisWebServiceContainerTest extends AbstractTestCase { 52 public AxisWebServiceContainerTest(String testName) { 53 super(testName); 54 } 55 56 public void testInvokeSOAP() throws Exception { 57 58 ClassLoader cl = Thread.currentThread().getContextClassLoader(); 59 JavaServiceDesc serviceDesc = new JavaServiceDesc(); 60 serviceDesc.setEndpointURL("http://127.0.0.1:8080/axis/services/echo"); 61 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 beanClass = EchoBean.class; 77 op.setMethod(beanClass.getMethod("echoString", new Class [] { String .class })); 78 ParameterDesc parameter = 79 new ParameterDesc( 80 new QName ("http://ws.apache.org/echosample", "in0"), 81 ParameterDesc.IN, 82 typeMapping.getTypeQName(String .class), 83 String .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 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 wsdlURL = new URI ("echo.wsdl"); 99 URI location = new URI (serviceDesc.getEndpointURL()); 100 Map wsdlMap = new HashMap (); 101 102 AxisWebServiceContainer container = 103 new AxisWebServiceContainer(location, wsdlURL, service, wsdlMap, cl); 104 105 InputStream 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 (), 115 location, 116 new HashMap ()); 117 118 ByteArrayOutputStream out = new ByteArrayOutputStream (); 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 (out.toByteArray())); 125 } finally { 126 if (in != null) { 127 try { 128 in.close(); 129 } catch (IOException ignore) { 130 } 132 } 133 } 134 } 135 136 protected void setUp() throws Exception { 137 } 138 139 protected void tearDown() throws Exception { 140 } 141 142 } 143 | Popular Tags |