2

I have a Http Outbound Gateway where I want to set a uri variable with a value from a Message header. I can see that this can be done like so:

            .handle(Http
                    .outboundGateway(serviceUri, restTemplate)
                    .uriVariable("var", expression)
                    .httpMethod(HttpMethod.POST)

The expression is of type org.springframework.expression.Expression. How do I create such an Expression object for say a JmsHeaders.CORRELATION_ID value? I can't find any examples anywhere. I know that the String SPEL would be "headers['correlationId']" but I don't know how to turn that into an Expression object?

I am using spring-integration-java-dsl:1.1.0.RELEASE.

1 Answer 1

1

See this answer to a similar question.

Note that JmsHeaders.CORRELATION_ID is actually jms_correlationId. It's safer to use the constant...

PARSER.parseExpression("headers['" + JmsHeaders.CORRELATION_ID + "']");
Sign up to request clarification or add additional context in comments.

3 Comments

Thanks for that Gary. Yes, I am using the constant in JmsHeaders. In the end I had created the expression as a literal (new LiteralExpression("headers['" + JmsHeaders.CORRELATION_ID + "']")) which I assume is also valid?
No; that is not correct; a LiteralExpression is an, err, literal - i.e. it will set the variable to the exact literal in the constructor. LiteralExpressions are not evaluated, getValue() simply returns the value passed into the constructor. You need to parse the expression so it is evaluated at runtime.
Ah, ok. I'll use the expression as you have provided then Gary.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.