Search in sources :

Example 1 with CachingResourceTransformer

use of org.springframework.web.reactive.resource.CachingResourceTransformer in project spring-framework by spring-projects.

the class ResourceChainRegistration method getResourceTransformers.

protected List<ResourceTransformer> getResourceTransformers() {
    if (this.hasVersionResolver && !this.hasCssLinkTransformer) {
        List<ResourceTransformer> result = new ArrayList<>(this.transformers);
        boolean hasTransformers = !this.transformers.isEmpty();
        boolean hasCaching = hasTransformers && this.transformers.get(0) instanceof CachingResourceTransformer;
        result.add(hasCaching ? 1 : 0, new CssLinkResourceTransformer());
        return result;
    }
    return this.transformers;
}
Also used : CssLinkResourceTransformer(org.springframework.web.reactive.resource.CssLinkResourceTransformer) ArrayList(java.util.ArrayList) CachingResourceTransformer(org.springframework.web.reactive.resource.CachingResourceTransformer) CachingResourceTransformer(org.springframework.web.reactive.resource.CachingResourceTransformer) ResourceTransformer(org.springframework.web.reactive.resource.ResourceTransformer) CssLinkResourceTransformer(org.springframework.web.reactive.resource.CssLinkResourceTransformer)

Example 2 with CachingResourceTransformer

use of org.springframework.web.reactive.resource.CachingResourceTransformer in project spring-framework by spring-projects.

the class ResourceHandlerRegistryTests method resourceChainWithOverrides.

@Test
public void resourceChainWithOverrides() throws Exception {
    CachingResourceResolver cachingResolver = Mockito.mock(CachingResourceResolver.class);
    VersionResourceResolver versionResolver = Mockito.mock(VersionResourceResolver.class);
    WebJarsResourceResolver webjarsResolver = Mockito.mock(WebJarsResourceResolver.class);
    PathResourceResolver pathResourceResolver = new PathResourceResolver();
    CachingResourceTransformer cachingTransformer = Mockito.mock(CachingResourceTransformer.class);
    AppCacheManifestTransformer appCacheTransformer = Mockito.mock(AppCacheManifestTransformer.class);
    CssLinkResourceTransformer cssLinkTransformer = new CssLinkResourceTransformer();
    this.registration.setCacheControl(CacheControl.maxAge(3600, TimeUnit.MILLISECONDS)).resourceChain(false).addResolver(cachingResolver).addResolver(versionResolver).addResolver(webjarsResolver).addResolver(pathResourceResolver).addTransformer(cachingTransformer).addTransformer(appCacheTransformer).addTransformer(cssLinkTransformer);
    ResourceWebHandler handler = getHandler("/resources/**");
    List<ResourceResolver> resolvers = handler.getResourceResolvers();
    assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
    assertThat(resolvers.get(0), Matchers.sameInstance(cachingResolver));
    assertThat(resolvers.get(1), Matchers.sameInstance(versionResolver));
    assertThat(resolvers.get(2), Matchers.sameInstance(webjarsResolver));
    assertThat(resolvers.get(3), Matchers.sameInstance(pathResourceResolver));
    List<ResourceTransformer> transformers = handler.getResourceTransformers();
    assertThat(transformers, Matchers.hasSize(3));
    assertThat(transformers.get(0), Matchers.sameInstance(cachingTransformer));
    assertThat(transformers.get(1), Matchers.sameInstance(appCacheTransformer));
    assertThat(transformers.get(2), Matchers.sameInstance(cssLinkTransformer));
}
Also used : CachingResourceResolver(org.springframework.web.reactive.resource.CachingResourceResolver) CssLinkResourceTransformer(org.springframework.web.reactive.resource.CssLinkResourceTransformer) PathResourceResolver(org.springframework.web.reactive.resource.PathResourceResolver) WebJarsResourceResolver(org.springframework.web.reactive.resource.WebJarsResourceResolver) AppCacheManifestTransformer(org.springframework.web.reactive.resource.AppCacheManifestTransformer) VersionResourceResolver(org.springframework.web.reactive.resource.VersionResourceResolver) CachingResourceResolver(org.springframework.web.reactive.resource.CachingResourceResolver) VersionResourceResolver(org.springframework.web.reactive.resource.VersionResourceResolver) PathResourceResolver(org.springframework.web.reactive.resource.PathResourceResolver) ResourceResolver(org.springframework.web.reactive.resource.ResourceResolver) WebJarsResourceResolver(org.springframework.web.reactive.resource.WebJarsResourceResolver) CachingResourceTransformer(org.springframework.web.reactive.resource.CachingResourceTransformer) ResourceWebHandler(org.springframework.web.reactive.resource.ResourceWebHandler) CachingResourceTransformer(org.springframework.web.reactive.resource.CachingResourceTransformer) CssLinkResourceTransformer(org.springframework.web.reactive.resource.CssLinkResourceTransformer) ResourceTransformer(org.springframework.web.reactive.resource.ResourceTransformer) Test(org.junit.Test)

Aggregations

CachingResourceTransformer (org.springframework.web.reactive.resource.CachingResourceTransformer)2 CssLinkResourceTransformer (org.springframework.web.reactive.resource.CssLinkResourceTransformer)2 ResourceTransformer (org.springframework.web.reactive.resource.ResourceTransformer)2 ArrayList (java.util.ArrayList)1 Test (org.junit.Test)1 AppCacheManifestTransformer (org.springframework.web.reactive.resource.AppCacheManifestTransformer)1 CachingResourceResolver (org.springframework.web.reactive.resource.CachingResourceResolver)1 PathResourceResolver (org.springframework.web.reactive.resource.PathResourceResolver)1 ResourceResolver (org.springframework.web.reactive.resource.ResourceResolver)1 ResourceWebHandler (org.springframework.web.reactive.resource.ResourceWebHandler)1 VersionResourceResolver (org.springframework.web.reactive.resource.VersionResourceResolver)1 WebJarsResourceResolver (org.springframework.web.reactive.resource.WebJarsResourceResolver)1