Hi Martina!

Here's the deal (maybe we can save Rich some time :)).  Axis takes all Java "linear 
collection" classes (i.e. anything that implements List) and serializes them as SOAP 
Arrays, to maximize interoperability with other toolkits.  When we receive a SOAP 
Array and want to deserialize it, we do so into a Java object array (hence the 
"[Ljava.lang.Object" in your error) by default, and then have a conversion function 
that handles doing all kinds of massaging to give you what you want.

The conversion function is org.apache.axis.utils.JavaUtils.convert(), and it takes an 
Object to convert and a Class to convert to.  So you could do this:

  return (java.util.Vector)JavaUtils.convert(resp, Vector.class);

But there's an even easier way.  Instead of using setReturnType(qname), use 
setReturnClass(Class):

  call.setReturnClass(Vector.class)

...and we'll automatically do the conversion for you.

(only read the following if you really care about some internals)

Your example appeared confusing at first because you set the returnType to be the old 
Apache SOAP encoding for Vectors, which was different from SOAP arrays.  So one might 
expect the deserialization to have failed when it received the SOAP array - but since 
the SOAP Array (being generated by Axis) had an xsi:type attribute on it, that type 
was used in picking a deserializer instead of the returnType you specified to the 
Call.... interesting.

--Glen

> -----Original Message-----
> From: R J Scheuerle Jr [mailto:[EMAIL PROTECTED]]
> Sent: Wednesday, March 20, 2002 5:26 PM
> To: [EMAIL PROTECTED]
> Cc: [EMAIL PROTECTED]
> Subject: Re: cast of returning object to vector doesn't work
> 
> 
> I might have some time Thursday to look at this problem.
> 
> Thanks,
> 
> Rich Scheuerle
> XML & Web Services Development
> 512-838-5115  (IBM TL 678-5115)
> 
> 
>                                                               
>                                                                  
>                       "Martina Brose"                         
>                                                                  
>                       <[EMAIL PROTECTED]        To:       
> <[EMAIL PROTECTED]>                                         
>                       -berlin.de>                 cc:         
>                                                                  
>                                                   Subject:  
> cast of returning object to vector doesn't work                    
>                       03/20/2002 11:55 AM                     
>                                                                  
>                       Please respond to                       
>                                                                  
>                       axis-user                               
>                                                                  
>                                                               
>                                                                  
>                                                               
>                                                                  
> 
> 
> 
> Hi, I tryed to make a web service using the wsdl2java tool 
> (Axis beta1).
> First everything went fine. I was able to compile the code, 
> to deploy the
> the service and to invoke the service using my client 
> application. I got no
> problems sending Strings, Vectors etc. and recieving Strings 
> or Booleans.
> The only problem is recieving a Vector.
> The ServiceImplementation methode that should return the vector is:
> 
> public Vector getVal(String key) throws java.rmi.RemoteException,
> beepingSoap.sessionXmpl.WrongKeyException {
>       if(logedUsers.containsKey(key)==true)
>       {
>          Vector valueList = new
> Vector(((User)logedUsers.get(key)).getList());
>          return valueList;
>       }
>       else
>       {
>          throw new WrongKeyException("Illegal Session Key");
>       }
> }
> 
> The corresponding part of the SoapBindingStub is:
> 
> public java.util.Vector getVal(java.lang.String in0) throws
> java.rmi.RemoteException, beepingSoap.sessionXmpl.WrongKeyException{
>     if (super.cachedEndpoint == null) {
>         throw new org.apache.axis.NoEndPointException();
>     }
>     org.apache.axis.client.Call call = getCall();
>     javax.xml.rpc.namespace.QName p0QName = new
> javax.xml.rpc.namespace.QName("", "in0");
>     call.addParameter(p0QName, new
> javax.xml.rpc.namespace.QName("http://schemas.xmlsoap.org/soap
> /encoding/",
> "string"), javax.xml.rpc.ParameterMode.PARAM_MODE_IN);
>     call.setReturnType(new
> javax.xml.rpc.namespace.QName("http://xml.apache.org/xml-soap";
> , "Vector"));
>     call.setUseSOAPAction(true);
>     call.setSOAPActionURI("");
>     call.setOperationStyle("rpc");
>     call.setOperationName(new
> javax.xml.rpc.namespace.QName("urn:sessionXmpl", "getVal"));
> 
>     Object resp = call.invoke(new Object[] {in0});
> 
>     if (resp instanceof java.rmi.RemoteException) {
>         throw (java.rmi.RemoteException)resp;
>     }
>     else {
>         return (java.util.Vector) resp;    // This is line 180 !!!
>     }
> }
> 
> But when I try to invoke the getVal Methode by:
>     ServiceAppService service = new ServiceAppServiceLocator();
>     ServiceApp port = service.getServiceApp();
>     Vector valueList = new Vector(port.getVal(key));
> I get the following error message:
> 
> java.lang.ClassCastException: [Ljava.lang.Object;
>         at
> beepingSoap.sessionXmpl.ServiceAppSoapBindingStub.getVal(ServiceAppSo
> apBindingStub.java:180)
>         at 
> beepingSoap.sessionXmpl.ValueGet.communicate(ValueGet.java:43)
>         at
> beepingSoap.sessionXmpl.ProcederGUI.getVals(ProcederGUI.java:175)
>         at
> beepingSoap.sessionXmpl.ProcederGUI.actionPerformed(ProcederGUI.java:
> 143)
>         at java.awt.Button.processActionEvent(Button.java:329)
>         at java.awt.Button.processEvent(Button.java:302)
>         at java.awt.Component.dispatchEventImpl(Component.java:2595)
>         at java.awt.Component.dispatchEvent(Component.java:2499)
>         at java.awt.EventQueue.dispatchEvent(EventQueue.java:319)
>         at
> java.awt.EventDispatchThread.pumpOneEvent(EventDispatchThread.java:10
> 3)
>         at
> java.awt.EventDispatchThread.pumpEvents(EventDispatchThread.java:93)
>         at 
> java.awt.EventDispatchThread.run(EventDispatchThread.java:84)
> 
> So why can't the object returned to the stub be casted to a 
> vector? I even
> tryed to cast it to a String, in case the returned object was a fault
> message, but I got the same exception.
> Can you help me?
> 
> Martina
> 
> 
> 
> 

Reply via email to