2016-09-29 49 views
0

我在我的項目中使用了Spring集成。我有RESTful類型的POST Web服務,它接受多部分/表單數據類型。我知道int-http:outbound-gateway可以用來執行web服務。使用Spring集成將多部分/表單數據參數傳遞給RESTful webservice

但我不知道如何將文件類型(multipart/form-data)傳遞給消息並在int-http:outbound-gateway中使用它們。

爲了得到一個想法,以下是POSTMAN客戶端的屏幕打印,其中傳遞了multipart/form-data類型的參數。 enter image description here

我想通過將參數合併到消息中,以相同的方式將參數傳遞給int-http:outbound-gateway。關於如何實現所需功能的任何想法?如果您需要任何其他信息,請告訴我。

回答

0

HttpRequestExecutingMessageHandler有這樣的代碼:

else if (content instanceof Map) { 
     // We need to check separately for MULTIPART as well as URLENCODED simply because 
     // MultiValueMap<Object, Object> is actually valid content for serialization 
     if (this.isFormData((Map<Object, ?>) content)) { 
      if (this.isMultipart((Map<String, ?>) content)) { 
       contentType = MediaType.MULTIPART_FORM_DATA; 
      } 
      else { 
       contentType = MediaType.APPLICATION_FORM_URLENCODED; 
      } 
     } 
    } 

爲此你所需要的僅僅是一個Map<String, ?>這充分反映了HTTP形式。

Multipart Http Sample也可以幫助你。