use of org.springframework.web.server.WebHandler 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");
}
use of org.springframework.web.server.WebHandler in project spring-framework by spring-projects.
the class WebHttpHandlerBuilder method build.
/**
* Build the {@link HttpHandler}.
*/
public HttpHandler build() {
WebHandler decorated;
decorated = new FilteringWebHandler(this.webHandler, this.filters);
decorated = new ExceptionHandlingWebHandler(decorated, this.exceptionHandlers);
HttpWebHandlerAdapter adapted = new HttpWebHandlerAdapter(decorated);
if (this.sessionManager != null) {
adapted.setSessionManager(this.sessionManager);
}
return adapted;
}
use of org.springframework.web.server.WebHandler in project spring-framework by spring-projects.
the class SimpleHandlerAdapter method handle.
@Override
public Mono<HandlerResult> handle(ServerWebExchange exchange, Object handler) {
WebHandler webHandler = (WebHandler) handler;
Mono<Void> mono = webHandler.handle(exchange);
return mono.then(aVoid -> Mono.empty());
}
use of org.springframework.web.server.WebHandler in project spring-framework by spring-projects.
the class AbstractDispatcherHandlerInitializer method registerDispatcherHandler.
/**
* Register a {@link DispatcherHandler} against the given servlet context.
* <p>This method will create a {@link DispatcherHandler}, initializing it with the application
* context returned from {@link #createApplicationContext()}. The created handler will be
* wrapped in a {@link ServletHttpHandlerAdapter} servlet with the name
* returned by {@link #getServletName()}, mapping it to the pattern
* returned from {@link #getServletMapping()}.
* <p>Further customization can be achieved by overriding {@link
* #customizeRegistration(ServletRegistration.Dynamic)} or
* {@link #createDispatcherHandler(ApplicationContext)}.
* @param servletContext the context to register the servlet against
*/
protected void registerDispatcherHandler(ServletContext servletContext) {
String servletName = getServletName();
Assert.hasLength(servletName, "getServletName() must not return empty or null");
ApplicationContext applicationContext = createApplicationContext();
Assert.notNull(applicationContext, "createApplicationContext() did not return an application " + "context for servlet [" + servletName + "]");
refreshApplicationContext(applicationContext);
registerCloseListener(servletContext, applicationContext);
WebHandler dispatcherHandler = createDispatcherHandler(applicationContext);
Assert.notNull(dispatcherHandler, "createDispatcherHandler() did not return a WebHandler for servlet [" + servletName + "]");
ServletHttpHandlerAdapter handlerAdapter = createHandlerAdapter(dispatcherHandler);
Assert.notNull(handlerAdapter, "createHttpHandler() did not return a ServletHttpHandlerAdapter for servlet [" + servletName + "]");
ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, handlerAdapter);
Assert.notNull(registration, "Failed to register servlet with name '" + servletName + "'." + "Check if there is another servlet registered under the same name.");
registration.setLoadOnStartup(1);
registration.addMapping(getServletMapping());
registration.setAsyncSupported(true);
customizeRegistration(registration);
}
use of org.springframework.web.server.WebHandler in project spring-framework by spring-projects.
the class WebFluxConfigurationSupportTests method resourceHandler.
@Test
public void resourceHandler() throws Exception {
ApplicationContext context = loadConfig(CustomResourceHandlingConfig.class);
String name = "resourceHandlerMapping";
AbstractHandlerMapping handlerMapping = context.getBean(name, AbstractHandlerMapping.class);
assertNotNull(handlerMapping);
assertEquals(Ordered.LOWEST_PRECEDENCE - 1, handlerMapping.getOrder());
assertNotNull(handlerMapping.getPathHelper());
assertNotNull(handlerMapping.getPathMatcher());
SimpleUrlHandlerMapping urlHandlerMapping = (SimpleUrlHandlerMapping) handlerMapping;
WebHandler webHandler = (WebHandler) urlHandlerMapping.getUrlMap().get("/images/**");
assertNotNull(webHandler);
}
Aggregations