2

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

我想使用 apache CXFRS 客户端访问上述 REST 服务并将结果写入文件。我正在做以下事情,任何人都可以查看以下内容并评论我做错的事情。

a) 我使用 apache 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 Proxy 服务接口

    @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"); 
    } 
} 
4

1 回答 1

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 PROXY CLIENT 并在您的代码中获取它 CityService cityService = (CityService) context.getBean("cityServiceClient"); cityService.getCities("印度");

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

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

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

于 2011-10-18T18:24:15.997 回答