You are viewing a plain text version of this content. The canonical link for it is here.
Posted to users@camel.apache.org by Marvin Froeder <ve...@gmail.com> on 2015/09/09 12:23:26 UTC
Reuse a rote...
Hey guys,
I have a bunch of routes very similar:
> from("direct:repo")
> .setHeader(HttpHeaders.AUTHORIZATION).constant("Basic XXX")
> .convertBodyTo(String.class, UTF_8.name())
... more steps
> .to("http4://{{service.url}}")
> .setHeader("repo", body());
from("direct:art")
> .setHeader(HttpHeaders.AUTHORIZATION).constant("Basic XXX")
> .convertBodyTo(String.class, UTF_8.name())
>
... same extra steps
.to("http4://{{service.url}}")
> .setHeader("art", body());
They are very similar... and there are more. The difference is this header
on the last line
I wonder if there is a better way to reuse this routes...
Would be nice if I could consolidate both into a direct:store
And then just call as direct:store?value=repo or direct:store?value=art
Them on setHeader(uri("value"), body());
Is there anything like this available?
Re: Reuse a rote...
Posted by Claus Ibsen <cl...@gmail.com>.
You cannot set a dynamic header key using setHeader. But you can do it
from java code with a java bean or Camel processor. And you can set
the key name as a exchange property.
On Wed, Sep 9, 2015 at 12:23 PM, Marvin Froeder <ve...@gmail.com> wrote:
> Hey guys,
>
> I have a bunch of routes very similar:
>
>> from("direct:repo")
>> .setHeader(HttpHeaders.AUTHORIZATION).constant("Basic XXX")
>> .convertBodyTo(String.class, UTF_8.name())
>
> ... more steps
>> .to("http4://{{service.url}}")
>> .setHeader("repo", body());
>
>
>
> from("direct:art")
>> .setHeader(HttpHeaders.AUTHORIZATION).constant("Basic XXX")
>> .convertBodyTo(String.class, UTF_8.name())
>>
> ... same extra steps
>
> .to("http4://{{service.url}}")
>> .setHeader("art", body());
>
>
> They are very similar... and there are more. The difference is this header
> on the last line
>
> I wonder if there is a better way to reuse this routes...
>
> Would be nice if I could consolidate both into a direct:store
> And then just call as direct:store?value=repo or direct:store?value=art
>
> Them on setHeader(uri("value"), body());
>
> Is there anything like this available?
--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2nd edition:
https://www.manning.com/books/camel-in-action-second-edition