kamaci
kamaci

Reputation: 75247

Spring REST DELETE example error

I want to implement Spring REST methods. I tried Get and it works:

@RequestMapping(value = "{systemId}", method = RequestMethod.GET)
    public
    @ResponseBody
    Configuration getConfigurationInJSON(HttpServletResponse response, @PathVariable long systemId) throws IOException {
        if (configurationMap.containsKey(systemId)) {
            return configurationMap.get(systemId);
        } else {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
            return null;
        }
    }

However when I want to implement DELETE it doesn't. My method is that:

@RequestMapping(value = "{systemId}", method = RequestMethod.DELETE)
    public void deleteConfiguration(HttpServletResponse response, @PathVariable long systemId) throws IOException {
        if (configurationMap.containsKey(systemId)) {
            configurationMap.remove(systemId);
            response.setStatus(HttpServletResponse.SC_FOUND);
        } else {
            response.sendError(HttpServletResponse.SC_NOT_FOUND);
        }

    }

My web.xml as follows:

mvc-dispatcher org.springframework.web.servlet.DispatcherServlet 1

<servlet-mapping>
    <servlet-name>mvc-dispatcher</servlet-name>
    <url-pattern>/ui/*</url-pattern>
</servlet-mapping>

<context-param>
    <param-name>contextConfigLocation</param-name>
    <param-value>/WEB-INF/mvc-dispatcher-servlet.xml</param-value>
</context-param>

<listener>
    <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>

Command that works when I try with Curl for GET:

curl http://localhost:8080/ui/webapp/conf/1

Command that doesn't work when I try with Curl for DELETE:

curl -x delete http://localhost:8080/ui/webapp/conf/1

Second command gives that error after a time later at curl:

curl: (7) couldn't connect to host

There is no error at Tomcat side and at debug it doesn't enter the delete method body.

Any ideas?

Upvotes: 1

Views: 1521

Answers (1)

Ralph
Ralph

Reputation: 120851

Try

curl -X DELETE http://localhost:8080/ui/webapp/conf/1

with uppercase DELETE and uppercase X

Upvotes: 1

Related Questions