Apache Camel:控制路由启动 [英] Apache Camel : Control over route startup

查看:37
本文介绍了Apache Camel:控制路由启动的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用 cxf 和骆驼配置的宁静网络服务.我的配置 xml 是:

i have a restful webservice configured using cxf and camel. My config xml is :

<jaxrs:server id="restContainer" address="/" staticSubresourceResolution="true"> <jaxrs:serviceBeans>  
<ref bean="FooBar" />
  </jaxrs:serviceBeans> 
 <jaxrs:providers>  
<bean class="org.apache.cxf.jaxrs.provider.JSONProvider">
  <property name="dropRootElement" value="true" /> 
 <property name="supportUnwrapped" value="true" /> 
 </jaxrs:providers>  
<camelcxf:rsServer id="rsServer" address="/" serviceClass="com.camel.example.FooBar" /> <camel:camelContext id="camelContext-1">  
<camel:route> 
 <camel:from uri="cxfrs:bean:rsServer" />  
<camel:to uri="http://localhost:8080/Google/rest/search" />  
</camel:route>  
</camel:camelContext> 

现在我有 FooBar 类,它作为服务公开,如下所示:

Now i have FooBar class which is exposed as a service and is like this :

@Service("Demo") @Path("/foo/bar") public class FooBar{

       @POST @Produces(MediaType.APPLICATION_JSON) @Consumes(MediaType.APPLICATION_JSON) public PoiDetailsResponse poiGetDetails(
            PoiDetailsRequest json)
    {
        System.out.println(json.getUname());
        System.out.println(json.getDeviceid());
        //do some validation and some business logic
        //return accordingly;
    }

我担心的是,当我点击我的服务器时 ..camelContext 立即接管并且我的类中存在的方法根本没有被触及..事实上,来自我的to"部分路由的任何响应都被发送回客户端..现在一种方法是我为每个业务逻辑添加多个处理器.但我真的想先执行我的方法,然后开始路由..我该怎么做??此外,我可以使用我想要的任何参数访问我的服务器,即使它们是错误的(意味着 PoiDetailsRequest 变量的错误数据类型)并获得任何响应参数(不属于 PoiDetailsResponse 的一部分),这当然不是一件好事..请提出一些建议..

My concern is that when i hit my server .. camelContext takes over immediately and the method present in my class is not at all touched .. infact whatever response comes from my "to" part of the route is send back to the client.. now one way is that i add multiple processor for every businesss logic. but i really want to have my method executed first and then route starts .. how can i do this ?? Also i can hit my server with whatever parameters i want, even if they are wrong (meaning wrong datatypes of variables of PoiDetailsRequest) and get any response parameters (which are not part of PoiDetailsResponse), this is ofcourse not a good thing.. please suggest something..

推荐答案

如果要公开 RS 服务并使用服务 bean,则不需要使用 Camel cxfrs 组件.您可以为此使用普通的 CXF RS.

You dont need to use the Camel cxfrs component if you want to expose a RS service and use the service bean. You can just use plain CXF RS for this.

Camel cxfrs 组件用于让 RS 服务直接路由到 Camel 路由中.

The Camel cxfrs component is for when you want to let the RS service route directly into the Camel route.

如果您希望首先执行您的方法,那么您可以从您的方法调用 Camel,方法是使用 ProducerTemplate 使用直接端点将消息发送到 Camel 路由.

If you want your method executed first, then you can from your method call Camel by using the ProducerTemplate to send a message to a Camel route using the direct endpoint.

这篇关于Apache Camel:控制路由启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆