[英]Camel With Cxf and Routing
I was doing some research on Camel - CXf integration and am confused about the below scenario. 我正在对Camel-CXf集成进行一些研究,并对以下情况感到困惑。
So i implemented a 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;
}
And the implementation as below 并实现如下
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();
}
} }
The Route 路线
<camel:from uri="cxfrs:bean:SampleRestEndPoint?bindingStyle=SimpleConsumer"></camel:from>
routes it into the implementation. 将其路由到实现中。 But since the implementation returns a response object am confused how to build the routes around this.
但是由于实现返回响应对象,因此如何构建路由变得很困惑。
Any pointers will be appreciated. 任何指针将不胜感激。
Dude, take a look at this - http://bushorn.com/camel-cxf-geocoder-example/ 杜德,看看这个-http://bushorn.com/camel-cxf-geocoder-example/
The above example is not REST though, but usage of CXF with Camel route is same. 上面的示例虽然不是REST,但是将CXF与Camel路由一起使用是相同的。
I will do these mandatory steps: 我将执行以下强制性步骤:
Avoid beans/custom classes - try to use the camel framework capabilities. 避免使用bean /自定义类-尝试使用骆驼框架功能。
Use XML - Spring/Blueprint DSL 使用XML-Spring / Blueprint DSL
Please look at the following thread. 请看下面的线程。
Apache Camel and web services Apache Camel和Web服务
I have successfully implemented web service consumption using camel and Apache CXF. 我已经使用骆驼和Apache CXF成功实现了Web服务使用。 If you have doubts, I can help you out.
如果您有任何疑问,我可以为您提供帮助。
Thanks, Gautham 谢谢Gautham
@GauthamHonnavara - that is an implementation of a JS webservice with an assosiated processor however it doesnt assosiate any direct route to the endpoint.Also my question was specific to JAX-RS where you cannot generate a service class from wsdl. @GauthamHonnavara-这是一个带有关联处理器的JS Web服务的实现,但是它没有关联到端点的任何直接路由。我的问题还专门针对无法从wsdl生成服务类的JAX-RS。
Assume this use case that u need a customer to invoke the endpoint and then go through say another 5 steps, reach out to another webservice etc and then sent a response back. 假设这个用例是,您需要客户调用端点,然后执行另外5个步骤,联系另一个Web服务,等等,然后将响应发送回去。 The above implementation sents a response back in the webservice implementation bean itself.
上面的实现将响应发送回webservice实现bean本身。
So to avoid this create a simple interface with the producer consumer etc, just like in my question and then make each method void if you want to inject the Exchange( if needed. ) and use below configuration 因此,为避免这种情况,请与生产者使用者等创建一个简单的接口,就像在我的问题中一样,然后如果要注入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 is to use the service class tag. 技巧是使用服务类标记。 If the interface is provided there then it doesn't need a concrete implementation from CXF.
如果在那里提供了接口,则它不需要CXF的具体实现。
Hope this helps. 希望这可以帮助。 Let me know
让我知道
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.