users@jersey.java.net

RE: [Jersey] DELETE method returns 405 from browser but returns ok from client

From: Dave Tkaczyk <Dave.Tkaczyk_at_innerwireless.com>
Date: Fri, 30 May 2008 11:06:38 -0500

Try this...

@DELETE
@Path("/delete/{id}")
public Response delete(@PathParam("id") String id) {
        return fpkSent.deleteFPKSent(id); //returns a Response Object
}

-----Original Message-----
From: Marc Hadley [mailto:Marc.Hadley_at_Sun.COM]
Sent: Thursday, May 29, 2008 5:38 PM
To: users_at_jersey.dev.java.net
Subject: Re: [Jersey] DELETE method returns 405 from browser but returns
ok from client

On May 29, 2008, at 5:22 PM, g f wrote:
>
> I have another problem wr to the delete method.
> It works fine from wiztools restclient however when I try to perform
> a delete through the browser,
> I get a 405 The specified HTTP method is not allowed for the
> requested resource ().
> Perhaps I am misunderstanding the capabilities of the delete method?
> Here is my code:
> @DELETE
> @Path("/delete/{arg1}")
> public Response delete(@PathParam("id")
> String id) {
> MultivaluedMap<String, String> params =
> context.getTemplateParameters();
> String s =
> params.getFirst("arg1");
> return fpkSent.deleteFPKSent(s);//returns a Response Object
> }
> Now I access the following url to perform the delete:
> http://localhost(tomcat6.1):8084/fpk/delete/recordtodelete
>
If you put that URL into a browser, it will use the HTTP GET method,
not DELETE. Its returning a 405 (Method not allowed" status because
your class doesn't have a method annotated with @GET.

You can issue a DELETE from a browser using JavaScript and
XmlHttpRequest or you can overload a POST method. You shouldn't use a
GET method to delete stuff since GET is supposed to be safe.

> One other problem I am having is accessing the PathParam...as you
> can see I am using the TemplateParameters to retrieve the args.
> In other words, if I do a System.out.println("PathParam id="+id) It
> returns null.
> Both of these problems are minor.

The value of the @PathParam has to match the path variable name. So,
e.g. in your code above you have

@Path("delete/{arg1}")

so to get the value of the "arg1" path parameter you need to use:

@PathParam("arg1")

Marc.

---
Marc Hadley <marc.hadley at sun.com>
CTO Office, Sun Microsystems.
 
 
 
Confidentiality Notice: This email message is covered by the Electronic Communications Privacy Act, 18 U.S.C. ?2510-2521 and is legally privileged. Unauthorized review, use, disclosure or distribution is strictly prohibited. If you are not the intended recipient, please contact Dave.Tkaczyk_at_innerwireless.com and destroy all copies of the original message. Thank you.