Apache Camel Filter bean 通过 REST DSL 响应

Apache Camel Filter bean response via REST DSL

我目前正在使用新的 Camel REST DSL 作为基础开发基于 REST 的 java 应用程序。我正在尝试在 return 客户端的 json 响应之前过滤对象列表的结果。

这是我正在尝试做的示例代码:

.get("/api/list").description("Search all data")
   .to("bean:apiService?method=searchAll")
.route().description("Lets suppose i need to aply a filter in return")
    .to("bean:apiService?method=filter").endRest();

但是在第二个 bean 执行期间我无法访问第一个 bean 执行的对象 returned。

class ApiService {

public MyResponseJSON searchAll(MyJsonObjectRequest request) {

    MyResponseJSON jsonReturn = new MyResponseJSON();

    return jsonReturn;
}


public MyResponseJSON filter(Exchange exchange) {
    //i can't do anything here. The message in exchange is empty
} 
}

而其余的return对客户端来说是空的。

我试图不将过滤器放在方法 searchAll 中,因为我使用的是单一职责原则。

如果我删除 .route()....endRest() 响应正常,但未过滤。

这可以使用 Apache Camel 的 REST DSL 来完成,如果可能的话,我做错了什么?

谢谢。

在 rest-dsl 中只有 toroute,而不是 both,例如:

.get("/api/list").description("Search all data")
   .route()
     .to("bean:apiService?method=searchAll")
     .to("bean:apiService?method=filter");