Debian Codegraph @

test/encoding/TestBody.java

raw
1 package test.encoding;
2
3 import junit.framework.TestCase;
4 import org.apache.axis.AxisEngine;
5 import org.apache.axis.Message;
6 import org.apache.axis.MessageContext;
7 import org.apache.axis.configuration.SimpleProvider;
8 import org.apache.axis.handlers.soap.SOAPService;
9 import org.apache.axis.message.RPCElement;
10 import org.apache.axis.message.SOAPEnvelope;
11 import org.apache.axis.providers.java.JavaProvider;
12 import org.apache.axis.providers.java.RPCProvider;
13 import org.apache.axis.server.AxisServer;
14
15 import javax.xml.namespace.QName;
16
17 /**
18 * Verify that deserialization actually can cause the soap service
19 * to be set...
20 */
21 public class TestBody extends TestCase {
22
23 public TestBody(String name) {
24 super(name);
25 }
26
27 private String namespace = "http://xml.apache.org/axis/TestBody";
28
29 private String request = "<?xml version=\"1.0\"?>\n" + "<soap:Envelope " + "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " + "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\">" + "<soap:Body>\n" + "<method xmlns=\"" + namespace + "\">\n" + "<arg>5</arg>" + "</method>\n" + "</soap:Body>\n" + "</soap:Envelope>\n";
30
31 public void testBodyNamespace() throws Exception {
32 SimpleProvider provider = new SimpleProvider();
33
34 // register the service with the engine
35 SOAPService target = new SOAPService(new RPCProvider());
36 target.setOption(JavaProvider.OPTION_CLASSNAME, "test.encoding.TestBody");
37 provider.deployService(new QName(null,namespace), target);
38
39 // setup
40 AxisEngine engine = new AxisServer(provider);
41 engine.init();
42
43 // create a message in context
44 MessageContext msgContext = new MessageContext(engine);
45 Message message = new Message(request);
46 message.setMessageContext(msgContext);
47
48 // ensure that the message is parsed
49 SOAPEnvelope envelope = message.getSOAPEnvelope();
50 RPCElement body = (RPCElement) envelope.getFirstBody();
51
52 // This is not necessarily true anymore...
53 //assertEquals("Namespace does not equal the message context target service.", namespace, msgContext.getTargetService());
54
55 // verify the service is set
56 assertEquals("The target is not the same as the message context service handler", target, msgContext.getService());
57 }
58
59 public static void main(String[] args) throws Exception {
60 TestBody tester = new TestBody("test");
61 tester.testBodyNamespace();
62 }
63 }