Question

I want to serialize the incoming message to XML. I'm starting from the camel-example-cxf-osgi example.

My Route:

JaxbDataFormat jaxb = new JaxbDataFormat();

from("cxf:bean:reportIncident")
 .convertBodyTo(InputReportIncident.class)
 .marshal(jaxb)
 .bean(new MyBean2())
 .transform(constant(ok));

But I'm getting error and I'm at a loss:

java.io.IOException: javax.xml.bind.JAXBException: class org.apache.camel.example.reportincident.InputReportIncident nor any of its super class is  known to this context.

Appreciate any help. Thx.

Pas de solution correcte

Autres conseils

Alternatively to the solution of Daniel, you could use

final JAXBContext jaxbContext = JAXBContext.newInstance(InputReportIncident.class);
final DataFormat jaxb = new JaxbDataFormat(jaxbContext);

This comes in handy if there is no ObjectFactory class. See Jaxb: How do I generate ObjectFactory class? for more general information about this subject.

You need to point your to the package where you keep your jaxb classes, something like

DataFormat jaxb = new JaxbDataFormat("com.acme.model");

The exception says that the jaxb context doesn't know how to marshal the class InputReportIncident.class.

Licencié sous: CC-BY-SA avec attribution
Non affilié à StackOverflow
scroll top