260.5. REST プロデューサーの例
rest コンポーネントを使用して、他の Camel コンポーネントと同様に REST サービスを呼び出すことができます。
たとえば、hello/{me}
を使用して REST サービスを呼び出すには、以下を実行できます。
from("direct:start") .to("rest:get:hello/{me}");
次に、動的な値 {me}
は、同じ名前を持つ Camel メッセージにマッピングされます。そのため、この REST サービスを呼び出すには、以下のように空のメッセージボディーとヘッダーを送信できます。
template.sendBodyAndHeader("direct:start", null, "me", "Donald Duck");
Rest プロデューサーは REST サービスのホスト名とポートを把握しておく必要があります。これは、以下のように host オプションを使用して設定できます。
from("direct:start") .to("rest:get:hello/{me}?host=myserver:8080/foo");
host オプションを使用する代わりに、以下のように restConfiguration
でホストを設定できます。
restConfiguration().host("myserver:8080/foo"); from("direct:start") .to("rest:get:hello/{me}");
producerComponent
を使用して、HTTP クライアントとして使用する Camel コンポーネントを選択できます。たとえば、http4 を使用できます。
restConfiguration().host("myserver:8080/foo").producerComponent("http4"); from("direct:start") .to("rest:get:hello/{me}");