简体   繁体   English

在Spring 5.0.1中无法处理多部分/报表数据。 它仅在请求中检测到多部分/表单数据

[英]Unable to process multipart/report data in Spring 5.0.1. It is only detecting multipart/form-data in the request

I am using Spring 5.0.1 and servlet 3.1.0 我正在使用Spring 5.0.1和Servlet 3.1.0

When user sends multipart/form-data in the request, spring is able to parse the request and make the parts out of it. 当用户在请求中发送multipart / form-data时,spring能够解析请求并从中取出零件。
request.getParts() will have those provided multiparts. request.getParts()将提供这些部分。

But when user sends multipart/report (content-type), spring does not parse this request properly. 但是,当用户发送multipart / report(内容类型)时,spring无法正确解析此请求。
It does not give any exception but it does not store anything in the request parts. 它不给出任何异常,但不在请求部分中存储任何内容。
request.getParts() will return empty array. request.getParts()将返回空数组。

Is there any configuration that has to be done so that spring parses any kind of multipart data. 是否需要进行任何配置,以便spring解析任何类型的多部分数据。

Posting my code and request payload below: 在下面发布我的代码并请求有效负载:

REST API does not have any restriction on the content type. REST API对内容类型没有任何限制。 It takes only request and response as parameters as shown below: 它仅将请求和响应作为参数,如下所示:

@RequestMapping (value = "/rest/external/integration/{serviceName}", method = RequestMethod.POST)   
public void executeAssemblyExternal (HttpServletRequest request, 
            HttpServletResponse response, @PathVariable String serviceName)  throws Exception    
{        
      Parts[] requestParts = request.getParts();   
}

Content-type header which is being sent with the request is : 与请求一起发送的内容类型标头是:
Content-Type multipart/report; 内容类型多部分/报告; Report-Type=disposition-notification; Report-Type =处置通知; boundary="----=_Part_82_645653877.1526452736757" boundary =“ ---- = _ Part_82_645653877.1526452736757”

Multipart data which is being sent to the REST API is as below: 发送到REST API的多部分数据如下:

------=_Part_82_645653877.1526452736757 Content-Type: text/plain; ------ = _ Part_82_645653877.1526452736757内容类型:文本/纯文本; charset=us-ascii Content-Transfer-Encoding: 7bit charset = us-ascii内容传输编码:7位

MDN for - Message ID: <1088014046.24.1526452734879@MCBKUM03.eur.ad.sag> From: SenderAS2 To: ReceiverAS2 Received on: 2018-05-16 at 12:08:56 (IST) Status: processed Comment: This is not a guarantee that the message has been completely processed or understood by the receiving translator MDN-消息ID:<1088014046.24.1526452734879@MCBKUM03.eur.ad.sag>发件人:SenderAS2收件人:ReceiverAS2接收日期:2018-05-16 at 12:08:56(IST)状态:已处理评论:这不是保证消息已被接收翻译者完全处理或理解

------=_Part_82_645653877.1526452736757 Content-Type: message/disposition-notification Content-Transfer-Encoding: 7bit ------ = _ Part_82_645653877.1526452736757内容类型:消息/处置通知内容传输编码:7位

Reporting-UA: webMethods Integration Server Original-Recipient: rfc822; Reporting-UA:webMethods Integration Server原始收件人:rfc822; ReceiverAS2 Final-Recipient: rfc822; ReceiverAS2最终收件人:rfc822; ReceiverAS2 Original-Message-ID: <1088014046.24.1526452734879@MCBKUM03.eur.ad.sag> Received-content-MIC: SezQZhP0aSchqB1zCO0Dq4J0u3U=, sha1 Disposition: automatic-action/MDN-sent-automatically; ReceiverAS2原始消息ID:<1088014046.24.1526452734879@MCBKUM03.eur.ad.sag>接收内容MIC:SezQZhP0aSchqB1zCO0Dq4J0u3U =,sha1处置:自动/自动发送MDN; processed 处理

------=_Part_82_645653877.1526452736757-- ------ = _ Part_82_645653877.1526452736757--

As Deinum mentioned in a comment, servlet can not handle multipart requests other than multipart/form-data. 正如Deinum在评论中提到的那样,除了multipart / form-data之外,servlet无法处理多部分请求。 So Written a custom dispatcherServlet where requests having header Content-Type as multipart with subtype other than form-data will be bypassed from getting processed through MultipartResolver. 因此,编写了一个自定义的dispatcherServlet,将通过MultipartResolver处理具有标头Content-Type为多部分且具有除表单数据以外的子类型的请求的情况。

By doing this request.getInputStream() will have whole multipart data as sent by the user. 通过执行此request.getInputStream()将具有用户发送的整个多部分数据。 Necessary actions can be performed on this inputstream at the server side. 可以在服务器端对此输入流执行必要的操作。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM