users@jersey.java.net

[Jersey] Re: Curl, Jersey and InFormParam multi valued map.

From: Rahul Babbar <rahul.babbar1_at_gmail.com>
Date: Thu, 31 Mar 2011 10:52:34 -0700

Thanks Jakub,

I was able to solve the problem by the following.

The following warning generated gave the clue.

Mar 31, 2011 10:26:23 AM com.sun.jersey.spi.container.servlet.WebComponent
filterFormParameters
WARNING: A servlet POST request, to the URI http://localhost:8080/<URI>,
contains form parameters in the request body but the request body has been
consumed by the servlet or a servlet filter
accessing the request parameters. Only resource methods using @FormParam
will work as expected. Resource methods consuming the request body by other
means will not work as expected.

I modified the method to

@POST
> @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
> public Response doAction(MultivaluedMap<String, String> inFormParams,
> @FormParam("action") String action) {
>
Response response = null;
> if(StringUtils.isEmpty(action)) {
> throw new UnrecoverableException("Unexpected null or empty action");
> }
> // get other parameters from the map and do something...
> return response;
> }
>

Not sure why the formParam is required but it works in my case because
atleast one parameter "action" is required.

Thanks

Rahul


On Tue, Mar 29, 2011 at 1:24 PM, Jakub Podlesak
<jakub.podlesak_at_oracle.com>wrote:

> Hi Rahul,
>
> i do not see anything wrong in the code regarding the form processing.
> This should just work. Could you please re-try without the
> username/password
> security thing?
>
> A similar form processing code could be find at the simple-console [1]
> jersey example for your reference.
>
> ~Jakub
>
> [1]
> http://download.java.net/maven/2/com/sun/jersey/samples/simple-console/1.6/simple-console-1.6-project.zip
>
>
>
> On 03/29/2011 10:23 AM, Rahul Babbar wrote:
>
> Any comments!!!
>
> Rahul
>
>
> On Mon, Mar 28, 2011 at 11:17 AM, Rahul Babbar <rahul.babbar1_at_gmail.com>wrote:
>
>> Hello all,
>>
>> I have the following piece of code.
>>
>>
>> @POST
>> @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
>> public Response doAction(MultivaluedMap<String, String> inFormParams) {
>> String action = inFormParams.getFirst("action");
>>
>> Response response = null;
>> if(StringUtils.isEmpty(action)) {
>> throw new UnrecoverableException("Unexpected null or empty action");
>> }
>> // do something...
>> return response;
>> }
>>
>>
>> And i post using the following command from Curl
>>
>> curl --data "action=updateCache" http://$USER:$PASSWORD@localhost:8080/
>> <URI>
>>
>> both inFormParams and action are empty.
>>
>> What am i doing wrong? How can i get the post parameters in a map?
>>
>> Thank you.
>>
>> Rahul
>>
>
>
>