Search code examples
javarestjerseyformsmultipart

multipart form generating a malformed packet


I'm attempting to include an email attachment in form submission. My backend has a tomcat server using jersey to receive RESTful calls.

When I try to generate a post with this form (all the styling has been stripped out)

<form  name="composeMailForm" enctype="multipart/form-data" method="POST" action="/myTarget">
    <input id="mailTo" type="text" name="to" class="span12" />                                                        
    <input type="text" name="subject" class="span8" />
    <textarea name="body" rows="5" class="span8">-</textarea>
    <input type="file" name="file" size=100 />
    <button type="submit" >Send</button>
</form> 

I get a 405 back.

My function definition on the backend is


@Path("/myTarget")
@POST
@Consumes(MediaType.MULTIPART_FORM_DATA)
public Response sendMail(
        @FormDataParam("to") String recipients,
        @FormDataParam("subject") String subject,
        @FormDataParam("body") String body,
        @FormDataParam("file") File loadedFile,
        @FormDataParam("file") FormDataContentDisposition headerDisp,
        @CookieParam("USER_COOKIE") String USER_COOKIE){

The biggest problem I can see is that when I watch the session in wire shark it says that the request packet is malformed

it gives an error of

[Malformed Packet: UASIP]

[Expert Info (Error/Malformed): Malformed Packet (Exception occurred)]

Any thoughts one what's going wrong in the form or the processing would be greatly appreciated.


Solution

  • An unrelated typo was causing Jersey to fail to map functions properly.

    The malformed packets stemmed from the fact that my computer was deferring checksum calculation to the router, so the packets had false checksums, but that was resolved by the time it hit the outside wire.