首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache的REST EndPoint

Apache的REST EndPoint
EN

Stack Overflow用户
提问于 2015-06-25 09:27:14
回答 1查看 3.2K关注 0票数 1

我正在尝试用Apache创建en REST端点。我已经有了一个REST服务,它返回JSON内容,我希望这个端点能够得到它。我的问题是,当我的骆驼路线建成时,我不知道发生了什么。就目前而言,它什么也做不了。这是我的代码:

代码语言:javascript
复制
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}.

我试过阅读文档,但是有两种语法,它们都不起作用:

代码语言:javascript
复制
from("rest:get:hello:/french/{me}").transform().simple("Bonjour ${header.me}");

代码语言:javascript
复制
rest("/say")
    .get("/hello").to("direct:hello")
    .get("/bye").consumes("application/json").to("direct:bye")
    .post("/bye").to("mock:update");

第一个是Java DSL,第二个是REST DSL,有什么区别?

非常感谢!

EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2015-06-25 11:08:07

首先,REST组件本身不是REST实现。它只是声明了描述REST端点的语言。您应该使用REST的实际实现,类似Restlet (请参阅完整列表这里)

我可能错了,但是REST端点只适用于您想要侦听来自另一个应用程序的REST请求的情况。您需要的是请求REST端点并对其进行处理。问题是:何时要触发请求?是某个事件,还是您希望定期检查外部REST服务?对于后一种情况,我使用以下模式:

代码语言:javascript
复制
<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组件这样的工具来重写它吧。

票数 1
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/31046314

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档