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

Enable auto JAXB bindings OR do JAXB manually

 
Nitin Gaur
Greenhorn
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Ivan Krizsan
Ranch Hand
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 27
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2198
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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!
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic