Search in sources :

Example 16 with ContentType

use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.

the class MarkupWriterFactoryImpl method newPartialMarkupWriter.

public MarkupWriter newPartialMarkupWriter(Page page) {
    boolean isHTML5 = hasHTML5Doctype(page);
    ContentType contentType = pageContentTypeAnalyzer.findContentType(page);
    return constructMarkupWriter(contentType, true, isHTML5);
}
Also used : ContentType(org.apache.tapestry5.http.ContentType)

Example 17 with ContentType

use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.

the class PageContentTypeAnalyzerImpl method findContentType.

public ContentType findContentType(Page page) {
    ComponentResources pageResources = page.getRootComponent().getComponentResources();
    String contentTypeString = metaDataLocator.findMeta(MetaDataConstants.RESPONSE_CONTENT_TYPE, pageResources, String.class);
    return new ContentType(contentTypeString).withCharset(outputCharset);
}
Also used : ContentType(org.apache.tapestry5.http.ContentType) ComponentResources(org.apache.tapestry5.ComponentResources)

Example 18 with ContentType

use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.

the class ResponseRendererImplTest method content_type_from_component.

@Test
public void content_type_from_component() {
    RequestPageCache cache = mockRequestPageCache();
    PageContentTypeAnalyzer analyzer = mockPageContentTypeAnalyzer();
    Component component = mockComponent();
    String pageName = "foo/bar";
    Page page = mockPage();
    ContentType contentType = new ContentType("zig/zag");
    ComponentResources resources = mockComponentResources();
    train_getComponentResources(component, resources);
    train_getPageName(resources, pageName);
    train_get(cache, pageName, page);
    train_findContentType(analyzer, page, contentType);
    replay();
    ResponseRenderer renderer = new ResponseRendererImpl(cache, analyzer, null);
    assertSame(renderer.findContentType(component), contentType);
    verify();
}
Also used : ContentType(org.apache.tapestry5.http.ContentType) ResponseRenderer(org.apache.tapestry5.services.ResponseRenderer) Page(org.apache.tapestry5.internal.structure.Page) Component(org.apache.tapestry5.runtime.Component) ComponentResources(org.apache.tapestry5.ComponentResources) Test(org.testng.annotations.Test)

Example 19 with ContentType

use of org.apache.tapestry5.http.ContentType 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;
        }
    });
}
Also used : ContentType(org.apache.tapestry5.http.ContentType) ResponseCompressionAnalyzer(org.apache.tapestry5.http.services.ResponseCompressionAnalyzer) Contribute(org.apache.tapestry5.ioc.annotations.Contribute)

Example 20 with ContentType

use of org.apache.tapestry5.http.ContentType in project tapestry-5 by apache.

the class StreamableResourceSourceImpl method getStreamableResource.

public StreamableResource getStreamableResource(Resource baseResource, StreamableResourceProcessing processing, ResourceDependencies dependencies) throws IOException {
    assert baseResource != null;
    if (!baseResource.exists()) {
        throw new IOException(String.format("Resource %s does not exist.", baseResource));
    }
    String fileSuffix = TapestryInternalUtils.toFileSuffix(baseResource.getFile());
    // Optionally, transform the resource. The main driver for this is to allow
    // for libraries like LessJS (http://lesscss.org/) or
    // http://jashkenas.github.com/coffee-script/
    ResourceTransformer rt = configuration.get(fileSuffix);
    InputStream transformed = rt == null ? baseResource.openStream() : rt.transform(baseResource, dependencies);
    assert transformed != null;
    BytestreamCache bytestreamCache = readStream(transformed);
    transformed.close();
    ContentType contentType = rt == null ? new ContentType(contentTypeAnalyzer.getContentType(baseResource)) : rt.getTransformedContentType();
    boolean compressable = compressionAnalyzer.isCompressable(contentType.getMimeType());
    long lastModified = resourceChangeTracker.trackResource(baseResource);
    return new StreamableResourceImpl(baseResource.toString(), contentType, compressable ? CompressionStatus.COMPRESSABLE : CompressionStatus.NOT_COMPRESSABLE, lastModified, bytestreamCache, checksumGenerator, null);
}
Also used : ContentType(org.apache.tapestry5.http.ContentType) InputStream(java.io.InputStream) IOException(java.io.IOException)

Aggregations

ContentType (org.apache.hc.core5.http.ContentType)58 Charset (java.nio.charset.Charset)18 IOException (java.io.IOException)15 ContentType (org.apache.tapestry5.http.ContentType)15 BasicRequestProducer (org.apache.hc.core5.http.nio.support.BasicRequestProducer)13 HttpException (org.apache.hc.core5.http.HttpException)12 HttpResponse (org.apache.hc.core5.http.HttpResponse)12 UnsupportedCharsetException (java.nio.charset.UnsupportedCharsetException)10 HttpRequest (org.apache.hc.core5.http.HttpRequest)10 BasicHttpRequest (org.apache.hc.core5.http.message.BasicHttpRequest)10 InputStream (java.io.InputStream)9 UnsupportedEncodingException (java.io.UnsupportedEncodingException)8 InetSocketAddress (java.net.InetSocketAddress)8 Header (org.apache.hc.core5.http.Header)8 Message (org.apache.hc.core5.http.Message)8 Test (org.junit.Test)8 Test (org.testng.annotations.Test)8 InterruptedIOException (java.io.InterruptedIOException)7 HttpEntity (org.apache.hc.core5.http.HttpEntity)7 StringTokenizer (java.util.StringTokenizer)6