一、問題描述
昨天研發(fā)反饋使用EDI的HTTP調(diào)用結(jié)點時抬旺,http響應(yīng)報錯如下:Failed to parse multipart servlet request; nested exception is java.io.IOException: org.apache.tomcat.util.http.fileupload.FileUploadException: the request was rejected because no multipart boundary was found
弊予。
二、原因
EDI在構(gòu)建http請求頭時設(shè)置了Content-Type為“multipart/form-data;charset=UTF-8”开财,缺失了boundary,導(dǎo)致了如上錯誤误褪。
正確的Content-Type格式應(yīng)該為:“multipart/form-data; boundary=<calculated when request is sent>”
三责鳍、代碼修改
設(shè)置Camel Body的時候需要一起設(shè)置header,最終發(fā)送請求的header格式類似:
"Content-Type": "multipart/form-data; boundary=BL6dpsdzxPuead3_GSOFXzNdhK6e85Wth_"
/*
* 此處必須復(fù)寫Content-Type兽间,使其格式為:multipart/form-data; boundary=<get after entity has been builded>
* 否則历葛,服務(wù)端會報錯如下:“the request was rejected because no multipart boundary was found”
*/
exchange.getIn().setHeader(Exchange.CONTENT_TYPE, httpEntity.getContentType().getValue());
exchange.getIn().setBody(httpEntity);
四、Postman驗證
上面的Content-Type是postman內(nèi)置的嘀略,下面的是手動加上的恤溶。
image.png
實驗:
1)兩者都勾選,上傳成功
Postman請求控制臺
2)只勾選手動添加的Content-Type帜羊,上傳失敗咒程,錯誤同上
Postman請求控制臺
3)只勾選內(nèi)置的Content-Type,上傳成功
Postman請求控制臺