xsd:int mapped to SoapPrimitive

Petri Rautakoski <[email protected]> Thu, 15 May 2003 10:28:14 +0300
Newsgroups gmane.comp.java.enhydra.ksoap
Message-ID <[email protected]>
Even specs tells that xsd:int value should be mapped straight to java.lang.Integer it doesn't happen in my application. I'm just starting to use SOAP and KSOAP so this could be dummy question. I attach here my wsdl-document and the Test-class where I handle the SOAP-response.

Thanks!

Petri Rautakoski

My wsdl-document:

<?xml version="1.0" encoding="UTF-8"?>
<wsdl:definitions targetNamespace="urn:usertest" xmlns="http://schemas.xmlsoap.org/wsdl/" xmlns:apachesoap="http://xml.apache.org/xml-soap" xmlns:impl="urn:usertest" xmlns:intf="urn:usertest" xmlns:soapenc="http://schemas.xmlsoap.org/soap/encoding/" xmlns:tns2="http://dto.view.data.codewitz.tpu.fi" xmlns:wsdl="http://schemas.xmlsoap.org/wsdl/" xmlns:wsdlsoap="http://schemas.xmlsoap.org/wsdl/soap/" xmlns:xsd="http://www.w3.org/2001/XMLSchema">
 <wsdl:types>
  <schema targetNamespace="http://dto.view.data.codewitz.tpu.fi" xmlns="http://www.w3.org/2001/XMLSchema">
   <import namespace="http://schemas.xmlsoap.org/soap/encoding/"/>
   <complexType name="InstitutionView">
    <sequence>
     <element name="contractLevel" nillable="true" type="xsd:string"/>
     <element name="country" nillable="true" type="xsd:string"/>
     <element name="id" nillable="true" type="xsd:int"/>
     <element name="name" nillable="true" type="xsd:string"/>
    </sequence>
   </complexType>
   <complexType name="UserView">
    <sequence>
     <element name="email" nillable="true" type="xsd:string"/>
     <element name="givenName" nillable="true" type="xsd:string"/>
     <element name="id" nillable="true" type="xsd:int"/>
     <element name="institution" nillable="true" type="tns2:InstitutionView"/>
     <element name="institutionId" nillable="true" type="xsd:int"/>
     <element name="password" nillable="true" type="xsd:string"/>
     <element name="surname" nillable="true" type="xsd:string"/>
     <element name="username" nillable="true" type="xsd:string"/>
    </sequence>
   </complexType>
  </schema>
 </wsdl:types>
   <wsdl:message name="getUserRequest">
      <wsdl:part name="in0" type="xsd:string"/>
   </wsdl:message>
   <wsdl:message name="getUsernameRequest">
      <wsdl:part name="in0" type="xsd:int"/>
   </wsdl:message>
   <wsdl:message name="getUsernameResponse">
      <wsdl:part name="getUsernameReturn" type="xsd:string"/>
   </wsdl:message>
   <wsdl:message name="getUserResponse">
      <wsdl:part name="getUserReturn" type="tns2:UserView"/>
   </wsdl:message>
   <wsdl:portType name="UserTest">
      <wsdl:operation name="getUser" parameterOrder="in0">
         <wsdl:input message="impl:getUserRequest" name="getUserRequest"/>
         <wsdl:output message="impl:getUserResponse" name="getUserResponse"/>
      </wsdl:operation>
      <wsdl:operation name="getUsername" parameterOrder="in0">
         <wsdl:input message="impl:getUsernameRequest" name="getUsernameRequest"/>
         <wsdl:output message="impl:getUsernameResponse" name="getUsernameResponse"/>
      </wsdl:operation>
   </wsdl:portType>
   <wsdl:binding name="UserTestSoapBinding" type="impl:UserTest">
      <wsdlsoap:binding style="rpc" transport="http://schemas.xmlsoap.org/soap/http"/>
      <wsdl:operation name="getUser">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="getUserRequest">
            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:usertest" use="encoded"/>
         </wsdl:input>
         <wsdl:output name="getUserResponse">
            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:usertest" use="encoded"/>
         </wsdl:output>
      </wsdl:operation>
      <wsdl:operation name="getUsername">
         <wsdlsoap:operation soapAction=""/>
         <wsdl:input name="getUsernameRequest">
            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:usertest" use="encoded"/>
         </wsdl:input>
         <wsdl:output name="getUsernameResponse">
            <wsdlsoap:body encodingStyle="http://schemas.xmlsoap.org/soap/encoding/" namespace="urn:usertest" use="encoded"/>
         </wsdl:output>
      </wsdl:operation>
   </wsdl:binding>
   <wsdl:service name="UserTestService">
      <wsdl:port binding="impl:UserTestSoapBinding" name="UserTest">
         <wsdlsoap:address location="http://localhost:8080/usertest/services/UserTest"/>
      </wsdl:port>
   </wsdl:service>
</wsdl:definitions>

Test.java

public class Test {
  public static void main(String [] args) throws Exception {
    try {
    // build request string
      SoapObject rpc = new SoapObject("urn:usertest.UserTest", "getUser");
      rpc.addProperty ("in0", "pete3");
      HttpTransportSE transport = new HttpTransportSE("http://localhost:8080/usertest/services/UserTest","uurn:usertest.UserTest#getUser");
      SoapObject result = (SoapObject)transport.call (rpc);
      Integer id = (Integer)result.getProeprty("id");

Here comes the ClassCastException because the result.getProperty("id") returns SoapPrimitive-object

     UserView user = parseUser(result);
    } catch (Exception e) {
      e.printStackTrace ();
    }
  }
}