Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Within CXF, why use any other binding than JAXB? (MTOM attachments, Aegis, XMLBeans,...)

I have been playing around with Apache CXF, in particular the various data bindings it supports: JAXB (the default), MTOM, Aegis and XMLBeans. Since all of these are supported, I suppose each has its merits. I came up with these:

  • Obviously, MTOM is to be preferred where large attachments are involved.
  • JAXB depends on annotations, so it is less suited when modification of classes is restricted.
  • Aegis has no wsdl2java tool, so it is less suited for "contract-first" development, i.e. start with a WSDL and generate your Java code from that.
  • It appears that Aegis provides slightly more control over the mapping between Java classes and XML through its declarative syntax in Class.aegis.xml files. On the other hand, I couldn't devise of any scenarios where JAXB did not do the trick.

I found this question juxtaposing JAXB and XMLBeans, but it doesn't give a comprehensive overview:

JAXB vs Apache XMLBeans

Besides these naive, a priori considerations, do you have any blood-and-guts experiences that would support the use of any other binding besides JAXB? I'm asking from a CXF point of view, but if any other options come to mind (e.g. Castor) please don't hesitate to elaborate.

like image 925
László van den Hoek Avatar asked Sep 03 '10 13:09

László van den Hoek


2 Answers

If starting from scratch to create a WSDL first web service, then I definitely would recommend sticking with JAXB 95% of the time (maybe even higher). It's definitely the best tested databinding in CXF and performs quite well.

Where the other databindings come in are usually for one of two cases:

1) Java first use cases where you have something already written in Java that you want to expose as a web service with little to no modifications to the code. Aegis has it's strengths here as it's designed to be able to handle a wider range of things than JAXB. However, if you CAN modify the code, adding JAXB annotations usually isn't that hard. If you have mostly normal "beans", it's not a big deal.

2) Existing applications that use a particular mapping. If you have exising applications that are expecting XMLBeans beans (or SDO beans if using 2.3-SNAPSHOT of CXF, or JiBX beans if following the GSoC project), then using the other databindings could help by removing any needed mappings from JAXB to those object models.

Hope that helps a little.

like image 168
Daniel Kulp Avatar answered Nov 10 '22 22:11

Daniel Kulp


Remember that JAXB is a specification so there are multiple implementations: Metro (Reference Implementation, MOXy (I'm the tech lead), etc.

JAXB can be used starting from Java classes or XML schema. If you have classes that cannot be modified individual JAXB implmentations offer extensions to handle that. See MOXy's externalizable metadata:

  • http://wiki.eclipse.org/EclipseLink/Examples/MOXy/EclipseLink-OXM.XML

JAXB was designed to work with MTOM attachments see the attachment marshaller/unmarshaller.

MOXy has XPath based mappings which offers full control of your object-to-XML binding see:

  • http://bdoughan.blogspot.com/2010/07/xpath-based-mapping.html
  • parse google geocode with xstream
like image 41
bdoughan Avatar answered Nov 10 '22 23:11

bdoughan