users@jersey.java.net

_at_Consumes attribute not working as expected.....

From: Jalpesh Patadia <jalpesh.patadia_at_clickbank.com>
Date: Fri, 7 Aug 2009 13:10:28 -0700

I think this is a bug, but I just wanted to confirm before I file it.

Here's a sample of my code :

        /** This method should trap normal posts */
   @Path("test1")
    @POST
    public void testMethod(@Context HttpServletRequest request) {
        System.out.println("Standard method.....");
    }

    /** Form based posts should throw an error */
    @Path("test1")
    @POST
    @Consumes(MediaType.APPLICATION_FORM_URLENCODED)
    public void formPostParameters(@Context HttpServletRequest request, MultivaluedMap<String, String> params) {
        System.out.println("Form post methods are not supported.....");
    }

What I'm seeing is that if I use a form based post (which has some post parameters) from a browser, the second method is called and the values of the form parameters are passed in correctly.

However If I use a regular post (same url), passing in query parameters instead of form post parameters, I get an error code 415 - Unsupported media type.

I would assume that jersey would invoke the second method when a form based post is encountered.
If a user did not specify a @Consumes annotation and is performing a normal HTTP Post with only query parameters the first method should be invoked.

Am I missing something in understanding the spec ? If so, how would I accomplish my use case ? Basically I want to find out if a user has specified some form post parameters, and I can't read them from the HttpServletRequest - the only possible way to do that is to use the MultivaluedMap.


Thanks,


Jalpesh
________________________________
PRIVILEGED AND CONFIDENTIAL
This transmission may contain privileged, proprietary or confidential information. If you are not the intended recipient, you are instructed not to review this transmission. If you are not the intended recipient, please notify the sender that you received this message and delete this transmission from your system.