0

I am implementing a simple rest service with the 4 http methods get,post, put and delete using sitebricks. trying to send a delete request to the defined service with a WebClient I get a 405 response. Does anyone knows why would I get such response ?

10:22:24.840 [5907955@qtp-6711891-2 - /r/clients/123] DEBUG org.mortbay.log - RESPONSE /r/clients/123 405

This is how I use web client

 WebClient client = web().clientOf(delete(123)).transports(String.class).over(Json.class);
    client.delete();

here is my delete method

 @Delete
  @At("/:id")
  public Reply delete(@Named("id") String id) {
    clientsRepository.delete(id);
    return Reply.saying().ok();
  }

I am using Jetty Server.

Adelin
  • 18,144
  • 26
  • 115
  • 175

2 Answers2

1

Response code 405 means that something is configured to not allow the use of the http DELETE method.

I can't speak for sitebricks itself, but servlet spec allows you to disable specific methods.

The web.xml of your webapp or the ${jetty.home}/etc/webdefault.xml, as either could be configured to disallow the use of specific HTTP methods (like TRACE, PUT, DELETE).

Check those files for <security-constraints> that might have <http-method> declarations for DELETE.

Also note that any code can trigger the 405 response itself. Since you are seeing this in Sitebricks, possibly a <filter> in your web.xml is preventing it.

Joakim Erdfelt
  • 46,896
  • 7
  • 86
  • 136
1

Are you constructing the request URI properly? Sitebricks returns 405 if there is no handler method. This test case verifies that @Delete does indeed work properly:

https://github.com/dhanji/sitebricks/blob/master/sitebricks-acceptance-tests/src/main/java/com/google/sitebricks/example/RestfulWebServiceWithSubpaths2.java

Also as joakime says, do check if any other filters or handlers are firing outside Sitebricks.

  • Yes, there is handler method.Also I wonder how to send request data with delete ? with post I can do webClient.post(someData).But, not with delete. – Adelin Apr 25 '13 at 08:27