1

When using a WSInboundGateway in Spring Integration Java DSL, is there a way to extract a header (its value) and use it for example to populate an Enum?

I've tried this but the SpEL does not evaluate:

@Bean
public IntegrationFlow aFlow() {
    return IntegrationFlows.from(aWSInboundGateway())
            .transform(
                    new GenericTransformer<JAXBElement<SomeStruct>, SpecificEvent>() {
                        @Override
                        public SpecificEvent transform(JAXBElement<SomeStruct> payload) {
                            return new SpecificEvent(
                                    payload.getValue(), 
                                    Source.valueOf("headers['source']")
                            );
                        }
                    })
            .channel(someChannel())
            .get();
}
Wivani
  • 2,036
  • 22
  • 28

1 Answers1

2

Your GenericTransformer impl must be like this:

new GenericTransformer<Message<JAXBElement<SomeStruct>>, SpecificEvent>() {
   @Override
   public SpecificEvent transform(Message<JAXBElement<SomeStruct>> message) {
        return new SpecificEvent(
                       message.getPayload().getValue(), 
                       Source.valueOf(message.getHeaders().get("source", String.class))
                       );
   }
}

From other side you should read the Spring Integration Manual a bit more to understand how that SpEL works at runtime and realize that this your Source.valueOf("headers['source']") attempt just doesn't make sense from the Spring Integration perspective.

Artem Bilan
  • 113,505
  • 11
  • 91
  • 118
  • You got me there: I'm new 'to the game' indeed. And admittedly the SpEL bit seemed awkward to say the least, even to my inexperienced eyes. Thanks for the hint; I'll work with it asap. – Wivani Sep 08 '15 at 14:46
  • I accepted your answer as it fitted sufficiently and helped me on my way with my project. Thanks alot. – Wivani Sep 12 '15 at 18:00