SOA专题

使用Apache Camel实现REST端点集成

  源码下载

  首先设置一个RESTful服务端点:

@Path("/customerservice/")
public class CustomerServiceResource {

// NOTE: The instance member variables will not be available to the
// Camel Exchange. They must be used as method parameters for them to
// be made available
@Context
private UriInfo uriInfo;

public CustomerServiceResource() {
}

@GET
@Path("/customers/{id}/")
@Produces("text/xml")
public Customer getCustomer(@PathParam("id") String id) {
    return null;
}

@PUT
@Path("/customers/")
public Response updateCustomer(Customer customer) {
    return null;
}

}

使用Mediation Router实现 CXF-RS端点有两种,一种是直接端点配置:

from("cxfrs://http://localhost:9090/route?resourceClasses=
           com.fusesource.samples.CustomerServiceResource")

 

更灵活方法是定义一个中间者rsServer:

from("cxfrs:bean:rsServer")

然后在Camel上下文中声明一下:

<cxf:rsServer id="rsServer" address="http://localhost:9090/route"  
             serviceClass="com.fusesource.samples.CustomerServiceResource"/>

 

EDA

猜你喜欢