我正在尝试用Apache创建en REST端点。我已经有了一个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());我在端口9080上的本地Tomcat上运行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,有什么区别?
非常感谢!
发布于 2015-06-25 11:08:07
首先,REST组件本身不是REST实现。它只是声明了描述REST端点的语言。您应该使用REST的实际实现,类似Restlet (请参阅完整列表这里)
我可能错了,但是REST端点只适用于您想要侦听来自另一个应用程序的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组件这样的工具来重写它吧。
https://stackoverflow.com/questions/31046314
复制相似问题