Search in sources :

Example 1 with ResourceWebHandler

use of org.springframework.web.reactive.resource.ResourceWebHandler in project spring-boot by spring-projects.

the class WebFluxAnnotationAutoConfigurationTests method shouldRegisterResourceHandlerMapping.

@Test
public void shouldRegisterResourceHandlerMapping() throws Exception {
    load();
    SimpleUrlHandlerMapping hm = this.context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class);
    assertThat(hm.getUrlMap().get("/**")).isInstanceOf(ResourceWebHandler.class);
    ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/**");
    assertThat(staticHandler.getLocations()).hasSize(5);
    assertThat(hm.getUrlMap().get("/webjars/**")).isInstanceOf(ResourceWebHandler.class);
    ResourceWebHandler webjarsHandler = (ResourceWebHandler) hm.getUrlMap().get("/webjars/**");
    assertThat(webjarsHandler.getLocations()).hasSize(1);
    assertThat(webjarsHandler.getLocations().get(0)).isEqualTo(new ClassPathResource("/META-INF/resources/webjars/"));
}
Also used : ResourceWebHandler(org.springframework.web.reactive.resource.ResourceWebHandler) SimpleUrlHandlerMapping(org.springframework.web.reactive.handler.SimpleUrlHandlerMapping) ClassPathResource(org.springframework.core.io.ClassPathResource) Test(org.junit.Test)

Example 2 with ResourceWebHandler

use of org.springframework.web.reactive.resource.ResourceWebHandler in project spring-boot by spring-projects.

the class WebFluxAnnotationAutoConfigurationTests method shouldMapResourcesToCustomPath.

@Test
public void shouldMapResourcesToCustomPath() throws Exception {
    load("spring.webflux.static-path-pattern:/static/**");
    SimpleUrlHandlerMapping hm = this.context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class);
    assertThat(hm.getUrlMap().get("/static/**")).isInstanceOf(ResourceWebHandler.class);
    ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/static/**");
    assertThat(staticHandler.getLocations()).hasSize(5);
}
Also used : ResourceWebHandler(org.springframework.web.reactive.resource.ResourceWebHandler) SimpleUrlHandlerMapping(org.springframework.web.reactive.handler.SimpleUrlHandlerMapping) Test(org.junit.Test)

Example 3 with ResourceWebHandler

use of org.springframework.web.reactive.resource.ResourceWebHandler in project spring-boot by spring-projects.

the class WebFluxAnnotationAutoConfigurationTests method resourceHandlerChainEnabled.

@Test
public void resourceHandlerChainEnabled() throws Exception {
    load("spring.resources.chain.enabled:true");
    SimpleUrlHandlerMapping hm = this.context.getBean("resourceHandlerMapping", SimpleUrlHandlerMapping.class);
    assertThat(hm.getUrlMap().get("/**")).isInstanceOf(ResourceWebHandler.class);
    ResourceWebHandler staticHandler = (ResourceWebHandler) hm.getUrlMap().get("/**");
    assertThat(staticHandler.getResourceResolvers()).extractingResultOf("getClass").containsOnly(CachingResourceResolver.class, PathResourceResolver.class);
    assertThat(staticHandler.getResourceTransformers()).extractingResultOf("getClass").containsOnly(CachingResourceTransformer.class);
}
Also used : ResourceWebHandler(org.springframework.web.reactive.resource.ResourceWebHandler) SimpleUrlHandlerMapping(org.springframework.web.reactive.handler.SimpleUrlHandlerMapping) Test(org.junit.Test)

Example 4 with ResourceWebHandler

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

the class ResourceHandlerRegistryTests method resourceChainWithoutCaching.

@Test
public void resourceChainWithoutCaching() throws Exception {
    this.registration.resourceChain(false);
    ResourceWebHandler handler = getHandler("/resources/**");
    List<ResourceResolver> resolvers = handler.getResourceResolvers();
    assertThat(resolvers, Matchers.hasSize(2));
    assertThat(resolvers.get(0), Matchers.instanceOf(WebJarsResourceResolver.class));
    assertThat(resolvers.get(1), Matchers.instanceOf(PathResourceResolver.class));
    List<ResourceTransformer> transformers = handler.getResourceTransformers();
    assertThat(transformers, Matchers.hasSize(0));
}
Also used : PathResourceResolver(org.springframework.web.reactive.resource.PathResourceResolver) WebJarsResourceResolver(org.springframework.web.reactive.resource.WebJarsResourceResolver) 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) 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)

Example 5 with ResourceWebHandler

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

the class ResourceHandlerRegistryTests method resourceChain.

@Test
public void resourceChain() throws Exception {
    ResourceResolver mockResolver = Mockito.mock(ResourceResolver.class);
    ResourceTransformer mockTransformer = Mockito.mock(ResourceTransformer.class);
    this.registration.resourceChain(true).addResolver(mockResolver).addTransformer(mockTransformer);
    ResourceWebHandler handler = getHandler("/resources/**");
    List<ResourceResolver> resolvers = handler.getResourceResolvers();
    assertThat(resolvers.toString(), resolvers, Matchers.hasSize(4));
    assertThat(resolvers.get(0), Matchers.instanceOf(CachingResourceResolver.class));
    CachingResourceResolver cachingResolver = (CachingResourceResolver) resolvers.get(0);
    assertThat(cachingResolver.getCache(), Matchers.instanceOf(ConcurrentMapCache.class));
    assertThat(resolvers.get(1), Matchers.equalTo(mockResolver));
    assertThat(resolvers.get(2), Matchers.instanceOf(WebJarsResourceResolver.class));
    assertThat(resolvers.get(3), Matchers.instanceOf(PathResourceResolver.class));
    List<ResourceTransformer> transformers = handler.getResourceTransformers();
    assertThat(transformers, Matchers.hasSize(2));
    assertThat(transformers.get(0), Matchers.instanceOf(CachingResourceTransformer.class));
    assertThat(transformers.get(1), Matchers.equalTo(mockTransformer));
}
Also used : ConcurrentMapCache(org.springframework.cache.concurrent.ConcurrentMapCache) CachingResourceResolver(org.springframework.web.reactive.resource.CachingResourceResolver) PathResourceResolver(org.springframework.web.reactive.resource.PathResourceResolver) WebJarsResourceResolver(org.springframework.web.reactive.resource.WebJarsResourceResolver) 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) CachingResourceTransformer(org.springframework.web.reactive.resource.CachingResourceTransformer) CssLinkResourceTransformer(org.springframework.web.reactive.resource.CssLinkResourceTransformer) ResourceTransformer(org.springframework.web.reactive.resource.ResourceTransformer) ResourceWebHandler(org.springframework.web.reactive.resource.ResourceWebHandler) Test(org.junit.Test)

Aggregations

ResourceWebHandler (org.springframework.web.reactive.resource.ResourceWebHandler)10 Test (org.junit.Test)8 SimpleUrlHandlerMapping (org.springframework.web.reactive.handler.SimpleUrlHandlerMapping)4 CachingResourceResolver (org.springframework.web.reactive.resource.CachingResourceResolver)4 CachingResourceTransformer (org.springframework.web.reactive.resource.CachingResourceTransformer)4 CssLinkResourceTransformer (org.springframework.web.reactive.resource.CssLinkResourceTransformer)4 PathResourceResolver (org.springframework.web.reactive.resource.PathResourceResolver)4 ResourceResolver (org.springframework.web.reactive.resource.ResourceResolver)4 ResourceTransformer (org.springframework.web.reactive.resource.ResourceTransformer)4 VersionResourceResolver (org.springframework.web.reactive.resource.VersionResourceResolver)4 WebJarsResourceResolver (org.springframework.web.reactive.resource.WebJarsResourceResolver)4 AppCacheManifestTransformer (org.springframework.web.reactive.resource.AppCacheManifestTransformer)2 LinkedHashMap (java.util.LinkedHashMap)1 BeanInitializationException (org.springframework.beans.factory.BeanInitializationException)1 ConcurrentMapCache (org.springframework.cache.concurrent.ConcurrentMapCache)1 ClassPathResource (org.springframework.core.io.ClassPathResource)1 MockServerWebExchange (org.springframework.mock.http.server.reactive.test.MockServerWebExchange)1 WebHandler (org.springframework.web.server.WebHandler)1