Menu Close
5.4.3. Camel REST DSL での JAX-RS コンシューマー
Camel REST DSL は、JAX-RS コンシューマーとして動作する Camel ルートを書き込む機能を提供します。以下の RouteBuilder クラスはこれを示しています。
@Startup @ApplicationScoped @ContextName("rest-camel-context") public class RestConsumerRouteBuilder extends RouteBuilder { @Override public void configure() throws Exception { // Use the camel-undertow component to provide REST integration restConfiguration().component("undertow") .contextPath("/rest").port(8080).bindingMode(RestBindingMode.json); rest("/customer") // GET /rest/customer .get() .produces(MediaType.APPLICATION_JSON) .to("direct:getCustomers") // GET /rest/customer/1 .get("/{id}") .produces(MediaType.APPLICATION_JSON) .to("direct:getCustomer") // POST /rest/customer .post() .type(Customer.class) .to("direct:createCustomer"); // PUT /rest/customer .put() .type(Customer.class) .to("direct:updateCustomer"); // DELETE /rest/customer/1 .delete("/{id}") .to("direct:deleteCustomer"); } }
バインディングモードを設定することで、Camel は 'produces()' または 'type()' 設定ステップを指定して JSON データをマーシャリングおよびアンマーシャリングできます。
注記
-
REST DSL 設定は
restConfiguration().component("undertow")
で始まります。 - Camel on EAP サブシステムは、REST DSL と使用する camel-servlet コンポーネントおよび camel-undertow コンポーネントのみをサポートします。ただし、他のコンポーネントを設定すると動作しません。