@Override public RouterFunctions.Builder path(String pattern, Consumer<RouterFunctions.Builder> builderConsumer) { return nest(RequestPredicates.path(pattern), builderConsumer); }
@Test public void predicates() { testPredicate(methods(HttpMethod.GET), "GET"); testPredicate(methods(HttpMethod.GET, HttpMethod.POST), "[GET, POST]"); testPredicate(path("/foo"), "/foo"); testPredicate(pathExtension("foo"), "*.foo"); testPredicate(contentType(MediaType.APPLICATION_JSON), "Content-Type: application/json"); testPredicate(contentType(MediaType.APPLICATION_JSON, MediaType.TEXT_PLAIN), "Content-Type: [application/json, text/plain]"); testPredicate(accept(MediaType.APPLICATION_JSON), "Accept: application/json"); testPredicate(queryParam("foo", "bar"), "?foo == bar"); testPredicate(method(HttpMethod.GET).and(path("/foo")), "(GET && /foo)"); testPredicate(method(HttpMethod.GET).or(path("/foo")), "(GET || /foo)"); testPredicate(method(HttpMethod.GET).negate(), "!(GET)"); testPredicate(GET("/foo") .or(contentType(MediaType.TEXT_PLAIN)) .and(accept(MediaType.APPLICATION_JSON).negate()), "(((GET && /foo) || Content-Type: text/plain) && !(Accept: application/json))"); }
@Override public RouterFunctions.Builder path(String pattern, Supplier<RouterFunction<ServerResponse>> routerFunctionSupplier) { return nest(RequestPredicates.path(pattern), routerFunctionSupplier); }
/** * Return a {@code RequestPredicate} that matches if request's HTTP method is {@code DELETE} * and the given {@code pattern} matches against the request path. * @param pattern the path pattern to match against * @return a predicate that matches if the request method is DELETE and if the given pattern * matches against the request path */ public static RequestPredicate DELETE(String pattern) { return method(HttpMethod.DELETE).and(path(pattern)); }
/** * Return a {@code RequestPredicate} that matches if request's HTTP method is {@code GET} * and the given {@code pattern} matches against the request path. * @param pattern the path pattern to match against * @return a predicate that matches if the request method is GET and if the given pattern * matches against the request path */ public static RequestPredicate GET(String pattern) { return method(HttpMethod.GET).and(path(pattern)); }
/** * Return a {@code RequestPredicate} that matches if request's HTTP method is {@code HEAD} * and the given {@code pattern} matches against the request path. * @param pattern the path pattern to match against * @return a predicate that matches if the request method is HEAD and if the given pattern * matches against the request path */ public static RequestPredicate HEAD(String pattern) { return method(HttpMethod.HEAD).and(path(pattern)); }
/** * Return a {@code RequestPredicate} that matches if request's HTTP method is {@code OPTIONS} * and the given {@code pattern} matches against the request path. * @param pattern the path pattern to match against * @return a predicate that matches if the request method is OPTIONS and if the given pattern * matches against the request path */ public static RequestPredicate OPTIONS(String pattern) { return method(HttpMethod.OPTIONS).and(path(pattern)); }
/** * Return a {@code RequestPredicate} that matches if request's HTTP method is {@code POST} * and the given {@code pattern} matches against the request path. * @param pattern the path pattern to match against * @return a predicate that matches if the request method is POST and if the given pattern * matches against the request path */ public static RequestPredicate POST(String pattern) { return method(HttpMethod.POST).and(path(pattern)); }
/** * Return a {@code RequestPredicate} that matches if request's HTTP method is {@code PUT} * and the given {@code pattern} matches against the request path. * @param pattern the path pattern to match against * @return a predicate that matches if the request method is PUT and if the given pattern * matches against the request path */ public static RequestPredicate PUT(String pattern) { return method(HttpMethod.PUT).and(path(pattern)); }
/** * Return a {@code RequestPredicate} that matches if request's HTTP method is {@code PATCH} * and the given {@code pattern} matches against the request path. * @param pattern the path pattern to match against * @return a predicate that matches if the request method is PATCH and if the given pattern * matches against the request path */ public static RequestPredicate PATCH(String pattern) { return method(HttpMethod.PATCH).and(path(pattern)); }
@Override protected RouterFunction<?> routerFunction() { return RouterFunctions.route(RequestPredicates.path("/"), this::render); }
@Bean public RouterFunction<ServerResponse> testFunRouterFunction() { RouterFunction<ServerResponse> route = RouterFunctions.route( RequestPredicates.path("/testfun"), request -> ServerResponse.ok().body(BodyInserters.fromObject("hello"))); return route; }
@Bean public RouterFunction<ServerResponse> testWhenMetricPathIsNotMeet() { RouterFunction<ServerResponse> route = RouterFunctions.route( RequestPredicates.path("/actuator/metrics/gateway.requests"), request -> ServerResponse.ok().body(BodyInserters.fromObject(HELLO_FROM_FAKE_ACTUATOR_METRICS_GATEWAY_REQUESTS))); return route; }
@Test public void path() { URI uri = URI.create("http://localhost/path"); RequestPredicate predicate = RequestPredicates.path("/p*"); MockServerRequest request = MockServerRequest.builder().uri(uri).build(); assertTrue(predicate.test(request)); request = MockServerRequest.builder().build(); assertFalse(predicate.test(request)); }
@Test public void pathEncoded() { URI uri = URI.create("http://localhost/foo%20bar"); RequestPredicate predicate = RequestPredicates.path("/foo bar"); MockServerRequest request = MockServerRequest.builder().uri(uri).build(); assertTrue(predicate.test(request)); request = MockServerRequest.builder().build(); assertFalse(predicate.test(request)); }
@Override protected RouterFunction<?> routerFunction() { NestedHandler nestedHandler = new NestedHandler(); return nest(path("/foo/"), route(GET("/bar"), nestedHandler::pattern) .andRoute(GET("/baz"), nestedHandler::pattern)) .andNest(GET("/{foo}"), route(GET("/bar"), nestedHandler::variables).and( nest(GET("/{bar}"), route(GET("/{baz}"), nestedHandler::variables)))) .andRoute(path("/{qux}/quux").and(method(HttpMethod.GET)), nestedHandler::variables) .andRoute(all(), nestedHandler::variables); }
public RouterFunction<ServerResponse> routes() { return nest(path("/test"), route(POST("/helloWorld2").and(accept(APPLICATION_JSON)), this::postHandler) .and(route(POST("/helloWorld"), this::getHandler) .and(route(GET("/rewrite"), this::rewriteHandler)) .and(route(GET("/pdm"), this::pdmHttpGet)) .and(route(GET("/oms"), this::omsHttpGet)) .and(route(GET("/timeout"), this::testRetry)))); }
/** * Return a {@code RequestPredicate} that matches if request's HTTP method is {@code PATCH} and the given * {@code pattern} matches against the request path. * * @param pattern the path pattern to match against * @return a predicate that matches if the request method is PATCH and if the given pattern matches against the * request path */ public static RequestPredicate PATCH(String pattern) { return method(HttpMethod.PATCH).and(path(pattern)); }
/** * Return a {@code RequestPredicate} that matches if request's HTTP method is {@code DELETE} and the given * {@code pattern} matches against the request path. * * @param pattern the path pattern to match against * @return a predicate that matches if the request method is DELETE and if the given pattern matches against the * request path */ public static RequestPredicate DELETE(String pattern) { return method(HttpMethod.DELETE).and(path(pattern)); }
public RouterFunction<ServerResponse> routingFunction() { PersonRepository repository = new DummyPersonRepository(); PersonHandler handler = new PersonHandler(repository); return nest(path("/person"), nest(accept(APPLICATION_JSON), route(GET("/{id}"), handler::getPerson) .andRoute(method(HttpMethod.GET), handler::listPeople) ).andRoute(POST("/").and(contentType(APPLICATION_JSON)), handler::createPerson)); }