use of org.springframework.http.server.reactive.HttpHandler in project spring-framework by spring-projects.
the class AbstractServletHttpHandlerAdapterInitializer method registerHandlerAdapter.
/**
* Register a {@link ServletHttpHandlerAdapter} against the given servlet context.
* <p>This method will create a {@code HttpHandler} using {@link #createHttpHandler()},
* and use it to create a {@code ServletHttpHandlerAdapter} with the name returned by
* {@link #getServletName()}, and mapping it to the patterns
* returned from {@link #getServletMappings()}.
* <p>Further customization can be achieved by overriding {@link
* #customizeRegistration(ServletRegistration.Dynamic)} or
* {@link #createServlet(HttpHandler)}.
* @param servletContext the context to register the servlet against
*/
protected void registerHandlerAdapter(ServletContext servletContext) {
String servletName = getServletName();
Assert.hasLength(servletName, "getServletName() must not return empty or null");
HttpHandler httpHandler = createHttpHandler();
Assert.notNull(httpHandler, "createHttpHandler() did not return a HttpHandler for servlet [" + servletName + "]");
ServletHttpHandlerAdapter servlet = createServlet(httpHandler);
Assert.notNull(servlet, "createHttpHandler() did not return a ServletHttpHandlerAdapter for servlet [" + servletName + "]");
ServletRegistration.Dynamic registration = servletContext.addServlet(servletName, servlet);
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(getServletMappings());
registration.setAsyncSupported(true);
customizeRegistration(registration);
}
use of org.springframework.http.server.reactive.HttpHandler in project spring-framework by spring-projects.
the class ContextPathIntegrationTests method setup.
@Before
public void setup() throws Exception {
AnnotationConfigApplicationContext context1 = new AnnotationConfigApplicationContext();
context1.register(WebApp1Config.class);
context1.refresh();
AnnotationConfigApplicationContext context2 = new AnnotationConfigApplicationContext();
context2.register(WebApp2Config.class);
context2.refresh();
HttpHandler webApp1Handler = DispatcherHandler.toHttpHandler(context1);
HttpHandler webApp2Handler = DispatcherHandler.toHttpHandler(context2);
this.server = new ReactorHttpServer();
this.server.registerHttpHandler("/webApp1", webApp1Handler);
this.server.registerHttpHandler("/webApp2", webApp2Handler);
this.server.afterPropertiesSet();
this.server.start();
}
use of org.springframework.http.server.reactive.HttpHandler in project spring-framework by spring-projects.
the class HttpServerTests method setUp.
@Before
public void setUp() throws Exception {
HttpHandler httpHandler = RouterFunctions.toHttpHandler(route(GET("/test"), request -> ServerResponse.ok().body(Mono.just("It works!"), String.class)));
this.server = new ReactorHttpServer();
this.server.setHandler(httpHandler);
this.server.afterPropertiesSet();
this.server.start();
this.client = WebTestClient.bindToServer().baseUrl("http://localhost:" + this.server.getPort()).build();
}
use of org.springframework.http.server.reactive.HttpHandler 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.http.server.reactive.HttpHandler in project tutorials by eugenp.
the class SpringSecurity5Application method nettyContext.
@Bean
public NettyContext nettyContext(ApplicationContext context) {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(context).build();
ReactorHttpHandlerAdapter adapter = new ReactorHttpHandlerAdapter(handler);
HttpServer httpServer = HttpServer.create("localhost", 8080);
return httpServer.newHandler(adapter).block();
}
Aggregations