use of org.springframework.http.server.reactive.HttpHandler in project spring-framework by spring-projects.
the class WebHttpHandlerBuilderTests method configWithoutFilters.
@Test
void configWithoutFilters() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(NoFilterConfig.class);
context.refresh();
HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(context).build();
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
MockServerHttpResponse response = new MockServerHttpResponse();
httpHandler.handle(request, response).block(ofMillis(5000));
assertThat(response.getBodyAsString().block(ofMillis(5000))).isEqualTo("handled");
}
use of org.springframework.http.server.reactive.HttpHandler in project spring-framework by spring-projects.
the class WebHttpHandlerBuilderTests method orderedWebExceptionHandlerBeans.
// SPR-15074
@Test
void orderedWebExceptionHandlerBeans() {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext();
context.register(OrderedExceptionHandlerBeanConfig.class);
context.refresh();
HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(context).build();
MockServerHttpRequest request = MockServerHttpRequest.get("/").build();
MockServerHttpResponse response = new MockServerHttpResponse();
httpHandler.handle(request, response).block(ofMillis(5000));
assertThat(response.getBodyAsString().block(ofMillis(5000))).isEqualTo("ExceptionHandlerB");
}
use of org.springframework.http.server.reactive.HttpHandler in project spring-framework by spring-projects.
the class WebHttpHandlerBuilderTests method httpHandlerDecoratorFactoryBeans.
@Test
void httpHandlerDecoratorFactoryBeans() {
HttpHandler handler = WebHttpHandlerBuilder.applicationContext(new AnnotationConfigApplicationContext(HttpHandlerDecoratorFactoryBeansConfig.class)).build();
MockServerHttpResponse response = new MockServerHttpResponse();
handler.handle(MockServerHttpRequest.get("/").build(), response).block();
Function<String, Long> headerValue = name -> Long.valueOf(response.getHeaders().getFirst(name));
assertThat(headerValue.apply("decoratorA")).isLessThan(headerValue.apply("decoratorB"));
assertThat(headerValue.apply("decoratorC")).isLessThan(headerValue.apply("decoratorB"));
}
use of org.springframework.http.server.reactive.HttpHandler in project spring-framework by spring-projects.
the class ContextPathIntegrationTests method servletPathMapping.
@Test
void servletPathMapping() throws Exception {
AnnotationConfigApplicationContext context = new AnnotationConfigApplicationContext(WebAppConfig.class);
TomcatHttpServer server = new TomcatHttpServer();
server.setContextPath("/app");
server.setServletMapping("/api/*");
HttpHandler httpHandler = WebHttpHandlerBuilder.applicationContext(context).build();
server.setHandler(httpHandler);
server.afterPropertiesSet();
server.start();
try {
String url = "http://localhost:" + server.getPort() + "/app/api/test";
String actual = new RestTemplate().getForObject(url, String.class);
assertThat(actual).isEqualTo("Tested in /app/api");
} finally {
server.stop();
}
}
use of org.springframework.http.server.reactive.HttpHandler in project spring-framework by spring-projects.
the class RouterFunctionsTests method toHttpHandlerHandlerThrowsException.
@Test
public void toHttpHandlerHandlerThrowsException() {
HandlerFunction<ServerResponse> handlerFunction = request -> {
throw new IllegalStateException();
};
RouterFunction<ServerResponse> routerFunction = RouterFunctions.route(RequestPredicates.all(), handlerFunction);
HttpHandler result = RouterFunctions.toHttpHandler(routerFunction);
assertThat(result).isNotNull();
MockServerHttpRequest httpRequest = MockServerHttpRequest.get("https://localhost").build();
MockServerHttpResponse httpResponse = new MockServerHttpResponse();
result.handle(httpRequest, httpResponse).block();
assertThat(httpResponse.getStatusCode()).isEqualTo(HttpStatus.INTERNAL_SERVER_ERROR);
}
Aggregations