|
1 | 1 | /*
|
2 |
| - * Copyright 2002-2019 the original author or authors. |
| 2 | + * Copyright 2002-2022 the original author or authors. |
3 | 3 | *
|
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License");
|
5 | 5 | * you may not use this file except in compliance with the License.
|
|
28 | 28 | import org.springframework.core.ParameterizedTypeReference;
|
29 | 29 | import org.springframework.http.HttpMethod;
|
30 | 30 | import org.springframework.http.HttpStatus;
|
| 31 | +import org.springframework.http.MediaType; |
31 | 32 | import org.springframework.http.ResponseEntity;
|
32 | 33 | import org.springframework.http.server.reactive.HttpHandler;
|
33 | 34 | import org.springframework.stereotype.Controller;
|
|
44 | 45 |
|
45 | 46 | import static org.assertj.core.api.Assertions.assertThat;
|
46 | 47 | import static org.springframework.web.reactive.function.BodyInserters.fromPublisher;
|
| 48 | +import static org.springframework.web.reactive.function.server.RequestPredicates.accept; |
47 | 49 | import static org.springframework.web.reactive.function.server.RouterFunctions.nest;
|
48 | 50 | import static org.springframework.web.reactive.function.server.RouterFunctions.route;
|
49 | 51 |
|
@@ -122,6 +124,15 @@ void attributes(HttpServer httpServer) throws Exception {
|
122 | 124 | assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK);
|
123 | 125 | }
|
124 | 126 |
|
| 127 | + @ParameterizedHttpServerTest |
| 128 | + void nested(HttpServer httpServer) throws Exception { |
| 129 | + startServer(httpServer); |
| 130 | + |
| 131 | + ResponseEntity<String> result = this.restTemplate |
| 132 | + .getForEntity("http://localhost:" + this.port + "/foo/bar", String.class); |
| 133 | + |
| 134 | + assertThat(result.getStatusCode()).isEqualTo(HttpStatus.OK); |
| 135 | + } |
125 | 136 |
|
126 | 137 | @EnableWebFlux
|
127 | 138 | @Configuration
|
@@ -157,6 +168,17 @@ public RouterFunction<ServerResponse> attributesRouterFunction(AttributesHandler
|
157 | 168 | return nest(RequestPredicates.GET("/attributes"),
|
158 | 169 | route(RequestPredicates.GET("/{foo}"), attributesHandler::attributes));
|
159 | 170 | }
|
| 171 | + |
| 172 | + @Bean |
| 173 | + public RouterFunction<ServerResponse> nested() { |
| 174 | + return route() |
| 175 | + .path("/foo", () -> route() |
| 176 | + .nest(accept(MediaType.APPLICATION_JSON), builder -> builder |
| 177 | + .GET("/bar", request -> ServerResponse.ok().build())) |
| 178 | + .build()) |
| 179 | + .build(); |
| 180 | + } |
| 181 | + |
160 | 182 | }
|
161 | 183 |
|
162 | 184 |
|
|
0 commit comments