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 Mike Patton <m_...@yahoo.com> on 2007/07/06 15:55:05 UTC

[Axis2] returning Array versus List , and more

I have a simple WS that has an Employee class (Pojo with getters and setters only), and a service class EmployeeService that has only one method that takes 3 String arguments and  returns a List of Employee objects. The actual list implementation returned is ArrayList.
   
  First is such a return type portable? Is it better to return Arrays instead?
   
  Second, how can I, from a client application,  retrieve the Employee objects from the list? I wrote the client code below but it is throwing the following exception. Could anyone point me to a tutorial or give a sample code to retrieve collection data from an Axis2 web service?
  Regards,
   
   
   
  Exception in thread "main" java.lang.RuntimeException: java.lang.RuntimeException: Unexpected subelement return
    at com.myCompany.service.EmployeeServiceSOAP11PortStub.fromOM(EmployeeServiceSOAP11PortStub.java:1342)
    at com.myCompany.service.EmployeeServiceSOAP11PortStub.getEmployees(EmployeeServiceSOAP11PortStub.java:159)
    at com.myCompany.client.Main.main(Main.java:34)
Caused by: java.lang.RuntimeException: Unexpected subelement return
    at com.myCompany.service.EmployeeServiceSOAP11PortStub$GetEmployeesResponse$Factory.parse(EmployeeServiceSOAP11PortStub.java:667)
    at com.myCompany.service.EmployeeServiceSOAP11PortStub.fromOM(EmployeeServiceSOAP11PortStub.java:1336)
    ... 2 more
    
    
    
    
The line 34 is:  EmployeeServiceSOAP11PortStub.GetEmployeesResponse getEmployeesResponse = stub.getEmployees(getEmployees);
    ------------------------------------------------------------
    
package com.myCompany.client;

import java.rmi.RemoteException;
import org.apache.axis2.AxisFault;
import javax.xml.stream.XMLStreamException;
import org.apache.axiom.om.OMElement;
import com.myCompany.service.EmployeeServiceSOAP11PortStub;
import com.myCompany.service.EmployeeService;
import com.myCompany.domain.Employee;
import java.util.List;

public class Main {
  public static void main(String[] args) {
     EmployeeServiceSOAP11PortStub stub;
     try{
           stub = new EmployeeServiceSOAP11PortStub("http://localhost:8080/axis2/services/EmployeeService");
           EmployeeServiceSOAP11PortStub.GetEmployees getEmployees = new EmployeeServiceSOAP11PortStub.GetEmployees();
           getEmployees.setViewDescription("GC_ALL");
           getEmployees.setUsername("Mike.Patton");
           getEmployees.setPassword("myPassword");
        ........
           EmployeeServiceSOAP11PortStub.GetEmployeesResponse getEmployeesResponse = stub.getEmployees(getEmployees);
           OMElement omelement = getEmployeesResponse.get_return();
           System.out.println(omelement.toStringWithConsume());
      }catch(AxisFault e){
           e.printStackTrace();
      }catch(RemoteException e){
           e.printStackTrace();
      }catch(XMLStreamException e){
           e.printStackTrace();
      }
   }
}



 
---------------------------------
Finding fabulous fares is fun.
Let Yahoo! FareChase search your favorite travel sites to find flight and hotel bargains.

Re: [Axis2] returning Array versus List , and more

Posted by Anne Thomas Manes <at...@gmail.com>.
As a general rule, you want to avoid returning data as an XML string.

Otherwise, Joe's advice is correct. Your interface should expose
simple types, structures of simple types, and arrays of simple types
or structures. Avoid returning Java-specific collections.

Note that you cannot send or return an array as a primary element
(direct child of the SOAP Body) unless the array is wrapped by another
element. The SOAP Body may contain at most one child element. An array
maps to multiple elements unless you wrap it.

Anne

On 7/6/07, Joe Nathan <jo...@yahoo.com> wrote:
>
> SOAP meant to be universal over both platforms and programming languages.
> This means that it's sensible to pass and return values in common datatypes
> in all platforms and languages which is "String", "Int", "Float". As all
> SOAP implementations support XML, you may return multiple values wrapped in
> a xml string. Your client may need to pass arrays imbedded in xml strings!
>
> --
> View this message in context: http://www.nabble.com/-Axis2--returning-Array-versus-List-%2C-and-more-tf4035642.html#a11474884
> Sent from the Axis - User mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
> For additional commands, e-mail: axis-user-help@ws.apache.org
>
>

---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org


Re: [Axis2] returning Array versus List , and more

Posted by Joe Nathan <jo...@yahoo.com>.
SOAP meant to be universal over both platforms and programming languages.
This means that it's sensible to pass and return values in common datatypes
in all platforms and languages which is "String", "Int", "Float". As all
SOAP implementations support XML, you may return multiple values wrapped in
a xml string. Your client may need to pass arrays imbedded in xml strings!

-- 
View this message in context: http://www.nabble.com/-Axis2--returning-Array-versus-List-%2C-and-more-tf4035642.html#a11474884
Sent from the Axis - User mailing list archive at Nabble.com.


---------------------------------------------------------------------
To unsubscribe, e-mail: axis-user-unsubscribe@ws.apache.org
For additional commands, e-mail: axis-user-help@ws.apache.org