users@jersey.java.net

RE: [Jersey] Multiple HTTP methods per resource method

From: Jeremy Whitlock <jwhitlock_at_collab.net>
Date: Fri, 14 Nov 2008 11:29:40 -0800

Paul,

            Thanks for the tip. (Your email made it hard to do an
inline reply so please forgive me.)

 

Take care,

 

Jeremy

 

________________________________

From: Paul.Sandoz_at_Sun.COM [mailto:Paul.Sandoz_at_Sun.COM]
Sent: Friday, November 14, 2008 12:21 PM
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] Multiple HTTP methods per resource method

 

 

On Nov 14, 2008, at 6:35 PM, Jeremy Whitlock wrote:





Hi All,
          Is there a technical reason for not allowing multiple HTTP
method annotations per single resource method?

 

Yes, it would encourage the bad practice of assuming that the semantics
of more that one HTTP method are the same.

 





 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?

 

The best approach is to use a filter.

 

Jersey has a server side filter you can use that supports the
X-HTTP-Method-Override header.

 

See the following thread for more details:

 

 
http://markmail.org/message/p7yxygz4wpakqno5?q=list:net.java.dev.jersey.
users+Filter&page=4

 

and see:

    

  com.sun.jersey.api.container.filter.PostReplaceFilter [1]

 

Paul.

 

https://jersey.dev.java.net/source/browse/*checkout*/jersey/tags/jersey-
1.0/api/jersey/com/sun/jersey/api/container/filter/PostReplaceFilter.htm
l



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


---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscribe_at_jersey.dev.java.net
For additional commands, e-mail: users-help_at_jersey.dev.java.net