Search in sources :

Example 1 with WebHandlerDecorator

use of org.springframework.web.server.handler.WebHandlerDecorator in project spring-boot by spring-projects.

the class HttpHandlerAutoConfigurationTests method shouldConfigureWebFiltersAnnotation.

@Test
public void shouldConfigureWebFiltersAnnotation() {
    load(AnnotationConfigWithWebFilters.class);
    HttpHandler handler = this.context.getBean(HttpHandler.class);
    assertThat(handler).isInstanceOf(WebHandler.class);
    WebHandler webHandler = (WebHandler) handler;
    while (webHandler instanceof WebHandlerDecorator) {
        if (webHandler instanceof FilteringWebHandler) {
            FilteringWebHandler filteringWebHandler = (FilteringWebHandler) webHandler;
            assertThat(filteringWebHandler.getFilters()).containsExactly(this.context.getBean("firstWebFilter", WebFilter.class), this.context.getBean("aWebFilter", WebFilter.class), this.context.getBean("lastWebFilter", WebFilter.class));
            return;
        }
        webHandler = ((WebHandlerDecorator) webHandler).getDelegate();
    }
    fail("Did not find any FilteringWebHandler");
}
Also used : HttpHandler(org.springframework.http.server.reactive.HttpHandler) WebFilter(org.springframework.web.server.WebFilter) FilteringWebHandler(org.springframework.web.server.handler.FilteringWebHandler) WebHandlerDecorator(org.springframework.web.server.handler.WebHandlerDecorator) WebHandler(org.springframework.web.server.WebHandler) FilteringWebHandler(org.springframework.web.server.handler.FilteringWebHandler) Test(org.junit.Test)

Example 2 with WebHandlerDecorator

use of org.springframework.web.server.handler.WebHandlerDecorator in project spring-boot by spring-projects.

the class HttpHandlerAutoConfigurationTests method shouldConfigureWebFiltersFunctional.

@Test
public void shouldConfigureWebFiltersFunctional() {
    load(FunctionalConfigWithWebFilters.class);
    assertThat(this.context.getBeansOfType(HttpHandler.class).size()).isEqualTo(1);
    HttpHandler handler = this.context.getBean(HttpHandler.class);
    assertThat(handler).isInstanceOf(WebHandler.class);
    WebHandler webHandler = (WebHandler) handler;
    while (webHandler instanceof WebHandlerDecorator) {
        if (webHandler instanceof FilteringWebHandler) {
            FilteringWebHandler filteringWebHandler = (FilteringWebHandler) webHandler;
            assertThat(filteringWebHandler.getFilters()).containsExactly(this.context.getBean("customWebFilter", WebFilter.class));
            return;
        }
        webHandler = ((WebHandlerDecorator) webHandler).getDelegate();
    }
    fail("Did not find any FilteringWebHandler");
}
Also used : HttpHandler(org.springframework.http.server.reactive.HttpHandler) WebFilter(org.springframework.web.server.WebFilter) FilteringWebHandler(org.springframework.web.server.handler.FilteringWebHandler) WebHandlerDecorator(org.springframework.web.server.handler.WebHandlerDecorator) WebHandler(org.springframework.web.server.WebHandler) FilteringWebHandler(org.springframework.web.server.handler.FilteringWebHandler) Test(org.junit.Test)

Aggregations

Test (org.junit.Test)2 HttpHandler (org.springframework.http.server.reactive.HttpHandler)2 WebFilter (org.springframework.web.server.WebFilter)2 WebHandler (org.springframework.web.server.WebHandler)2 FilteringWebHandler (org.springframework.web.server.handler.FilteringWebHandler)2 WebHandlerDecorator (org.springframework.web.server.handler.WebHandlerDecorator)2