You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by axdz <ho...@gmail.com> on 2016/10/05 07:31:54 UTC
Access header in camel route
Hi all,
I config a route in xml file
*<route>
<from uri="activemq:test" />
<process ref="MyProcessor" />
<to uri="activemq:${in.header.fieldname}" />
</route>*
and here i MyProcessor class
* public class MyProcessor implements Processor {
public void process(Exchange exchange) throws Exception {
exchange.getIn().setHeader("fieldname", "valuename");
}
}*
Above code can not show "valuename" by ${in.header.fieldname}.
Please give me some advice,
Thanks,
--
View this message in context: http://camel.465427.n5.nabble.com/Access-header-in-camel-route-tp5788372.html
Sent from the Camel - Users mailing list archive at Nabble.com.
RE: Access header in camel route
Posted by Steve Huston <sh...@riverace.com>.
I believe for the "to" routing, it's plain text... if you want to use a header value you need to use dynamic to:
http://camel.apache.org/how-to-use-a-dynamic-uri-in-to.html
http://www.davsclaus.com/2015/10/apache-camel-216-released-top-10.html
-Steve
> -----Original Message-----
> From: koperdraat.jk@gmail.com [mailto:koperdraat.jk@gmail.com] On
> Behalf Of Jonas Koperdraat
> Sent: Wednesday, October 05, 2016 7:25 AM
> To: users@camel.apache.org
> Subject: Re: Access header in camel route
>
> I believe the right way to access a header is either by using
> ${header.fieldname} or by using the @Header annotation.
>
> See http://camel.apache.org/simple.html
> and http://camel.apache.org/parameter-binding-annotations.html for
> references.
>
> Regards,
>
> Jonas
>
> On Wed, Oct 5, 2016 at 9:31 AM, axdz <ho...@gmail.com> wrote:
> > Hi all,
> >
> > I config a route in xml file
> >
> > *<route>
> > <from uri="activemq:test" />
> > <process ref="MyProcessor" />
> > <to uri="activemq:${in.header.fieldname}" />
> >
> > </route>*
> >
> > and here i MyProcessor class
> > * public class MyProcessor implements Processor {
> >
> > public void process(Exchange exchange) throws Exception {
> > exchange.getIn().setHeader("fieldname", "valuename");
> > }
> >
> > }*
> >
> > Above code can not show "valuename" by ${in.header.fieldname}.
> > Please give me some advice,
> > Thanks,
> >
> >
> >
> > --
> > View this message in context:
> > http://camel.465427.n5.nabble.com/Access-header-in-camel-route-
> tp57883
> > 72.html Sent from the Camel - Users mailing list archive at
> > Nabble.com.
Re: Access header in camel route
Posted by Brad Johnson <br...@mediadriver.com>.
@axdz
To amplify what Jonas said, you don't need to use a Processor. Just use a
regular Pojo.
public class MyHandler {
public void modify(@Headers Map<String,Object> headers)
{
headers.put("filedname", "value");
}
}
On Wed, Oct 5, 2016 at 6:25 AM, Jonas Koperdraat <jo...@jonaskoperdraat.nl>
wrote:
> I believe the right way to access a header is either by using
> ${header.fieldname} or by using the @Header annotation.
>
> See http://camel.apache.org/simple.html
> and http://camel.apache.org/parameter-binding-annotations.html for
> references.
>
> Regards,
>
> Jonas
>
> On Wed, Oct 5, 2016 at 9:31 AM, axdz <ho...@gmail.com> wrote:
> > Hi all,
> >
> > I config a route in xml file
> >
> > *<route>
> > <from uri="activemq:test" />
> > <process ref="MyProcessor" />
> > <to uri="activemq:${in.header.fieldname}" />
> >
> > </route>*
> >
> > and here i MyProcessor class
> > * public class MyProcessor implements Processor {
> >
> > public void process(Exchange exchange) throws Exception {
> > exchange.getIn().setHeader("fieldname", "valuename");
> > }
> >
> > }*
> >
> > Above code can not show "valuename" by ${in.header.fieldname}.
> > Please give me some advice,
> > Thanks,
> >
> >
> >
> > --
> > View this message in context: http://camel.465427.n5.nabble.
> com/Access-header-in-camel-route-tp5788372.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
>
Re: Access header in camel route
Posted by Jonas Koperdraat <jo...@jonaskoperdraat.nl>.
I believe the right way to access a header is either by using
${header.fieldname} or by using the @Header annotation.
See http://camel.apache.org/simple.html
and http://camel.apache.org/parameter-binding-annotations.html for references.
Regards,
Jonas
On Wed, Oct 5, 2016 at 9:31 AM, axdz <ho...@gmail.com> wrote:
> Hi all,
>
> I config a route in xml file
>
> *<route>
> <from uri="activemq:test" />
> <process ref="MyProcessor" />
> <to uri="activemq:${in.header.fieldname}" />
>
> </route>*
>
> and here i MyProcessor class
> * public class MyProcessor implements Processor {
>
> public void process(Exchange exchange) throws Exception {
> exchange.getIn().setHeader("fieldname", "valuename");
> }
>
> }*
>
> Above code can not show "valuename" by ${in.header.fieldname}.
> Please give me some advice,
> Thanks,
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Access-header-in-camel-route-tp5788372.html
> Sent from the Camel - Users mailing list archive at Nabble.com.