eclipse-ee4j / eclipse-ee4j/jersey

NullpointerException when using content type multipart/form-data

Open
#3,728 3 comments 0 reactions 0 assignees View on GitHub
Jersey 1.x
Dominant language
Java
Stars
730
Forks
382
PR merge metrics
No merged PRs in 30d

Description

I have a rest resource with a method as follows

```java
@PUT
@Consumes(MediaType.MULTIPART_FORM_DATA)
@Path()
public Response receiveIntraDayData(@FormDataParam("file") InputStream inputStream) {
//do some stuff here
}
```

When I perform a request to this endpoint I get a nullpointerexception

```
curl -X PUT http://localhost:8085/somepath   -H 'cache-control: no-cache'   -H 'content-type: multipart/form-data'
```

```
java.lang.NullPointerException: null
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.unquoteMediaTypeParameters(MultiPartReaderClientSide.java:245) ~[90:com.sun.jersey.contribs.jersey-multipart:1.19.0]
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readMultiPart(MultiPartReaderClientSide.java:172) ~[90:com.sun.jersey.contribs.jersey-multipart:1.19.0]
at com.sun.jersey.multipart.impl.MultiPartReaderServerSide.readMultiPart(MultiPartReaderServerSide.java:80) ~[90:com.sun.jersey.contribs.jersey-multipart:1.19.0]
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(MultiPartReaderClientSide.java:158) ~[90:com.sun.jersey.contribs.jersey-multipart:1.19.0]
at com.sun.jersey.multipart.impl.MultiPartReaderClientSide.readFrom(MultiPartReaderClientSide.java:85) ~[90:com.sun.jersey.contribs.jersey-multipart:1.19.0]
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:490) ~[72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.spi.container.ContainerRequest.getEntity(ContainerRequest.java:555) ~[72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.multipart.impl.FormDataMultiPartDispatchProvider$FormDataInjectableValuesProvider.getInjectableValues(FormDataMultiPartDispatchProvider.java:122) ~[90:com.sun.jersey.contribs.jersey-multipart:1.19.0]
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153) ~[72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203) ~[72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75) ~[72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:302) ~[72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108) ~[72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147) ~[72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84) ~[72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1542) ~[72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1473) [72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1419) [72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1409) [72:com.sun.jersey.jersey-server:1.19.0]
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:409) [55:com.sun.jersey.servlet:1.19.0]
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:558) [55:com.sun.jersey.servlet:1.19.0]
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:733) [55:com.sun.jersey.servlet:1.19.0]
at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) [63:org.ops4j.pax.web.pax-web-jetty-bundle:4.2.5]
at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:812) [63:org.ops4j.pax.web.pax-web-jetty-bundle:4.2.5]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1669) [63:org.ops4j.pax.web.pax-web-jetty-bundle:4.2.5]
at be.aca.logging.api.HttpRequestLoggingFilter.doFilter(HttpRequestLoggingFilter.java:47) [54:be.aca.logging-utils:5.2.0]
at org.eclipse.jetty.servlet.ServletHandler$CachedChain.doFilter(ServletHandler.java:1652) [63:org.ops4j.pax.web.pax-web-jetty-bundle:4.2.5]
at ...
```

It looks like Jersey cannot handle the missing boundary part. Because if I perform the following request

```
curl -X PUT http://localhost:8085/somepath -H 'cache-control: no-cache' -H 'content-type: multipart/form-data; boundary=----WebKitFormBoundary7MA4YWxkTrZu0gW'
```

I get the expected failure from my own code checking that the file parameter is not present.

Why is this boundary required?
When using tools like Postman and not setting the ContentType header manually, the boundary is correctly generated, but when setting the ContentType header by myself makes the request fail as the boundary is missing.

Contributor guide

Open the contributing guide

Assessment

This issue has not been assessed yet.

Get new issues in your inbox

A short digest of beginner-friendly GitHub issues.