users@jersey.java.net

[Jersey] Re: multipart in Jersey 1.11

From: Ronak Patel <ronak2121_at_yahoo.com>
Date: Sun, 4 Mar 2012 15:03:08 -0800 (PST)

The even weirder thing here is that I never saw Glassfish run the same code below on the following Multipart request I made.
Jersey has no problem parsing this. I never added any fancy \r\n to produce the results below and get Glassfish/Jersey to accept it.

This is the weirdest part.

PUT icefan2121 HTTP/1.1
Host: testserver.dyndns.org:8080
User-Agent: Snocell/2.1.1 CFNetwork/548.0.3 Darwin/11.2.0
Content-Length: 256966
Accept: application/json
Accept-Encoding: gzip
Content-Type: multipart/form-data; boundary=Boundary_1_27742346_1325633997534
MIME-Version: 1.0
Accept-Language: en-us
Connection: keep-alive


--Boundary_1_27742346_1325633997534
Content-Type: text/plain
Content-Disposition: form-data; name="nickname"

icefan2121
--Boundary_1_27742346_1325633997534
Content-Type: text/plain
Content-Disposition: form-data; name="email"

ronak2121_at_yahoo.com
--Boundary_1_27742346_1325633997534
Content-Type: text/plain
Content-Disposition: form-data; name="country"

Cambodia
--Boundary_1_27742346_1325633997534
Content-Type: text/plain
Content-Disposition: form-data; name="bio"

This is some about me text.
--Boundary_1_27742346_1325633997534
Content-Type: text/plain
Content-Disposition: form-data; name="device"

6d813645 534d4826 3df7b205 b7e10605 88eeeb9f 348855a1 f6bfa16b 750c9ba0
--Boundary_1_27742346_1325633997534
Content-Type: text/plain
Content-Disposition: form-data; name="avatarUrl"

http://d1kmlsgixq1e9g.cloudfront.net/nhlfan2121-1330894884252-.png
--Boundary_1_27742346_1325633997534
Content-Type: text/plain
Content-Disposition: form-data; name="avatarThumbnailUrl"

http://d1kmlsgixq1e9g.cloudfront.net/nhlfan2121-1330894884252--thumbnail.png
--Boundary_1_27742346_1325633997534
Content-Type: text/plain
Content-Disposition: form-data; name="avatarTinyThumbnailUrl"

http://d1kmlsgixq1e9g.cloudfront.net/nhlfan2121-1330894884252--tiny-thumbnail.png
--Boundary_1_27742346_1325633997534
Content-Type: image/png
Content-Disposition: form-data; name="avatar"; filename="image.png"

āPNG
--Boundary_1_27742346_1325633997534--


________________________________
 From: Ronak Patel <ronak2121_at_yahoo.com>
To: Ronak Patel <ronak2121_at_yahoo.com>; "users_at_jersey.java.net" <users_at_jersey.java.net>
Sent: Sunday, March 4, 2012 5:34 PM
Subject: Re: [Jersey] multipart in Jersey 1.11
 

Through some fancy detective work (going through the Glassfish Source Code), I was able to get Glassfish to acknowledge the Multipart Message as a valid one.
It seems Glassfish is now sensitive to catch CRLF separators.

However, I now see:

java.lang.NullPointerException
at com.sun.jersey.moxy.MoxyMessageBodyWorker.typeIsKnown(MoxyMessageBodyWorker.java:110)
at com.sun.jersey.moxy.MoxyMessageBodyWorker.isReadable(MoxyMessageBodyWorker.java:133)
at com.sun.jersey.core.spi.factory.MessageBodyFactory._getMessageBodyReader(MessageBodyFactory.java:345)
at com.sun.jersey.core.spi.factory.MessageBodyFactory._getMessageBodyReader(MessageBodyFactory.java:315)
at com.sun.jersey.core.spi.factory.MessageBodyFactory.getMessageBodyReader(MessageBodyFactory.java:298)
at com.sun.jersey.multipart.impl.FormDataMultiPartDispatchProvider$FormDataMultiPartParamInjectable.getValue(FormDataMultiPartDispatchProvider.java:297)
at com.sun.jersey.server.impl.inject.InjectableValuesProvider.getInjectableValues(InjectableValuesProvider.java:46)
at com.sun.jersey.multipart.impl.FormDataMultiPartDispatchProvider$FormDataInjectableValuesProvider.getInjectableValues(FormDataMultiPartDispatchProvider.java:125)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$EntityParamInInvoker.getParams(AbstractResourceMethodDispatchProvider.java:153)
at com.sun.jersey.server.impl.model.method.dispatch.AbstractResourceMethodDispatchProvider$ResponseOutInvoker._dispatch(AbstractResourceMethodDispatchProvider.java:203)
at com.sun.jersey.server.impl.model.method.dispatch.ResourceJavaMethodDispatcher.dispatch(ResourceJavaMethodDispatcher.java:75)
at com.sun.jersey.server.impl.uri.rules.HttpMethodRule.accept(HttpMethodRule.java:288)
at com.sun.jersey.server.impl.uri.rules.ResourceClassRule.accept(ResourceClassRule.java:108)
at com.sun.jersey.server.impl.uri.rules.RightHandPathRule.accept(RightHandPathRule.java:147)
at com.sun.jersey.server.impl.uri.rules.RootResourceClassesRule.accept(RootResourceClassesRule.java:84)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1469)
at com.sun.jersey.server.impl.application.WebApplicationImpl._handleRequest(WebApplicationImpl.java:1400)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1349)
at com.sun.jersey.server.impl.application.WebApplicationImpl.handleRequest(WebApplicationImpl.java:1339)
at com.sun.jersey.spi.container.servlet.WebComponent.service(WebComponent.java:416)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:537)
at com.sun.jersey.spi.container.servlet.ServletContainer.service(ServletContainer.java:708)


________________________________
 From: Ronak Patel <ronak2121_at_yahoo.com>
To: "users_at_jersey.java.net" <users_at_jersey.java.net>
Sent: Saturday, March 3, 2012 7:45 AM
Subject: [Jersey] multipart in Jersey 1.11
 

Hi All,

I'm seeing an exception occurring in Jersey 1.11 when I POST this specific Multipart request to the server.
This used to work just fine in Jersey 1.9.1.

This is my request:

POST /service/v2/posting/ HTTP/1.1
Host: testserver.dyndns.org:8080
User-Agent: CFNetwork/548.0.3 Darwin/11.2.0
Content-Length: 269
Accept: application/json
Content-Type: multipart/form-data; boundary=Boundary_1_27742346_1325633997534
Accept-Encoding: gzip
MIME-Version: 1.0
Accept-Language: en-us
Connection: keep-alive


--Boundary_1_27742346_1325633997534
Content-Disposition: form-data; name="resortId"
Content-Type: text/plain

0
--Boundary_1_27742346_1325633997534
Content-Disposition: form-data; name="text"
Content-Type: text/plain

yo
--Boundary_1_27742346_1325633997534--

Glassfish throws a 500 and says:

Caused by: org.apache.catalina.fileupload.MultipartStream$MalformedStreamException: Stream ended unexpectedly
at org.apache.catalina.fileupload.MultipartStream$ItemInputStream.makeAvailable(MultipartStream.java:960)
at org.apache.catalina.fileupload.MultipartStream$ItemInputStream.read(MultipartStream.java:867)
at java.io.InputStream.read(InputStream.java:82)
at org.apache.catalina.fileupload.Streams.copy(Streams.java:137)
at org.apache.catalina.fileupload.Streams.copy(Streams.java:107)
at org.apache.catalina.fileupload.Multipart.initParts(Multipart.java:157)
at org.apache.catalina.fileupload.Multipart.init(Multipart.java:101)
... 62 more

What gives?

This error is now blocking the launch of my software....