In one of the few questions (with answers) I have found on SO regarding JAX-RS and caching, the answer to generating ETags (for caching) is by setting some values on the Respons
Yes you might be able to use interceptors to achieve this if you could generate the E-tag AFTER you create your response object.
public class MyInterceptor extends AbstractPhaseInterceptor {
public MyInterceptor () {
super(Phase.MARSHAL);
}
public final void handleMessage(Message message) {
MultivaluedMap headers = (MetadataMap) message.get(Message.PROTOCOL_HEADERS);
if (headers == null) {
headers = new MetadataMap();
}
//generate E-tag here
String etag = getEtag();
//
String cc = 600;
headers.add("E-Tag", etag);
headers.add("Cache-Control", cc);
message.put(Message.PROTOCOL_HEADERS, headers);
}
}
If that way isn't viable, I would use the original solution that you posted, and just add your Person entity to the builder:
Person p = _dao.getPerson(name);
return builder.entity(p).cacheControl(cc).lastModified(person.getUpdated()).build();