I know I can set the ETAG and LastModified properties on Representation/RepresentationInfo. But I have a simple resource implemented like this :
public class AccountServerResource extends ServerResource implements AccountResource {
private static Logger log = Logger.getLogger(AccountServerResource.class.getName());
@Override
public Account retrieve() {
User user = getClientInfo().getUser();
AccountDAO dao = new AccountDAO();
Account ret = dao.getAccountByEmail(user.getEmail());
log.info("retrieved " + ret);
// getResponse().getEntity() == null at this point !!!
// ---> cannot do this : getResponse().getEntity().setModificationDate(ret.getLastModified());
return ret;
}
}
The representation is not yet attached to the response at this time. When/how do I set the ETAG/LastModified tags ?
What is the recommended practice here ?
---UPDATE---
I tried this approach without luck :
@Override
public Account retrieve() {
User user = getClientInfo().getUser();
AccountDAO dao = new AccountDAO(user.getNamespace());
AccountDAO dao = new AccountDAO();
Account ret = dao.getAccountByEmail(user.getEmail());
log.info("retrieved " + ret);
setOnSent(new StrongEtagCallback<Account>(ret));
return ret;
}
And implementation of the StrongEtagCallback like this :
public class StrongEtagCallback<T extends DomainResource> implements Uniform {
private static SimpleDateFormat df = new SimpleDateFormat("ddMMyyyyHHmmssSSS");
private DomainResource d;
public StrongEtagCallback(T domainResource) {
d = domainResource;
}
@Override
public void handle(Request request, Response response) {
String eTag = d.getClass().getSimpleName() + "-" + d.getId() + "-" + df.format(d.getLastModified());
response.getEntity().setTag(new Tag(eTag, false));
}
}
Where all my entities implement DomainResource which require them to have an ID and LastModified date.
But it does NOT work. I really expected this to work, it is very elegant !
The StrongEtagCallback is being called though, the ETAG set server-side on the entity. My Wireshark nor my GWT client sees a E-TAG header on the response of the response. Diving deeper now.