Velocity Reviews - Computer Hardware Reviews

Velocity Reviews > Newsgroups > Programming > Java > Complex types in web services

Reply
Thread Tools

Complex types in web services

 
 
ses
Guest
Posts: n/a
 
      10-22-2010
What's the best approach for dealing with complex types (such as
HashMap<String,String>) with web services? Obviously for full
interoperability the only option would be to convert to a string array
- String[][]

But I tried using a wrapper class around a HashMap<String, String> and
it will build and deploy fine, though when I query the web service
using a tool such as soapUI, I simply get <return/> as the value for
what should contain my hashmap wrapper.

Is there any way I can get the wsgen tool to generate a complex type
of this sort or is it a much better idea to use primitives??
 
Reply With Quote
 
 
 
 
projectmoon
Guest
Posts: n/a
 
      10-22-2010
On Fri, 22 Oct 2010 02:54:29 -0700, ses wrote:

> What's the best approach for dealing with complex types (such as
> HashMap<String,String>) with web services? Obviously for full
> interoperability the only option would be to convert to a string array -
> String[][]
>
> But I tried using a wrapper class around a HashMap<String, String> and
> it will build and deploy fine, though when I query the web service using
> a tool such as soapUI, I simply get <return/> as the value for what
> should contain my hashmap wrapper.
>
> Is there any way I can get the wsgen tool to generate a complex type of
> this sort or is it a much better idea to use primitives??


Most web app frameworks will have tools for serializing complex types in
web services. Spring has its own stuff, and there is a (proposed?)
standard called JAX-WS that will also do it. The main thing to watch out
for with complex types is cyclical references, assuming you're using
JSON. JSON cannot handle cyclical references.
 
Reply With Quote
 
 
 
 
Arne Vajh°j
Guest
Posts: n/a
 
      10-22-2010
On 22-10-2010 05:54, ses wrote:
> What's the best approach for dealing with complex types (such as
> HashMap<String,String>) with web services? Obviously for full
> interoperability the only option would be to convert to a string array
> - String[][]
>
> But I tried using a wrapper class around a HashMap<String, String> and
> it will build and deploy fine, though when I query the web service
> using a tool such as soapUI, I simply get<return/> as the value for
> what should contain my hashmap wrapper.
>
> Is there any way I can get the wsgen tool to generate a complex type
> of this sort or is it a much better idea to use primitives??


I would convert HashMap<String,String> to NameValuePair[] - that
is a very portable structure.

Arne

 
Reply With Quote
 
Arne Vajh°j
Guest
Posts: n/a
 
      10-22-2010
On 22-10-2010 09:49, Steve W. Jackson wrote:
> In article<4cc18968$0$15424$c3e8da3$(E-Mail Removed) raweb.com>,
> projectmoon<(E-Mail Removed)> wrote:
>
>> On Fri, 22 Oct 2010 02:54:29 -0700, ses wrote:
>>
>>> What's the best approach for dealing with complex types (such as
>>> HashMap<String,String>) with web services? Obviously for full
>>> interoperability the only option would be to convert to a string array -
>>> String[][]
>>>
>>> But I tried using a wrapper class around a HashMap<String, String> and
>>> it will build and deploy fine, though when I query the web service using
>>> a tool such as soapUI, I simply get<return/> as the value for what
>>> should contain my hashmap wrapper.
>>>
>>> Is there any way I can get the wsgen tool to generate a complex type of
>>> this sort or is it a much better idea to use primitives??

>>
>> Most web app frameworks will have tools for serializing complex types in
>> web services. Spring has its own stuff, and there is a (proposed?)
>> standard called JAX-WS that will also do it. The main thing to watch out
>> for with complex types is cyclical references, assuming you're using
>> JSON. JSON cannot handle cyclical references.

>
> JAX-WS is out and has been for a *very* long time now. Much of it is
> integrated with JDK 6 as of around update 11 or 14, I forget which. And
> it can already handle some of these complex types. In particular, the
> cited example of HashMap<String,String> can be done, since it uses only
> known types inside. Doing one with a more complex type takes more work,
> which is what JAXB is for.


JAX-WS came with 1.6.nothing.

And the default handling of HashMap is not that useful.

Arne

 
Reply With Quote
 
Tom Anderson
Guest
Posts: n/a
 
      10-23-2010
On Fri, 22 Oct 2010, Arne Vajh?j wrote:

> On 22-10-2010 05:54, ses wrote:
>> What's the best approach for dealing with complex types (such as
>> HashMap<String,String>) with web services? Obviously for full
>> interoperability the only option would be to convert to a string array
>> - String[][]
>>
>> But I tried using a wrapper class around a HashMap<String, String> and
>> it will build and deploy fine, though when I query the web service
>> using a tool such as soapUI, I simply get<return/> as the value for
>> what should contain my hashmap wrapper.
>>
>> Is there any way I can get the wsgen tool to generate a complex type
>> of this sort or is it a much better idea to use primitives??

>
> I would convert HashMap<String,String> to NameValuePair[] - that
> is a very portable structure.


That's a better idea than either a String[][] or a tool-mapped HashMap.

But i'd go a step further and use something with domain meaning instead
ofa a NameValuePair. Say, if you want to move the names of characters in a
play with their descriptions, send a List<CharacterDefinition>, where:

public class CharacterDefinition {
private final String name;
private final String description;
// constructor, getters, etc
}

That should get mapped into a suitable schema type, and leads to more
readable XML, and a measure of additional type safety and
self-documentation in the consuming system.

tom

--
I'm having trouble getting women. Does anyone have Justina Robson's
email? -- Martin
 
Reply With Quote
 
 
 
Reply

Thread Tools

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
HELP!!! .NET 2.0 - Problem with Web Service Complex Types - 500 Internal Server Error? Framework Bug??? Spam Catcher ASP .Net 4 07-06-2007 05:14 PM
complex types in a Web service William F. Kinsley ASP .Net Web Services 4 02-17-2006 04:09 AM
Can XSD simple types be derived from complex types? Soren Kuula XML 2 12-01-2005 07:51 PM
Web Service with complex paramters and return types J.Marsch ASP .Net Web Services 1 11-14-2003 02:31 AM
Complex data types in Java Web Service Michael Java 0 09-16-2003 08:07 PM



Advertisments