• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Paul Clapham
  • Ron McLeod
Sheriffs:
  • Jeanne Boyarsky
  • Liutauras Vilda
Saloon Keepers:
  • Tim Holloway
  • Carey Brown
  • Roland Mueller
  • Piet Souris
Bartenders:

Java Collections Usage in Webservice

 
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

Suppose I write a WebService in Java. And, the return type of that webservice is any Java collection say a Map<String, Object>. Now, as per the webservice definition, I can invoke this webservice from any technology code like C, Perl, C++, .net etc. Now, I am curious to know how that particular collection of Map<String, Object> will be handled by a C, C++, Perl code or any other language code where we don't have any that kind of collection available.

Thanks & Regards,
Vaibhav Garg
 
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By its very definition an HTTP response is text, so you cannot return any collection, Java, C C++ or otherwise. You must return text.

Therefore, your response needs to be encoded as text. Customary formats are XML or JSON, with the latter becoming more popular with non-SOAP web services; especially RESTful web services.
 
Vaibhav G Garg
Ranch Hand
Posts: 143
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Bear for your response.

That right that we will be returning the text as in XML. So, we will return the map or list as text through XML but I am wondering how this XML will regenerate the data structure back on client side where we have code in C/C++.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You should restrict yourself to the data types defined in XML Schema, since only those are guaranteed to work cross-platform. On the Java side, that means arrays, not collections: http://www.ibm.com/developerworks/webservices/library/ws-tip-coding/index.html

Bear Bibeault wrote:By its very definition an HTTP response is text, so you cannot return any collection, Java, C C++ or otherwise. You must return text.


The problem is somewhat different that that. Using Java types as such is no problem, since they will automatically be mapped to XML by the SOAP framework. Using types that can not be mapped to one of the types defined XML Schema is a problem, though.
 
Bear Bibeault
Sheriff
Posts: 67756
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
In whatever way that client code deems suitable for its purposes using the constructs available in the client language.
 
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Vaibhav G Garg wrote:...I am wondering how this XML will regenerate the data structure back on client side where we have code in C/C++.


You could even put JSON in SOAP envelope and deserialize it on C/C++ side if it has JSON-library.
 
Ranch Hand
Posts: 491
5
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
1. Rest webservice:

On the server side, if you create a Restful webservice (using any restful framework) and try to return a map,
the framework's runtime will convert the map into text-based json format before it travel thru http.

-Have a look at REST Jersey or Spring MVC for example.

On the client, it's easy to consume a text-baseD json format.

-Have a look at JQUERY for example or any language

2. Soap webservice:

Look at data type allowed by JAX-WS spec. See Metro implementaion for example.
 
surlac surlacovich
Ranch Hand
Posts: 296
Spring
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Ulf Dittmer wrote:You should restrict yourself to the data types defined in XML Schema, since only those are guaranteed to work cross-platform.


But it is also possible to define more complex data-type which reflects Map data-type. So any client code, that has XSD, can demarshall XML to objects (C++, Java, etc.). So define something like:
 
Ulf Dittmer
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
That, to me, is still a data type defined in XML Schema. Maybe "data type defined using XML Schema" is clearer.
 
reply
    Bookmark Topic Watch Topic
  • New Topic