我正在对Camel-CXf集成进行一些研究,并对下面的情况感到困惑。
所以我实施了一个Rest Endpoint
@Path("/authenticate")
public interface Sample {
@GET
@Path("/handshake")
@Produces(MediaType.TEXT_PLAIN)
public Response handshake();
@POST
@Path("/login")
@Consumes({MediaType.APPLICATION_JSON,MediaType.APPLICATION_XML})
@Produces(MediaType.APPLICATION_JSON)
public Response login(LoginRequest request) throws JsonGenerationException, JsonMappingException, IOException;
}
并执行如下
public class SampleImpl implements Sample{
@Context
private HttpHeaders headers;
@Autowired
CamelContext context;
public Response handshake()
{
System.out.println("HandShake Executed Successfully");
return Response.status(Status.OK).entity("This is a Message after Routing").build();
}
public Response login(LoginRequest request) throws JsonGenerationException, JsonMappingException, IOException {
System.out.println("The Rquest objecr is Received "+request);
return Response.status(Status.OK).entity(mapper.writeValueAsString(request)).build();
}
}
路线
<camel:from uri="cxfrs:bean:SampleRestEndPoint?bindingStyle=SimpleConsumer"></camel:from>
将其路由到实现中。但是由于实现返回一个响应对象,我很困惑如何围绕这个构建路由。
任何指针都将受到赞赏。
答案 0 :(得分:0)
老兄,看看这个 - http://bushorn.com/camel-cxf-geocoder-example/
上面的示例不是REST,但CXF与Camel路由的使用是相同的。
我将执行以下强制性步骤:
避免使用bean /自定义类 - 尝试使用camel框架功能。
使用XML - Spring / Blueprint DSL
答案 1 :(得分:0)
答案 2 :(得分:0)
@GauthamHonnavara - 这是一个带有相关处理器的JS web服务的实现,但是它不会指向任何到端点的直接路由。另外我的问题是针对JAX-RS的,你不能从wsdl生成服务类。
假设这个用例需要客户调用端点,然后再说5个步骤,联系另一个webservice等,然后发回一个响应。上面的实现在webservice实现bean本身中返回一个响应。
所以为了避免这种情况,请与生产者消费者等创建一个简单的界面,就像在我的问题中一样,如果你想注入Exchange(如果需要的话),那么让每个方法都无效,并使用下面的配置
<!-- Created the CXF End Point For the Calls to Come IN -->
<cxf:rsServer id="RestEndPoint" address="/rest"
serviceClass="com.poc.camel.cxf.service.incoming.xxx"
loggingFeatureEnabled="true" loggingSizeLimit="20">
<cxf:providers>
<bean class="org.codehaus.jackson.jaxrs.JacksonJsonProvider" >
<!-- <constructor-arg ref="customObjectMapper" type="org.codehaus.jackson.map.ObjectMapper"/> -->
</bean>
</cxf:providers>
</cxf:rsServer>
Trick是使用服务类标记。如果在那里提供了接口,那么它不需要CXF的具体实现。
希望这会有所帮助。让我知道