如何在apache骆驼中发送空响应以进行休息电话

时间:2019-01-30 08:09:00

标签: apache-camel spring-camel

我有用于删除操作的休息服务,实际上什么也没返回。如何在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;

1 个答案:

答案 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)

来自以下服务器的响应 enter image description here

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));


}