Wednesday, July 4, 2007

"Introducing" JAXB Annotations on Unannotated Java Typesets

Over the past few weeks we worked on migrating the SOAPProcessor (formerly known as "JBossWSAdapter") up to the JBossWS 2.0.x codebase. This was important for us because we wanted to get away from our dependency on a non-public JBossWS 1.x API. JBossWS has introduced a new SPI into the 2.x codebase. Changing the JBossESB SOAPProcessor action component to depend on this public SPI was a no-brainer.

However, the native SOAP stack in JBossWS 2.x depends on JAXB for SOAP<->Java binding. This raised an issue for us because JAXB is 100% driven by annotations on the Java binding classes. If your Webservice Java bindings are not JAXB annotated, JAXB will not marshal/unmarshal SOAP<->Java properly (see JAXB forum post).

A classic JBossESB usecase is one where the ESB is used to expose a Webservice interface for an existing Java based Service that doesn't already expose a Webservice interface. In this situation, you can use the ESB to define a "wrapper webservice" that maps calls to the target Service (we'll be automating this in a future release). In this situation you'll also want to use the Java types that define the target Service, when defining the "wrapper webservice" e.g. use an EJB's remote interface, without modification, to define a JSR 181 wrapper service.

So, in the usecase outlined above, the Java types that define the target Service are obviously not going to be JAXB annotated (or at least they typically will not be). At this point, using JAXB (and therefore JBossWS 2.x) is no longer an option, since JAXB will not work against an unannotated interface.

The JAXB RI API supports setting a RuntimeInlineAnnotationReader during JAXBContext creation. We've used this feature to support "Introduction" of the JAXB annotations, from an XML configuration, for interfaces that are not JAXB annotated. It works by creating dynamic proxies for the annotations as they are requested by JAXB RI, with the dynamic proxies being fed via an XML configuration. See "JAXB Annotation Introductions" for more details.

Having done this, and having talked with the JBossWS guys, it would appear as though users of JAXB are not the only ones that run into trouble as a result of not having an alternative to a purely annotation driven configuration model (JSR 181 being another example that Thomas Diesler and Hieko Braun have pointed out). Is there room for a general purpose mechanism that can be used to manually "Introduce" annotations in situations like this? Obviously you could suggest that implementations should just support 2 configuration models - internal (annotations) and external (something else - fed by XML, or whatever). But surely a single underlying configuration/metadata "access" mechanism (the Annotations API) is preferable.

The Annotation Reader approach (ala JAXB Introductions) seems to offer something along these lines, but it would be nice if it could be done without requiring the annotation reader i.e. it would be nice if we could introduce annotations directly on the Annotations API (AOP style).


Anonymous said...

Is there any way of getting this to work with FIELD access type? What if the fields are constructor-initialized and 'final'?

Anonymous said...

Also, I don't think XmlAttribute works. For example, this works:

<Method name="getA">
    <XmlElement name="A" required="true"/>

...but this does not:

<Method name="getA">
    <XmlAttribute name="A" required="true"/>

(it still comes out as an element)

Anonymous said...

I have added support for the XmlAccessorType class annotation, and fixed a couple of bugs which were stopping field annotations from working. Patch to follow.

Anonymous said...

Here's the patch:

With the patch you can do:

<Class name="blah.CustomerOrder">
  <XmlAccessorType value="FIELD"/>
  <Field name="header">
    <XmlElement namespace="http://..."/>
  <Field name="items">
    <XmlElement namespace="http://..."/>

You can also bind to attributes as well, using XmlAttribute.

sexy11 said...







sex999 said...



eda said...



Kayla said... Web site for the majority of the china wholesalers, and buy products wholesale to provide information and buy wholesale from china information exchange platform dedicated to becoming China Wholesale.
cell phones
cheap cell phones
wholesale cell phones
discount cell phones
cell phone china
cell phones wholesale
Mobil phones

dfadf said...

i like it
Microsoft Office 2010
Office 2010
Office 2007
Microsoft Office 2007
Microsoft Office
Windows 7
Microsoft outlook
Outlook 2010
Microsoft outlook 2010