FileDocCategorySizeDatePackage
TestXsiType.javaAPI DocApache Axis 1.44051Sat Apr 22 18:57:28 BST 2006test.encoding

TestXsiType

public class TestXsiType extends TestCase
Verify that shutting off xsi:types in the Message Context works as expected.

Fields Summary
private org.apache.axis.configuration.SimpleProvider
provider
private org.apache.axis.server.AxisServer
server
Constructors Summary
public TestXsiType()

    
     
    
        super("testing");
    
public TestXsiType(String name)

        super(name);
    
Methods Summary
public static voidmain(java.lang.String[] args)

        TestXsiType tester = new TestXsiType("test");
        tester.testNoXsiTypes();
        tester.testTypelessDeserialization();
    
public doubleserviceMethod()
A method for our service, returning a double.

        return 3.14159;
    
public voidtestNoXsiTypes()
Trivial test just to make sure there aren't xsi:type attributes

        MessageContext msgContext = new MessageContext(server);

        // Don't serialize xsi:type attributes
        msgContext.setProperty(Call.SEND_TYPE_ATTR, "false" );

        SOAPEnvelope msg = new SOAPEnvelope();
        RPCParam arg1 = new RPCParam("urn:myNamespace",
                                     "testParam",
                                     "this is a string");
        RPCElement body = new RPCElement("urn:myNamespace",
                                         "method1",
                                         new Object[]{ arg1 });
        msg.addBodyElement(body);

        Writer stringWriter = new StringWriter();
        SerializationContext context = new SerializationContext(stringWriter,
                                                                    msgContext);

        msg.output(context);

        String msgString = stringWriter.toString();
        assertTrue("Found unexpected xsi:type!",
                   msgString.indexOf("xsi:type") == -1);
    
public voidtestTypelessDeserialization()
More complex test which checks to confirm that we can still in fact deserialize if we know the type via the Call object.

        server.setOption(AxisEngine.PROP_SEND_XSI, Boolean.FALSE);
        
        SOAPService service = new SOAPService(new RPCProvider());
        service.setOption("className", "test.encoding.TestXsiType");
        service.setOption("allowedMethods", "*");
        provider.deployService("TestService", service);
        
        // Call that same server, accessing a method we know returns
        // a double.  We should figure this out and deserialize it
        // correctly, even without the xsi:type attribute, because
        // we set the return type manually.
        
        Service S_service = new Service();
        Call call = (Call) S_service.createCall();
        call.setTransport(new LocalTransport(server));
        call.setReturnType(XMLType.XSD_DOUBLE);
        
        Object result = call.invoke("TestService", 
                                    "serviceMethod", 
                                    new Object [] {});
        
        assertTrue("Return value (" + result.getClass().getName() +
                   ") was not the expected type (Double)!",
                    (result instanceof Double));