@Test public void andOther() { HandlerFunction<ServerResponse> handlerFunction = request -> ServerResponse.ok().body(fromObject("42")); RouterFunction<?> routerFunction1 = request -> Mono.empty(); RouterFunction<ServerResponse> routerFunction2 = request -> Mono.just(handlerFunction); RouterFunction<?> result = routerFunction1.andOther(routerFunction2); assertNotNull(result); MockServerRequest request = MockServerRequest.builder().build(); Mono<? extends HandlerFunction<?>> resultHandlerFunction = result.route(request); StepVerifier.create(resultHandlerFunction) .expectNextMatches(o -> o.equals(handlerFunction)) .expectComplete() .verify(); }
public static RouterFunction<?> doRoute(final ApiHandler handler, final ErrorHandler errorHandler) { return ApiRouter .doRoute(handler, errorHandler) .andOther(StaticRouter.doRoute()); } }
static RouterFunction<?> doRoute(final ApiHandler apiHandler, final ErrorHandler errorHandler) { return nest(path(API_PATH), nest(accept(APPLICATION_JSON), route(GET(LOCATION_WITH_ADDRESS_PATH), apiHandler::getLocation) .andRoute(POST(LOCATION_PATH), apiHandler::postLocation) ).andOther(route(RequestPredicates.all(), errorHandler::notFound)) ); } }
@Bean RouterFunction routes(final HandlerFunction<ServerResponse> fallbackHandler) { return nest( path("/"), nest( accept(APPLICATION_JSON), route( GET("/api/orders"), getOrdersHandler() ) ).andNest( accept(APPLICATION_JSON), route( GET("/api"), getCountQueryHandler() ) ) ).andOther( route( GET("/**"), fallbackHandler ) ) ; } }