wood burning stoves 2.0*
The moose likes Web Services and the fly likes Working With Complex Data Types Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Working With Complex Data Types" Watch "Working With Complex Data Types" New topic
Author

Working With Complex Data Types

Venkat Ram
Greenhorn

Joined: Apr 06, 2008
Posts: 5
BackGround:
With all the help and documentation available online i have been able to get startedp and make a fair amount of progress with implementing web services in Java 6. So, far I had been able to have my webmethod return primitive types such as string etc and even had luck with Vector and ArrayList.

Problem: Unable to figure out how to have the webmethod return more complex data types such as an vector of vectors or arraylist of arraylists or arraylist of a certain custom java class object.

My webservice client is a java servlet, which after making the call simply forwards the call to a JSP page after setting the returned complex data type as the HttpSession variable. On the JSP page, i am unable to retreive the complex data type. The errors I see are either that the current context doesnt know about the POJO class that i have written on the server or trouble unmarshalling the complex data type.

Components used: netbeans 6.0, jax-ws, glassfishv2.

Alternatives Known: Axis from apache heard allows for handling complex data types & Java objects.

With the amount of time invested in using Jax-ws, Im looking for help to get complex data types / objects around. All the examples I found are always dealing with simpler types.

Any help in getting me an idea or pointer to understand working with complex data types will be much appreciated!

Thanks
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2921
    
    5
Welcome to JavaRanch,

Please check your private messages.
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2921
    
    5
Originally posted by Eye Geek:
Im looking for help to get complex data types / objects around.


That is where your problem is - XML can represent complex data but not "objects". There is no equivalent for Vectors and Arraylists in XML Schema - it has a "sequence" which is mapped to an array in Java. Furthermore non-Java web service consumers would have no idea what java.util.Vector and java.util.Arraylist are. Futhermore XML, being hierarchical in nature, has difficulties representing complex, possibly cyclical object graphs.

SOAP is not a remote object access protocol - it's an XML-based messaging protocol.

Have look at contract first development and "Item 43: Recognize the object-hierarchical impedance mismatch" in Effective Enterprise Java: Ch.5: State Management (PDF)
Venkat Ram
Greenhorn

Joined: Apr 06, 2008
Posts: 5
Thanks Peer. You are right. Once I am thinking of transferring Java Objects using webservices, then I am not making it interoperable with other all SOAP clients. Thanks for the schema document, it helped.

For the record, I was able to get the java object transferred using jax-ws. With Netbeans, using Jax-WS and transferring java object almost feels like RMI or Corba where stubs are created on the client side. Netbeans was actually getting all the classes from the server side that are needed for using the object on the client side when pointing to the Webservice operation / wsdl file.

But, now that I figured this could be done using Jax-WS. I will now move on implementing a complex data using xml schema that soap supports and can work with other soap clients.

Thanks again.
chin desai
Greenhorn

Joined: Nov 17, 2008
Posts: 2
Originally posted by Venkat Ram:
Thanks Peer. You are right. Once I am thinking of transferring Java Objects using webservices, then I am not making it interoperable with other all SOAP clients. Thanks for the schema document, it helped.

For the record, I was able to get the java object transferred using jax-ws. With Netbeans, using Jax-WS and transferring java object almost feels like RMI or Corba where stubs are created on the client side. Netbeans was actually getting all the classes from the server side that are needed for using the object on the client side when pointing to the Webservice operation / wsdl file.

But, now that I figured this could be done using Jax-WS. I will now move on implementing a complex data using xml schema that soap supports and can work with other soap clients.

Thanks again.


I am also facing the similar scenario where i want to pass my entity bean as return type of my web service, but I am getting cyclical reference error while validating the WSDL file. I am using Netbeans 6.1 to create Web Services and Web service clients.
Can you guide me as to how can I get rid of cyclical reference errors and send the entity bean as response back to the calling client? Can I do that? If not, then How can i send the complex data back to the client?

Thanks
Peer Reynders
Bartender

Joined: Aug 19, 2005
Posts: 2921
    
    5
Originally posted by chin desai:
send the entity bean as response back to the calling client? Can I do that? If not, then How can i send the complex data back to the client?


If your client could use the entity bean in the first place wouldn't you just use EJB rather than web services? A SOAP web service client and service exchange SOAP requests and responses that carry XML payloads. The complex data is captured in the XML document.

This topic might be of some interest.
[ November 18, 2008: Message edited by: Peer Reynders ]
Ushan Adikaram
Greenhorn

Joined: Mar 29, 2009
Posts: 6
i'm a newbie to java. i need to develop a web service to get and set customer information (customer id, name, address and phone number). in my case address is the complex data type and it includes home number, street and town. can any body give a sample for this so then i can easily figure out how this works. regards.

ushan
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Working With Complex Data Types
 
Similar Threads
How to read Object data and List of Objects data through SOAP?
Is JAX-WS method ArrayList
New to Web services- Problem
jax-ws : return list of JPA entities