users@jersey.java.net

Consuming "application/x-www-form-urlencoded" form data does not seem to work

From: Anjum Naseer <tpanjum_at_hotmail.com>
Date: Tue, 5 May 2009 22:03:06 +0000

Hi,

I am unable to create a simple Jersey resource that consumes a PUT
request where the data is encoded as "application/x-www-form-urlencoded".
Here is a snippet of my code:

@PUT
@Consumes("application/x-www-form-urlencoded")
public Response doStuff(final MultivaluedMap formParameters)
{
   ...
}

I am exercising this using htmlunit with code like this:

public WebResponse testService(final WebClient browser)
{
   final WebRequestSettings settings = new WebRequestSettings(new
URL(...), HttpMethod.PUT);

   settings.setEncodingType(FormEncodingType.URL_ENCODED);
   settings.setRequestBody("p1=123");

   return browser.loadWebResponse(settings);
}

I am using Jersey v1.0.3 running on Glassfish v2, and the error I get
(shown in Glassfish server logs) is:

SEVERE: A message body reader for Java type, interface
javax.ws.rs.core.MultivaluedMap, and MIME media type,
application/octet-stream, was not found

If I change my web service to pickup a specific form parameter as follows:

@PUT
@Consumes("application/x-www-form-urlencoded")
public Response doStuff(final @FormParam("p1") String formParameter)
{
   ...
}

then I do get the value "123" as expected. Have I misunderstood how to
pickup all form parameters?

I referred to this web page as a guide:
http://docs.sun.com/app/docs/doc/820-4867/ghrst?a=view

Can anyone shed any light on what I am doing wrong?

Thanks in advance.

Anjum.


_________________________________________________________________
Share your photos with Windows Live Photos – Free.
http://clk.atdmt.com/UKM/go/134665338/direct/01/