use of org.apache.tapestry5.http.services.Response 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.http.services.Response in project tapestry-5 by apache.
the class PageTesterModule method setupTestableOverrides.
@Contribute(ServiceOverride.class)
public static void setupTestableOverrides(MappedConfiguration<Class, Object> configuration, @Local TestableRequest request, @Local TestableResponse response, final ObjectLocator locator) {
configuration.add(Request.class, request);
configuration.add(Response.class, response);
TestableCookieSinkSource cookies = new TestableCookieSinkSource();
configuration.add(CookieSink.class, cookies);
configuration.add(CookieSource.class, cookies);
// With the significant changes to the handling of assets in 5.4, we introduced a problem:
// We were checking at page render time whether to generate URLs for normal or compressed
// assets and that peeked at the HttpServletRequest global, which isn't set up by PageTester.
// What we're doing here is using a hacked version of that code to force GZip support
// on.
configuration.add(ResponseCompressionAnalyzer.class, new ResponseCompressionAnalyzer() {
public boolean isGZipEnabled(ContentType contentType) {
return locator.getObject(CompressionAnalyzer.class, null).isCompressable(contentType.getMimeType());
}
public boolean isGZipSupported() {
return true;
}
});
}
use of org.apache.tapestry5.http.services.Response in project tapestry-5 by apache.
the class ClasspathAssetRequestHandler method handleAssetRequest.
public boolean handleAssetRequest(Request request, Response response, String extraPath) throws IOException {
ChecksumPath path = new ChecksumPath(streamer, baseFolder, extraPath);
final boolean handled;
if (classpathAssetProtectionRule.block(path.resourcePath) && !path.resourcePath.equals(ChecksumPath.NON_EXISTING_RESOURCE)) {
if (LOGGER.isWarnEnabled()) {
LOGGER.warn("Blocked request for classpath asset '" + path.resourcePath + "'. Contribute a new ClasspathAssetProtectionRule if you need this asset to be publicly accessible.");
}
handled = false;
} else {
Resource resource = assetSource.resourceForPath(path.resourcePath);
handled = path.stream(resource);
}
return handled;
}
use of org.apache.tapestry5.http.services.Response in project tapestry-5 by apache.
the class TestableResponseImplTest method http_headers.
@Test
public void http_headers() {
Document document = tester.renderPage(TestPageForHttpHeaders.class.getSimpleName());
assertTrue(document.toString().contains("Test page for HTTP headers"));
TestableResponse response = tester.getService(TestableResponse.class);
assertEquals(response.getHeader(TestPageForHttpHeaders.DATE_HEADER_NAME), 12345L);
assertEquals(response.getHeader(TestPageForHttpHeaders.INT_HEADER_NAME), 6789);
assertEquals(response.getHeader(TestPageForHttpHeaders.STRING_HEADER_NAME), "foo-bar-baz-barney");
}
use of org.apache.tapestry5.http.services.Response in project tapestry-5 by apache.
the class ComponentEventLinkEncoderImplTest method root_index_page_gone.
@Test
public void root_index_page_gone() {
RequestSecurityManager manager = mockRequestSecurityManager();
Response response = mockResponse();
ContextPathEncoder contextPathEncoder = getService(ContextPathEncoder.class);
expect(manager.checkPageSecurity("Index")).andReturn(LinkSecurity.INSECURE);
train_encodeURL(response, "/", "MAGIC");
replay();
ComponentEventLinkEncoder encoder = new ComponentEventLinkEncoderImpl(null, contextPathEncoder, null, response, manager, null, null, false, "", "", null, null);
PageRenderRequestParameters parameters = new PageRenderRequestParameters("Index", new EmptyEventContext());
Link link = encoder.createPageRenderLink(parameters);
assertEquals(link.toURI(), "MAGIC");
verify();
}
Aggregations