2011-10-15 169 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

得到了最後解決 –