5.4. JAX-RS
Cryostat-RS 지원은 Camel CXF-RS 에서 제공합니다.
5.4.1. CXF-RS Producer
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<cxf:rsClient id="cxfProducer"
address="http://localhost:8080/rest"
serviceClass="org.wildfly.camel.examples.cxf.jaxrs.GreetingService" />
<camelContext id="cxfrs-camel-context" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="direct:start" />
<setHeader headerName="operationName">
<simple>greet</simple>
</setHeader>
<setHeader headerName="CamelCxfRsUsingHttpAPI">
<constant>false</constant>
</setHeader>
<to uri="cxfrs:bean:cxfProducer" />
</route>
</camelContext>
</beans>5.4.2. CXF-RS 소비자
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:cxf="http://camel.apache.org/schema/cxf"
xsi:schemaLocation="
http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://camel.apache.org/schema/cxf http://camel.apache.org/schema/cxf/camel-cxf.xsd
http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd">
<cxf:rsServer id="cxfConsumer"
address="http://localhost:8080/rest"
serviceClass="org.wildfly.camel.examples.cxf.jaxrs.GreetingService" />
<camelContext id="cxfrs-camel-context" xmlns="http://camel.apache.org/schema/spring">
<route>
<from uri="cxfrs:bean:cxfConsumer" />
<setBody>
<constant>Hello world</constant>
</setBody>
</route>
</camelContext>
</beans>5.4.3. Camel REST DSL을 사용한 Cryostat-RS 소비자
Camel REST DSL은 Cryostat-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")로 시작됩니다. - EAP Cryostat의 Camel은 REST DSL과 함께 사용할 수 있도록 camel-servlet 및 camel-undertow 구성 요소만 지원합니다. 그러나 다른 구성 요소를 구성하면 작동하지 않습니다.
5.4.4. 보안
Cryostat -RS 보안 섹션을 참조하십시오.
5.4.5. EAP의 Fuse 빠른 시작 예
빠른 시작 예제는 빠른 시작/camel/camel-cxf-jaxrs 디렉터리에 있는 EAP 설치의 Fuse에서 사용할 수 있습니다.