Hi
First of all welcome to Apache Camel!
As you don't own a XSD you can't make use of JDK-XJC compiler tool to
create your JAXB-POJOs. However having a proper XSD had made your use
case much easier. As then JAXB would have taken over the job of
"Unmarshalling" from XML to POJO.
Nevertheless I used [1] to show you *one possible way* you could go for it.
The idea is really simple, just put a Processor in between which does the
conversion of DOMSource-Object => JPA-Object:
@Override
protected RouteBuilder createRouteBuilder() throws Exception {
return new RouteBuilder() {
@Override
public void configure() throws Exception {
// START SNIPPET: e1
from("file:target/pair")
// split the order child tags, and inherit namespaces from
the
// orders root tag
.split().tokenizeXML("order", "orders").process(new
Processor() {
@Override
public void process(Exchange exchange) throws
Exception {
DOMSource source =
exchange.getIn().getBody(DOMSource.class);
Node order = source.getNode();
NodeList childs = order.getChildNodes();
for (int j = 0; j < childs.getLength(); j++) {
Node text = childs.item(j);
// instead of just dumping the content as I
do here,
// just create an object of your POJO and
set the properties
// on it using the "current" Node here and
then do something like:
// WeatherCurrent weather = ne
WeatherCurrent();
// weather.setXXX(text.getTextContent());
// weather.set...
//
// exchange.getIn().setBody(weather);
System.out.println(text.getTextContent());
}
}
})
// of course you would instead send the current exchange
to
// the JPA producer instead of "mock"
// .to("jpa://com.foo.WeatherCurrent ")
.to("mock:split");
// END SNIPPET: e1
}
};
}
If you would run this test with my modifications it would additionally dump
the following into the console:
Camel in Action
ActiveMQ in Action
DSL in Action
[1]
https://svn.apache.org/repos/asf/camel/trunk/camel-core/src/test/java/org/apache/camel/language/TokenXMLPairNamespaceSplitTest.java
Babak
--
View this message in context:
http://camel.465427.n5.nabble.com/How-to-create-a-Camel-route-which-takes-XML-and-bind-some-data-to-JPA-annotated-POJO-tp5564614p5565135.html
Sent from the Camel - Users mailing list archive at Nabble.com.