@Override protected WebHttpHandlerBuilder initHttpHandlerBuilder() { return WebHttpHandlerBuilder.webHandler(this.webHandler); }
@Override protected WebHttpHandlerBuilder initHttpHandlerBuilder() { WebHandler webHandler = RouterFunctions.toWebHandler(this.routerFunction, this.handlerStrategies); return WebHttpHandlerBuilder.webHandler(webHandler) .filters(filters -> filters.addAll(this.handlerStrategies.webFilters())) .exceptionHandlers(handlers -> handlers.addAll(this.handlerStrategies.exceptionHandlers())) .localeContextResolver(this.handlerStrategies.localeContextResolver()); }
@Override protected WebHttpHandlerBuilder initHttpHandlerBuilder() { return WebHttpHandlerBuilder.webHandler(exchange -> { DefaultDataBufferFactory factory = new DefaultDataBufferFactory(); String text = exchange.getAttributes().toString(); DataBuffer buffer = factory.wrap(text.getBytes(StandardCharsets.UTF_8)); return exchange.getResponse().writeWith(Mono.just(buffer)); }); } }
/** * Convert the given {@linkplain RouterFunction router function} into a {@link HttpHandler}, * using the given strategies. * <p>The returned {@code HttpHandler} can be adapted to run in * <ul> * <li>Servlet 3.1+ using the * {@link org.springframework.http.server.reactive.ServletHttpHandlerAdapter},</li> * <li>Reactor using the * {@link org.springframework.http.server.reactive.ReactorHttpHandlerAdapter},</li> * <li>Undertow using the * {@link org.springframework.http.server.reactive.UndertowHttpHandlerAdapter}.</li> * </ul> * @param routerFunction the router function to convert * @param strategies the strategies to use * @return an http handler that handles HTTP request using the given router function */ public static HttpHandler toHttpHandler(RouterFunction<?> routerFunction, HandlerStrategies strategies) { WebHandler webHandler = toWebHandler(routerFunction, strategies); return WebHttpHandlerBuilder.webHandler(webHandler) .filters(filters -> filters.addAll(strategies.webFilters())) .exceptionHandlers(handlers -> handlers.addAll(strategies.exceptionHandlers())) .localeContextResolver(strategies.localeContextResolver()) .build(); }
@Override protected HttpHandler createHttpHandler() { this.wac = new AnnotationConfigApplicationContext(); this.wac.register(TestConfiguration.class); this.wac.refresh(); return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(this.wac)).build(); }
@Override protected HttpHandler createHttpHandler() { AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); wac.register(TestConfiguration.class); wac.refresh(); return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build(); }
@Override protected HttpHandler createHttpHandler() { this.wac = new AnnotationConfigApplicationContext(); this.wac.register(TestConfiguration.class); this.wac.refresh(); return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(this.wac)).build(); }
@Override protected HttpHandler createHttpHandler() { AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); wac.register(TestConfiguration.class); wac.refresh(); return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)).build(); }
@Override protected HttpHandler createHttpHandler() { this.wac = new AnnotationConfigApplicationContext(); this.wac.register(TestConfiguration.class); this.wac.refresh(); DispatcherHandler webHandler = new DispatcherHandler(); webHandler.setApplicationContext(this.wac); return WebHttpHandlerBuilder.webHandler(webHandler).build(); }
@Override protected HttpHandler createHttpHandler() { this.sessionManager = new DefaultWebSessionManager(); this.handler = new TestWebHandler(); return WebHttpHandlerBuilder.webHandler(this.handler).sessionManager(this.sessionManager).build(); }
@Override protected HttpHandler createHttpHandler() { AnnotationConfigApplicationContext wac = new AnnotationConfigApplicationContext(); wac.register(WebConfig.class); wac.refresh(); return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(wac)) .exceptionHandler(new ResponseStatusExceptionHandler()) .build(); }
private HttpHandler createHttpHandler() { this.wac = new AnnotationConfigApplicationContext(); this.wac.register(TestConfiguration.class); this.wac.refresh(); return WebHttpHandlerBuilder.webHandler(new DispatcherHandler(this.wac)).build(); }
@Test public void handleErrorFromFilter() throws Exception { MockServerHttpRequest request = MockServerHttpRequest.get("/").build(); MockServerHttpResponse response = new MockServerHttpResponse(); TestExceptionHandler exceptionHandler = new TestExceptionHandler(); WebHttpHandlerBuilder.webHandler(new StubWebHandler()) .filter(new ExceptionFilter()) .exceptionHandler(exceptionHandler).build() .handle(request, response) .block(); assertEquals(HttpStatus.INTERNAL_SERVER_ERROR, response.getStatusCode()); assertNotNull(exceptionHandler.ex); assertEquals("boo", exceptionHandler.ex.getMessage()); }
@Override protected WebHttpHandlerBuilder initHttpHandlerBuilder() { return WebHttpHandlerBuilder.webHandler(this.webHandler); }
@Override protected WebHttpHandlerBuilder initHttpHandlerBuilder() { return WebHttpHandlerBuilder.webHandler(this.webHandler); }
@Override protected WebHttpHandlerBuilder initHttpHandlerBuilder() { WebHandler webHandler = RouterFunctions.toWebHandler(this.routerFunction, this.handlerStrategies); return WebHttpHandlerBuilder.webHandler(webHandler) .filters(filters -> filters.addAll(this.handlerStrategies.webFilters())) .exceptionHandlers(handlers -> handlers.addAll(this.handlerStrategies.exceptionHandlers())) .localeContextResolver(this.handlerStrategies.localeContextResolver()); }
@Override protected WebHttpHandlerBuilder initHttpHandlerBuilder() { WebHandler webHandler = RouterFunctions.toWebHandler(this.routerFunction, this.handlerStrategies); return WebHttpHandlerBuilder.webHandler(webHandler) .filters(filters -> filters.addAll(this.handlerStrategies.webFilters())) .exceptionHandlers(handlers -> handlers.addAll(this.handlerStrategies.exceptionHandlers())) .localeContextResolver(this.handlerStrategies.localeContextResolver()); }