我有用于删除操作的休息服务,实际上什么也没返回。如何在Apache骆驼休息服务中不返回内容()无效响应作为响应
@RequestMapping(value = URI_REMOVE_ACTIVITY_DELETE, method = DELETE)
public void delete(@PathVariable Long id) {
super.delete(id, principal);
}
Class<Void> RESULT_URI_REMOVE_ACTIVITY_DELETE = void.class;
答案 0 :(得分:0)
这是一个原始的实现,您可以对其进行进一步的改进。
public class MyRouteBuilder extends RouteBuilder {
public void configure() {
restConfiguration().component("jetty").host("localhost").port("8080");
rest().produces("application/json").delete("/something/{id}").to("direct:delete");
from("direct:delete")
.log("Delete ${in.header.id}")
.process(exchange -> {
String id = exchange.getIn().getHeader("id",String.class);
//doDelete(id);
})
.setHeader(Exchange.HTTP_RESPONSE_CODE,constant(200));
}
}
exchange.getIn().getHeader("id",String.class)
大致等于@PathVariable
。 @RequestMapping(value = URI_REMOVE_ACTIVITY_DELETE, method = DELETE)
应该成为.delete(URI_REMOVE_ACTIVITY_DELETE)
将bindingMode
设置为JSON的修改后的代码。
public void configure() {
restConfiguration().component("jetty").host("localhost").port("8080").bindingMode(RestBindingMode.json);
rest().produces("text/plain").delete("/something").to("direct:delete");
from("direct:delete")
.process(exchange -> {
Map<String, Object> requestObject = (Map<String, Object>) exchange.getIn().getBody();
//doDelete(requestObject.get("id"));
})
.setHeader(Exchange.HTTP_RESPONSE_CODE, constant(200));
}