The approach I use involves overriding Resource.toRepresentation:

    @Override public Representation toRepresentation(Object source, Variant
target) {
        Representation rep = super.toRepresentation(source, target);
        if (source instanceof HasLastModified) {
            HasLastModified hlm = (HasLastModified) source;
            rep.setModificationDate(hlm.getLastModified());
        }
        if (source instanceof HasEtag) {
            HasEtag he = (HasEtag) source;
            rep.setTag(he.gettag());
        }
        return rep;
    }


On Wed, Jan 25, 2012 at 6:55 PM, Koen Maes <k...@koma.be> wrote:

> Hi
>
> 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() {
>                AccountDAO dao = new AccountDAO(user);
>                Account ret =
> dao.getAccountByEmail(UserServiceFactory.getUserService().getCurrentUser().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 ?
>
>
> Thx
>
> Koen
>
> ------------------------------------------------------
>
> http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2911155
>

------------------------------------------------------
http://restlet.tigris.org/ds/viewMessage.do?dsForumId=4447&dsMessageId=2911368

Reply via email to