This week's book giveaway is in the OCPJP forum.
We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line!
See this thread for details.
The moose likes Web Services and the fly likes Web Services/SOAP Newbie question Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of OCA/OCP Java SE 7 Programmer I & II Study Guide this week in the OCPJP forum!
JavaRanch » Java Forums » Java » Web Services
Bookmark "Web Services/SOAP Newbie question" Watch "Web Services/SOAP Newbie question" New topic
Author

Web Services/SOAP Newbie question

Dale Christ
Greenhorn

Joined: Jun 05, 2010
Posts: 3
I'm new to Web services, and am working on developing a SOAP service. From the examples I've seen using JAX-WS, I can issue what ever input parameters to a SOAP service that I want to. What isn't clear is how to get anything other than a String in the return message.

Here's a sample return from a "Ping" soap service that I created:



What I would like to have is "richer" output - for example:



So how can I create a response that includes XML that I have? Or is there a way that I can return either a POJO, or a Document (org.w3c.Document)?

Thanks in advance for any help.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Are you developing the web service by writing the code first or do you write the WSDL first?
I suspect the former, so I will answer that here. If you indeed are doing WSDL-first development, then go directly for the XML schema below.

You can use a Java Bean class of your own as parameter or return type in a method that is exposed in your web service.
JAXB, the framework responsible for converting data from a Java object hierarchy to a XML representation, will take care of the mapping.
Example:
I implemented the following class to use as the type of a parameter sent to an operation in my web service:


Having deployed the web service, the following XML schema fragment was generated corresponding to the above class:


A SOAP request to the operation looks like this:

Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Dale Christ
Greenhorn

Joined: Jun 05, 2010
Posts: 3
Thanks for the help so far. This is close to what I'm looking for, and it definitely covers POJOs.

The next thing that I need is something like this (think HTML table, but it can be just about any kind of free form XML - I usually create a Document (org.w3c.Document) from a jar file that I created, then parse it when I create my web page):



This kind of output is pretty easy to do in REST, but SOAP seems a little more challenging. I like the ability to have complex inputs to a SOAP request, but the simplicity (in my case, I can do XML) of a REST response

Again, thanks for any info.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Personally, I would not have a web service generate HTML. To me, this feels like assigning a responsibility that belongs in the presentation layer to another layer (perhaps this can be called the service layer).
This will lead to to service layer being coupled to the HTML presentation and there will be difficulties creating, for example, a Swing client that uses the same service layer.
A, in my opinion, better idea is to have the service(s) produce XML data, which is later (in the presentation layer) either used to render a presentation or transformed using XSLT to HTML or XHTML.
Best wishes!
Dale Christ
Greenhorn

Joined: Jun 05, 2010
Posts: 3
Ivan Krizsan wrote:Hi!
Personally, I would not have a web service generate HTML. To me, this feels like assigning a responsibility that belongs in the presentation layer to another layer (perhaps this can be called the service layer).
This will lead to to service layer being coupled to the HTML presentation and there will be difficulties creating, for example, a Swing client that uses the same service layer.
A, in my opinion, better idea is to have the service(s) produce XML data, which is later (in the presentation layer) either used to render a presentation or transformed using XSLT to HTML or XHTML.
Best wishes!


I was thinking the same thing after I did a little more researching and coding last night. I'm going to set up the service (database) layer to create the POJOs that I need. I can then translate the POJOs into the final format (XML, HTML, etc.) on my client/presentation layer.

Thanks again for the help.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: Web Services/SOAP Newbie question