从入站网关检索多个查询参数

时间:2016-05-03 19:06:37

标签: http spring-integration

我有一个应该为查询参数提供服务并返回响应的配置。这是我的配置。不幸的是,Spring无法创建Service Activator bean。

<int-http:inbound-gateway request-channel="inChannel"
        reply-channel="outChannel" supported-methods="GET" 
        path="/ticket">

        <int-http:request-mapping consumes="text/plain" params="param1,param2,param3"
            produces="text/plain" />
</int-http:inbound-gateway>

<int:service-activator ref="ticketIssuingService" method="processTicket"
        input-channel="inChannel" output-channel="outChannel"/>
@MessageEndpoint
public class TicketIssuingService {



    public String processTicket(??? payload){
        System.out.println("Query Paramter String is "+payload);
        return null;
    }
}

http://localhost:8080/job/ticket?param1=type&param2=linkstate&param3=duration

如何检索参数以便我可以切换到processTicket方法? Spring抱怨没有找到符合条件的方法。方法processTicket的参数应该是什么?请帮忙

1 个答案:

答案 0 :(得分:2)

对于没有GET的{​​{1}}方法,payload-expression payload的{​​{1}}就是这个对象:

Message<?>

因此,这应该是关于inChannel服务方法中MultiValueMap<String, String> requestParams = this.convertParameterMap(servletRequest.getParameterMap()); ... if (payload == null) { if (requestBody != null) { payload = requestBody; } else { payload = requestParams; } } 类型的问题的答案。

请注意,您可以通过payload自定义processTicket并使用内置的SpEL payload variables,如:

payload-expression

有些示例可以获得EvaluationContext

#requestParams - the MultiValueMap from the ServletRequest parameterMap.
#pathVariables - the Map from URI Template placeholders and their values;
#matrixVariables - the Map of MultiValueMap according to Spring MVC Specification. Note, #matrixVariables require Spring MVC 3.2 or higher;
#requestAttributes - the org.springframework.web.context.request.RequestAttributes associated with the current Request;
#requestHeaders - the org.springframework.http.HttpHeaders object from the current Request;
#cookies - the Map<String, Cookie> of javax.servlet.http.Cookie s from the current Request.