1 16 17 package test.encoding; 18 19 import junit.framework.TestCase; 20 import org.apache.axis.Constants; 21 import org.apache.axis.Message; 22 import org.apache.axis.MessageContext; 23 import org.apache.axis.client.Call; 24 import org.apache.axis.client.Service; 25 import org.apache.axis.configuration.BasicServerConfig; 26 import org.apache.axis.description.OperationDesc; 27 import org.apache.axis.description.ParameterDesc; 28 import org.apache.axis.description.ServiceDesc; 29 import org.apache.axis.handlers.soap.SOAPService; 30 import org.apache.axis.message.RPCElement; 31 import org.apache.axis.message.RPCParam; 32 import org.apache.axis.message.SOAPEnvelope; 33 import org.apache.axis.providers.java.RPCProvider; 34 import org.apache.axis.server.AxisServer; 35 import org.apache.axis.transport.local.LocalTransport; 36 37 import javax.xml.namespace.QName ; 38 39 45 public class TestOmittedValues extends TestCase { 46 String header = 47 "<?xml version=\"1.0\"?>\n" + 48 "<soap:Envelope " + 49 "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + 50 "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" " + 51 "xmlns:me=\"urn:me\" " + 52 "xmlns:xsi=\"" + Constants.URI_2001_SCHEMA_XSI + "\" " + 53 "xmlns:xsd=\"" + Constants.URI_2001_SCHEMA_XSD + "\">\n" + 54 "<soap:Body>\n" + 55 "<method>\n"; 56 57 String missingParam2 = 58 " <param1 xsi:type=\"xsd:string\">One</param1>\n" + 59 " <param3 xsi:type=\"xsd:string\">Three</param3>\n"; 60 61 String footer = 62 "</method>\n" + 63 "</soap:Body>\n" + 64 "</soap:Envelope>\n"; 65 66 public TestOmittedValues(String s) { 67 super(s); 68 } 69 70 public TestOmittedValues() { 71 super("service version"); 72 } 73 74 public void testOmittedValue() throws Exception { 75 BasicServerConfig config = new BasicServerConfig(); 77 AxisServer server = new AxisServer(config); 78 79 SOAPService service = new SOAPService(new RPCProvider()); 80 service.setOption("className", "test.encoding.TestOmittedValues"); 81 service.setOption("allowedMethods", "*"); 82 83 ServiceDesc desc = service.getServiceDescription(); 84 ParameterDesc [] params = new ParameterDesc [] { 87 new ParameterDesc(new QName ("", "param1"), ParameterDesc.IN, null), 88 new ParameterDesc(new QName ("", "param2"), ParameterDesc.IN, null), 89 new ParameterDesc(new QName ("", "param3"), ParameterDesc.IN, null), 90 }; 91 OperationDesc oper = new OperationDesc("method", params, null); 92 desc.addOperationDesc(oper); 93 config.deployService("testOmittedValue", service); 94 95 String msg = header + missingParam2 + footer; 96 Message message = new Message(msg); 97 MessageContext context = new MessageContext(server); 98 context.setRequestMessage(message); 99 100 Call call = new Call(new Service()); 101 102 LocalTransport transport = new LocalTransport(server); 103 transport.setRemoteService("testOmittedValue"); 104 105 call.setTransport(transport); 106 107 SOAPEnvelope resEnv = call.invoke(message.getSOAPEnvelope()); 108 RPCElement rpcElem = (RPCElement)resEnv.getFirstBody(); 109 RPCParam param = (RPCParam)rpcElem.getParams().get(0); 110 assertEquals("OK!", param.getObjectValue()); 111 } 112 113 public String method(String p1, String p2, String p3) { 115 if (p1.equals("One") && p2 == null && p3.equals("Three")) { 116 return "OK!"; 117 } 118 return "Bad arguments!"; 119 } 120 } 121 | Popular Tags |