How to use camel-jaxb in fuse esb (4.1.0.0)
muellerc May 10, 2009 5:31 PMHi folks!
In a simple project, I would consume a xml file with camel-file from the file system, marshal the body with camel-jaxb to a domain object and then call a osgi service with this domain object.
But if I unmarshal the body, I receive always an exception, depending on wath I try:
My starting point was a simple "file move route". This route works great.
from("/tmp/events/incoming/")
.to("/tmp/events/outgoing");
Now, I create my schema (with namespaces) an generate the java code with the maven-jaxb2-plugin. After that, I create the jaxb.index file, added my domain model name and put it into the correct subdirectory under my src/main/resources directory. At the end, I installed the camel-jaxb feature in FUSE ESB.
case 1:
I read the doc http://fusesource.com/docs/router/1.6/defining_routes/FMRS.TMC.html and try it.
from("/tmp/events/incoming/")
.unmarshal(new org.apache.camel.model.dataformat.JaxbDataFormat())
.to("/tmp/events/outgoing");
But this class has no constructor which takes a string (typo?), so I use the default constructor. But I receive the following exception:
22:54:18,631 | WARN | Component@64b7e3 | ResolverUtil | g.apache.camel.util.ResolverUtil 517 | Could not find class 'org/apache/servicemix/nmr/core/converter/StringSourceConverter.class' in any classloaders:
...
22:54:18,645 | ERROR | Component@64b7e3 | DeadLetterChannel | rg.apache.camel.processor.Logger 203 | Failed delivery for exchangeId: ID-chris/50428-1241953976871/0-19. On delivery attempt: 0 caught: java.io.IOException: unexpected element (uri:"http://ps4b.de/rfid/model/Matrics", local:"Matrics"). Expected elements are (none)
java.io.IOException: unexpected element (uri:"http://ps4b.de/rfid/model/Matrics", local:"Matrics"). Expected elements are (none)
at org.apache.camel.util.IOHelper.createIOException(IOHelper.java:85)
case 2:
Because I think in case 1 was a type, I use the org.apache.camel.converter.jaxb.JaxbDataFormat instead
from("/tmp/events/incoming/")
.unmarshal(new org.apache.camel.converter.jaxb.JaxbDataFormat("de.ps4b.rfid.model.matrics"))
.to("/tmp/events/outgoing");
But again, I receive an exception:
23:02:42,912 | WARN | Component@db7208 | ResolverUtil | g.apache.camel.util.ResolverUtil 517 | Could not find class 'org/apache/servicemix/nmr/core/converter/StringSourceConverter.class'
...
23:02:42,943 | ERROR | Component@db7208 | DeadLetterChannel | rg.apache.camel.processor.Logger 203 | Failed delivery for exchangeId: ID-chris/50428-1241953976871/0-20. On delivery attempt: 0 caught: org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: class org.apache.camel.component.file.FileMessage to the required type: java.io.InputStream with value FileMessage: /Applications/apache-servicemix-4.1.0.0-fuse/incomingEvents/sample_event.xml
org.apache.camel.NoTypeConversionAvailableException: No type converter available to convert from type: class org.apache.camel.component.file.FileMessage to the required type: java.io.InputStream with value FileMessage: /Applications/apache-servicemix-4.1.0.0-fuse/incomingEvents/sample_event.xml
at org.apache.camel.impl.converter.DefaultTypeConverter.doConvertTo(DefaultTypeConverter.java:147)
case 3:
I searched the web and found an article at DZone: http://architects.dzone.com/articles/apache-camel-integration?page=0,0.
So, my route now looks like:
from("/tmp/events/incoming/")
.convertBodyTo(String.class)
.unmarshal(new org.apache.camel.converter.jaxb.JaxbDataFormat("de.ps4b.rfid.model.matrics"))
.to("/tmp/events/outgoing");
But I receive the same exception like case 2.
case 4:
I read, that camel use a JAXB fallback Type Converter (I think if the class has a @XmlRootElement annotation) http://camel.apache.org/etl-example.html. So, I try the following route:
from("/tmp/events/incoming/")
.convertBodyTo(Matrics.class)
.to("/tmp/events/outgoing");
And I got a warning, but the file was moved:
23:24:45,717 | WARN | Component@f0fef9 | ConvertBodyProcessor | l.processor.ConvertBodyProcessor 46 | Could not convert body of IN message: FileMessage: /Applications/apache-servicemix-4.1.0.0-fuse/incomingEvents/sample_event2.xml to type: de.ps4b.rfid.model.matrics.Matrics
case 5:
Ok, let me see what is the body class:
from("/tmp/events/incoming/")
.convertBodyTo(Matrics.class)
.process(new Processor() {
public void process(Exchange exchange) throws Exception {
logger.info("the body class is: " + exchange.getIn().getBody().getClass());
}
})
.to("/tmp/events/outgoing");
And I got:
23:30:42,327 | INFO | Component@61c570 | FileEventReader | ps4b.rfid.file.FileEventReader$1 38 | the body class is: class java.io.File
What can I do to receive my Matrics object? Any idea what is wrong or has anyone a running sample for me which can adopt?
Thank you for your help,
Christian