• 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
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Web Services/SOAP Newbie question

 
Greenhorn
Posts: 3
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Popeye has his spinach. I have this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic