Search in sources :

Example 1 with ResourceUrlEncodingFilter

use of org.springframework.web.servlet.resource.ResourceUrlEncodingFilter in project spring-boot by spring-projects.

the class ThymeleafServletAutoConfigurationTests method registerResourceHandlingFilterWithResourceRegistrationBean.

@Test
@SuppressWarnings("rawtypes")
void registerResourceHandlingFilterWithResourceRegistrationBean() {
    // gh-14926
    this.contextRunner.withUserConfiguration(FilterRegistrationResourceConfiguration.class).withPropertyValues("spring.web.resources.chain.enabled:true").run((context) -> {
        Map<String, FilterRegistrationBean> beans = context.getBeansOfType(FilterRegistrationBean.class);
        assertThat(beans).hasSize(1);
        FilterRegistrationBean registration = beans.values().stream().filter((r) -> r.getFilter() instanceof ResourceUrlEncodingFilter).findFirst().get();
        assertThat(registration).hasFieldOrPropertyWithValue("dispatcherTypes", EnumSet.of(DispatcherType.INCLUDE));
    });
}
Also used : ResourceUrlEncodingFilter(org.springframework.web.servlet.resource.ResourceUrlEncodingFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Test(org.junit.jupiter.api.Test)

Example 2 with ResourceUrlEncodingFilter

use of org.springframework.web.servlet.resource.ResourceUrlEncodingFilter in project spring-boot by spring-projects.

the class FreeMarkerServletWebConfiguration method resourceUrlEncodingFilter.

@Bean
@ConditionalOnEnabledResourceChain
@ConditionalOnMissingFilterBean(ResourceUrlEncodingFilter.class)
FilterRegistrationBean<ResourceUrlEncodingFilter> resourceUrlEncodingFilter() {
    FilterRegistrationBean<ResourceUrlEncodingFilter> registration = new FilterRegistrationBean<>(new ResourceUrlEncodingFilter());
    registration.setDispatcherTypes(DispatcherType.REQUEST, DispatcherType.ERROR);
    return registration;
}
Also used : ResourceUrlEncodingFilter(org.springframework.web.servlet.resource.ResourceUrlEncodingFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnEnabledResourceChain(org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain) ConditionalOnMissingFilterBean(org.springframework.boot.autoconfigure.web.servlet.ConditionalOnMissingFilterBean) ConditionalOnMissingBean(org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) ConditionalOnMissingFilterBean(org.springframework.boot.autoconfigure.web.servlet.ConditionalOnMissingFilterBean) Bean(org.springframework.context.annotation.Bean)

Example 3 with ResourceUrlEncodingFilter

use of org.springframework.web.servlet.resource.ResourceUrlEncodingFilter in project spring-boot by spring-projects.

the class FreeMarkerAutoConfigurationServletIntegrationTests method registerResourceHandlingFilterWithResourceRegistrationBean.

@Test
@SuppressWarnings("rawtypes")
void registerResourceHandlingFilterWithResourceRegistrationBean() {
    // gh-14926
    load(FilterRegistrationResourceConfiguration.class, "spring.web.resources.chain.enabled:true");
    Map<String, FilterRegistrationBean> beans = this.context.getBeansOfType(FilterRegistrationBean.class);
    assertThat(beans).hasSize(1);
    FilterRegistrationBean registration = beans.values().stream().filter((r) -> r.getFilter() instanceof ResourceUrlEncodingFilter).findFirst().get();
    assertThat(registration).hasFieldOrPropertyWithValue("dispatcherTypes", EnumSet.of(DispatcherType.INCLUDE));
}
Also used : ResourceUrlEncodingFilter(org.springframework.web.servlet.resource.ResourceUrlEncodingFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Test(org.junit.jupiter.api.Test)

Example 4 with ResourceUrlEncodingFilter

use of org.springframework.web.servlet.resource.ResourceUrlEncodingFilter in project spring-boot by spring-projects.

the class FreeMarkerAutoConfigurationServletIntegrationTests method registerResourceHandlingFilterWithOtherRegistrationBean.

@Test
@SuppressWarnings("rawtypes")
void registerResourceHandlingFilterWithOtherRegistrationBean() {
    // gh-14897
    load(FilterRegistrationOtherConfiguration.class, "spring.web.resources.chain.enabled:true");
    Map<String, FilterRegistrationBean> beans = this.context.getBeansOfType(FilterRegistrationBean.class);
    assertThat(beans).hasSize(2);
    FilterRegistrationBean registration = beans.values().stream().filter((r) -> r.getFilter() instanceof ResourceUrlEncodingFilter).findFirst().get();
    assertThat(registration).hasFieldOrPropertyWithValue("dispatcherTypes", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));
}
Also used : ResourceUrlEncodingFilter(org.springframework.web.servlet.resource.ResourceUrlEncodingFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Test(org.junit.jupiter.api.Test)

Example 5 with ResourceUrlEncodingFilter

use of org.springframework.web.servlet.resource.ResourceUrlEncodingFilter in project spring-boot by spring-projects.

the class ThymeleafServletAutoConfigurationTests method registerResourceHandlingFilterWithOtherRegistrationBean.

@Test
@SuppressWarnings("rawtypes")
void registerResourceHandlingFilterWithOtherRegistrationBean() {
    // gh-14897
    this.contextRunner.withUserConfiguration(FilterRegistrationOtherConfiguration.class).withPropertyValues("spring.web.resources.chain.enabled:true").run((context) -> {
        Map<String, FilterRegistrationBean> beans = context.getBeansOfType(FilterRegistrationBean.class);
        assertThat(beans).hasSize(2);
        FilterRegistrationBean registration = beans.values().stream().filter((r) -> r.getFilter() instanceof ResourceUrlEncodingFilter).findFirst().get();
        assertThat(registration).hasFieldOrPropertyWithValue("dispatcherTypes", EnumSet.of(DispatcherType.REQUEST, DispatcherType.ERROR));
    });
}
Also used : ResourceUrlEncodingFilter(org.springframework.web.servlet.resource.ResourceUrlEncodingFilter) FilterRegistrationBean(org.springframework.boot.web.servlet.FilterRegistrationBean) Test(org.junit.jupiter.api.Test)

Aggregations

FilterRegistrationBean (org.springframework.boot.web.servlet.FilterRegistrationBean)5 ResourceUrlEncodingFilter (org.springframework.web.servlet.resource.ResourceUrlEncodingFilter)5 Test (org.junit.jupiter.api.Test)4 ConditionalOnMissingBean (org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean)1 ConditionalOnEnabledResourceChain (org.springframework.boot.autoconfigure.web.ConditionalOnEnabledResourceChain)1 ConditionalOnMissingFilterBean (org.springframework.boot.autoconfigure.web.servlet.ConditionalOnMissingFilterBean)1 Bean (org.springframework.context.annotation.Bean)1