users@jersey.java.net

[Jersey] Re: Fwd: JAX-RS 2 PUT method

From: Miroslav Fuksa <miroslav.fuksa_at_oracle.com>
Date: Fri, 10 Jan 2014 15:03:52 +0100

Hi Valentina,

Form parameters should work with Jersey 2.x. I was curious if there is a bug and tried this simple test:

public class FormTest extends JerseyTest {
    @Override
    protected Application configure() {
        return new ResourceConfig(FormResource.class);

    }

    @Path("form")
    public static class FormResource {
        @PUT
        public String put(@FormParam("key") String injectedFormParam) {
            return injectedFormParam;
        }
    }

    @Test
    public void test() {
        Form form = new Form();
        form.param("key", "value");
        final Response response = target().path("form").request().put(Entity.form(form));
        Assert.assertEquals(200, response.getStatus());
        Assert.assertEquals("value", response.readEntity(String.class));
    }
}

it works fine. Do you have any exception in the log? What does it mean it does not work - you get null instead of form param value? Can you please provide more details?

Anyway, yes, POST should be used for updating the resource.

thanks
Mira
 

On Jan 10, 2014, at 1:46 PM, valentina armenise <valentina.armenise_at_gmail.com> wrote:

>
> Hi everyone,
>
> I have recently moved from jersey1.9 to jersey2 and with my surprise my PUT method can't access the FormParameter of my Form anymore.
>
> I know FormParameter are used for POST, but I have a form to update a resource. These are my concerns:
>
> 1)why was it working in jersey1.9, is that due to some new JAX-RS specifications?
>
> 2) Is it correct to use POST method to update purposes?
> 3) should I rather use PUT and use PathParameter?
>
> Thank you,
>
> Valentina
>