1 package test.outparams; 2 3 import junit.framework.TestCase; 4 import org.apache.axis.Constants; 5 import org.apache.axis.Handler; 6 import org.apache.axis.Message; 7 import org.apache.axis.MessageContext; 8 import org.apache.axis.client.Call; 9 import org.apache.axis.client.Service; 10 import org.apache.axis.configuration.SimpleProvider; 11 import org.apache.axis.encoding.XMLType; 12 import org.apache.axis.handlers.soap.SOAPService; 13 import org.apache.axis.message.SOAPEnvelope; 14 import org.apache.axis.server.AxisServer; 15 import org.apache.axis.transport.local.LocalTransport; 16 17 import javax.xml.namespace.QName ; 18 import java.util.Map ; 19 20 25 public class TestOutParams extends TestCase { 26 private final String serviceURN = "urn:X-test-outparams"; 27 28 29 30 private final String message = 31 "<?xml version=\"1.0\"?>\n" + 32 "<soap:Envelope " + 33 "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 34 "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" " + 35 "xmlns:xsi=\"" + Constants.URI_DEFAULT_SCHEMA_XSI + "\" " + 36 "xmlns:xsd=\"" + Constants.URI_DEFAULT_SCHEMA_XSD + "\">\n" + 37 "<soap:Body>\n" + 38 "<ns:someMethod xmlns:ns=\"" + serviceURN + "\"/>\n" + 39 "</soap:Body>\n" + 40 "</soap:Envelope>\n"; 41 42 private Service s_service = null ; 43 private Call client = null ; 44 private SimpleProvider provider = new SimpleProvider(); 45 private AxisServer server = new AxisServer(provider); 46 47 public TestOutParams(String name) { 48 super(name); 49 server.init(); 50 } 51 52 55 public void testOutputParams() throws Exception { 56 Handler h = new ServiceHandler(); 58 s_service = new Service(); 59 client = (Call) s_service.createCall(); 60 61 63 SOAPService service = new SOAPService(h); 64 provider.deployService(serviceURN, service); 65 66 client.setTransport(new LocalTransport(server)); 68 69 MessageContext msgContext = new MessageContext(server); 71 72 SOAPEnvelope envelope = new SOAPEnvelope(); 74 msgContext.setRequestMessage(new Message(envelope)); 75 76 client.addParameter( 77 new QName ("", "string"), 78 XMLType.XSD_STRING, 79 javax.xml.rpc.ParameterMode.IN); 80 client.addParameter( 81 new QName ("", "out1"), 82 XMLType.XSD_STRING, 83 javax.xml.rpc.ParameterMode.OUT); 84 client.addParameter( 85 new QName ("", "out2"), 86 XMLType.XSD_FLOAT, 87 javax.xml.rpc.ParameterMode.OUT); 88 client.setReturnType(XMLType.XSD_INT); 89 Object ret = client.invoke(serviceURN, "method", 91 new Object [] { "test" }); 92 93 Map outParams = client.getOutputParams(); 94 assertNotNull("No output Params returned!", outParams); 95 96 Object param = outParams.get(new QName (null, "out1")); 97 assertEquals("Param out1 does not equal expected value", ServiceHandler.OUTPARAM1, param); 98 99 param = outParams.get(new QName (null, "out2")); 100 assertEquals("Param out2 does not equal expected value", ServiceHandler.OUTPARAM2, param); 101 102 assertEquals("Return value does not equal expected value", ((Integer )ret).intValue(), ServiceHandler.RESPONSE.intValue()); 103 } 104 105 public static void main(String args[]) 106 { 107 try { 108 TestOutParams tester = new TestOutParams("RPC test"); 109 tester.testOutputParams(); 110 } catch (Exception e) { 111 e.printStackTrace(); 112 } 113 } 114 } 115 | Popular Tags |