Red Hat Training
A Red Hat training course is available for Red Hat Fuse
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 コンポーネントのみをサポートします。他のコンポーネントを設定した場合は機能しません。