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 Certification (SCDJWS/OCEJWSD) and the fly likes JAX-WS data conversion 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 » Certification » Web Services Certification (SCDJWS/OCEJWSD)
Bookmark "JAX-WS data conversion" Watch "JAX-WS data conversion" New topic
Author

JAX-WS data conversion

Mustafa Garhi
Ranch Hand

Joined: Nov 05, 2008
Posts: 111
Hi,

Please point me to a tutorial which talks about conversion of data from one form to another in JAX-WS from a client to the service and back.

I know java object is converted to XML to SOAP to object back on the service side. But a detailed web page listing the components that are responsible for the format changes and the reason behind the conversion will be a help. I tried looking on web but couldn't find anything specific.

Thanks in advance,
Asif G.
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Hi Asif,

Please elaborate on data conversion from one form to another. Did you mean accessing the raw xml at both client and service side. Dispatch and Provider interfaces deal with raw XML and you can use SAAJ, if you really want to build from scratch. Would not this be any help to you and also Ivan's notes has some examples dealing with Dispatch and Provider.


Regards
KumarRaja

Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
If you want to transform XML data in one format to XML data in another format, then you may want to take a look at XSLT: http://en.wikipedia.org/wiki/Xslt
An XSLT tutorial can be found at: http://www.w3schools.com/xsl/
An example how to perform XSLT transforms in Java can be found here: http://java.sun.com/developer/technicalArticles/xml/WebAppDev2/#code13
Best wishes!


My free books and tutorials: http://www.slideshare.net/krizsan
Mustafa Garhi
Ranch Hand

Joined: Nov 05, 2008
Posts: 111
Hi guys,

Thanks for your help.

I do not want to do any conversion on myself.

What i want to know is how data is converted or put to different forms starting from a java object in a web service world.

So if i was sending an employee object to a web service method, in what all forms will this object undergo a change before reaching the method.

e.g. employee object to XML on clien side(some component would do this); then to say binary 1s and 0s (to travel on wire) and then a receiver would convert that to java object again for the method. I want to know all the forms of my employee object would be converted to and the API responsible for the conversion. A diagram architecture would be a help. I hope this makes things clear.

Thanks in advance
Asif
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
In most cases with JAX-WS, JAXB is responsible for marshalling and unmarshalling XML data to Java objects and vice versa.
Best wishes!
Mustafa Garhi
Ranch Hand

Joined: Nov 05, 2008
Posts: 111
Thanks, ill have a loot at JAXB.

I guess what travels is SOAP. What converts XML to SOAP?

And what converts SOAP to packets that travel over wire?

Thanks again
Asif G
Kumar Raja
Ranch Hand

Joined: Mar 18, 2010
Posts: 519
    
    2

Mustafa Garhi wrote:Thanks, ill have a loot at JAXB.

I guess what travels is SOAP. What converts XML to SOAP?

And what converts SOAP to packets that travel over wire?

Thanks again
Asif G


Hi Asif,

JAX-WS runtime would convert your plain method calls to SOAP request/response at both client and service side, with the help of binding mechanism say JAXB. So when you annotate your classes with @WebService, runtime would take care of this conversion. But you can have a bit more control if you go with SAAJ, where you would build the SOAP from scratch. Remember SOAP is an XML document confirming the SOAP schema.
Mustafa Garhi
Ranch Hand

Joined: Nov 05, 2008
Posts: 111
So is this correct:

1. Java object is first converted to XML.
2. This XML is serialized
3. The serialized XML is marshelled
4. The marshelled XML travels over http.
5. This is received at server and reverse of above steps would occur.

Regards
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Delete steps 2 and 3 and you have a good description!
Regarding SAAJ: Yes, SAAJ will give you more control over building requests etc, but using SAAJ also means writing code - code of similar functionality that may be generated in seconds from a WSDL using JAXB. If you really need SAAJ, then go for it, but my experience is that JAXB is to be preferred in most of the cases I have seen.
My recommendation is to learn both how to use JAXB and how to use SAAJ - then you can decide yourself which is more appropriate!
Best wishes!
 
Don't get me started about those stupid light bulbs.
 
subject: JAX-WS data conversion