[英]Outbound Gateway post request to spring MVC controller
我尝试通过出站网关将具有MultiValueMap类型的有效负载发送到spring MVC控制器。 但是似乎地图数据没有到达控制器。 不知道什么是错的或丢失的。 我的代码是这样的:
出站配置:
<int-http:outbound-gateway id="outGateway"
http-method="POST"
request-channel="responseChannel"
url="http://localhost:8081/SpringIntegration-In-out-test/responseReq"
extract-request-payload="true">
</int-http:outbound-gateway>
控制器配置:
@RequestMapping("/responseReq")
public ModelAndView goResponse(@RequestBody MultiValueMap<String,String> body){
Iterator it = body.entrySet().iterator();
while (it.hasNext()) {
MultiValueMap.Entry pairs = (MultiValueMap.Entry)it.next();
System.out.println(pairs.getKey() + " = " + pairs.getValue());
it.remove();
}
return new ModelAndView("response");
}
我使用Iterator获取地图值,但没有任何价值。
一切看起来不错。
我建议您“嗅探”您的HTTP流量,并看看您的身体正在发生什么。 在Windows上,我使用T CP Trace 。 在这里,您应该确保确实将Map
作为有效内容发送。
另一方面,例如使用一些RestClient,分别测试您的Controller
。 我的偏好-Firefox插件 。 在此处手动构建表单,该表单应在DispatcherServlet
转换为MultiValueMap
,并且不要忘记提供标题Content-Type: application/x-www-form-urlencoded
如果出站适配器将以单向方式使用(仅发送),则应使用outbound-channel-adapter
:
<int-http:outbound-channel-adapter
id="outAdapter"
channel="responseChannel"
url="http://localhost:8081/SpringIntegration-In-out-test/responseReq"
http-method="POST"
charset="UTF-8"
/>
其次,通过将RequestMethod
定义为POST
,使您的请求映射更加精确:
@RequestMapping(value="/responseReq", method=RequestMethod.POST)
最后,为什么要通过设置extract-request-payload="true"
将Spring Integration Message转换为JMS Message。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.