Win a copy of Think Java: How to Think Like a Computer Scientist this week in the Java in General forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Web Services/SOAP Newbie question

 
Dale Christ
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
Dale Christ
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 3
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic