Search in sources :

Example 1 with Asset

use of org.apache.tapestry5.Asset in project gapic-generator-java by googleapis.

the class AsyncListAssetsPaged method asyncListAssetsPaged.

public static void asyncListAssetsPaged() throws Exception {
    // It may require modifications to work in your environment.
    try (AssetServiceClient assetServiceClient = AssetServiceClient.create()) {
        ListAssetsRequest request = ListAssetsRequest.newBuilder().setParent(FeedName.ofProjectFeedName("[PROJECT]", "[FEED]").toString()).setReadTime(Timestamp.newBuilder().build()).addAllAssetTypes(new ArrayList<String>()).setContentType(ContentType.forNumber(0)).setPageSize(883849137).setPageToken("pageToken873572522").addAllRelationshipTypes(new ArrayList<String>()).build();
        while (true) {
            ListAssetsResponse response = assetServiceClient.listAssetsCallable().call(request);
            for (Asset element : response.getResponsesList()) {
            // doThingsWith(element);
            }
            String nextPageToken = response.getNextPageToken();
            if (!Strings.isNullOrEmpty(nextPageToken)) {
                request = request.toBuilder().setPageToken(nextPageToken).build();
            } else {
                break;
            }
        }
    }
}
Also used : ListAssetsRequest(com.google.cloud.asset.v1.ListAssetsRequest) AssetServiceClient(com.google.cloud.asset.v1.AssetServiceClient) ArrayList(java.util.ArrayList) Asset(com.google.cloud.asset.v1.Asset) ListAssetsResponse(com.google.cloud.asset.v1.ListAssetsResponse)

Example 2 with Asset

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

the class ResourceStreamerImpl method streamResource.

public boolean streamResource(Resource resource, StreamableResource streamable, String providedChecksum, Set<Options> options) throws IOException {
    assert streamable != null;
    assert providedChecksum != null;
    assert options != null;
    String actualChecksum = streamable.getChecksum();
    if (providedChecksum.length() > 0 && !providedChecksum.equals(actualChecksum)) {
        // TAP5-2185: Trying to find the wrongly-checksummed resource in the classpath and context,
        // so we can create an Asset with the correct checksum and redirect to it.
        Asset asset = null;
        if (resource != null) {
            asset = findAssetInsideWebapp(resource);
        }
        if (asset != null) {
            response.sendRedirect(asset.toClientURL());
            return true;
        }
        return false;
    }
    // ETag should be surrounded with quotes.
    String token = QUOTE + actualChecksum + QUOTE;
    // Even when sending a 304, we want the ETag associated with the request.
    // In most cases (except JavaScript modules), the checksum is also embedded into the URL.
    // However, E-Tags are also useful for enabling caching inside intermediate servers, CDNs, etc.
    response.setHeader("ETag", token);
    // If the client can send the correct ETag token, then its cache already contains the correct
    // content.
    String providedToken = request.getHeader("If-None-Match");
    if (token.equals(providedToken)) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return true;
    }
    long lastModified = streamable.getLastModified();
    long ifModifiedSince;
    try {
        ifModifiedSince = request.getDateHeader(IF_MODIFIED_SINCE_HEADER);
    } catch (IllegalArgumentException ex) {
        // Simulate the header being missing if it is poorly formatted.
        ifModifiedSince = -1;
    }
    if (ifModifiedSince > 0 && ifModifiedSince >= lastModified) {
        response.setStatus(HttpServletResponse.SC_NOT_MODIFIED);
        return true;
    }
    // Prevent the upstream code from compressing when we don't want to.
    response.disableCompression();
    response.setDateHeader("Last-Modified", lastModified);
    if (productionMode && !options.contains(Options.OMIT_EXPIRATION)) {
        // Starting in 5.4, this is a lot less necessary; any change to a Resource will result
        // in a new asset URL with the changed checksum incorporated into the URL.
        response.setDateHeader("Expires", lastModified + InternalConstants.TEN_YEARS);
    }
    // mostly result in quick SC_NOT_MODIFIED responses.
    if (options.contains(Options.OMIT_EXPIRATION)) {
        response.setHeader("Cache-Control", omitExpirationCacheControlHeader);
    }
    if (streamable.getCompression() == CompressionStatus.COMPRESSED) {
        response.setHeader(TapestryHttpInternalConstants.CONTENT_ENCODING_HEADER, TapestryHttpInternalConstants.GZIP_CONTENT_ENCODING);
    }
    ResponseCustomizer responseCustomizer = streamable.getResponseCustomizer();
    if (responseCustomizer != null) {
        responseCustomizer.customizeResponse(streamable, response);
    }
    if (!request.getMethod().equals("HEAD")) {
        response.setContentLength(streamable.getSize());
        OutputStream os = response.getOutputStream(streamable.getContentType().toString());
        streamable.streamTo(os);
        os.close();
    }
    return true;
}
Also used : OutputStream(java.io.OutputStream) Asset(org.apache.tapestry5.Asset)

Example 3 with Asset

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

the class AssetSourceImplTest method missing_resource.

@Test
public void missing_resource() {
    ThreadLocale threadLocale = mockThreadLocale();
    Map<String, AssetFactory> configuration = Collections.emptyMap();
    replay();
    AssetSource source = new AssetSourceImpl(threadLocale, configuration, null, null, tracker);
    try {
        source.getAsset(baseResource, "DoesNotExist.properties", Locale.UK);
        unreachable();
    } catch (RuntimeException ex) {
        assertEquals(ex.getMessage(), "Unable to locate asset 'classpath:org/apache/tapestry5/internal/services/DoesNotExist.properties' (the file does not exist).");
    }
    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 Asset

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

the class AssetSourceImplTest method get_classpath_asset.

@Test
public void get_classpath_asset() {
    AssetFactory factory = mockAssetFactory();
    ThreadLocale threadLocale = mockThreadLocale();
    Asset asset = mockAsset();
    Resource expectedResource = baseResource.forFile("SimpleComponent_en_GB.properties");
    train_getRootResource(factory, rootResource);
    train_createAsset(factory, expectedResource, asset);
    Map<String, AssetFactory> configuration = Collections.singletonMap("classpath", factory);
    replay();
    AssetSource source = new AssetSourceImpl(threadLocale, configuration, null, null, tracker);
    // First try creates it:
    assertSame(source.getClasspathAsset("org/apache/tapestry5/internal/services/SimpleComponent.properties", Locale.UK), asset);
    verify();
}
Also used : AssetSource(org.apache.tapestry5.services.AssetSource) ThreadLocale(org.apache.tapestry5.ioc.services.ThreadLocale) 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 5 with Asset

use of org.apache.tapestry5.Asset 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)

Aggregations

Asset (org.apache.tapestry5.Asset)19 Resource (org.apache.tapestry5.commons.Resource)10 Test (org.testng.annotations.Test)9 AssetFactory (org.apache.tapestry5.services.AssetFactory)8 AssetSource (org.apache.tapestry5.services.AssetSource)8 ThreadLocale (org.apache.tapestry5.ioc.services.ThreadLocale)6 ClasspathResource (org.apache.tapestry5.ioc.internal.util.ClasspathResource)5 ComponentResources (org.apache.tapestry5.ComponentResources)3 Path (org.apache.tapestry5.annotations.Path)3 Asset (com.google.cloud.asset.v1.Asset)2 AssetServiceClient (com.google.cloud.asset.v1.AssetServiceClient)2 ListAssetsRequest (com.google.cloud.asset.v1.ListAssetsRequest)2 IOException (java.io.IOException)2 ArrayList (java.util.ArrayList)2 Matcher (java.util.regex.Matcher)2 ListAssetsResponse (com.google.cloud.asset.v1.ListAssetsResponse)1 OutputStream (java.io.OutputStream)1 SoftReference (java.lang.ref.SoftReference)1 URL (java.net.URL)1 DateFormat (java.text.DateFormat)1