You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by edhansen42 <ed...@vsp.com> on 2014/06/26 21:11:50 UTC
Passing Headers to a Route Invoked via Proxy
I have a route (A) that invokes a bean. In the bean I am using the @Produce
annotation to proxy to an endpoint associated with route B.
When the endpoint for route B is invoked, camel creates a new exchange for
it and sets the body to the BeanInvocation from the proxy call.
But route B needs information that is stored in the headers of the exchange
from route A.
What is the best way to get information from the headers of the exchange for
route A transferred to route B?
--
View this message in context: http://camel.465427.n5.nabble.com/Passing-Headers-to-a-Route-Invoked-via-Proxy-tp5752894.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Passing Headers to a Route Invoked via Proxy
Posted by edhansen42 <ed...@vsp.com>.
That would certainly help get the header values I need into Bean A as shown
below.
Route A:
from("direct:RouteA")
.beanRef("beanA", "retrieve(${headers})")
;
Bean A
@Produce(uri = "direct:foobar")
protected FooBarService fooBarService;
public ReturnValue retrieve(Map<String,String>headers) {
String someHeader = headers.get("someHeader");
someValue = fooBarService.foobar();
return someValue;
}
But I'm still not clear on how I would pass on the header value retrieved
above so that I have access to it in Route B. In Route B, I end up with a
new DefaultExchange that doesn't contain any of the header information from
Route A.
I imagine I could modify the foobar() method in the FooBarService interface
to pass the header value, but I'm still not sure how I would have access to
the value in Route B, plus that approach seems too invasive.
Route B:
from("direct:foobar")
.beanRef("bean that somehow set's 'someHeader' on this
route's Exchange")
.to("some other uri")
;
I'm probably missing something obvious here, so any enlightenment would be
greatly appreciated.
--
View this message in context: http://camel.465427.n5.nabble.com/Passing-Headers-to-a-Route-Invoked-via-Proxy-tp5752894p5752975.html
Sent from the Camel - Users mailing list archive at Nabble.com.
Re: Passing Headers to a Route Invoked via Proxy
Posted by Claus Ibsen <cl...@gmail.com>.
Hi
Maybe the Camel bean parameter binding works
http://camel.apache.org/parameter-binding-annotations.html
On Thu, Jun 26, 2014 at 9:11 PM, edhansen42 <ed...@vsp.com> wrote:
> I have a route (A) that invokes a bean. In the bean I am using the @Produce
> annotation to proxy to an endpoint associated with route B.
>
> When the endpoint for route B is invoked, camel creates a new exchange for
> it and sets the body to the BeanInvocation from the proxy call.
>
> But route B needs information that is stored in the headers of the exchange
> from route A.
>
> What is the best way to get information from the headers of the exchange for
> route A transferred to route B?
>
>
>
>
>
> --
> View this message in context: http://camel.465427.n5.nabble.com/Passing-Headers-to-a-Route-Invoked-via-Proxy-tp5752894.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/
Re: Passing Headers to a Route Invoked via Proxy
Posted by edhansen42 <ed...@vsp.com>.
I was able to accomplish the goal by using RoutePolicySupport.
When an Exchange begins, I store the Exchange in a ThreadLocal variable on a
singleton class, which is defined as a @Bean and injected where needed.
Before I store the Exchange, I check to see if there is an existing one
already in the ThreadLocal variable. If so, I pull the headers from the
existing Exchange and set them on the new one.
When the Exchange ends, I clear the Exchange in the ThreadLocal variable.
--
View this message in context: http://camel.465427.n5.nabble.com/Passing-Headers-to-a-Route-Invoked-via-Proxy-tp5752894p5752982.html
Sent from the Camel - Users mailing list archive at Nabble.com.