REST端点Apache的骆驼(REST EndPoint for Apache Camel)

2019-10-23 12:14发布

我试图建立连接REST端点与Apache骆驼。 我已经有一个REST服务返回JSON我的内容,我想这个端点得到它。 我的问题是,我不知道发生了什么,当我的骆驼途径是建立..目前,它不会做任何事情。 这里是我的代码:

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

我在端口上运行我的REST服务上的本地Tomcat的9080 ,我的完整URL是

/ ContextServices / REST / contextServices /文件/ {收集} / {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,有什么区别?

非常感谢 !

Answer 1:

首先,REST组件本身并不是一个REST实现。 它只是声明语言来描述REST端点。 你应该用实际执行的休息时间,像的Restlet(查看完整列表在这里 )

我可能是错的,但是当你想监听从其他应用程序REST请求AFAIR,REST端点仅供情况。 你需要的是做出请求REST端点,并对其进行处理。 现在的问题是:当你想激活请求? 它是一些事件,也可以要定期检查外部REST服务? 对于后一种情况我使用以下图案:

<route>
  <from uri="timer:polling-rest?period=60000"/>
  <setHeader headerName="CamelHttpMethod">
    <constant>GET</constant>
  </setHeader>
  <recipientList>
    <simple>http://${properties:service.url}/api/outbound-messages/all</simple>
  </recipientList>
  <unmarshal ref="message-format"/>

  <!-- do something with the message, transform it, log,
       send to another services, etc -->

  <setHeader headerName="CamelHttpMethod">
    <constant>DELETE</constant>
  </setHeader>
  <recipientList>
    <simple>http://${properties:service.url}/api/outbound-messages/by-id/${header.id}</simple>
  </recipientList>
</route>

遗憾用于与例如http组件,而不是REST 。 我简单地复制粘贴从我的工作项目,该项目采用纯它http 。 我想,通过类似的Restlet或CXF组件重写此。



文章来源: REST EndPoint for Apache Camel