【发布时间】:2017-02-19 07:50:25
【问题描述】:
我正在运行一些这样声明的 JAX-RS 资源:
public interface MyEntityServiceV2 {
@PUT
@Consumes({"application/myentity-v2+json"})
@Produces({"application/myentity-v2+json"})
@Path("/{uuid:[0-9a-fA-F]{8}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{4}-[0-9a-fA-F]{12}}")
Response putMyEntity(@PathParam("uuid") String uuid, MyEntityDto myEntity);
}
现在我想使用 Jersey-Client(或任何其他客户端,如果它有助于解决我的问题)来测试它们:
MyEntityDto dto = new MyEntityDto();
Entity<MyEntityDto> entity = Entity.entity(dto, MediaType.APPLICATION_JSON_TYPE);
Client client = ClientBuilder.newClient();
WebTarget target = client.target("http://localhost:7001/path/" + UUID.randomUUID().toString());
Invocation.Builder builder = target.request("application/myentity-v2+json");
builder.header("Content-Type", "application/myentity-v2+json");
Response response = builder.put(entity);
不幸的是,这不起作用。请求始终包含 application/json 的内容类型。而且这个和服务器上的接口不匹配。
作为替代方案,我可以使用我的自定义 MediaType 创建实体,这也会导致错误,因为它找不到该类型的 MessageBodyWriter。
哦,我不能更改服务声明。
您认为测试此资源的最佳方法是什么?
【问题讨论】:
标签: java json jax-rs content-type