use of org.apache.tapestry5.services.HttpError 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");
}
};
}
use of org.apache.tapestry5.services.HttpError in project tapestry-5 by apache.
the class UnknownActivationContextHandlerImpl method handleUnknownContext.
public void handleUnknownContext(ComponentResources pageResources, EventContext activationContext) throws IOException {
logger.warn("Activate event on page {} was fired with context {} but was not handled", pageResources.getPage().getClass(), activationContext);
String message = String.format("Activation context %s unrecognized for page %s", activationContext, pageResources.getPage().getClass());
resultProcessor.processResultValue(new HttpError(HttpServletResponse.SC_NOT_FOUND, message));
}
Aggregations