Search in sources :

Example 1 with Path

use of org.apache.tapestry5.annotations.Path in project flowlogix by flowlogix.

the class GwtCachingFilter method service.

@Override
public boolean service(HttpServletRequest request, HttpServletResponse response, HttpServletRequestHandler chainHandler) throws IOException {
    String path = request.getServletPath();
    boolean neverExpire = checkConfig(path, response);
    if (neverExpire == false) {
        return chainHandler.service(request, response);
    }
    log.finer("GwtCachingFilter: Processing " + path);
    Request rq = new RequestImpl(request, applicationCharset, sessionFactory);
    Response rsp = new ResponseImpl(request, response);
    rg.storeRequestResponse(rq, rsp);
    rsp.setDateHeader("Expires", new Date().getTime() + InternalConstants.TEN_YEARS);
    try {
        return carh.handleAssetRequest(rq, rsp, pathProcessor.removeAssetPathPart(path));
    } catch (Exception e) {
        return chainHandler.service(request, response);
    }
}
Also used : Response(org.apache.tapestry5.services.Response) HttpServletResponse(javax.servlet.http.HttpServletResponse) HttpServletRequest(javax.servlet.http.HttpServletRequest) Request(org.apache.tapestry5.services.Request) RequestImpl(org.apache.tapestry5.internal.services.RequestImpl) ResponseImpl(org.apache.tapestry5.internal.services.ResponseImpl) Date(java.util.Date) IOException(java.io.IOException)

Example 2 with Path

use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.

the class AssetSourceImplTest method get_expanded_asset.

@Test
public void get_expanded_asset() {
    AssetFactory factory = mockAssetFactory();
    Asset asset = mockAsset();
    SymbolSource symbolSource = mockSymbolSource();
    Resource expectedResource = baseResource.forFile("SimpleComponent.properties");
    train_getRootResource(factory, rootResource);
    train_createAsset(factory, expectedResource, asset);
    train_expandSymbols(symbolSource, "${path}/SimpleComponent.properties", "org/apache/tapestry5/internal/services/SimpleComponent.properties");
    Map<String, AssetFactory> configuration = Collections.singletonMap("classpath", factory);
    replay();
    AssetSource source = new AssetSourceImpl(null, configuration, symbolSource, null, tracker);
    // First try creates it:
    assertSame(source.getExpandedAsset("${path}/SimpleComponent.properties"), asset);
    verify();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) SymbolSource(org.apache.tapestry5.ioc.services.SymbolSource) Resource(org.apache.tapestry5.commons.Resource) ClasspathResource(org.apache.tapestry5.ioc.internal.util.ClasspathResource) Asset(org.apache.tapestry5.Asset) AssetFactory(org.apache.tapestry5.services.AssetFactory) Test(org.testng.annotations.Test)

Example 3 with Path

use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.

the class AssetSourceImplTest method unknown_asset_prefix.

@Test
public void unknown_asset_prefix() {
    ThreadLocale threadLocale = mockThreadLocale();
    Map<String, AssetFactory> configuration = Collections.emptyMap();
    replay();
    AssetSource source = new AssetSourceImpl(threadLocale, configuration, null, null, tracker);
    try {
        source.getAsset(baseResource, "classpath:org/apache/tapestry5/internal/services/SimpleComponent.properties", Locale.UK);
        unreachable();
    } catch (IllegalArgumentException ex) {
        assertEquals(ex.getMessage(), "Unknown prefix for asset path 'classpath:org/apache/tapestry5/internal/services/SimpleComponent.properties'.");
    }
    verify();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) AssetFactory(org.apache.tapestry5.services.AssetFactory) Test(org.testng.annotations.Test)

Example 4 with Path

use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.

the class AbstractAssetFactory method createAsset.

protected Asset createAsset(final Resource resource, final String folder, final String resourcePath) {
    assert resource != null;
    assert InternalUtils.isNonBlank(folder);
    assert InternalUtils.isNonBlank(resourcePath);
    return new AbstractAsset(false) {

        public String toClientURL() {
            try {
                // Get the uncompressed version, so that we can identify its content type (and remember, the extension is not enough,
                // as some types get translated to new content types by the SRS).
                StreamableResource uncompressed = streamableResourceSource.getStreamableResource(resource, StreamableResourceProcessing.COMPRESSION_DISABLED, resourceChangeTracker);
                StreamableResource forRequest = isCompressable(uncompressed) ? streamableResourceSource.getStreamableResource(resource, StreamableResourceProcessing.COMPRESSION_ENABLED, resourceChangeTracker) : uncompressed;
                return assetPathConstructor.constructAssetPath(folder, resourcePath, forRequest);
            } catch (IOException ex) {
                throw new RuntimeException(String.format("Unable to construct asset path for %s: %s", resource, ExceptionUtils.toMessage(ex)), ex);
            }
        }

        public Resource getResource() {
            return resource;
        }
    };
}
Also used : StreamableResource(org.apache.tapestry5.services.assets.StreamableResource) IOException(java.io.IOException)

Example 5 with Path

use of org.apache.tapestry5.annotations.Path in project tapestry-5 by apache.

the class AssetInjectionProvider method provideInjection.

public boolean provideInjection(PlasticField field, ObjectLocator locator, MutableComponentModel componentModel) {
    Path path = field.getAnnotation(Path.class);
    if (path == null) {
        return false;
    }
    final String assetPath = path.value();
    final String libraryName = componentModel.getLibraryName();
    ComputedValue<Asset> computedAsset = new ComputedValue<Asset>() {

        public Asset get(InstanceContext context) {
            ComponentResources resources = context.get(ComponentResources.class);
            // a different library name than the subclass).
            return assetSource.getComponentAsset(resources, assetPath, libraryName);
        }
    };
    field.injectComputed(computedAsset);
    return true;
}
Also used : Path(org.apache.tapestry5.annotations.Path) ComputedValue(org.apache.tapestry5.plastic.ComputedValue) InstanceContext(org.apache.tapestry5.plastic.InstanceContext) Asset(org.apache.tapestry5.Asset) ComponentResources(org.apache.tapestry5.ComponentResources)

Aggregations

Test (org.testng.annotations.Test)22 Request (org.apache.tapestry5.http.services.Request)14 Context (org.apache.tapestry5.http.services.Context)9 Resource (org.apache.tapestry5.commons.Resource)8 Path (io.fabric8.annotations.Path)6 IOException (java.io.IOException)6 URL (java.net.URL)6 HttpServletResponse (javax.servlet.http.HttpServletResponse)6 RequestFilter (org.apache.tapestry5.http.services.RequestFilter)5 RequestHandler (org.apache.tapestry5.http.services.RequestHandler)5 Response (org.apache.tapestry5.http.services.Response)5 ComponentClassResolver (org.apache.tapestry5.services.ComponentClassResolver)5 LocalizationSetter (org.apache.tapestry5.services.LocalizationSetter)5 MetaDataLocator (org.apache.tapestry5.services.MetaDataLocator)5 PageRenderRequestParameters (org.apache.tapestry5.services.PageRenderRequestParameters)5 Configuration (io.fabric8.annotations.Configuration)4 Endpoint (io.fabric8.annotations.Endpoint)4 External (io.fabric8.annotations.External)4 PortName (io.fabric8.annotations.PortName)4 Protocol (io.fabric8.annotations.Protocol)4