users@jersey.java.net

Re: [Jersey] form multipart post "Missing start boundary" exception

From: Paul Sandoz <Paul.Sandoz_at_Sun.COM>
Date: Fri, 14 Aug 2009 10:48:17 +0200

On Aug 13, 2009, at 6:56 PM, Jonathan Locke wrote:

>
> okay, makes sense.
>
> thanks for a really nice framework. i have a number of friends who
> swear by it, and this little issue aside, i also like it a lot.

Thanks for the kind words!

Paul.

>
> best,
>
> jon
>
> On Thu, Aug 13, 2009 at 9:32 AM, Paul Sandoz <Paul.Sandoz_at_sun.com>
> wrote:
>
> On Aug 13, 2009, at 6:04 PM, Jonathan Locke wrote:
>
>>
>> awesome! it works now.
>>
>
> Great.
>
>
>> it was the "id" versus "name" attribute that caused the problem. i
>> should have seen that.
>>
>> would be nice if jersey could give a nicer error message, but that
>> might not be possible and not too many people will make this
>> particular typo.
>>
>
> It might be tricky for Jersey to do anything, because the error was
> originating from the JavaMail API so all Jersey could state is
> multipart/form-data message could not be processed.
>
> I still cannot reproduce the error with JavaMail however i can
> reproduce a similar error when using the jersey-mutlipart module
> which originates in the MimePull API:
>
> Caused by: org.jvnet.mimepull.MIMEParsingException: Missing start
> boundary
> at
> org.jvnet.mimepull.MIMEParser.skipPreamble(MIMEParser.java:308)
> at org.jvnet.mimepull.MIMEParser.access$300(MIMEParser.java:
> 62)
> at org.jvnet.mimepull.MIMEParser
> $MIMEEventIterator.next(MIMEParser.java:138)
> at org.jvnet.mimepull.MIMEParser
> $MIMEEventIterator.next(MIMEParser.java:123)
> at
> org.jvnet.mimepull.MIMEMessage.makeProgress(MIMEMessage.java:193)
> at org.jvnet.mimepull.MIMEMessage.parseAll(MIMEMessage.java:
> 176)
> at
> org.jvnet.mimepull.MIMEMessage.getAttachments(MIMEMessage.java:101)
> at
> com
> .sun
> .jersey.multipart.impl.MultiPartReader.readFrom(MultiPartReader.java:
> 166)
>
>
> I actually think that browsers like Firefox are sending a malformed
> multipart/form-data message.
>
> An empty message should be something like this:
>
> -----------------------------586097576344710431681718658
> -----------------------------586097576344710431681718658--
>
> as defined by the collective grammar specified in the following:
>
> http://tools.ietf.org/html/rfc2046#page-43
>
> Paul.
>
>> thanks for your help!
>>
>> jon
>>
>> On Wed, Aug 12, 2009 at 1:50 PM, Paul Sandoz <Paul.Sandoz_at_sun.com>
>> wrote:
>>
>> On Aug 12, 2009, at 10:45 PM, Paul Sandoz wrote:
>>
>>> Hi,
>>>
>>
>>> The log presents an empty multipart message (the -- on the end
>>> signals that and t is correct) and then i rechecked your form and
>>> there is an issue, you need to use:
>>>
>>> <form action="<url>/addl"
>>> method="POST" enctype="multipart/form-data">
>>> <input type="file" name="file" />
>>> <input type="submit" name="submit" value="upload" />
>>> </form>
>>>
>>
>> I should have also said i cannot reproduce your error when i use
>> the same HTML form you previously presented. Perhaps it is a
>> JavaMail version difference? what version are you using?
>>
>> Paul.
>>
>>> I have attached a simple maven project that exercises forms using
>>> the jersey-multipart module and JavaMail.
>>>
>>> Paul.
>>>
>>> <fileupload.zp>
>>>
>>>
>>> On Aug 12, 2009, at 10:17 PM, Jonathan Locke wrote:
>>>
>>>> thanks for the speedy response!
>>>>
>>>> output is below. it looks like the boundary is two characters
>>>> different (the -- on the end). i'm using safari on a macbook pro,
>>>> but also have the same problem with firefox.
>>>>
>>>> 1 * In-bound request received
>>>> 1 > POST http://localhost:7979/services/rest/probeprocessor/csv/v1/add/
>>>> 1 > Content-Length: 44
>>>> 1 > Accept-Encoding: gzip, deflate
>>>> 1 > Referer: http://localhost:7979/debug/home.0
>>>> 1 > Connection: keep-alive
>>>> 1 > Accept-Language: en-us
>>>> 1 > Host: localhost:7979
>>>> 1 > User-Agent: Mozilla/5.0 (Macintosh; U; Intel Mac OS X 10_5_8;
>>>> en-us) AppleWebKit/530.19.2 (KHTML, like Gecko) Version/4.0.2
>>>> Safari/530.19
>>>> 1 > Origin: http://localhost:7979
>>>> 1 > Content-Type: multipart/form-data; boundary=----
>>>> WebKitFormBoundary5Kzj3IivAxrpF7Qn
>>>> 1 > Cookie: JSESSIONID=1w8232e2jko9l
>>>> 1 > Accept: application/xml,application/xhtml+xml,text/
>>>> html;q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
>>>> 1 >
>>>> ------WebKitFormBoundary5Kzj3IivAxrpF7Qn--
>>>>
>>>> ERROR - log - Nested in
>>>> javax.servlet.ServletException:
>>>> com.sun.jersey.api.container.ContainerException:
>>>> javax.mail.MessagingException: Missing start boundary:
>>>> com.sun.jersey.api.container.ContainerException:
>>>> javax.mail.MessagingException: Missing start boundary
>>>> at
>>>> com
>>>> .sun
>>>> .jersey
>>>> .server
>>>> .impl
>>>> .model
>>>> .method
>>>> .dispatch
>>>> .MultipartFormDispatchProvider
>>>> .processForm(MultipartFormDispatchProvider.java:91)
>>>>
>>>>
>>>>
>>>>
>>>> On Wed, Aug 12, 2009 at 12:40 PM, Paul Sandoz
>>>> <Paul.Sandoz_at_sun.com> wrote:
>>>> Hi Jonathan,
>>>>
>>>> Your HTML looks fine, so i am not sure why it is failing. Perhaps
>>>> you can enable server side logging and see if the HTTP request
>>>> has a Content-Type header with a boundary parameter:
>>>>
>>>> https://jersey.dev.java.net/nonav/apidocs/1.0.3/jersey/com/sun/jersey/api/container/filter/LoggingFilter.html
>>>>
>>>>
>>>> Note that the use of multpart/form-data with @FormParam has been
>>>> deprecated due to semantic issues overloading for two different
>>>> media types that operate on characters and bytes. I need to log a
>>>> warning stating that it is deprecated.
>>>>
>>>> I recommend using the jersey-multipart module and use
>>>> @FormDataParam:
>>>>
>>>> https://jersey.dev.java.net/nonav/apidocs/1.0.3/contribs/jersey-multipart/com/sun/jersey/multipart/FormDataParam.html
>>>>
>>>> For example:
>>>>
>>>> @POST
>>>> @Path("add")
>>>> @Consumes("multipart/form-data")
>>>> public Response add(@FormDataParam("file") final InputStream
>>>> input)
>>>> {
>>>>
>>>> Or if you want the form multipart data directly use:
>>>>
>>>> https://jersey.dev.java.net/nonav/apidocs/1.0.3/contribs/jersey-multipart/com/sun/jersey/multipart/FormDataMultiPart.html
>>>>
>>>> For example:
>>>>
>>>> @POST
>>>> @Path("add")
>>>> @Consumes("multipart/form-data")
>>>> public Response add(final FormDataMultipart parts)
>>>> {
>>>>
>>>> See the dependencies for the jersey-multipart module:
>>>>
>>>> https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-1.0.3/jersey/dependencies.html
>>>>
>>>> Paul.
>>>>
>>>> On Aug 12, 2009, at 8:02 PM, Jonathan Locke wrote:
>>>>
>>>>>
>>>>> i am using jersey 1.0.3 and currently getting an exception when
>>>>> i try to handle multipart form data. i've tried several
>>>>> approaches, but the preferable one was:
>>>>>
>>>>> @POST
>>>>> @Path("add")
>>>>> @Consumes("multipart/form-data")
>>>>> public Response add(@FormParam("file") final InputStream
>>>>> input)
>>>>> {
>>>>>
>>>>> however, i never get to the method due to this exception:
>>>>>
>>>>> com.sun.jersey.api.container.ContainerException:
>>>>> javax.mail.MessagingException: Missing start boundary
>>>>> at
>>>>> com
>>>>> .sun
>>>>> .jersey
>>>>> .server
>>>>> .impl
>>>>> .model
>>>>> .method
>>>>> .dispatch
>>>>> .MultipartFormDispatchProvider
>>>>> .processForm(MultipartFormDispatchProvider.java:91)
>>>>> at
>>>>> com
>>>>> .sun
>>>>> .jersey.server.impl.model.method.dispatch.FormDispatchProvider
>>>>> $
>>>>> FormParameterProvider
>>>>> .getInjectableValues(FormDispatchProvider.java:108)
>>>>> * snip *
>>>>> Caused by: javax.mail.MessagingException: Missing start boundary
>>>>> at javax.mail.internet.MimeMultipart.parsebm(MimeMultipart.java:
>>>>> 713)
>>>>> at javax.mail.internet.MimeMultipart.parse(MimeMultipart.java:
>>>>> 383)
>>>>>
>>>>> the HTML form i'm using to post the data is just a regular file
>>>>> upload form (i assume this is okay?):
>>>>>
>>>>> <form method="post" enctype="multipart/form-data"
>>>>> action="<url>/add">
>>>>> <input value="file" id="file" type="file">
>>>>> <p></p>
>>>>> <input type="submit" value="Upload">
>>>>> </form>
>>>>>
>>>>>
>>>>
>>>>
>>>
>>
>>
>
>