sme*_*eeb 6 java rest jersey webservices-client dropwizard
DropWizard在引擎盖下使用Jersey进行REST.我试图找出如何为我的DropWizard应用程序将公开的RESTful端点编写客户端.
为了这个例子,让我们说我的DropWizard应用程序有一个CarResource,它为CRUDding汽车公开了一些简单的RESTful端点:
@Path("/cars")
public class CarResource extends Resource {
    // CRUDs car instances to some database (DAO).
    public CardDao carDao = new CarDao();
    @POST
    public Car createCar(String make, String model, String rgbColor) {
        Car car = new Car(make, model, rgbColor);
        carDao.saveCar(car);
        return car;
    }
    @GET
    @Path("/make/{make}")
    public List<Car> getCarsByMake(String make) {
        List<Car> cars = carDao.getCarsByMake(make);
        return cars;
    }
}
所以,我会想象,一个结构化的API客户端会是这样的一个CarServiceClient:
// Packaged up in a JAR library. Can be used by any Java executable to hit the Car Service
// endpoints.
public class CarServiceClient {
    public HttpClient httpClient;
    public Car createCar(String make, String model, String rgbColor) {
        // Use 'httpClient' to make an HTTP POST to the /cars endpoint.
        // Needs to deserialize JSON returned from server into a `Car` instance.
        // But also needs to handle if the server threw a `WebApplicationException` or
        // returned a NULL.
    }
    public List<Car> getCarsByMake(String make) {
        // Use 'httpClient' to make an HTTP GET to the /cars/make/{make} endpoint.
        // Needs to deserialize JSON returned from server into a list of `Car` instances.
        // But also needs to handle if the server threw a `WebApplicationException` or
        // returned a NULL.
    }
}
但我能找到的只有两个对Drop Wizard客户的官方引用完全相互矛盾:
car-client下的项目中car.service.client; 但是之后...所以我想问一下,为DropWizard Web服务编写Java API客户端的标准方法是什么?DropWizard有一个我可以用于此类用例的客户端库吗?我应该通过一些Jersey客户端API实现客户端吗?有人可以添加伪代码给我,CarServiceClient所以我可以理解这将如何工作?
| 归档时间: | 
 | 
| 查看次数: | 7381 次 | 
| 最近记录: |