如何解决MediaType = multipart / form-data找不到的MessageBodyWriter

时间:2019-02-04 13:04:05

标签: rest web-services jersey

我们正在尝试在服务器端读取多部分REST请求。

在一个正常运行的REST java项目中进行了以下更改。

web.xml

>  PayloadTooLargeError: request entity too large
    >     at readStream (/home/innvoot/Desktop/Projects/innmee/innmee_api/node_modules/raw-body/index.js:155:17)
    >     at getRawBody (/home/innvoot/Desktop/Projects/innmee/innmee_api/node_modules/raw-body/index.js:108:12)
    >     at read (/home/innvoot/Desktop/Projects/innmee/innmee_api/node_modules/body-parser/lib/read.js:77:3)
    >     at urlencodedParser (/home/innvoot/Desktop/Projects/innmee/innmee_api/node_modules/body-parser/lib/types/urlencoded.js:116:5)
    >     at Layer.handle [as handle_request] (/home/innvoot/Desktop/Projects/innmee/innmee_api/node_modules/express/lib/router/layer.js:95:5)
    >     at trim_prefix (/home/innvoot/Desktop/Projects/innmee/innmee_api/node_modules/express/lib/router/index.js:317:13)
    >     at /home/innvoot/Desktop/Projects/innmee/innmee_api/node_modules/express/lib/router/index.js:284:7
    >     at Function.process_params (/home/innvoot/Desktop/Projects/innmee/innmee_api/node_modules/express/lib/router/index.js:335:12)
    >     at next (/home/innvoot/Desktop/Projects/innmee/innmee_api/node_modules/express/lib/router/index.js:275:10)
    >     at jsonParser (/home/innvoot/Desktop/Projects/innmee/innmee_api/node_modules/body-parser/lib/types/json.js:119:7)
    > message: 'request entity too large',   expected: 299371,   length:
    > 299371,   limit: 102400,   type: 'entity.too.large'

dependencies.gradle

<servlet>
        <servlet-name>AbcServlet</servlet-name>
        <servlet-class>org.glassfish.jersey.servlet.ServletContainer</servlet-class>
        <init-param>
            <param-name>javax.ws.rs.Application</param-name>
            <param-value>filter-name</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.config.property.packages</param-name>
            <param-value>package-name</param-value>
        </init-param>
        <init-param>
            <param-name>com.sun.jersey.api.json.POJOMappingFeature</param-name>
            <param-value>true</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>

Java代码:

compile('com.sun.jersey.contribs:jersey-multipart:1.2')
compile('org.jvnet:mimepull:1.4')

但是当我使用POSTMan测试此REST服务时,出现以下错误:

    @POST
    @Path("/upload")
    @Consumes("multipart/form-data")
    @Produces("application/xml")
    public Response upload(@Context UriInfo uriInfo, @Context HttpServletRequest request, FormDataMultiPart multipart ) {

.....java code....

}

我还按照Jersey client exception: A message body writer was not found

阅读并进行了更改

请告知需要解决的问题。

您是否还可以提供客户端代码以在测试用例中对其进行测试?

1 个答案:

答案 0 :(得分:0)

通过将所有球衣罐版本都设置为相同,可以解决该问题。