Search in sources :

Example 1 with HttpError

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");
        }
    };
}
Also used : HttpServletResponse(javax.servlet.http.HttpServletResponse) Response(org.apache.tapestry5.http.services.Response) StreamResponse(org.apache.tapestry5.StreamResponse) ByteArrayInputStream(java.io.ByteArrayInputStream) StreamResponse(org.apache.tapestry5.StreamResponse) HttpError(org.apache.tapestry5.services.HttpError) ByteArrayOutputStream(java.io.ByteArrayOutputStream) BufferedImage(java.awt.image.BufferedImage)

Example 2 with HttpError

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));
}
Also used : HttpError(org.apache.tapestry5.services.HttpError)

Aggregations

HttpError (org.apache.tapestry5.services.HttpError)2 BufferedImage (java.awt.image.BufferedImage)1 ByteArrayInputStream (java.io.ByteArrayInputStream)1 ByteArrayOutputStream (java.io.ByteArrayOutputStream)1 HttpServletResponse (javax.servlet.http.HttpServletResponse)1 StreamResponse (org.apache.tapestry5.StreamResponse)1 Response (org.apache.tapestry5.http.services.Response)1