Thanks Claus, I was trying to keep out the Camel annotations. I wanted to have all the config/routes in Spring. My example route is:
> <route> > > <from>"ftp://rider.com/orders?username=rider&password=secret"</from> > <filter> > <simple>${bean:xmlFilter?method=match}</simple> > <to uri="log:worked"/> > </filter> > </route> How can I use XPath to pass the user to xmlFilter.match() in the below? <simple>${bean:xmlFilter?method=match}</simple> Thanks -----Original Message----- From: Claus Ibsen [mailto:[email protected]] Sent: Wednesday, February 01, 2012 9:26 AM To: [email protected] Subject: Re: Passing parameter values to bean methods via spring Hi You can use the Camel @Xpath annotation on a 2nd parameter in that method signature public boolean match(String username, @XPath("/Example/User") String user) { You may have to fiddle a bit to get the xpath expression working. Also sometimes you may have to use /text() to tell it to return the text content of the xml node. On Wed, Feb 1, 2012 at 3:05 PM, Gershaw, Geoffrey <[email protected]> wrote: > Thanks for the reply. Could you give me an example for 1c? I mocked up an > example. Assume the below XML comes from the ftp site. The XMLFilter's match > method accepts the username. How can I use XPath to pass the user to the > match method? > > > <Example> > > <User>joe</User> > > </Example> > > Class XMLFilter{ > > public boolean match(String username){ > //check db for user > //if found return true/else false > } > } > > <route> > > <from>"ftp://rider.com/orders?username=rider&password=secret"</from> > <filter> > <simple>${bean:xmlFilter?method=match}</simple> > <to uri="log:worked"/> > </filter> > </route> > > Thanks > > -----Original Message----- > From: Claus Ibsen [mailto:[email protected]] > Sent: Wednesday, February 01, 2012 3:20 AM > To: [email protected] > Subject: Re: Passing parameter values to bean methods via spring > > Hi > > On Tue, Jan 31, 2012 at 5:10 PM, Gershaw, Geoffrey > <[email protected]> wrote: >> Hello, >> >> >> >> I am a newbie to Camel. I've read a bunch of docs, but have not found an >> answer to this specific use case. >> > > Welcome to the community. > >> >> >> 1. Assume the following. >> >> a. I have the belown XML msg in the body of my Message. >> >> <Example> >> >> <User>joe</User> >> >> </Example> >> >> b. I am using a bean as a Filter. The method signature is >> >> i. >> public boolean validateUser(String user) >> >> c. Ideally I would like to user xpath in the config file to pass >> "Joe" to the validateUser method >> > > Yes xpath works fine for grabbing content from a XML doc. > However where it get tricky is if your XML uses namespaces. If so > your XPath expression *must* also use namespaces. > > >> d. If the method returns false, I would like the route to stop. >> Don't know how to do this. >> > > You can use a Content Based Router, and in the otherwise leg, you can > use the stop DSL. > > >> e. If the method returns true, I would like to pass the original >> XML msg to a processor and finish the route. >> > > Yes this happens already, the filter predicate is just for determine > true | false > >> f. Is this possible? >> >> > > Yes, something a like > > from X > choice > when bean (myFilterBean) > to Y > otherwise > stop > > > >> >> >> >> Thanks >> >> Geoff Gershaw >> >> >> =============================================================================== >> Please access the attached hyperlink for an important electronic >> communications disclaimer: >> http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html >> =============================================================================== >> > > > > -- > Claus Ibsen > ----------------- > FuseSource > Email: [email protected] > Web: http://fusesource.com > Twitter: davsclaus, fusenews > Blog: http://davsclaus.blogspot.com/ > Author of Camel in Action: http://www.manning.com/ibsen/ > > =============================================================================== > Please access the attached hyperlink for an important electronic > communications disclaimer: > http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html > =============================================================================== > -- Claus Ibsen ----------------- FuseSource Email: [email protected] Web: http://fusesource.com Twitter: davsclaus, fusenews Blog: http://davsclaus.blogspot.com/ Author of Camel in Action: http://www.manning.com/ibsen/ =============================================================================== Please access the attached hyperlink for an important electronic communications disclaimer: http://www.credit-suisse.com/legal/en/disclaimer_email_ib.html ===============================================================================
