1

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?

1 Answer 1

1

Try

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

with uppercase DELETE and uppercase X

Sign up to request clarification or add additional context in comments.

1 Comment

@Daniel Stenberg: you are right, I have corrected/extended the answer

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.