0

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.

Ya.
  • 1,671
  • 4
  • 27
  • 53
  • Update: the "problem" got mysteriously solved. Now my object is converted to XML automatically. I didn't mention it before but I was getting a conversion exception when applying steps that would automatically transform it to a string. Now I'm getting a nice XML w/o having do do anything. My apologies, I've no idea what I did, I'm still relatively new to Camel. – Ya. May 17 '14 at 01:50

2 Answers2

2

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.

Community
  • 1
  • 1
Peter Keller
  • 7,526
  • 2
  • 26
  • 29
1

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.

Peter Keller
  • 7,526
  • 2
  • 26
  • 29
Daniel
  • 2,050
  • 7
  • 31
  • 55