Ok here is my solution ... In my app module I added ..
public void contributeComponentEventResultProcessor(final Response response, MappedConfiguration<Class<?>, ComponentEventResultProcessor<HttpErrorNotModified>> configuration) { configuration.add(HttpErrorNotModified.class, new ComponentEventResultProcessor<HttpErrorNotModified>() { public void processResultValue(HttpErrorNotModified value) throws IOException { response.sendError(304, ""); } }); } In page onActivate i do ... String since = request.getHeader("If-Modified-Since"); if (since != null) { try { UTTime sincetime = new UTTime(HTTP_DATE_FORMAT.parse(since)); if (!file.getUpdated().isAfter(sincetime)) { return new HttpErrorNotModified(); } } catch (ParseException e) { log.error("Faield to parse http time: " + since, e); } } The new return type is package utskicket.util.tapestry; /** * An event handler method may return an instance of this class to send an 304 response to the client. */ public class HttpErrorNotModified { } -------- Sometimes I think that the whole web is a leaky abstraction ... but perhaps it's not an abstraction at all ... 2012/2/26 Gunnar Eketrapp <gunnar.eketr...@gmail.com> > I just saw that ResourceStreamerImpl.java checks modification time and > does ... > > response.sendError(HttpServletResponse.SC_NOT_MODIFIED, ""); > > Is there a way for me to achieve the same from my onActivate() method > below ... > > I.e. how do I return a 304 when my image hasn't been changed according to > the > I*f-Modified-Since* header that I receive. > > Or do I have to it in some other way .. I guess so! > > 2012/2/26 Howard Lewis Ship <hls...@gmail.com> > >> Do the images ever change? If not, you can use the same kind of >> approach Tapestry uses for assets: incorporate a version number (or >> SHA1 checksum) into the path, and set the headers that ensure caching >> on the client (I'd have to check the Tapestry code for the exact ones >> that work). >> >> On Sat, Feb 25, 2012 at 9:25 AM, Gunnar Eketrapp >> <gunnar.eketr...@gmail.com> wrote: >> > Hi! >> > >> > I currently store uploaded files in the db. >> > >> > I then retrieve those images with via an Image page. >> > >> > My problem now is that the client does not cache these images. >> > >> > Is there an easy way to fix my erreneous solution !? >> > >> > public void prepareResponse(Response r) { >> > r.setHeader("Cache-Control", "max-age=3600"); >> > } >> > >> > I have included the entire Image.java below ... >> > >> > Thanks in advance, >> > Gunnar >> > >> > ================================================================ >> > >> > package utskicket.pages; >> > >> > import java.io.IOException; >> > import java.io.InputStream; >> > >> > import org.apache.tapestry5.StreamResponse; >> > import org.apache.tapestry5.ioc.annotations.Inject; >> > import org.apache.tapestry5.services.Response; >> > import org.slf4j.Logger; >> > >> > import utskicket.base.BasePage; >> > import utskicket.model.dao.UploadedFileDAO; >> > import utskicket.model.entity.UploadedFile; >> > >> > >> > public class Image extends BasePage { >> > >> > private Long groupId; >> > private Long imageId; >> > >> > @Inject >> > private UploadedFileDAO fileDAO; >> > >> > @Inject >> > private Logger log; >> > >> > public class UploadedFileStreamResponse implements StreamResponse { >> > private final UploadedFile file; >> > >> > public UploadedFileStreamResponse(UploadedFile file) { >> > this.file = file; >> > } >> > >> > public String getContentType() { >> > return file.getContentType(); >> > } >> > >> > public InputStream getStream() throws IOException { >> > return file.getInputStream(); >> > } >> > >> > // TODO: Find out how to get images cached by browser's. This >> does >> > not work! >> > public void prepareResponse(Response r) { >> > r.setHeader("Cache-Control", "max-age=3600"); >> > } >> > } >> > >> > // >> > >> ------------------------------------------------------------------------------ >> > // -- Tapestry event methods - Tapestry event methods - Tapestry >> event >> > methods -- >> > // >> > >> ------------------------------------------------------------------------------ >> > >> > StreamResponse onActivate(Long groupId, Long imageId) { >> > this.groupId = groupId; >> > this.imageId = imageId; >> > >> > // UploadedFile file = cache.uploadedFileLookup(imageId); >> > UploadedFile file = fileDAO.findById(imageId); >> > >> > if (null == file) { >> > log.warn("Failed to load image #" + imageId); >> > return null; >> > } else { >> > log.debug("Loaded file #" + imageId + " with a size of " + >> > file.getContent().length + " bytes"); >> > return new UploadedFileStreamResponse(file); >> > } >> > } >> > >> > Object[] onPassivate() { >> > return new Object [] {groupId, imageId}; >> > } >> > } >> >> >> >> -- >> Howard M. Lewis Ship >> >> Creator of Apache Tapestry >> >> The source for Tapestry training, mentoring and support. Contact me to >> learn how I can get you up and productive in Tapestry fast! >> >> (971) 678-5210 >> http://howardlewisship.com >> >> --------------------------------------------------------------------- >> To unsubscribe, e-mail: users-unsubscr...@tapestry.apache.org >> For additional commands, e-mail: users-h...@tapestry.apache.org >> >> > > > -- > [Hem: 08-715 59 57, Mobil: 0708-52 62 90] > Allévägen 2A, 132 42 Saltsjö-Boo > -- [Hem: 08-715 59 57, Mobil: 0708-52 62 90] Allévägen 2A, 132 42 Saltsjö-Boo