问题描述
我一直在使用CXF和骆驼配置的RESTful Web服务。我的配置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立即接管,并在我的类中的方法present根本没有被感动.. INFACT任何响应来自我到路线的一部分是送回客户端..现在的一种方法是,我添加多个处理器为每个businesss逻辑。但我真的希望有我的方法执行,然后再启动路线..我怎么能做到这一点?另外我打我的,我想任何参数的服务器,即使他们是错的(意思PoiDetailsRequest变量错误数据类型),并得到任何响应参数(这是不PoiDetailsResponse的一部分),这是ofcourse不是一件好事..请建议东西..
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..
推荐答案
您不需要使用骆驼cxfrs组件,如果你想公开一个RS服务,使用该服务的bean。你可以只使用纯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.
骆驼cxfrs组件是当你想直接让RS业务路由到骆驼的路线。
The Camel cxfrs component is for when you want to let the RS service route directly into the Camel route.
如果你希望你的方法首先执行,那么你可以从你的方法调用骆驼使用ProducerTemplate使用直接端点发送消息到骆驼的路线。
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的骆驼:控制线路启动的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!