我想通过点击http://someotherhost站点上可用的REST web服务来使用REST结果。我已经为它写了一个代理客户端
我想使用apache CXFRS客户端访问上面的REST服务,并将结果写入一个文件。我正在做下面的事情,有没有人可以回顾一下下面的内容,并评论一下我做错了什么。
a)我使用apache cxf进行的camel上下文配置如下
<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)我的代理服务接口
@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");
}
} 发布于 2011-10-19 02:24:16
我得到了解决方案,基本上我的camel上下文配置没有达到这个标准,
下面的配置解决了我的问题。
<! -- 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)代理客户端将调用实际的真实服务器
https://stackoverflow.com/questions/7777703
复制相似问题