Two Laptop Bag*
The moose likes Web Services and the fly likes Enable auto JAXB bindings OR do JAXB manually Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Web Services
Bookmark "Enable auto JAXB bindings OR do JAXB manually" Watch "Enable auto JAXB bindings OR do JAXB manually" New topic
Author

Enable auto JAXB bindings OR do JAXB manually

Nitin Gaur
Greenhorn

Joined: Sep 06, 2003
Posts: 27
We are considering 2 approaches while exposing web services to internal applications. Please help in deciding the pros and cons of each.

Approach-1 is now standard in which JAXB bindings are applied at both sides (client and server) internally. Client and Server code work on Java objects and not on SOAP XML message directly.

Approach-2 is old way in which JAXB bindings are NOT applied at both sides (client and server) internally. Client constructs SOAP XML message and server receives XML and unmarshall into JAXB object.


If you don't like something, change it. If you can't change it, change your attitude. Don't complain.
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
I would suggest using approach 1 with automated generation of client artifacts in the client's build script. This way all client artifacts, including JAXB binding classes, are created when the build script is run and you do not need to write any code dealing with those parts. If the web service changes significantly, then of course you will have to modify the code using the generated artifacts.

Motivation:
As far as I understand, this will save you time and reduce the amount of code you need to write.
However, there may be circumstances that justify processing of raw XML which I do not know about. Please include more details if you want further analysis.

Special case:
If you want to develop a general, document-based, web service that is to be extensible by, for instance, adding support for processing documents belonging to new namespaces, then the JAXB approach may have limited value.
Best wishes!
Nitin Gaur
Greenhorn

Joined: Sep 06, 2003
Posts: 27
Thanks Evan,

But I wonder how would I generate the XML just by looking at the schema (if available). I must generate JAXB bindings from WSDL, populate them and then do marshaling to generate the XML SOAP message. Right?

The motivation to process raw XML is to provide uniform processing at server side that defines XML as common input format to integrate through any type of communication medium e.g. SOAP/HTTP or JMS or RMI (rare case)
Ivan Krizsan
Ranch Hand

Joined: Oct 04, 2006
Posts: 2198
    
    1
Hi!
Nitin Gaur wrote:But I wonder how would I generate the XML just by looking at the schema (if available). I must generate JAXB bindings from WSDL, populate them and then do marshaling to generate the XML SOAP message. Right?

Well, you can write code that expects certain XML data using, for instance, the SAAJ API. This is of course much more work than using JAXB, but it is still an available option.

The motivation to process raw XML is to provide uniform processing at server side that defines XML as common input format to integrate through any type of communication medium e.g. SOAP/HTTP or JMS or RMI (rare case)

Well again, what is stopping you from using JAXB independent of the transport medium?
If you use the XJC JAXB schema compiler, generating JAXB classes, then you can write your own code that uses these JAXB classes, regardless of whether the XML data is received over HTTP, JMS, RMI or even in an email.
Of course you can still use the JAXB classes generated by wsimport in your own code.
Best wishes!
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
 
subject: Enable auto JAXB bindings OR do JAXB manually
 
Similar Threads
Query regarding RPC/Document Style,WSGEN and WSIMPORT
Expose all operations OR just one
Facade design pattern in web services
Client/Server
How to marshal data from a SOAP header and write it to disc