RE: Conditional GETs?
Hi Peter, This case is handled a bit differently because we do want to return the representation's metadata to the client in this case. Currently, the Response's entity must be an instance of Representation and not a simple Variant. Note that the HTTP connectors do recognize the 204 status and won't send the Representation's content, only the metadata, but it is true that Resource#getRepresentation(Variant) will be invoked. Do you have use cases that would help me feel how important it is to optimize this? As a workaround to returning full representations, you could write an EmptyRepresentation that would be a Variant with no content. Maybe that would be a useful addition to the API. Best regards, Jerome > -Message d'origine- > De : news [mailto:[EMAIL PROTECTED] De la part de Peter Lacey > Envoyé : mercredi 20 juin 2007 18:26 > À : discuss@restlet.tigris.org > Objet : Re: Conditional GETs? > > Jerome, > > Here's another variant of the same issue. If the server > wants to return > a 204 (No Content), then #getRepresentation() is still > called. Does it > make sense to optimize this out of the way so that the status > can be set > in the constructor and Restlet takes care of doing the right > thing, or > should the status be set by the developer in #getRepresentation() and > null returned? > > Pete > > Jerome Louvel wrote: > > Hi all, > > > > This RFE is now fixed in SVN trunk and will be testable in > the upcoming 1.1 > > snapshot. Great optimization, thanks Stian for the idea. > > > > Best regards, > > Jerome > > > >> -Message d'origine- > >> De : Jerome Louvel [mailto:[EMAIL PROTECTED] > >> Envoyé : mardi 12 juin 2007 08:55 > >> À : discuss@restlet.tigris.org > >> Objet : Re: Conditional GETs? > >> > >> Hi Adam, > >> > >> There is already a "tag" property on the Variant class > that you can > >> already use. In 1.1, we will simply use this property > earlier in the > >> algorithm to not call getRepresentation(Variant) when not > necessary. > >> > >> Best regards, > >> Jerome > >> > >> > >> Adam Taft a écrit : > >>> By the way, I love the suggestion. > >>> > >>> Can't you add getTag() (or some method) sooner rather than > >> later? The > >>> default implementation would simply return NULL which would > >> then force > >>> the algorithm to call getRepresentation() just like it > >> currently does. > >>> There should be no consequence of this in 1.0.x code? > >>> > >>> Just curious. > >>> > >>> Adam > >>> > >>> > >>> Jerome Louvel wrote: > >>>> Hi Stian, > >>>> > >>>> We haven't forgotten about your suggestion, just dealing > >> with a long > >>>> email > >>>> backlog :) > >>>> It is perfectly possible to optimize the internal > algorithm so that > >>>> getRepresentation(Variant) is never called when the > variant's tag > >>>> matches > >>>> the one provided by the client. > >>>> > >>>> I've entered a RFE to keep track of it: > >>>> http://restlet.tigris.org/issues/show_bug.cgi?id=319 > >>>> > >>>> As it changes the observed behavior a bit, it should only go in > >>>> Restlet 1.1, > >>>> IMHO. > >>>> > >>>> Best regards, > >>>> Jerome > >>>>> -Message d'origine- > >>>>> De : Stian Soiland [mailto:[EMAIL PROTECTED] Envoyé > >> : mercredi > >>>>> 6 juin 2007 11:23 > >>>>> À : discuss@restlet.tigris.org > >>>>> Objet : Re: Conditional GETs? > >>>>> > >>>>> > >>>>> On 4 Jun 2007, at 15:53, Peter Lacey wrote: > >>>>> > >>>>>> 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; > >>>>>> } > >>>>> It's really clever, except you still have to create that XML > >>>>> representation that never needs to be sent out. > >>>>> > >>>>> If there was some getTag() method or something you could > >> override > >>>>> this to check directly with the database on whatever > you need to > >>>>> calculate the tag, and hence getRepresentation() wouldn't > >> even need > >>>>> to be called. > >>>>> > >>>>> To support this I think some kind of getLastModified() > would also > >>>>> be cool. (I've made such a thing in my subclass of Resource) > >>>>> > >>>>> -- > >>>>> Stian Soiland, myGrid team > >>>>> School of Computer Science > >>>>> The University of Manchester > >>>>> http://www.cs.man.ac.uk/~ssoiland/ > >>>>> > >
Re: Conditional GETs?
Jerome, Here's another variant of the same issue. If the server wants to return a 204 (No Content), then #getRepresentation() is still called. Does it make sense to optimize this out of the way so that the status can be set in the constructor and Restlet takes care of doing the right thing, or should the status be set by the developer in #getRepresentation() and null returned? Pete Jerome Louvel wrote: Hi all, This RFE is now fixed in SVN trunk and will be testable in the upcoming 1.1 snapshot. Great optimization, thanks Stian for the idea. Best regards, Jerome -Message d'origine- De : Jerome Louvel [mailto:[EMAIL PROTECTED] Envoyé : mardi 12 juin 2007 08:55 À : discuss@restlet.tigris.org Objet : Re: Conditional GETs? Hi Adam, There is already a "tag" property on the Variant class that you can already use. In 1.1, we will simply use this property earlier in the algorithm to not call getRepresentation(Variant) when not necessary. Best regards, Jerome Adam Taft a écrit : By the way, I love the suggestion. Can't you add getTag() (or some method) sooner rather than later? The default implementation would simply return NULL which would then force the algorithm to call getRepresentation() just like it currently does. There should be no consequence of this in 1.0.x code? Just curious. Adam Jerome Louvel wrote: Hi Stian, We haven't forgotten about your suggestion, just dealing with a long email backlog :) It is perfectly possible to optimize the internal algorithm so that getRepresentation(Variant) is never called when the variant's tag matches the one provided by the client. I've entered a RFE to keep track of it: http://restlet.tigris.org/issues/show_bug.cgi?id=319 As it changes the observed behavior a bit, it should only go in Restlet 1.1, IMHO. Best regards, Jerome -Message d'origine- De : Stian Soiland [mailto:[EMAIL PROTECTED] Envoyé : mercredi 6 juin 2007 11:23 À : discuss@restlet.tigris.org Objet : Re: Conditional GETs? On 4 Jun 2007, at 15:53, Peter Lacey wrote: 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; } It's really clever, except you still have to create that XML representation that never needs to be sent out. If there was some getTag() method or something you could override this to check directly with the database on whatever you need to calculate the tag, and hence getRepresentation() wouldn't even need to be called. To support this I think some kind of getLastModified() would also be cool. (I've made such a thing in my subclass of Resource) -- Stian Soiland, myGrid team School of Computer Science The University of Manchester http://www.cs.man.ac.uk/~ssoiland/
Re: Conditional GETs?
Great news, thanks! Avi On 6/18/07, Jerome Louvel <[EMAIL PROTECTED]> wrote: Hi Avi, A matter of days! Version 1.0.2 is pending too. Best regards, Jerome
RE: Conditional GETs?
Hi Avi, A matter of days! Version 1.0.2 is pending too. Best regards, Jerome > -Message d'origine- > De : Avi Flax [mailto:[EMAIL PROTECTED] > Envoyé : lundi 18 juin 2007 20:05 > À : discuss@restlet.tigris.org > Objet : Re: Conditional GETs? > > Jerome, I'm eagerly awaiting this snapshot! No pressure, but > are we looking at a matter of days here, or is it more like weeks? > > Thanks! > Avi > > > On 6/16/07, Jerome Louvel <[EMAIL PROTECTED]> wrote: > > > Hi all, > > This RFE is now fixed in SVN trunk and will be testable > in the upcoming 1.1 > snapshot. Great optimization, thanks Stian for the idea. > > Best regards, > Jerome > >
Re: Conditional GETs?
Jerome, I'm eagerly awaiting this snapshot! No pressure, but are we looking at a matter of days here, or is it more like weeks? Thanks! Avi On 6/16/07, Jerome Louvel <[EMAIL PROTECTED]> wrote: Hi all, This RFE is now fixed in SVN trunk and will be testable in the upcoming 1.1 snapshot. Great optimization, thanks Stian for the idea. Best regards, Jerome
RE: Conditional GETs?
Hi all, This RFE is now fixed in SVN trunk and will be testable in the upcoming 1.1 snapshot. Great optimization, thanks Stian for the idea. Best regards, Jerome > -Message d'origine- > De : Jerome Louvel [mailto:[EMAIL PROTECTED] > Envoyé : mardi 12 juin 2007 08:55 > À : discuss@restlet.tigris.org > Objet : Re: Conditional GETs? > > Hi Adam, > > There is already a "tag" property on the Variant class that you can > already use. In 1.1, we will simply use this property earlier in the > algorithm to not call getRepresentation(Variant) when not necessary. > > Best regards, > Jerome > > > Adam Taft a écrit : > > > > By the way, I love the suggestion. > > > > Can't you add getTag() (or some method) sooner rather than > later? The > > default implementation would simply return NULL which would > then force > > the algorithm to call getRepresentation() just like it > currently does. > > > > There should be no consequence of this in 1.0.x code? > > > > Just curious. > > > > Adam > > > > > > Jerome Louvel wrote: > >> Hi Stian, > >> > >> We haven't forgotten about your suggestion, just dealing > with a long > >> email > >> backlog :) > >> It is perfectly possible to optimize the internal algorithm so that > >> getRepresentation(Variant) is never called when the variant's tag > >> matches > >> the one provided by the client. > >> > >> I've entered a RFE to keep track of it: > >> http://restlet.tigris.org/issues/show_bug.cgi?id=319 > >> > >> As it changes the observed behavior a bit, it should only go in > >> Restlet 1.1, > >> IMHO. > >> > >> Best regards, > >> Jerome > >>> -Message d'origine- > >>> De : Stian Soiland [mailto:[EMAIL PROTECTED] Envoyé > : mercredi > >>> 6 juin 2007 11:23 > >>> À : discuss@restlet.tigris.org > >>> Objet : Re: Conditional GETs? > >>> > >>> > >>> On 4 Jun 2007, at 15:53, Peter Lacey wrote: > >>> > >>>> 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; > >>>> } > >>> It's really clever, except you still have to create that XML > >>> representation that never needs to be sent out. > >>> > >>> If there was some getTag() method or something you could > override > >>> this to check directly with the database on whatever you need to > >>> calculate the tag, and hence getRepresentation() wouldn't > even need > >>> to be called. > >>> > >>> To support this I think some kind of getLastModified() would also > >>> be cool. (I've made such a thing in my subclass of Resource) > >>> > >>> -- > >>> Stian Soiland, myGrid team > >>> School of Computer Science > >>> The University of Manchester > >>> http://www.cs.man.ac.uk/~ssoiland/ > >>> > >
Re: Conditional GETs?
Hi Adam, There is already a "tag" property on the Variant class that you can already use. In 1.1, we will simply use this property earlier in the algorithm to not call getRepresentation(Variant) when not necessary. Best regards, Jerome Adam Taft a écrit : By the way, I love the suggestion. Can't you add getTag() (or some method) sooner rather than later? The default implementation would simply return NULL which would then force the algorithm to call getRepresentation() just like it currently does. There should be no consequence of this in 1.0.x code? Just curious. Adam Jerome Louvel wrote: Hi Stian, We haven't forgotten about your suggestion, just dealing with a long email backlog :) It is perfectly possible to optimize the internal algorithm so that getRepresentation(Variant) is never called when the variant's tag matches the one provided by the client. I've entered a RFE to keep track of it: http://restlet.tigris.org/issues/show_bug.cgi?id=319 As it changes the observed behavior a bit, it should only go in Restlet 1.1, IMHO. Best regards, Jerome -Message d'origine- De : Stian Soiland [mailto:[EMAIL PROTECTED] Envoyé : mercredi 6 juin 2007 11:23 À : discuss@restlet.tigris.org Objet : Re: Conditional GETs? On 4 Jun 2007, at 15:53, Peter Lacey wrote: 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; } It's really clever, except you still have to create that XML representation that never needs to be sent out. If there was some getTag() method or something you could override this to check directly with the database on whatever you need to calculate the tag, and hence getRepresentation() wouldn't even need to be called. To support this I think some kind of getLastModified() would also be cool. (I've made such a thing in my subclass of Resource) -- Stian Soiland, myGrid team School of Computer Science The University of Manchester http://www.cs.man.ac.uk/~ssoiland/
Re: Conditional GETs?
By the way, I love the suggestion. Can't you add getTag() (or some method) sooner rather than later? The default implementation would simply return NULL which would then force the algorithm to call getRepresentation() just like it currently does. There should be no consequence of this in 1.0.x code? Just curious. Adam Jerome Louvel wrote: Hi Stian, We haven't forgotten about your suggestion, just dealing with a long email backlog :) It is perfectly possible to optimize the internal algorithm so that getRepresentation(Variant) is never called when the variant's tag matches the one provided by the client. I've entered a RFE to keep track of it: http://restlet.tigris.org/issues/show_bug.cgi?id=319 As it changes the observed behavior a bit, it should only go in Restlet 1.1, IMHO. Best regards, Jerome -Message d'origine- De : Stian Soiland [mailto:[EMAIL PROTECTED] Envoyé : mercredi 6 juin 2007 11:23 À : discuss@restlet.tigris.org Objet : Re: Conditional GETs? On 4 Jun 2007, at 15:53, Peter Lacey wrote: 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; } It's really clever, except you still have to create that XML representation that never needs to be sent out. If there was some getTag() method or something you could override this to check directly with the database on whatever you need to calculate the tag, and hence getRepresentation() wouldn't even need to be called. To support this I think some kind of getLastModified() would also be cool. (I've made such a thing in my subclass of Resource) -- Stian Soiland, myGrid team School of Computer Science The University of Manchester http://www.cs.man.ac.uk/~ssoiland/
RE: Conditional GETs?
Hi Stian, We haven't forgotten about your suggestion, just dealing with a long email backlog :) It is perfectly possible to optimize the internal algorithm so that getRepresentation(Variant) is never called when the variant's tag matches the one provided by the client. I've entered a RFE to keep track of it: http://restlet.tigris.org/issues/show_bug.cgi?id=319 As it changes the observed behavior a bit, it should only go in Restlet 1.1, IMHO. Best regards, Jerome > -Message d'origine- > De : Stian Soiland [mailto:[EMAIL PROTECTED] > Envoyé : mercredi 6 juin 2007 11:23 > À : discuss@restlet.tigris.org > Objet : Re: Conditional GETs? > > > On 4 Jun 2007, at 15:53, Peter Lacey wrote: > > > 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; > > } > > It's really clever, except you still have to create that XML > representation that never needs to be sent out. > > If there was some getTag() method or something you could override > this to check directly with the database on whatever you need to > calculate the tag, and hence getRepresentation() wouldn't even need > to be called. > > To support this I think some kind of getLastModified() would also be > cool. (I've made such a thing in my subclass of Resource) > > -- > Stian Soiland, myGrid team > School of Computer Science > The University of Manchester > http://www.cs.man.ac.uk/~ssoiland/ >
Re: Conditional GETs?
On 4 Jun 2007, at 15:53, Peter Lacey wrote: 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; } It's really clever, except you still have to create that XML representation that never needs to be sent out. If there was some getTag() method or something you could override this to check directly with the database on whatever you need to calculate the tag, and hence getRepresentation() wouldn't even need to be called. To support this I think some kind of getLastModified() would also be cool. (I've made such a thing in my subclass of Resource) -- Stian Soiland, myGrid team School of Computer Science The University of Manchester http://www.cs.man.ac.uk/~ssoiland/
Re: Conditional GETs?
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