You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@servicemix.apache.org by Juan José Vázquez Delgado <ju...@gmail.com> on 2010/11/29 10:18:02 UTC
JAXB marshaling issue with Camel and SMX 4.2
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
Re: JAXB marshaling issue with Camel and SMX 4.2
Posted by Juan José Vázquez Delgado <ju...@gmail.com>.
Hi,
The same thing happens using the camel-soap component in SMX 4.3.0
FUSE 03-00. So far, my workaround has been:
SoapJaxbDataFormat soap = new SoapJaxbDataFormat("", new
ServiceInterfaceStrategy(PortType.class, true));
soap.setContext(JAXBContext.newInstance(MyFirstClass.class,
MySecondClass.class, ....));
Any ideas about how to avoid having to set the JAXB context class by class?
BR,
Juanjo.
2010/11/29 Juan José Vázquez Delgado <ju...@gmail.com>:
> 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
>