users@jersey.java.net

[Jersey] Passing form-urlencoded body with PUT

From: Michael Pratt <prattm_at_gmail.com>
Date: Fri, 3 Oct 2014 14:12:20 -0600

I'm having issues in Jersey 2.12 accepting form data with PUT:

@PUT
@Path("/myresource")
public Response put(@FormParam("userId") final int currentUserId,
                    @FormParam("newPosition") final int newAlbumPosition,
                    final MultivaluedMap<String, String> formParams)
{
}

Notice I did *not* annotate with @Consumes. This method works fine in our
Jersey 1 deployment, but in 2.12 this same method causes an
IllegalStateException, even if I do add
@Consumes("application/x-www-form-urlencoded"):

*java.lang.IllegalStateException: The @FormParam is utilized when the
content type of the request entity is not application/x-www-form-urlencoded*

The problem is that my clients are not including Content-Type header, but
apparently didn't need to with Jersey 1. It's unreasonable for me to force
that on them now given how many mobile clients are deployed in the wild
today. Is there a trick to make this work? I considered writing a request
filter to examine the request body and add the Content-Type header
manually, but this seems a little overkill.

Thanks,
Mike