On May 6, 2009, at 12:03 AM, Anjum Naseer wrote:
> 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)
> {
> ...
> }
>
Try:
@PUT
@Consumes("application/x-www-form-urlencoded")
public Response doStuff(final MultivaluedMap<String, String>
formParameters)
{
...
}
See the following for more details:
https://jersey.dev.java.net/documentation/1.1.0-ea/user-
guide.html#d4e218
Paul.
> 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. Try it Now!