2012-04-16 106 views
9

我目前正在使用HTTP方法來調用一些將會產生JIRA問題的URL。如何通過Apache Camel調用RESTful服務?

現在我想使用Apache Camel,我該如何使用它?

我需要通過駱駝調用以下鏈接:

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

由於我是新來的駱駝,請提出了一些解決方案和實例了。

感謝

回答

7

你可以很容易地使用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頭,豐富您的消息。

+0

CXFRS如何用於執行簡單的HTTP請求? – Phil 2015-08-17 04:46:08

8

參考這個FAQ關於駱駝 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> 

介意駱駝的HTTP組件是完全同步的。如果你想要做的請求/應答通過HTTP和避免使呼叫者塊,同時等待應答消息,則可以使用其他一些HTTP組件的從駱駝如:

  • 駱駝AHC
  • 駱駝http4
  • 駱駝碼頭
1

我使用Apache的駱駝碼頭

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

    } 

}); 

所以具有 http://localhost:9008/api/v2.0/offers這休息資源getOffers將被調用

所以現在定義getOffers終點

context.addRoutes(new RouteBuilder(){ 
    public void configure(){ 
      from("direct:getOffers") 
      .to("jetty:http://localhost:9008/api/v2.0/offers? 
      bridgeEndpoint=true") 
     .end(); 

    } 

}); 

這裏的另一個服務正在運行在9008:在這裏,當用戶將達到http://localhost:9000/offers則端點直接是我試圖消費的資源。

所以當駱駝實例啓動時它註冊兩個途徑則它上面

所描述的處理說明其重要補充的選項?bridgeEndpoint = true以使其工作