i want to consume the REST result by hitting a REST web Service available at http://someotherhost
site. i have written a proxy client for it
I want to hit the above REST service using apache CXFRS client and the write the result to a file. for which i am doing the following,could any one review the below and comment the things i have done wrong .
a) My camel context configuration with apache cxf is as below
<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 service Interface
@Path(value="/getCities")
public interface CityService {
@POST
@Produces(value="text/xml")
public String getCities(@QueryParam("countrycode") String countryCode);
}
c) Call to service
CityService cityService = (CityService) context.getBean("cityServiceClient");
cityService.getCities("ae");
d) Camel Routes
public class CityRoutes extends RouteBuilder {
public void configure() throws Exception {
//ROUTES
from("cxfbean:cityServiceClient")
.to("file://data/xmls/cities?fileName=test.xml");
}
}
I got the solution, basically my camel-context configuration was not up to that mark,
The below configuration solved my problem.
<! -- 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" />
THE STEPS ARE
1) create JAXRS PROXY CLIENT and get it in your have code CityService cityService = (CityService) context.getBean("cityServiceClient"); cityService.getCities("INDIA");
2) the above code will call the SERVER (LOCAL)
3) the above step will call YOUR PROXY CLIENT
4) the PROXY CLIENT will call the ACTUAL REAL SERVER