use of org.apache.tapestry5.StreamResponse in project tapestry-5 by apache.
the class KaptchaImage method onImage.
Object onImage() throws IOException {
if (captchaText == null) {
return new HttpError(HttpServletResponse.SC_NOT_FOUND, "Session expired.");
}
return new StreamResponse() {
@Override
public String getContentType() {
return "image/jpeg";
}
@Override
public InputStream getStream() throws IOException {
BufferedImage image = producer.createImage(captchaText);
ByteArrayOutputStream baos = new ByteArrayOutputStream();
ImageIO.write(image, "jpg", baos);
return new ByteArrayInputStream(baos.toByteArray());
}
@Override
public void prepareResponse(Response response) {
response.setDateHeader("Expires", 0);
// Set standard HTTP/1.1 no-cache headers.
response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate");
// Set IE extended HTTP/1.1 no-cache headers (use addHeader).
response.addHeader("Cache-Control", "post-check=0, pre-check=0");
// Set standard HTTP/1.0 no-cache header.
response.setHeader("Pragma", "no-cache");
}
};
}
Aggregations