You are viewing a plain text version of this content. The canonical link for it is here.
Posted to java-user@axis.apache.org by Martin May <ma...@sun.com> on 2002/08/21 18:54:15 UTC

Complex return types

Hi folks,

I've been trying to use an Apache Axis client to connect to a server
using Sun's WSDP. The service returns an array of a custom class
(Course), which is available at the client. The SOAP communication seems
to work fine, but apparently Axis can't handle the complex return type
(see attached stack trace).

I've seen some messages on this list suggesting that SOAP wasn't meant
for complex data structures, could anybody confirm this and possibly
point me to URL which documents that?

Here is the client code:

--------------------------------------------

import org.apache.axis.client.Call;
import org.apache.axis.client.Service;

import javax.xml.namespace.QName;

public class TestClient
{
    public static void main(String [] args) {
     try {
            String endpoint =
                     "http://127.0.0.1:7000/jaxrpc-sunreg/jaxrpc/SunReg";

            Service  service = new Service();
        Call        call    = (Call) service.createCall();
        call.setTargetEndpointAddress( new java.net.URL(endpoint) );
        call.setOperationName(new QName("http://localhost:8080/wsdl",
"getCourseInfo") );
             call.setReturnType(org.apache.axis.Constants.SOAP_ARRAY);

            // Call to addParameter/setReturnType as described in
user-guide.html
        //call.addParameter("testParam",
        //            org.apache.axis.Constants.XSD_STRING,
        //            javax.xml.rpc.ParameterMode.IN);
        //call.setReturnType(org.apache.axis.Constants.XSD_STRING);

            Course[] courseArray = (Course[]) call.invoke(new Object[] { });

            //System.out.println("Sent 'Hello!', got '" + ret + "'");

            for (int i = 0 ; i < courseArray.length; i++) {
              System.out.println("Course Id : " +
courseArray[i].getCourseID());
              System.out.println("Course Desc : " +
courseArray[i].getCourseDesc());
        }
        } catch (Exception e) {
        System.err.println(e.toString());
     }
    }

--------------------------------------------

The stack trace:

Aug 21, 2002 10:09:44 AM org.apache.axis.client.Call invoke
SEVERE: Exception:
org.xml.sax.SAXException: No deserializer defined for array type
{http://localhost:8080/types}Course
     at
org.apache.axis.encoding.ser.ArrayDeserializer.onStartElement(ArrayDeserializer.java:254)
     at
org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:393)
     at
org.apache.axis.encoding.DeserializationContextImpl.startElement(DeserializationContextImpl.java:870)
     at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:199)
     at
org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:644)
     at
org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java:369)
     at
org.apache.axis.encoding.DeserializationContextImpl.startElement(DeserializationContextImpl.java:870)
     at
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:199)
     at
org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:644)
     at org.apache.axis.message.RPCElement.deserialize(RPCElement.java:235)
     at org.apache.axis.message.RPCElement.getParams(RPCElement.java:259)
     at org.apache.axis.client.Call.invoke(Call.java:1806)
     at org.apache.axis.client.Call.invoke(Call.java:1711)
     at org.apache.axis.client.Call.invoke(Call.java:1251)
     at TestClient.main(TestClient.java:27)
org.xml.sax.SAXException: No deserializer defined for array type
{http://localhost:8080/types}Course

--------------------------------------------

The SOAP Request:

POST /jaxrpc-sunreg/jaxrpc/SunReg HTTP/1.0
Host: tofu.central
Content-Type: text/xml; charset=utf-8
SOAPAction: ""
Content-Length: 454

<?xml version="1.0" encoding="UTF-8"?>
<soapenv:Envelope
soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
  <soapenv:Body>
   <ns1:getCourseInfo xmlns:ns1="http://localhost:8080/wsdl"/>
  </soapenv:Body>
</soapenv:Envelope>

--------------------------------------------

The SOAP Response:

HTTP/1.1 200 OK
Content-Type: text/xml; charset="utf-8"
SOAPAction: ""
Date: Wed, 21 Aug 2002 16:09:00 GMT
Server: Apache Coyote HTTP/1.1 Connector [1.0]
Connection: close

<?xml version="1.0" encoding="UTF-8"?>
<env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
xmlns:xsd="http://www.w3.org/2001/XMLSchema"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
xmlns:ns0="http://localhost:8080/types"
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><env:Body><ans1:getCourseInfoResponse 

xmlns:ans1="http://localhost:8080/wsdl"><result
href="#ID1"/></ans1:getCourseInfoResponse><ns0:ArrayOfCourse id="ID1"
xsi:type="enc:Array" enc:arrayType="ns0:Course[2]"><item
href="#ID2"/><item href="#ID3"/></ns0:ArrayOfCourse><ns0:Course id="ID2"
xsi:type="ns0:Course"><courseDesc
xsi:type="xsd:string">Course1</courseDesc><courseID
xsi:type="xsd:int">1</courseID></ns0:Course><ns0:Course id="ID3"
xsi:type="ns0:Course"><courseDesc
xsi:type="xsd:string">Course2</courseDesc><courseID
xsi:type="xsd:int">2</courseID></ns0:Course></env:Body></env:Envelope>

--------------------------------------------

The Course class:

public class Course {
      private int    courseID;
      private String courseDesc;

      public Course() {
      }

      public Course(int courseID, String courseDesc) {
           this.courseID = courseID;
           this.courseDesc = courseDesc;
      }

      public int getCourseID() {
           return courseID;
      }

      public String getCourseDesc() {
           return courseDesc;
      }

      public void setCourseID(int courseID) {
           this.courseID = courseID;
      }

      public void setCourseDesc(String courseDesc) {
           this.courseDesc = courseDesc;
      }

}

--------------------------------------------


Is there any way hat I can make this work, or is this just a very bad
idea for a webservice, basing it on complex types? BTW. We have a WSDP
client which works fine, but it uses stubs.

Best regards,

Martin

-- 

      _/_/_/                     Martin May
     _/                          Sun Microsystems Inc.
    _/_/_/  _/  _/  _/  _/       Enterprise Services
       _/  _/  _/  _/_/_/        Mailstop UBRM06-257
  _/_/_/  _/_/_/  _/  _/         500 Eldorado Blvd
                                 Broomfield, CO 80020
  M I C R O S Y S T E M S
           I N C                 phone:  (303) 272-5118 (x75118)
                                 email:  martin.may@sun.com




Re: Complex return types

Posted by Steve Loughran <st...@iseran.com>.
----- Original Message -----
From: "Martin May" <ma...@sun.com>
To: <ax...@xml.apache.org>
Sent: Wednesday, August 21, 2002 9:54 AM
Subject: Complex return types


>
> Hi folks,
>
> I've been trying to use an Apache Axis client to connect to a server
> using Sun's WSDP. The service returns an array of a custom class
> (Course), which is available at the client. The SOAP communication seems
> to work fine, but apparently Axis can't handle the complex return type
> (see attached stack trace).

It should handle it once it knows about it fully, which means having a
deserializer registered for it; the standard Bean one should suffice. Did
you generate the client by importing the WSDL? If so everythng should be
autogenerated.

>
> I've seen some messages on this list suggesting that SOAP wasn't meant
> for complex data structures, could anybody confirm this and possibly
> point me to URL which documents that?

well, you should have acess to the JAX-RPC docs; see also

http://cvs.apache.org/viewcvs.cgi/~checkout~/xml-axis/java/docs/user-guide.h
tml#DataMapping

though we should update that now that axis does handle unsigned stuff.

>
> Here is the client code:
>
> --------------------------------------------
>
> import org.apache.axis.client.Call;
> import org.apache.axis.client.Service;
>
> import javax.xml.namespace.QName;
>
> public class TestClient
> {
>     public static void main(String [] args) {
>      try {
>             String endpoint =
>                      "http://127.0.0.1:7000/jaxrpc-sunreg/jaxrpc/SunReg";
>
>             Service  service = new Service();
>         Call        call    = (Call) service.createCall();
>         call.setTargetEndpointAddress( new java.net.URL(endpoint) );
>         call.setOperationName(new QName("http://localhost:8080/wsdl",
> "getCourseInfo") );
>              call.setReturnType(org.apache.axis.Constants.SOAP_ARRAY);
>
>             // Call to addParameter/setReturnType as described in
> user-guide.html
>         //call.addParameter("testParam",
>         //            org.apache.axis.Constants.XSD_STRING,
>         //            javax.xml.rpc.ParameterMode.IN);
>         //call.setReturnType(org.apache.axis.Constants.XSD_STRING);
>
>             Course[] courseArray = (Course[]) call.invoke(new Object[]
{ });
>
>             //System.out.println("Sent 'Hello!', got '" + ret + "'");
>
>             for (int i = 0 ; i < courseArray.length; i++) {
>               System.out.println("Course Id : " +
> courseArray[i].getCourseID());
>               System.out.println("Course Desc : " +
> courseArray[i].getCourseDesc());
>         }
>         } catch (Exception e) {
>         System.err.println(e.toString());
>      }
>     }
>
> --------------------------------------------
>
> The stack trace:
>
> Aug 21, 2002 10:09:44 AM org.apache.axis.client.Call invoke
> SEVERE: Exception:
> org.xml.sax.SAXException: No deserializer defined for array type
> {http://localhost:8080/types}Course
>      at
>
org.apache.axis.encoding.ser.ArrayDeserializer.onStartElement(ArrayDeseriali
zer.java:254)
>      at
>
org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java
:393)
>      at
>
org.apache.axis.encoding.DeserializationContextImpl.startElement(Deserializa
tionContextImpl.java:870)
>      at
>
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:199)
>      at
>
org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:
644)
>      at
>
org.apache.axis.encoding.DeserializerImpl.startElement(DeserializerImpl.java
:369)
>      at
>
org.apache.axis.encoding.DeserializationContextImpl.startElement(Deserializa
tionContextImpl.java:870)
>      at
>
org.apache.axis.message.SAX2EventRecorder.replay(SAX2EventRecorder.java:199)
>      at
>
org.apache.axis.message.MessageElement.publishToHandler(MessageElement.java:
644)
>      at
org.apache.axis.message.RPCElement.deserialize(RPCElement.java:235)
>      at org.apache.axis.message.RPCElement.getParams(RPCElement.java:259)
>      at org.apache.axis.client.Call.invoke(Call.java:1806)
>      at org.apache.axis.client.Call.invoke(Call.java:1711)
>      at org.apache.axis.client.Call.invoke(Call.java:1251)
>      at TestClient.main(TestClient.java:27)
> org.xml.sax.SAXException: No deserializer defined for array type
> {http://localhost:8080/types}Course
>
> --------------------------------------------
>
> The SOAP Request:
>
> POST /jaxrpc-sunreg/jaxrpc/SunReg HTTP/1.0
> Host: tofu.central
> Content-Type: text/xml; charset=utf-8
> SOAPAction: ""
> Content-Length: 454
>
> <?xml version="1.0" encoding="UTF-8"?>
> <soapenv:Envelope
> soapenv:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"
> xmlns:soapenv="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:SOAP-ENC="http://schemas.xmlsoap.org/soap/encoding/">
>   <soapenv:Body>
>    <ns1:getCourseInfo xmlns:ns1="http://localhost:8080/wsdl"/>
>   </soapenv:Body>
> </soapenv:Envelope>
>
> --------------------------------------------
>
> The SOAP Response:
>
> HTTP/1.1 200 OK
> Content-Type: text/xml; charset="utf-8"
> SOAPAction: ""
> Date: Wed, 21 Aug 2002 16:09:00 GMT
> Server: Apache Coyote HTTP/1.1 Connector [1.0]
> Connection: close
>
> <?xml version="1.0" encoding="UTF-8"?>
> <env:Envelope xmlns:env="http://schemas.xmlsoap.org/soap/envelope/"
> xmlns:xsd="http://www.w3.org/2001/XMLSchema"
> xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
> xmlns:enc="http://schemas.xmlsoap.org/soap/encoding/"
> xmlns:ns0="http://localhost:8080/types"
>
env:encodingStyle="http://schemas.xmlsoap.org/soap/encoding/"><env:Body><ans
1:getCourseInfoResponse
>
> xmlns:ans1="http://localhost:8080/wsdl"><result
> href="#ID1"/></ans1:getCourseInfoResponse><ns0:ArrayOfCourse id="ID1"
> xsi:type="enc:Array" enc:arrayType="ns0:Course[2]"><item
> href="#ID2"/><item href="#ID3"/></ns0:ArrayOfCourse><ns0:Course id="ID2"
> xsi:type="ns0:Course"><courseDesc
> xsi:type="xsd:string">Course1</courseDesc><courseID
> xsi:type="xsd:int">1</courseID></ns0:Course><ns0:Course id="ID3"
> xsi:type="ns0:Course"><courseDesc
> xsi:type="xsd:string">Course2</courseDesc><courseID
> xsi:type="xsd:int">2</courseID></ns0:Course></env:Body></env:Envelope>
>
> --------------------------------------------
>
> The Course class:
>
> public class Course {
>       private int    courseID;
>       private String courseDesc;
>
>       public Course() {
>       }
>
>       public Course(int courseID, String courseDesc) {
>            this.courseID = courseID;
>            this.courseDesc = courseDesc;
>       }
>
>       public int getCourseID() {
>            return courseID;
>       }
>
>       public String getCourseDesc() {
>            return courseDesc;
>       }
>
>       public void setCourseID(int courseID) {
>            this.courseID = courseID;
>       }
>
>       public void setCourseDesc(String courseDesc) {
>            this.courseDesc = courseDesc;
>       }
>
> }
>
> --------------------------------------------
>
>
> Is there any way hat I can make this work, or is this just a very bad
> idea for a webservice, basing it on complex types? BTW. We have a WSDP
> client which works fine, but it uses stubs.
>
> Best regards,
>
> Martin
>
> --
>
>       _/_/_/                     Martin May
>      _/                          Sun Microsystems Inc.
>     _/_/_/  _/  _/  _/  _/       Enterprise Services
>        _/  _/  _/  _/_/_/        Mailstop UBRM06-257
>   _/_/_/  _/_/_/  _/  _/         500 Eldorado Blvd
>                                  Broomfield, CO 80020
>   M I C R O S Y S T E M S
>            I N C                 phone:  (303) 272-5118 (x75118)
>                                  email:  martin.may@sun.com
>
>
>
>