2

I am trying to delete a "Contact" from the "Contacts" table using the following @DELETE method (using Jersey Framework (JAX-RS implementation)

@DELETE
@Path("/delete/{contact}")
public String deleteContact(@PathParam("contact") String name) throws ClassNotFoundException, SQLException {

    String response = DAOaccess.deleteContact(name);
    return response; 
}

And the following url is used to invoke the webservice from the browser:

/contacts/delete/contactname

But HTTP Status 405 - Method Not Allowed is thrown on doing so.

What might be the reason? How do I overcome this?

Chillax
  • 4,418
  • 21
  • 56
  • 91
  • Is /contacts/delete/etc the right URL, ie as opposed to /delete/etc? – Martin Wilson Oct 01 '12 at 12:35
  • @MartinWilson I'm using @Path(/contacts) annotation at class level – Chillax Oct 01 '12 at 12:39
  • Well, @DELETE means Delete HTTP method, right? And you are calling GET HTTP method, so, I think you should use another test method :) – Plínio Pantaleão Oct 01 '12 at 12:43
  • @PlínioPantaleão Does that mean that I cant access a 'Delete' webservice method from the url? I did try by invoking the service via code, but that too is throwing an error.I have posted that as a separate question here:http://stackoverflow.com/questions/12670169/not-able-to-invoke-an-delete-web-service-in-rest-jersey – Chillax Oct 01 '12 at 12:51

2 Answers2

7

URL = /contacts/delete/contactname

405 because

It seems delete is always behave as submit (Post method) and you are trying to call as like get method from the URL. This is not possible to call the post method as like get. if you really want to call this web service from the browser to test, just download a Mozilla plugin (Poster) which will help you to submit the web service in your all method types.

subodh
  • 6,136
  • 12
  • 51
  • 73
  • I found this questions now in 2014 at one of top search results so I need to do a little update on this. There is a really good Client for the test of webservices. So feel free and have a look at: http://www.getpostman.com/ It's a really nice tool to simulate a web client. You can add collections with every call you do and with every type you want - GET, POST, PUT, DELETE, PATCH, ... – DominikAngerer Jul 18 '14 at 06:33
2

If you are using Firefox use this plugin to test your service. When you directly hit the URL from browser it goes as a @GET request which is not allowed in this case. RestClient is also available as standalone app. If you need more functionalities try SoapUI. I have also posted a response to your question on @DELETE.

Community
  • 1
  • 1
basiljames
  • 4,777
  • 4
  • 24
  • 41