Hi,
This weekend I bumped into an annoying issue regarding camel jaxb
marshaling in SMX 4.2. The issue had been discussed previously in the
Camel users list [1] but I couldn't find the right solution in it.
To make the long story short, a Camel JaxbDataFormat is unable to
create the JaxbContext from a bundle, even though it imports the
involved packages properly. A code like the next one doesn't work:
private JaxbDataFormat jaxb = new
JaxbDataFormat("my.package.with.jaxb.annotated.classes");
@Override
public void configure() throws Exception {
from("nmr:myNmrEndpoint")
.marshal(jaxb)
.to("log:out");
}
The package "my.package.with.jaxb.annotated.classes" contains an
ObjectFactory class and, as I said before, is exported and imported
properly. As it's discussed here [2], it's probably a classloading
issue but I don't know where it should be definitely solved.
So far, my workaround has been setting the jaxb context with the
classloader of the ObjectFactory class. Something like this:
@Override
public void configure() throws Exception {
JaxbDataFormat jaxb = new JaxbDataFormat();
// I'd like getting rid of this
ClassLoader cl =
my.package.with.jaxb.annotated.classes.ObjectFactory.class.getClassLoader();
jaxb.setContext(JAXBContext.newInstance("my.package.with.jaxb.annotated.classes",
cl));
from("nmr:myNmrEndpoint")
.marshal(jaxb)
.to("log:out");
}
This code works but an smarter approach would be fine.
Thanks in advance.
BR,
Juanjo.
[1]
http://camel.465427.n5.nabble.com/Help-with-Camel-JAXB-SMX4-Camel-2-1-0-td470566.html
[2]
http://efreedom.com/Question/1-1043109/JAXB-Find-Jaxbindex-Running-Inside-Apache-Felix