Title: RE: Lists (was RE: How to use a return type java.util.List)

I have a process question related to this issue. To create my web service, I usually run Java2WSDL on my interface followed by WSDL2Java. I assume that I have to tweak the files Generated by Java2WSDL in order to make this work.

For example, when I run Java2WSDL on something like

        public Collection echoList(Collection c) { return c; }

and then run WSDL2Java on the resulting wsdl file, I assume that I will get

        public Object[] echoList(Object[] c) { return c; }

Is this assumption valid?

Naresh

-----Original Message-----
From: Glen Daniels [mailto:[EMAIL PROTECTED]]
Sent: Wednesday, April 17, 2002 5:25 PM
To: '[EMAIL PROTECTED]'
Cc: Axis-Dev (E-mail)
Subject: FAQ: Lists (was RE: How to use a return type java.util.List)



(hey Russell, could you add this to the FAQ while you're working on it?  Is this too long?)

Q: How do I use Java Collection classes and Arrays with Axis?

A: Axis automatically understands how to serialize and deserialize arrays and Java
   Collections "out of the box".  All of these things will be serialized as SOAP
   Arrays (for maximum interoperability), and will by default deserialize into
   Object arrays (Object []).  Of course, to successfully serialize any collection/
   array, you must have serializers mapped for every type which is represented in
   the contents of the collection/array - in other words, Axis will recognize a
   "Pet []" as an array, but you need to make sure the "Pet" class has been mapped.

   You do NOT have to explicitly map any of the Collection types or array types
   in order to have them work with Axis.

   Axis has a built-in "convert()" method (org.apache.axis.utils.JavaUtils.convert())
   which knows how to turn various kinds of collections into equivalent arrays, and
   vice versa.  This is important because as we said above, Axis will deserialize
   SOAP Arrays by default into Object[]s.  If you're a client calling a SOAP method
   and you want the return to be some other type, such as a List, you have to tell
   the Call object to give you a list as follows:

     // set up the call, etc....
     call.setReturnClass(java.util.List.class); // Note that we want a List
     List return = (List)call.invoke(...);

   This will cause Axis to automatically convert() the Object[] generated from
   deserializing the SOAP array into a List, and therefore the cast will work.

   On the server side, we will also automatically map a SOAP array to any desired
   Collection class in a method signature - in other words, if your service class
   has the following method:

      public List echoList(List l) { return l; }

   The engine will convert an incoming SOAP array to a List, and then serialize
   the outgoing List as a SOAP array as well.  So on the wire, there is no
   difference between that method and this one:

      public Collection echoList(Collection c) { return c; }

   One last point - typed arrays (i.e. Pet[]) will be represented on the wire as
   SOAP arrays with arrayType="<xmlType>" where <xmlType> is the XML type QName
   associated with the Java Pet class.  Collections will always be represented on
   the wire as SOAP arrays with arrayType="xsd:anyType[]", since it's possible to
   put a heterogeneous collection of Objects into a Java collection.

--Glen

> -----Original Message-----
> From: Cun Yong Tan [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, April 17, 2002 5:06 PM
> To: [EMAIL PROTECTED]
> Subject: Re: How to use a return type java.util.List
>
>
>
> I don't use JWS but in the services I've created, when
> I return a List from a service method, the client receives
> it as an Object[]  (not a List).
> And you don't need a bean mapping for List in your
> WSDD.
>
>
> >From: "Vaishakhi Ajmera" <[EMAIL PROTECTED]>
> >Reply-To: [EMAIL PROTECTED]
> >To: <[EMAIL PROTECTED]>
> >Subject: How to use a return type java.util.List
> >Date: Wed, 17 Apr 2002 15:08:51 -0500
> >
> >Hello,
> >I have a webservice for which I have used axis instant
> deployment and this
> >service returns to me a java.util.List.
> >I have used the return type in my client class that calls
> the service to be
> >of type XMLType.SOAP_ARRAY
> >
> >However I get the following error when I run my class
> >         .
> >         .
> >         .
> >         .
> >         at java.lang.Thread.run(Thread.java:536)
> >Caused by: org.xml.sax.SAXParseException: Document root
> element is missing.
> >         at
> org.apache.crimson.parser.Parser2.fatal(Parser2.java:3182)
> >         at
> org.apache.crimson.parser.Parser2.fatal(Parser2.java:3170)
> >         at
> >org.apache.crimson.parser.Parser2.parseInternal(Parser2.java:501)
> >         at org.apache.crimson.parser.Parser2.parse(Parser2.java:305)
> >         at
> >org.apache.crimson.parser.XMLReaderImpl.parse(XMLReaderImpl.java:442)
> >         at javax.xml.parsers.SAXParser.parse(SAXParser.java:345)
> >         at
> >org.apache.axis.encoding.DeserializationContextImpl.parse(Unk
> nown Source)
> >
> >
> >I am thinking that maybe the types do not match.
> >
> >In the axis user guide I see an example (example5) of using
> bean mapping in
> >the wsdd file to specify that the parameter being passed is
> of type Order.
> >In my case the parameter returned is of a complex type. Does
> the bean
> >mapping apply in that case too.
> >
> >Also I tried to make a deploy.wsdd file for my webservice
> >
> ><deployment xmlns="http://xml.apache.org/axis/wsdd/"
> >            
> xmlns:java="http://xml.apache.org/axis/wsdd/providers/java">
> >
> >  <service name="UserManager" provider="java:RPC">
> >   <parameter name="className"
> >value="com.ardec.ebf.usermgr.webservices.UserList"/>
> >   <parameter name="allowedMethods" value="*"/>
> >
> >   <beanMapping qname="myNS:List" xmlns:myNS="urn:UserList"
> >                languageSpecificType="java:java.util.List"/>
> >  </service>
> >
> ></deployment>
> >
> >but I am not sure if the bean mapping is correct. Any insight?
> >
> >Any help will be highly appreciated.
> >
> >Thanks
> >Vaishakhi
> >
>
>
> _________________________________________________________________
> Send and receive Hotmail on your mobile device: http://mobile.msn.com
>

Reply via email to