2011-10-15 119 views
2

我想通过点击在http://someotherhost网站上提供的REST Web服务来使用REST结果。我已经为它写了一个代理客户端Apache CXFRS和CAMEL配置

我想使用apache CXFRS客户端命中上述REST服务并将结果写入文件。为此,我正在做以下工作,是否有人可以查看下面的内容,并评论我做错的事情。

a)用阿帕奇CXF我的骆驼上下文配置是如下

<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)MY代理服务接口

@Path(value="/getCities") 
    public interface CityService { 

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

c)中召唤而

CityService cityService = (CityService) context.getBean("cityServiceClient"); 
    cityService.getCities("ae"); 

d)骆驼路线

public class CityRoutes extends RouteBuilder { 

    public void configure() throws Exception { 

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

回答

3

我得到了解决,基本上我的骆驼上下文配置达不到该商标,

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

<! -- 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(“INDIA”);

2)上面的代码将调用SERVER(LOCAL)

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

4)代理客户端将调用实际的真实SERVER

+0

得到了最后解决 –