users@jersey.java.net

Multiple HTTP methods per resource method

From: Jeremy Whitlock <jwhitlock_at_collab.net>
Date: Fri, 14 Nov 2008 09:35:37 -0800

Hi All,
        Is there a technical reason for not allowing multiple HTTP
method annotations per single resource method? For example, I'd like
something like this:

@POST
@PUT
@Path("/person/create.{format}")
@Produces({"application/json", "application/xml"})
@Consumes("application/x-www-form-urlencoded")
public Response createPerson(@PathParam("format") String format, Form
formData) {
  // Do work
}

The reason for this is that some web browsers do not allow the PUT
method to be used, or haven't in the past. That being said, many
service providers using REST end up having to support both PUT and POST
for create operations. Whenever I try this with Jersey, I get an error
saying that this isn't allowed. Can someone shed some light on this?

Take care,

Jeremy Whitlock | Software Engineer | CollabNet, Inc.
8000 Marina Blvd. Suite 600 | Brisbane, CA 94005 | USA
O 650.228.2516 | C 970.988.8822 | jwhitlock_at_collab.net