0

My flow is like this

private IntegrationFlow myChannel() {
    return f -> f
            ...
            .handle("myHandler", "myMethod")
            ...
}

How to resolve the handler myHandler and the method myMethod dynamically from the headers?

Mike
  • 541
  • 1
  • 4
  • 18

2 Answers2

1

Add a .router() with subflows for each header value.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
  • See my answer. Not sure though that it is so legitimate way to abuse dependency injection :-) – Artem Bilan Jan 18 '19 at 17:08
  • Thanks. I think the `.router()` method is the best and standard way to handle this, but it's also good to know the `MethodInvokingMessageProcessor` method. – Mike Jan 20 '19 at 07:23
1

We need to understand first of all what is the purpose of such a business logic.

I think we can achieve your requirements with this code:

.handle((p, h) -> 
        new MethodInvokingMessageProcessor(h.get("myHandler"), h.get("myMethod", String.class)
                        .processMessage(new GenericMessage<>(p, h))))
Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • Thanks for the answer. The purpose is that I have implemented the integration application, which integrates the REST services. The services have different types of the authentication (the Basic, the api key, custom etc.) and I wanted to have the different authentication sub classes for the different authentication types. Those classes all have same goal to set the `Authorization` header. – Mike Jan 20 '19 at 07:20