【发布时间】:2015-06-25 09:27:14
【问题描述】:
我正在尝试使用 Apache Camel 创建一个 REST 端点。我已经有一个返回 JSON 内容的 REST 服务,我希望这个端点能够获取它。我的问题是,当我的骆驼路线建成时,我不知道发生了什么。目前,它什么也没做。这是我的代码:
restConfiguration().component("servlet")
.bindingMode(RestBindingMode.json)
.dataFormatProperty("prettyPrint", "true").host("localhost")
.port(9080);
rest("/ContextServices/rest/contextServices/document")
.consumes("application/json").produces("application/json")
.get("/testContext/557064c8f7f71f29cea0e657").outTypeList(String.class)
.to("bean:processor?method=affiche")
.to(dest.getRouteTo());
我正在本地 Tomcat 上的端口 9080 上运行我的 REST 服务,我的完整 URL 是
/ContextServices/rest/contextServices/document/{collection}/{id}。
我尝试阅读文档,但有两种语法,但都不起作用:
from("rest:get:hello:/french/{me}").transform().simple("Bonjour ${header.me}");
或
rest("/say")
.get("/hello").to("direct:hello")
.get("/bye").consumes("application/json").to("direct:bye")
.post("/bye").to("mock:update");
第一个是Java DSL,第二个是REST DSL,有什么区别?
非常感谢!
【问题讨论】:
-
您有任何支持 REST 的组件吗?例如骆驼servlet
-
您好,如果这是您的问题,我已将 camel-servlet 添加到 pom 中
-
只对pom?您还必须在 web.xml 中设置 servlet(检查 camel.apache.org/servlet.html)
标签: java rest apache-camel