You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Elezabeth <El...@ibsplc.com> on 2012/09/17 12:13:02 UTC
Dynamically variable in Camel
Hi ,
I am new to Camel.
My requirement is something like this . I have to read a csv file in a
folder when an HTTP url is invoked.
This is fine. But I will get a url with a requestparameter called "fileName"
and now this is the name of that csv file which i have to read.
Eg;
if my url is*/ http://localhost/test?filename=sample-2.csv/* , then I have
to read *sample-2.csv *from that folder.
I tried doing this in either way - using XML and using Java code.
This is how I configured the route
public class OagBuilder extends RouteBuilder {
CamelContext camelContext = new DefaultCamelContext();
DataFormat bindy = new BindyCsvDataFormat(
"jp.co.airlink.gavss.adapter.eai.oag.job");
String file = null;
public void add(Exchange exchnage){
file= (String) exchnage.getIn().getHeader("filename");
}
@Override
public void configure() throws Exception {
from("jetty:http://localhost:8080/test").inOnly("seda:myfile").to("bean:oagProcessor?method=add");
//file= Exchange.HTTP_QUERY.split("filename");
//System.out.println("fileis " + file) ;
from("seda:myfile").pollEnrich("file:d:/a/?fileName=" +
file).unmarshal(bindy).to("bean:validateFileInput?method=configure");
}
}
I am not getting the value of the variable "file" in the second route.
Can anyone help me .
--
View this message in context: http://camel.465427.n5.nabble.com/Dynamically-variable-in-Camel-tp5719462.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Dynamically variable in Camel
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
The RouteBuilder configure method is only invoked once, to setup the
Camel routes.
So if you want in the 2nd route to refer to a file name from a header,
you can use the file/simple language for that.
from("seda:myfile").pollEnrich("file:d:/a/?fileName=" +
file).unmarshal(bindy).to("bean:validateFileInput?method=configure");
Should be
from("seda:myfile").pollEnrich("file:d:/a/?fileName=${header.filename}")
.unmarshal(bindy).to("bean:validateFileInput?method=configure");
eg notice the fileName parameter refers to a header with the key filename.
Some links to check:
http://camel.apache.org/simple.html
http://camel.apache.org/file-language.html
http://camel.apache.org/file2
On Mon, Sep 17, 2012 at 12:13 PM, Elezabeth
<El...@ibsplc.com> wrote:
> Hi ,
>
> I am new to Camel.
>
> My requirement is something like this . I have to read a csv file in a
> folder when an HTTP url is invoked.
>
> This is fine. But I will get a url with a requestparameter called "fileName"
> and now this is the name of that csv file which i have to read.
>
> Eg;
>
> if my url is*/ http://localhost/test?filename=sample-2.csv/* , then I have
> to read *sample-2.csv *from that folder.
> I tried doing this in either way - using XML and using Java code.
>
> This is how I configured the route
>
> public class OagBuilder extends RouteBuilder {
>
> CamelContext camelContext = new DefaultCamelContext();
> DataFormat bindy = new BindyCsvDataFormat(
> "jp.co.airlink.gavss.adapter.eai.oag.job");
> String file = null;
>
> public void add(Exchange exchnage){
>
> file= (String) exchnage.getIn().getHeader("filename");
> }
>
> @Override
> public void configure() throws Exception {
>
>
> from("jetty:http://localhost:8080/test").inOnly("seda:myfile").to("bean:oagProcessor?method=add");
> //file= Exchange.HTTP_QUERY.split("filename");
> //System.out.println("fileis " + file) ;
> from("seda:myfile").pollEnrich("file:d:/a/?fileName=" +
> file).unmarshal(bindy).to("bean:validateFileInput?method=configure");
> }
>
> }
>
> I am not getting the value of the variable "file" in the second route.
>
> Can anyone help me .
>
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Dynamically-variable-in-Camel-tp5719462.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
--
Claus Ibsen
-----------------
FuseSource
Email: cibsen@fusesource.com
Web: http://fusesource.com
Twitter: davsclaus, fusenews
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
Re: Dynamic variable in Camel
Posted by Elezabeth <El...@ibsplc.com>.
Hi ,
I tried the way u suggested , but still it is not working ..
While searching I came across a link in which it is mentioned that for
*PollEnrich* , the ${ } is not working...
This is the link :
https://issues.apache.org/jira/browse/CAMEL-4596
Can you suggest any other way?
Thanks in advance
Elz
--
View this message in context: http://camel.465427.n5.nabble.com/Dynamic-variable-in-Camel-tp5719462p5719500.html
Sent from the Camel - Users mailing list archive at Nabble.com.