0

There is below main Spring Integration flow that receives the request through HTTP, handle it using several subflows and then replies to the consumer. The problem is that when the flow enters the first subflow, it loses practically all its headers including reply channel.

I want to know to what point the headers from the request should reach? to the end of the flow(RESPONSE_CHANNEL)? And how to avoid losing headers after entering subflow?

@Bean
public IntegrationFlow exampleFlow() {
  return IntegrationFlows.from(
      Http.inboundGateway("/conversions/lower")
          .requestMapping(r -> r.methods(HttpMethod.POST)
          .mappedRequestHeaders("*") 
          .requestPayloadType(Foo.class)
          .replyChannel(RESPONSE_CHANNEL)
          .mappedResponseHeaders("*")
        )
      .transform(this:transforFoo)
      .channel(CHANNEL1)
      .handle(fooFlowConfiguration.flowHandler())
//several handlers in another subflow 
      .channel(RESPONSE_CHANNEL)
      .get();
}

I tried to enrich headers before the end of the flow, but it does not help And tried to add .mappedResponseHeaders("*")

Anna Bar
  • 31
  • 5

1 Answers1

1

I think you just move to .channel(CHANNEL1).

And this part doesn't work:

handle(fooFlowConfiguration.flowHandler())
//several handlers in another subflow 
      .channel(RESPONSE_CHANNEL)

This one .replyChannel(RESPONSE_CHANNEL) I think for outbound gateway.

As I know the http gateway works in sync and just return last flow value. In your case its CHANNEL1 last step

Shakirov Ramil
  • 1,381
  • 9
  • 13
  • 1
    another update. Transform return new Message. Did you copy headers? return MessageBuilder .withPayload(transformedPayload) .copyHeaders(originalMessage.getHeaders()) .build(); – Shakirov Ramil Nov 28 '22 at 11:34
  • Yes, I also think that you lose your header exactly in your ` .transform(this:transforFoo)`. Revise it to return just payload or really copy request headers as Ramil suggests. you also don't need that ` .replyChannel(RESPONSE_CHANNEL)` and ` .channel(RESPONSE_CHANNEL)`: as long as your last handler is replying the message is going to be sent to the `replyChannel` header set by the HTTP Inbound Gateway. – Artem Bilan Nov 28 '22 at 14:57