1 package test.outparams2; 2 3 import junit.framework.TestCase; 4 5 import org.apache.axis.EngineConfiguration; 6 import org.apache.axis.Message; 7 import org.apache.axis.client.Call; 8 import org.apache.axis.client.Service; 9 import org.apache.axis.description.ServiceDesc; 10 import org.apache.axis.description.OperationDesc; 11 import org.apache.axis.description.ParameterDesc; 12 import org.apache.axis.configuration.DefaultEngineConfigurationFactory; 13 import org.apache.axis.configuration.SimpleProvider; 14 import org.apache.axis.handlers.soap.SOAPService; 15 import org.apache.axis.message.SOAPEnvelope; 16 import org.apache.axis.providers.java.RPCProvider; 17 import org.apache.axis.server.AxisServer; 18 import org.apache.axis.transport.local.LocalTransport; 19 20 import javax.xml.rpc.holders.StringHolder ; 21 import javax.xml.namespace.QName ; 22 23 public class TestOutParams extends TestCase { 24 25 26 private final String message = 27 "<?xml version=\"1.0\"?>\n" + 28 "<soapenv:Envelope " + 29 "xmlns:soapenv=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 30 "xmlns:xsd=\"http://www.w3.org/2001/XMLSchema\" " + 31 "xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\">" + 32 "<soapenv:Body>\n" + 33 "<ns1:serviceMethod soapenv:encodingStyle=\"http://schemas.xmlsoap.org/soap/encoding/\" " + 34 "xmlns:ns1=\"outParamsTest\"> </ns1:serviceMethod>\n" + 35 "</soapenv:Body></soapenv:Envelope>\n"; 36 37 private Service s_service = null ; 38 private Call client = null ; 39 private SimpleProvider provider = new SimpleProvider(); 40 private AxisServer server = new AxisServer(provider); 41 42 private static boolean called = false; 43 44 public TestOutParams(String name) { 45 super(name); 46 server.init(); 47 } 48 49 public TestOutParams() { 50 super("Test Out Params"); 51 } 52 53 public void testOutputParams() throws Exception { 54 s_service = new Service(); 56 client = (Call) s_service.createCall(); 57 58 SOAPService service = new SOAPService(null, 59 new RPCProvider(), 60 null); 61 service.setName("TestOutParamsService"); 62 service.setOption("className", "test.outparams2.TestOutParams"); 63 service.setOption("allowedMethods", "serviceMethod"); 64 65 EngineConfiguration defaultConfig = 66 (new DefaultEngineConfigurationFactory()).getServerEngineConfig(); 67 SimpleProvider config = new SimpleProvider(defaultConfig); 68 config.deployService("outParamsTest", service); 69 provider.deployService("outParamsTest", service); 70 71 client.setTransport(new LocalTransport(server)); 73 74 Message msg = new Message(message, false); 75 SOAPEnvelope env = msg.getSOAPEnvelope(); 76 77 client.invoke(env); 79 80 assertTrue(called); 82 83 ServiceDesc description = null; 84 OperationDesc operation = null; 85 ParameterDesc parameter = null; 86 87 description = service.getServiceDescription(); 88 operation = description.getOperationByName("serviceMethod"); 89 parameter = operation.getParamByQName(new QName ("", "out1")); 90 91 assertEquals(ParameterDesc.INOUT, parameter.getMode()); 92 93 parameter.setMode(ParameterDesc.OUT); 95 96 called = false; 98 99 client.invoke(env); 101 assertTrue(this.called); 102 } 103 104 public void serviceMethod(String in1, StringHolder out1) { 105 called = true; 106 } 107 108 public static void main(String args[]) 109 { 110 try { 111 TestOutParams tester = new TestOutParams("OutParams Test"); 112 tester.testOutputParams(); 113 } catch (Exception e) { 114 e.printStackTrace(); 115 } 116 } 117 } 118 | Popular Tags |