簡體   English   中英

到Spring MVC控制器的出站網關發布請求

[英]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獲取地圖值,但沒有任何價值。

一切看起來不錯。

  1. 我建議您“嗅探”您的HTTP流量,並看看您的身體正在發生什么。 在Windows上,我使用T CP Trace 在這里,您應該確保確實將Map作為有效內容發送。

  2. 另一方面,例如使用一些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.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM