Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Spring - 405 Http method DELETE is not supported by this URL

Well I have a strange problem with executing a "DELETE" HTTP request in Spring.

I have a controller method which I have mapped a DELETE request to:

    @RequestMapping(value = "/{authorizationUrl}",method=DELETE)
    public void deleteAuthorizationServer(
            @RequestHeader(value="Authorization") String authorization,
            @PathVariable("authorizationUrl") String authorizationUrl)
            throws  IOException {

        System.out.println("TEST");

    }

The controller is mapped using @RequestMapping("/authorization_servers"); When I send a request through my DEV Http Client, I am getting the response : 405 Http method DELETE is not supported by this URL.

The request looks like this:

 DELETE    localhost:8080/authorization_servers/asxas

  Headers:
  Authorization: "test:<stuff>"

If someone can look into this and help me, I would be grateful

like image 392
Sasanka Panguluri Avatar asked Apr 28 '14 19:04

Sasanka Panguluri


People also ask

How do I fix 405 method not allowed in spring boot?

As the name here suggests, the reason for this error is sending the request with a non-supported method. As we can expect, we can solve this by defining an explicit mapping for PUT in the existing method mapping: @RequestMapping( value = "/employees", produces = "application/json", method = {RequestMethod.

How do I delete a spring boot map?

The DELETE HTTP method is used to delete the resource and @DeleteMapping annotation maps the HTTP DELETE requests onto specific handler methods of a Spring controller. You can use this annotation only at the method level. You can use only the @RequestMapping annotation at the class level.

What is http delete?

The HTTP DELETE method is used to delete a resource from the server. Unlike GET and HEAD requests, the DELETE requests may change the server state. Sending a message body on a DELETE request might cause some servers to reject the request. But you still can send data to the server using URL parameters.

What are the HTTP methods that Cannot be implemented in spring boot rest Service patch?

Return 405 (Method Not Allowed), unless you want to replace every resource in the entire collection of resource - use with caution. 404 (Not Found) - if id not found or invalid and creating new resource is not allowed. Return 405 (Method Not Allowed), unless you want to modify the collection itself..


2 Answers

This will work:

@RequestMapping(value = "/{authorizationUrl}", method = DELETE)
@ResponseBody
public void deleteAuthorizationServer(
    @RequestHeader(value="Authorization") String authorization,
    @PathVariable("authorizationUrl") String authorizationUrl
){
    System.out.printf("Testing: You tried to delete %s using %s\n", authorizationUrl, authorization);
}

You were missing @ResponseBody. Your method was actually getting called; it was what happened after that that was producing the error code.

like image 174
Rob Worsnop Avatar answered Oct 18 '22 15:10

Rob Worsnop


Your annotation should look like this:

@RequestMapping(value = "/{authorizationUrl}",method=RequestMethod.DELETE)

I don't know where you got that DELETE variable from. :-)

like image 26
jgitter Avatar answered Oct 18 '22 14:10

jgitter