1
votes

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();
}
1

1 Answers

2
votes

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.