You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by harinair <ha...@hotmail.com> on 2008/11/10 05:30:18 UTC

Setting HTTP headers before send

Hi All:

I use the recipientList to send to different endpoints like ftp/sftp/http
depending on the header route.  I have a requirement of setting the headers
before the send - especially the WSSE headers that contains a unique nonce
and the created date. I have to set this every time the HTTP endpoint or any
endpoint try to send it - even on retries I have to modify these headers. Is
there any easy way to do this?

Any help will be greatly appreciated.
Hari Gangadharan

-- 
View this message in context: http://www.nabble.com/Setting-HTTP-headers-before-send-tp20414207s22882p20414207.html
Sent from the Camel - Users mailing list archive at Nabble.com.


Re: Setting HTTP headers before send

Posted by Claus Ibsen <cl...@gmail.com>.
Hi

Use a plain POJO to send it and inject a ProducerTemplate so you can
send it easily
>From the POJO (java code) you are in full power what to do before sending it.

Camel however also have a intercept() DSL that might come handy but
it's not used as much,
but I guess the interceptor might not kick in on retries. So a POJO
would be my advice, giving you 100% full control.

See
http://activemq.apache.org/camel/pojo-producing.html


Then you can have a simple route as:
from("direct:tohttp").to("bean:myPOJOSender");

Where the bean will set the correct headers and send it to the http endpoint.


public class MyPOJOSender {

  public void doSomething(Exchange exchange) {
     // here you can set the header, instead of the route above
     // then you can set some other values before you send it as well
     // as they will be updated also for retries
     template.send("http:/xxx", exchange);
  }




/Claus Ibsen
Apache Camel Committer
Blog: http://davsclaus.blogspot.com/



On Fri, Nov 14, 2008 at 10:10 PM, harinair <ha...@hotmail.com> wrote:
>
> Claus:
>
> Thanks for the reply... I would not have much control since I use dynamic
> routing address by recipientList. Probably to refresh WSSE for every retry,
> I may have to modify the HTTP component??? Is there no other way to
> introduce some kind of send filter on the component so that I can get the
> control before each send? Probably not possible - right?
>
> Regards.
> Hari Gangadharan
>
>
>
> Claus Ibsen wrote:
>>
>> Hi
>>
>> You could send it to a direct endpoint and then you can set the header
>> before sending it to the real http endpoint.
>>
>> Something like this - where we use a POJO to compute the header value:
>>
>> from("direct:tohttp").setHeader("wsse").bean(MySetHeaderBean.class).to("http:xxxx")
>>
>> You can also use the simple language to set the date and a constant text.
>> Maybe that is sufficient for your requirement:
>>
>> from("direct:tohttp").setHeader("wsse").simple("${date:now:YYYY-mm-dd}
>> Hello World").to("http:xxxx")
>>
>>
>>
>> Oh the problem with setting on retries is a bit more cumbersome; you can
>> use a POJO to send it so you can be in full power, where you set the
>> updated header.
>>
>> from("direct:tohttp").to("bean:sendtohttp");
>>
>> And in the POJO sendtohttp you set the new updated header.
>> Then Camel will handle retry and invoke you bean for each retry where you
>> set a fresh updated header.
>>
>>
>>
>> Med venlig hilsen
>>
>> Claus Ibsen
>> ......................................
>> Silverbullet
>> Skovsgårdsvænget 21
>> 8362 Hørning
>> Tlf. +45 2962 7576
>> Web: www.silverbullet.dk
>> -----Original Message-----
>> From: harinair [mailto:hari_g@hotmail.com]
>> Sent: 10. november 2008 05:30
>> To: camel-user@activemq.apache.org
>> Subject: Setting HTTP headers before send
>>
>>
>> Hi All:
>>
>> I use the recipientList to send to different endpoints like ftp/sftp/http
>> depending on the header route.  I have a requirement of setting the
>> headers
>> before the send - especially the WSSE headers that contains a unique nonce
>> and the created date. I have to set this every time the HTTP endpoint or
>> any
>> endpoint try to send it - even on retries I have to modify these headers.
>> Is
>> there any easy way to do this?
>>
>> Any help will be greatly appreciated.
>> Hari Gangadharan
>>
>> --
>> View this message in context:
>> http://www.nabble.com/Setting-HTTP-headers-before-send-tp20414207s22882p20414207.html
>> Sent from the Camel - Users mailing list archive at Nabble.com.
>>
>>
>>
>
> --
> View this message in context: http://www.nabble.com/Setting-HTTP-headers-before-send-tp20414207s22882p20508355.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>

Re: Setting HTTP headers before send

Posted by Willem Jiang <wi...@gmail.com>.
Hi Hari,

If you want to send the message to a http endpoint , you could set routing
address to be "direct:tohttp" and set the message header with

.setHeader(org.apache.camel.component.http.HttpProducer.HTTP_URI,
constant("http://newhost"))

then you can get what you want.

BTW, the HTTP_URI header was just added into the Camel 1.5.1.*

*Willem*
*
On Sat, Nov 15, 2008 at 5:10 AM, harinair <ha...@hotmail.com> wrote:

>
> Claus:
>
> Thanks for the reply... I would not have much control since I use dynamic
> routing address by recipientList. Probably to refresh WSSE for every retry,
> I may have to modify the HTTP component??? Is there no other way to
> introduce some kind of send filter on the component so that I can get the
> control before each send? Probably not possible - right?
>
> Regards.
> Hari Gangadharan
>
>
>
> Claus Ibsen wrote:
> >
> > Hi
> >
> > You could send it to a direct endpoint and then you can set the header
> > before sending it to the real http endpoint.
> >
> > Something like this - where we use a POJO to compute the header value:
> >
> >
> from("direct:tohttp").setHeader("wsse").bean(MySetHeaderBean.class).to("http:xxxx")
> >
> > You can also use the simple language to set the date and a constant text.
> > Maybe that is sufficient for your requirement:
> >
> > from("direct:tohttp").setHeader("wsse").simple("${date:now:YYYY-mm-dd}
> > Hello World").to("http:xxxx")
> >
> >
> >
> > Oh the problem with setting on retries is a bit more cumbersome; you can
> > use a POJO to send it so you can be in full power, where you set the
> > updated header.
> >
> > from("direct:tohttp").to("bean:sendtohttp");
> >
> > And in the POJO sendtohttp you set the new updated header.
> > Then Camel will handle retry and invoke you bean for each retry where you
> > set a fresh updated header.
> >
> >
> >
> > Med venlig hilsen
> >
> > Claus Ibsen
> > ......................................
> > Silverbullet
> > Skovsgårdsvænget 21
> > 8362 Hørning
> > Tlf. +45 2962 7576
> > Web: www.silverbullet.dk
> > -----Original Message-----
> > From: harinair [mailto:hari_g@hotmail.com]
> > Sent: 10. november 2008 05:30
> > To: camel-user@activemq.apache.org
> > Subject: Setting HTTP headers before send
> >
> >
> > Hi All:
> >
> > I use the recipientList to send to different endpoints like ftp/sftp/http
> > depending on the header route.  I have a requirement of setting the
> > headers
> > before the send - especially the WSSE headers that contains a unique
> nonce
> > and the created date. I have to set this every time the HTTP endpoint or
> > any
> > endpoint try to send it - even on retries I have to modify these headers.
> > Is
> > there any easy way to do this?
> >
> > Any help will be greatly appreciated.
> > Hari Gangadharan
> >
> > --
> > View this message in context:
> >
> http://www.nabble.com/Setting-HTTP-headers-before-send-tp20414207s22882p20414207.html
> > Sent from the Camel - Users mailing list archive at Nabble.com.
> >
> >
> >
>
> --
> View this message in context:
> http://www.nabble.com/Setting-HTTP-headers-before-send-tp20414207s22882p20508355.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
>
>

RE: Setting HTTP headers before send

Posted by harinair <ha...@hotmail.com>.
Claus:

Thanks for the reply... I would not have much control since I use dynamic
routing address by recipientList. Probably to refresh WSSE for every retry,
I may have to modify the HTTP component??? Is there no other way to
introduce some kind of send filter on the component so that I can get the
control before each send? Probably not possible - right?

Regards.
Hari Gangadharan



Claus Ibsen wrote:
> 
> Hi
> 
> You could send it to a direct endpoint and then you can set the header
> before sending it to the real http endpoint.
> 
> Something like this - where we use a POJO to compute the header value:
> 
> from("direct:tohttp").setHeader("wsse").bean(MySetHeaderBean.class).to("http:xxxx")
> 
> You can also use the simple language to set the date and a constant text.
> Maybe that is sufficient for your requirement:
> 
> from("direct:tohttp").setHeader("wsse").simple("${date:now:YYYY-mm-dd}
> Hello World").to("http:xxxx")
> 
> 
> 
> Oh the problem with setting on retries is a bit more cumbersome; you can
> use a POJO to send it so you can be in full power, where you set the
> updated header.
> 
> from("direct:tohttp").to("bean:sendtohttp");
>  
> And in the POJO sendtohttp you set the new updated header.
> Then Camel will handle retry and invoke you bean for each retry where you
> set a fresh updated header.
> 
> 
> 
> Med venlig hilsen
>  
> Claus Ibsen
> ......................................
> Silverbullet
> Skovsgårdsvænget 21
> 8362 Hørning
> Tlf. +45 2962 7576
> Web: www.silverbullet.dk
> -----Original Message-----
> From: harinair [mailto:hari_g@hotmail.com] 
> Sent: 10. november 2008 05:30
> To: camel-user@activemq.apache.org
> Subject: Setting HTTP headers before send
> 
> 
> Hi All:
> 
> I use the recipientList to send to different endpoints like ftp/sftp/http
> depending on the header route.  I have a requirement of setting the
> headers
> before the send - especially the WSSE headers that contains a unique nonce
> and the created date. I have to set this every time the HTTP endpoint or
> any
> endpoint try to send it - even on retries I have to modify these headers.
> Is
> there any easy way to do this?
> 
> Any help will be greatly appreciated.
> Hari Gangadharan
> 
> -- 
> View this message in context:
> http://www.nabble.com/Setting-HTTP-headers-before-send-tp20414207s22882p20414207.html
> Sent from the Camel - Users mailing list archive at Nabble.com.
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/Setting-HTTP-headers-before-send-tp20414207s22882p20508355.html
Sent from the Camel - Users mailing list archive at Nabble.com.


RE: Setting HTTP headers before send

Posted by Claus Ibsen <ci...@silverbullet.dk>.
Hi

You could send it to a direct endpoint and then you can set the header before sending it to the real http endpoint.

Something like this - where we use a POJO to compute the header value:

from("direct:tohttp").setHeader("wsse").bean(MySetHeaderBean.class).to("http:xxxx")

You can also use the simple language to set the date and a constant text. Maybe that is sufficient for your requirement:

from("direct:tohttp").setHeader("wsse").simple("${date:now:YYYY-mm-dd} Hello World").to("http:xxxx")



Oh the problem with setting on retries is a bit more cumbersome; you can use a POJO to send it so you can be in full power, where you set the updated header.

from("direct:tohttp").to("bean:sendtohttp");
 
And in the POJO sendtohttp you set the new updated header.
Then Camel will handle retry and invoke you bean for each retry where you set a fresh updated header.



Med venlig hilsen
 
Claus Ibsen
......................................
Silverbullet
Skovsgårdsvænget 21
8362 Hørning
Tlf. +45 2962 7576
Web: www.silverbullet.dk
-----Original Message-----
From: harinair [mailto:hari_g@hotmail.com] 
Sent: 10. november 2008 05:30
To: camel-user@activemq.apache.org
Subject: Setting HTTP headers before send


Hi All:

I use the recipientList to send to different endpoints like ftp/sftp/http
depending on the header route.  I have a requirement of setting the headers
before the send - especially the WSSE headers that contains a unique nonce
and the created date. I have to set this every time the HTTP endpoint or any
endpoint try to send it - even on retries I have to modify these headers. Is
there any easy way to do this?

Any help will be greatly appreciated.
Hari Gangadharan

-- 
View this message in context: http://www.nabble.com/Setting-HTTP-headers-before-send-tp20414207s22882p20414207.html
Sent from the Camel - Users mailing list archive at Nabble.com.