2

I have a HttpRequestExecutingMessageHandler which should make HTTP GET requests to an endpoint URI and, for each request, it should pass two URL parameters with values obtained from the flowing message's headers. How can I get a Message's header values and apply them to each request made via the HttpRequestExecutingMessageHandler?

So far I have tried configuring my handler as follows:

    SpelExpressionParser expressionParser = new SpelExpressionParser();

    Map<String, Expression> uriVariableExpressions = new HashMap<String, Expression>(2);
    uriVariableExpressions.put("userId", expressionParser.parseExpression("headers.userId"));
    uriVariableExpressions.put("roleId", expressionParser.parseExpression("headers.roleId"));

    HttpRequestExecutingMessageHandler handler = new HttpRequestExecutingMessageHandler(uri);
    handler.setHttpMethod(HttpMethod.GET);
    handler.setUriVariableExpressions(uriVariableExpressions);

but, when a message flows through and the HTTP request is made, the Message's userId and roleId header values are not set as parameters in the request's URL. When debugging, I can see that the Message's headers and values are definitely in the flowing Messages. Is the spel expression correct?

Thanks, PM

1 Answer 1

1

Your uri has to have placeholders to substitute your variables, e.g.:

http://foo.com/service?userId={userId}&roleId={roleId}

From other side, show, please, your uri and the logs, when you send a message.

Sign up to request clarification or add additional context in comments.

1 Comment

Hello Artem, I did not have the placeholders in the uri itself. Once I added the placeholders as part of the uri, I then got a new error: EL1008E:(pos 8): Field or property 'userId' cannot be found on object of type.... So I then changed the spel expression to the following form: "headers['userId']" and "headers['roleId']" instead of "headers.userId" and "headers.roleId", and now the URI parameters are being included and requests are being sent okay. Thanks again!

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.