Spring REST メソッドを実装したい。Get を試してみましたが、動作します:
@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;
}
}
ただし、DELETE を実装したい場合は実装しません。私の方法は次のとおりです。
@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);
}
}
次のように私のweb.xml:
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>
Curl for GET を試したときに機能するコマンド:
curl http://localhost:8080/ui/webapp/conf/1
Curl for DELETE で試したときに機能しないコマンド:
curl -x delete http://localhost:8080/ui/webapp/conf/1
2 番目のコマンドは、後で curl でそのエラーを返します。
curl: (7) couldn't connect to host
Tomcat 側ではエラーが発生せず、debug では delete メソッド本体に入りません。
何か案は?