如何通过Apache Camel调用RESTful服务?

时间:2012-04-16 06:25:57

标签: java rest jira apache-camel

我目前正在使用HTTP方法调用一些会产生JIRA问题的URL。

现在我想使用Apache Camel,我该如何使用它?

我需要通过Camel调用以下链接:

http://localhost:8080/rest/api/2/project/" + key + /components

由于我是Camel的新手,请提供一些解决方案和示例。

由于

4 个答案:

答案 0 :(得分:9)

另请参阅此常见问题解答,了解如何在Camel中使用动态到端点 http://camel.apache.org/how-do-i-use-dynamic-uri-in-to.html

基本上,EIP模式是收件人列表。

因此,在您的情况下,它也可以简化为一个EIP

<recipientList>
  <simple>http://localhost:8080/rest/api/2/project/${header.myKey}/components</simple>
</recipientList>

请注意,Camel中的http组件是完全同步的。如果您想通过HTTP进行请求/回复并避免在等待回复消息时使用调用程序块,那么您可以使用Camel中的一些其他HTTP组件,例如:

  • 驼-AHC
  • 驼http4
  • 驼码头

答案 1 :(得分:8)

您可以轻松使用CXFRS Component;如果由于某种原因你需要使用HTTP Component来完成它,你也可以轻松使用它:

<setHeader headerName="CamelHttpUri">
      <simple>http://localhost:8080/rest/api/2/project/${header.myKey}/components</simple>
</setHeader>
<inOut uri="http://doesnt.matter.we/override/it/anyways" />

当然,在进入路线的这一部分之前,您需要使用myKey标题来丰富您的信息。

答案 2 :(得分:2)

我正在使用apache camel jetty

textContent

所以当用户点击http://localhost:9000/offers时,端点直接:getOffers将被调用

现在定义getOffers端点

CamelContext context = new DefaultCamelContext();
    public void configure(){
           context.addRoutes(new RouteBuilder(){
           from("jetty:localhost:9000/offers")
           .to("direct:getOffers")
           .end();

    }

});

此处另一项服务正在9008运行,其休息资源为 http://localhost:9008/api/v2.0/offers这是我想要消耗的资源。

因此,当camel实例启动时,它会注册两个路由,然后执行上述处理

注意重要的是添加?bridgeEndpoint = true选项以使其正常工作

答案 3 :(得分:0)

您可以使用CXFRS Component从驼峰中使用REST服务.Apache camel有足够的信息。

http://camel.apache.org/cxfrs.html

相关问题