axis-java-user mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "R J Scheuerle Jr" <sc...@us.ibm.com>
Subject RE: cast of returning object to vector doesn't work
Date Thu, 21 Mar 2002 16:22:03 GMT
Just committed the fix.  Please get the latest build.

Rich Scheuerle
XML & Web Services Development
512-838-5115  (IBM TL 678-5115)


                                                                                         
                                  
                      R J Scheuerle                                                      
                                  
                      Jr/Austin/IBM@IBM        To:       axis-user@xml.apache.org, gdaniels@macromedia.com
                 
                      US                       cc:                                       
                                  
                                               Subject:  RE: cast of returning object to vector
doesn't work                
                      03/21/2002 10:05                                                   
                                  
                      AM                                                                 
                                  
                      Please respond to                                                  
                                  
                      axis-user                                                          
                                  
                                                                                         
                                  
                                                                                         
                                  



What Glen said is true.  However, Martina is using the Axis generated
Stubs.

The Vector is being serialized over the wire as an array.  The server side
automatically converts the array back into a Vector to invoke the server
side
method.

The method then returns a Vector, which is serialized over the wire as an
array.
The stub receives the array and tries to cast it to a vector.  Kaboom!

So the fix is to improve the Stubs so that they use JavaUtils.convert(...)
it the cast
fails.  This will fix Martina's problems and makes the stubs more flexible
for
future changes.

I am working on the change right now (the stub generation code needs to be
cleaned
up in this area anyway).

...Hey my test passed, I should commit the code within an hour.

Thanks,

Rich Scheuerle
XML & Web Services Development
512-838-5115  (IBM TL 678-5115)



                      Glen Daniels

                      <gdaniels@macrome        To:
"'axis-user@xml.apache.org'" <axis-user@xml.apache.org>
                      dia.com>                 cc:

                                               Subject:  RE: cast of
returning object to vector doesn't work
                      03/20/2002 09:32

                      PM

                      Please respond to

                      axis-user







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:scheu@us.ibm.com]
> Sent: Wednesday, March 20, 2002 5:26 PM
> To: axis-user@xml.apache.org
> Cc: axis-user@xml.apache.org
> 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"
>
>                       <brose@informatik.hu        To:
> <axis-user@xml.apache.org>
>                       -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
>
>
>
>







Mime
View raw message