1

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

<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 类,它作为服务公开,就像这样:

@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 的一部分),这当然不是一件好事..请建议一些东西..

4

1 回答 1

0

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.

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

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.

于 2012-04-23T17:10:40.633 回答