我想通过点击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");
}
}