I have a http-inbound-gateway and I want to retrieve a request parameter to fill in the inbound channel as payload. I find that http-inbound-gateway supports spring expression, so I can use #requestParams to retrieve request parameters. It seems #requestParams is equivalent to request.getParameters('key') which returns a Map but I expect to invoke request.getParameter('key') which returns a String. Currently I have to use new String(#requestParams['key']) to fix this. Is there any better way to do this?
<int-http:inbound-gateway path="/mypath"
supported-methods="GET" payload-expression="new String(#requestParams['key']?:'')"
request-channel="inboundChannel" reply-channel="outboundChannel"
error-channel="errorChannel"
message-converters="stringHttpMessageConverterUsingUtf8">
</int-http:inbound-gateway>
I find the source code in org.springframework.integration.http.inbound.HttpRequestHandlingEndpointSupport
@SuppressWarnings({ "rawtypes", "unchecked" })
private Message<?> actualDoHandleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) throws IOException {
//omitted codes
LinkedMultiValueMap<String, String> requestParams = this.convertParameterMap(servletRequest.getParameterMap());
evaluationContext.setVariable("requestParams", requestParams);
//omitted codes
}
so the #requestParameters is a LinkedMultiValueMap object. I can use
#requestParams.get('your key')?:''//null safe
to get the desired String request parameter.