273.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 サービスのホスト名とポートを認識する必要があります。

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}");