aspose file tools*
The moose likes Web Services and the fly likes soap web service communication Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "soap web service communication" Watch "soap web service communication" New topic
Author

soap web service communication

Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
I want to make a SOAP WS where the client sends an XML to WS and WS will process it and returns the xml of the result. I've seen in some example that I must construct the message manually (convert the POJO to XML using dom.createElement). There are also examples using Qname, but I'm still confused with qname. Is there a way to automate this? because the object is quite complex. any java built-in lib? I'm using java 6.
David Blevins
Greenhorn

Joined: May 03, 2010
Posts: 18
I might suggest REST (JAX-RS) instead of JAX-WS (or both -- you can do both from the same class if you use an EJB).

This is a fairly comprehensive "getting started" doc for JAX-WS and shows all the code, all the WSDL and all the SOAP messages sent back an forth.

It's attempting to expose as much of the "guts" as possible to give you enough of a comfort level that if you wanted to do something different (like use a different stack) you'll be better prepared:

http://tomee.apache.org/examples-trunk/simple-webservice/README.html

Note all of the above can work in Java SE provided you use the Embeddable EJB Container API part of EJB 3.1 (also shown in that example). You just need the right libraries in the classpath.
Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
will it be a problem if I don't use EJB? because we're instructed not to use EJB by my supervisor.
David Blevins
Greenhorn

Joined: May 03, 2010
Posts: 18
EJB not required, works fine with the @Stateless annotation removed and deployed in a .war file into a Java EE 6 certified server such as TomEE, JBoss or GlassFish.

Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
By the way, the sample in the link you gave me only pass primitive type like int, while in my case, the client will send XML file that contains XML like so:



only in my case, the XML will be more complex (up to 7 levels deep). how do you construct the soap message for this case? also what's the type in the parameter of the activated method in the server side to receive the XML?
I notice that if the wsdl is automatically generated (in my case using eclipse), third party lib must be used (like axis). or am I wrong?
If I'm not wrong, is there any way to construct and receive the soap message using java 6 built-in libs? more preferrably the one providing a template for the soap message so I just need to somehow embed the client's XML inside the template message. thanks
David Blevins
Greenhorn

Joined: May 03, 2010
Posts: 18
only in my case, the XML will be more complex (up to 7 levels deep). how do you construct the soap message for this case? also what's the type in the parameter of the activated method in the server side to receive the XML?
I notice that if the wsdl is automatically generated (in my case using eclipse), third party lib must be used (like axis). or am I wrong?
If I'm not wrong, is there any way to construct and receive the soap message using java 6 built-in libs? more preferrably the one providing a template for the soap message so I just need to somehow embed the client's XML inside the template message. thanks


JAXB 2 is what is used by default in JAX-WS to marshal objects to/from xml when sending receiving SOAP. The @WebService method returns an object annotated with JAXB annotations, it will be marshalled to xml and sent as the response.

JAXB iss built into the VM in Java 6, so you could potentially have a "real" server and a "fake" client that doesn't truly understand all of SOAP and just creates messages by hand. You'd just need a set of JAXB objects to match the xml you plan to send back and forth and construct soap messages by hand in a client.

Are you attempting to create a client for an existing webservice or are you creating both the client and the server?
Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
I'm trying to create both actually. legal department will be the client while the finance department will be the one providing financial web service.

this is my web service's interface:


as you can see, the return and parameter are both String. Is this what you meant? is this correct?

and in the client side, do you mean that I need to construct the SOAP Message? the legal department provides valid XML documents. do you mean something like:


thank you.
David Blevins
Greenhorn

Joined: May 03, 2010
Posts: 18
Passing a String back and forth will work. The contents of the String will simply be wrapped in a CDATA block.

The bigger question is if that is really what you want. If you intend to manipulate these xml documents as java objects on either the client or server then I recommend taking a day or two and learning about JAXB.

This is a really large example, but the related xml should be quite familiar. This class is annotated with JAXB annotations and is capable of reading and writing web.xml files. Most the fields and elements should be fairly intuitive:

http://svn.apache.org/repos/asf/openejb/trunk/openejb/container/openejb-jee/src/main/java/org/apache/openejb/jee/WebApp.java

This ties into JAX-WS in the following way. Say your doService method actually looked like this:



What would happen is the JAX-WS engine would see that the WebApp class was annotated with JAXB annotations and would then create a web.xml "file" from that object and pass it back to the client in the SOAP response. I put "file" in quotes as of course there is no file, you'd simply get the contents of what would be the web.xml file version of the WebApp object you return.

So you have the choice to handle your requests and responses as Strings or Java classes of your making. It's up to you. I'd probably put the time into learning JAXB.
Hendra Kurniawan
Ranch Hand

Joined: Jan 31, 2011
Posts: 239
yes, I already tried that in the server part. The problem is, how would the client class look like? I've changed the server implementation to:


where RiskValue is annotated with jaxb. Is the parameter still string xmlString? or should that be changed too? if so, to what. The main concern is the client. How to send the XML file (is it sent as filestream or string or other?) and how to receive the object from the service. Does that mean I have to create the class RiskValue in the client class? thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: soap web service communication