You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Licia <al...@gmail.com> on 2014/07/16 13:57:35 UTC

Give setHeader a non-constant value

Hello everyone, 

I encountered a problem. I would like to pass to setHeader a non-constant
expression, but I can't seem to manage to do it. 

My *route* looks like that : 

//My own function that works well
int monthId = getLastIdFromBasis();

//Transforming xml into database
		from ("file:src/data/xmlTest")
			.split(xpath("/numbers/month"))
			.filter().xpath(xpathReq)
			.setHeader("ca", xpath("/month/ca/text()"))
		        .setHeader("margin", xpath("/month/margin/text()"))
		        .setHeader("monthName", xpath("/month/@name"))
		 *   //.setHeader("monthId").body()*
			.setBody(simple("INSERT INTO month VALUES (4, '${header.monthName}',
${header.ca}, ${header.margin}, 1);"))
                        .to("jdbc:dataSource?useHeadersAsParameters=true");

The line I can't seem to code is the one in bold. I'd like to give it the
monthId I get few lines above and give it as a parameter into the SQL
Request too. Do you have any idea how I could do that ? 
			



--
View this message in context: http://camel.465427.n5.nabble.com/Give-setHeader-a-non-constant-value-tp5753914.html
Sent from the Camel - Users mailing list archive at Nabble.com.

Re: Give setHeader a non-constant value

Posted by Claus Ibsen <cl...@gmail.com>.
setHeader("foo", constant("bar")) is setting a fixed value.

For the message body / headers etc use the simple language
http://camel.apache.org/simple

setHeader("foo", simple("${body}")) etc

On Wed, Jul 16, 2014 at 1:57 PM, Licia <al...@gmail.com> wrote:
> Hello everyone,
>
> I encountered a problem. I would like to pass to setHeader a non-constant
> expression, but I can't seem to manage to do it.
>
> My *route* looks like that :
>
> //My own function that works well
> int monthId = getLastIdFromBasis();
>
> //Transforming xml into database
>                 from ("file:src/data/xmlTest")
>                         .split(xpath("/numbers/month"))
>                         .filter().xpath(xpathReq)
>                         .setHeader("ca", xpath("/month/ca/text()"))
>                         .setHeader("margin", xpath("/month/margin/text()"))
>                         .setHeader("monthName", xpath("/month/@name"))
>                  *   //.setHeader("monthId").body()*
>                         .setBody(simple("INSERT INTO month VALUES (4, '${header.monthName}',
> ${header.ca}, ${header.margin}, 1);"))
>                         .to("jdbc:dataSource?useHeadersAsParameters=true");
>
> The line I can't seem to code is the one in bold. I'd like to give it the
> monthId I get few lines above and give it as a parameter into the SQL
> Request too. Do you have any idea how I could do that ?
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Give-setHeader-a-non-constant-value-tp5753914.html
> Sent from the Camel - Users mailing list archive at Nabble.com.



-- 
Claus Ibsen
-----------------
Red Hat, Inc.
Email: cibsen@redhat.com
Twitter: davsclaus
Blog: http://davsclaus.com
Author of Camel in Action: http://www.manning.com/ibsen
hawtio: http://hawt.io/
fabric8: http://fabric8.io/