File: TestOutParams.java

package info (click to toggle)
axis 1.4-29
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 52,100 kB
  • sloc: java: 129,124; xml: 10,602; jsp: 983; sh: 84; cs: 36; makefile: 18
file content (114 lines) | stat: -rw-r--r-- 4,006 bytes parent folder | download | duplicates (10)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
package test.outparams;

import junit.framework.TestCase;
import org.apache.axis.Constants;
import org.apache.axis.Handler;
import org.apache.axis.Message;
import org.apache.axis.MessageContext;
import org.apache.axis.client.Call;
import org.apache.axis.client.Service;
import org.apache.axis.configuration.SimpleProvider;
import org.apache.axis.encoding.XMLType;
import org.apache.axis.handlers.soap.SOAPService;
import org.apache.axis.message.SOAPEnvelope;
import org.apache.axis.server.AxisServer;
import org.apache.axis.transport.local.LocalTransport;

import javax.xml.namespace.QName;
import java.util.Map;

/**
 * Test org.apache.axis.handlers.RPCDispatcher
 *
 * @author Sam Ruby <rubys@us.ibm.com>
 */
public class TestOutParams extends TestCase {
    private final String serviceURN = "urn:X-test-outparams";


    /** A fixed message, since the return is hardcoded */
    private final String message =
        "<?xml version=\"1.0\"?>\n" +
        "<soap:Envelope " +
             "xmlns:soap=\"http://schemas.xmlsoap.org/soap/envelope/\" " +
             "xmlns:soapenc=\"http://schemas.xmlsoap.org/soap/encoding/\" " +
             "xmlns:xsi=\"" + Constants.URI_DEFAULT_SCHEMA_XSI + "\" " +
             "xmlns:xsd=\"" + Constants.URI_DEFAULT_SCHEMA_XSD + "\">\n" +
             "<soap:Body>\n" +
             "<ns:someMethod xmlns:ns=\"" + serviceURN + "\"/>\n" +
             "</soap:Body>\n" +
        "</soap:Envelope>\n";

    private Service s_service = null ;
    private Call    client    = null ;
    private SimpleProvider provider = new SimpleProvider();
    private AxisServer server = new AxisServer(provider);

    public TestOutParams(String name) {
        super(name);
        server.init();
    }

    /**
     * Test returning output params
     */
    public void testOutputParams() throws Exception {
        // Register the service
        Handler h = new ServiceHandler();
        s_service = new Service();
        client  = (Call) s_service.createCall();

        // ??? Do we need to register the handler?

        SOAPService service = new SOAPService(h);
        provider.deployService(serviceURN, service);

        // Make sure the local transport uses the server we just configured
        client.setTransport(new LocalTransport(server));

        // Create the message context
        MessageContext msgContext = new MessageContext(server);

        // Construct the soap request
        SOAPEnvelope envelope = new SOAPEnvelope();
        msgContext.setRequestMessage(new Message(envelope));

        client.addParameter(
                new QName("", "string"),
                XMLType.XSD_STRING,
                javax.xml.rpc.ParameterMode.IN);
        client.addParameter(
                new QName("", "out1"),
                XMLType.XSD_STRING,
                javax.xml.rpc.ParameterMode.OUT);
        client.addParameter(
                new QName("", "out2"),
                XMLType.XSD_FLOAT,
                javax.xml.rpc.ParameterMode.OUT);
        client.setReturnType(XMLType.XSD_INT);
        // Invoke the Axis server
        Object ret = client.invoke(serviceURN, "method",
                                new Object [] { "test" });

        Map outParams = client.getOutputParams();
        assertNotNull("No output Params returned!", outParams);

        Object param = outParams.get(new QName(null, "out1"));
        assertEquals("Param out1 does not equal expected value", ServiceHandler.OUTPARAM1, param);

        param = outParams.get(new QName(null, "out2"));
        assertEquals("Param out2 does not equal expected value", ServiceHandler.OUTPARAM2, param);

        assertEquals("Return value does not equal expected value", ((Integer)ret).intValue(), ServiceHandler.RESPONSE.intValue());
    }

    public static void main(String args[])
    {
      try {
        TestOutParams tester = new TestOutParams("RPC test");
        tester.testOutputParams();
      } catch (Exception e) {
        e.printStackTrace();
      }
    }
}