首页
学习
活动
专区
圈层
工具
发布
社区首页 >问答首页 >Apache CXFRS和CAMEL配置

Apache CXFRS和CAMEL配置
EN

Stack Overflow用户
提问于 2011-10-15 20:01:00
回答 1查看 3.3K关注 0票数 2

我想通过点击http://someotherhost站点上可用的REST web服务来使用REST结果。我已经为它写了一个代理客户端

我想使用apache CXFRS客户端访问上面的REST服务,并将结果写入一个文件。我正在做下面的事情,有没有人可以回顾一下下面的内容,并评论一下我做错了什么。

a)我使用apache cxf进行的camel上下文配置如下

代码语言:javascript
复制
    <jaxrs:client address="http://someotherhost/test/" id="cityServiceClient" username="test"         
            password="pwd" 
            serviceClass="com.santosh.proxy.service.city.CityService">
            <jaxrs:features>
                    <ref bean="loggingFeature" />
            </jaxrs:features>
    </jaxrs:client>  

    <camelContext xmlns="http://camel.apache.org/schema/spring">
            <package>com.santosh.routes</package>
            <routeBuilder ref="cityserviceroutebuilder" />
    </camelContext>

b)我的代理服务接口

代码语言:javascript
复制
    @Path(value="/getCities") 
    public interface CityService   { 

       @POST 
       @Produces(value="text/xml") 
       public String getCities(@QueryParam("countrycode") String countryCode); 
    } 

c)调用服务

代码语言:javascript
复制
   CityService cityService = (CityService) context.getBean("cityServiceClient"); 
   cityService.getCities("ae"); 

d)骆驼路线

代码语言:javascript
复制
  public class CityRoutes extends RouteBuilder { 

    public void configure() throws Exception { 

   //ROUTES 
    from("cxfbean:cityServiceClient") 
      .to("file://data/xmls/cities?fileName=test.xml"); 
    } 
} 
EN

回答 1

Stack Overflow用户

回答已采纳

发布于 2011-10-19 02:24:16

我得到了解决方案,基本上我的camel上下文配置没有达到这个标准,

下面的配置解决了我的问题。

代码语言:javascript
复制
    <! -- 4 THE ACTUAL SERVER WHICH WILL GET HIT -->
    <jaxrs:server id="restService" depends-on="camelContext" 
            address="http://REALSERVER.COM/REST/" createdFromAPI="true" 
            staticSubresourceResolution="true">
            <jaxrs:serviceBeans>
                    <ref bean="servicecity" />
            </jaxrs:serviceBeans>
    </jaxrs:server>

    <bean name="servicecity" id="servicecity" class="com.santosh.CityServiceImpl" />


    <! -- 3  YOUR PROXY CLIENT -->
    <cxf:rsClient id="rsClient" address="http://REALSERVER.COM/REST/"  
                              serviceClass="com.santosh.CityServiceImpl" 
                      username="santosh" password="pwd" />

    <! -- 1 JAXRS PROXY CLIENT  -->  
    <jaxrs:client id="cityServiceClient" address="http://localhost:8123/REST/"
            serviceClass="com.santosh.CityService" username="santosh" password="pwd">
    </jaxrs:client>

   <! -- 2  YOUR LOCAL SERVER THAT YOU NEED TO HIT, YOUR LOCAL SERVER -->
    <cxf:rsServer id="rsServer" address="http://localhost:8123/REST/" serviceClass="com.santosh.CityServiceImpl" />

具体步骤如下

1)创建JAXRS代理客户端并将其放入您的代码CityService cityService = (CityService) context.getBean("cityServiceClient");cityService.getCities(“印度”);

2)上面的代码将调用服务器(本地)

3)上述步骤将调用您的代理客户端

4)代理客户端将调用实际的真实服务器

票数 3
EN
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/7777703

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档