在one of the few questions (with answers)我已经找到关于JAX-RS和缓存的SO,生成ETags(用于缓存)的答案是通过在Response对象上设置一些值。如下面的:是否可以使用JAX-RS设置ETags而不使用Response对象?
@GET
@Path("/person/{id}")
public Response getPerson(@PathParam("id") String name, @Context Request request){
Person person = _dao.getPerson(name);
if (person == null) {
return Response.noContent().build();
}
EntityTag eTag = new EntityTag(person.getUUID() + "-" + person.getVersion());
CacheControl cc = new CacheControl();
cc.setMaxAge(600);
ResponseBuilder builder = request.evaluatePreconditions(person.getUpdated(), eTag);
if (builder == null) {
builder = Response.ok(person);
}
return builder.cacheControl(cc).lastModified(person.getUpdated()).build();
}
的问题是不会被注释与@WebMethod(SOAP),@ GET方法为我们工作,因为两者都会使用SOAP相同的方法和REST服务,(和我们可能需要披露该服务的其他任何内容)。以前的服务是这样给我们(不包括创建头):
@WebMethod
@GET
@Path("/person/{id}")
public Person getPerson(@WebParam(name="id") @PathParam("id") String name){
return _dao.getPerson(name);
}
有什么办法 - 通过一些额外的配置 - 设置这些头的?这是我第一次发现使用Response对象实际上比自动转换有一些好处...
我们正在使用Apache CXF。
我可能使用某种拦截器吗? http://stackoverflow.com/questions/3165647/apache-cxf-how-to-add-custom-http-header-to-jax-rs-response?rq=1 – oligofren