setHeader not working as expected with split

classic Classic list List threaded Threaded
2 messages Options
Reply | Threaded
Open this post in threaded view
|

setHeader not working as expected with split

imranrazakhan
This post was updated on .
I have following code, in which header is not available in main route after
coming back from direct route and which is set after split


from("timer://ipc?repeatCount=1&delay=5000")
.routeId("timer-ipc")
.to("direct:Route1")
.choice()
       .when(  simple("${in.header.bookno} != null ") )
          .to("direct:Route2")
.end()
.to("log:my?showAll=true&multiline=true");


from("direct:Route1")
.routeId("Route1")
.to("kubernetes-config-maps:///?kubernetesClient=#kubernetesClient&operation=getConfigMap")
.setBody( simple("${body.getData()[my.json]}") )
.setHeader("Test",simple("This Header is available in timer-ipc route "))
.choice()
      .when().jsonpath("$.store.book[?(@.price < 10)]")
              .setBody( simple("${body[0]}") )
               //.split(body())
              .setHeader("bookno",simple("${body[no]}")   )  // This Header is not
                                                  accessible in timer-ipc route if set after split but works with setBody
.end();
Reply | Threaded
Open this post in threaded view
|

Re: setHeader not working as expected with split

Claus Ibsen-2
Hi

If you want to change the message after the split based on what you do
inside the splitter, then use an aggregation strategy on the splitter,
where you can merge the data as you wish.
See the splitter docs, or the CiA2 book that covers this pattern too.

On Mon, May 11, 2020 at 8:49 PM Imran Raza Khan <[hidden email]> wrote:

>
> I have following code, in which header is not available in main route after
> coming back from direct route and which is set after split
>
>
> from("timer://ipc?repeatCount=1&delay=5000")
> .routeId("timer-ipc")
> .to("direct:Route1")
> .choice()
> .when(  simple("${in.header.bookno} != null ") )
> .to("direct:Route2")
> .end()
> .to("log:my?showAll=true&multiline=true");
>
>
> from("direct:Route1")
> .routeId("Route1")
> .to("kubernetes-config-maps:///?kubernetesClient=#kubernetesClient&operation=getConfigMap")
> .setBody( simple("${body.getData()[my.json]}") )
> .setHeader("Test",simple("This Header is available in timer-ipc route "))
> .choice()
> .when().jsonpath("$.store.book[?(@.price < 10)]")
> .setBody( simple("${body[0]}") )
> //.split(body())
> .setHeader("bookno",simple("${body[no]}")   )  // This Header is not
> accessible in timer-ipc route if set after split but works with setBody
> .end();



--
Claus Ibsen
-----------------
http://davsclaus.com @davsclaus
Camel in Action 2: https://www.manning.com/ibsen2