I'd like to read XML files that will have some number of parameters defined
for a bean and ultimately store the information into a database.  

Currently I am reading from a JMS queue and using a toJdbc method on my bean
to create the sql to pass on to my database endpoint.  That works fine.  now
I want to pull the same parameters out of XML files.

It seems like this should be simple, but haven't had any luck.

my toJDBC looks like..

public String toJdbc(Exchange exchange){
    Map<String,Object> theHeaders = exchange.getIn().getHeaders();
    String theBody = exchange.getIn().getBody(String.class);
    StringBuilder sb = .... 
       8<....
    sb.append(((theHeaders.containsKey("age"))...
    &lt;build the rest of the jdbc string using theHeaders&gt;
     ...
    return sb.toString();

(but the problem seems to be with unmarshalling the XML file)

Things I've tried:
1) "*file://c:/infile).beanRef("myBean","toJdbc").to("stream:out")*;
    this grabs the file and loads the full XML text into the msg parameter
of my jdbc (that method loads exchange.getIn().getBody into the msg
parameter), which i suppose I could parse by hand.

2)
*file://c:/infile).marshal().xtream().convertBodyTo(com.me.MyBean.class).beanRef("myBean","toJdbc")*
    Hoping for some magic conversion, but no luck

3) I wrote a method for my bean with annotated XML parameters like:
    public void fromXML(@XPath("/account/option/value") String value,
   ....
   System.out.println("value="+value);

   But, value is always empty when i use the route:

   
*file://c:/infile).marshal().xtream().beanRef("myBean","fromXML").to("stream:out");*

So, my question is/are:
1) should #3 work?  

2) Isn't there a better way?

3) Ideally, i'd like to parse the xml that comes in and NOT assume the XPATH
is correct.  Do I need to do that myself?

Thanks!
-J

--
View this message in context: 
http://camel.465427.n5.nabble.com/Reading-XML-file-into-a-bean-tp4617160p4617160.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Reply via email to