如何使用apache camel调用restful webservice

时间:2014-11-06 06:26:33

标签: rest cxf apache-camel

我的宁静服务是

import java.util.List;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.PathParam;
import javax.ws.rs.Produces;
import org.hibernate.Query;
import org.hibernate.Session;
import org.json.JSONArray;


@Path("/detailsservice/")
public class DetailsService {
 Dao d=new Dao();

@GET
@Path("/details/{id}/")
@Produces("text/xml")

public Details getDetails(@PathParam("id") String id) {

    Session hs = d.dao();
    Details de = (Details) hs.load(Details.class,new Integer(id));

    return de;
 }
}

我使用jetty服务器在网络上公开了这项服务

 import org.apache.cxf.jaxrs.JAXRSServerFactoryBean;
 import org.apache.cxf.jaxrs.lifecycle.SingletonResourceProvider;


 public class Server {

 protected Server() throws Exception {
    JAXRSServerFactoryBean sf = new JAXRSServerFactoryBean();
    sf.setResourceClasses(DetailsService.class);
    System.out.println("two");
    sf.setResourceProvider(DetailsService.class, new SingletonResourceProvider(new  DetailsService()));
    sf.setAddress("http://localhost:9000/");
    sf.create();
}

public static void main(String args[]) throws Exception {
  new Server();
    System.out.println("Server ready...");

    Thread.sleep(5 * 6000 * 1000);
    System.out.println("Server exiting");
    System.exit(0);
}

}

如何使用apache camel调用此服务。 请详细解释我,因为我是骆驼的新手。 提前致谢

1 个答案:

答案 0 :(得分:1)

您可以使用http4组件:

<route>
  <from uri="http4://localhost:9000/detailsservice/details/1234" />
  <!-- add your processors here -->
  <to uri="..." />
</route>