Never mind.  I figured it out.

For the record. It's enough to just tack the ETag onto the representation. RESTlet is smart enough to compare it to the client conditions and send back the 304 and an empty representation for you if necessary. Cool! I was expecting to have to do a lot more work.

For instance:

public Representation getRepresentation(Variant variant) {
    Representation result = null;

    if (variant.getMediaType().equals(MediaType.APPLICATION_XML)) {
        
        // create DOM
        
        result = new DomRepresentation(MediaType.APPLICATION_XML, doc);
        result.setTag(new Tag([your etag], false));
    }
    return result;
}


Peter Lacey wrote:
Hi,

I'm new to RESTlet and trying to create a resource that supports conditional gets (ETag, Not Modied). So far I have the normal GET done, I can attach an ETag to the representation, I can see how to get the conditions from the client request, and I can see how to send back a 304. But for the life of me, I can't see how to send back a 304 _and_ the ETag.

To send the ETag I need to call setTag on a Representation. But when I'm returning a 304, I don't have a Representation per se. I've tried returning Variants and empty Representations (DomRepresentation in my case) from my resource's getRepresentation() method, but these attempts didn't pan out. Nor has anything else I tried.

I would really appreciate it, if someone could explain or provide some sample code that shows how to do this.

Thanks,
Pete

Reply via email to