Search code examples
spring-integrationspring-el

Spring Integration HttpRequestExecutingMessageHandler with url parameter expressions


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


Solution

  • 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.