spring-framework icon indicating copy to clipboard operation
spring-framework copied to clipboard

WebFlux equivalent of MvcUriComponentsBuilder [SPR-15953]

Open spring-projects-issues opened this issue 8 years ago • 10 comments

Arjen Poutsma opened SPR-15953 and commented

We could use a WebFluxUriComponentsBuilder that has similar functionality as the ServletUriComponentsBuilder,

An additional method that WebFluxUriComponentsBuilder should have is fromServerRequest, taking a ServerRequest from WebFlux.fn, as that type does not implement HttpRequest, and therefore cannot be used with UriComponentsBuilder.fromHttpRequest.


Issue Links:

  • #20485 ReactorServerHttpRequest.getUri() does not include scheme
  • #20546 WebFlux support for UriBuilder, UriComponentsBuilder controller method arguments

Referenced from: commits https://github.com/spring-projects/spring-framework/commit/1a3cc3df94c0f8e504f36e9be8e6f2ded5a12750, https://github.com/spring-projects/spring-framework/commit/a7617a264120ca486d7c92bb4255ec1ac3ef986e

spring-projects-issues avatar Sep 12 '17 15:09 spring-projects-issues

Rossen Stoyanchev commented

ServerRequestUriComponentsBuilder has methods to build from a request instance. Considering that UriComponentsBuilder.fromHttpRequest already exists what else would WebFluxUriComponentsBuilder have besides a fromServerRequest(ServerRequest) method?

Note that we will also need an equivalent of MvcUriComponentsBuilder where the name WebFluxUriComponentsBuilder would be a good fit.

spring-projects-issues avatar Sep 13 '17 12:09 spring-projects-issues

Rossen Stoyanchev commented

An alternative idea is something like ServerRequest.relativeToRequestUri returning UriComponentsBuilder.

spring-projects-issues avatar Sep 13 '17 13:09 spring-projects-issues

Arjen Poutsma commented

Initial version committed at https://github.com/spring-projects/spring-framework/commit/a7617a264120ca486d7c92bb4255ec1ac3ef986e.

As discussed, Rossen Stoyanchev will add subsequent @Controller-related methods.

spring-projects-issues avatar Sep 15 '17 12:09 spring-projects-issues

Rossen Stoyanchev commented

Arjen Poutsma taking a quick look, for WebFluxUriComponentsBuilder to have @Controller methods its current location could be an issue. MvcUriComponentsBuilder by comparison in is in the same package as all the other annotation related classes. Even if we don't run into circular dependencies, arguably such a builder should be in the annotations package. Also I can't imagine that using such a WebFluxUriComponentsBuilder from the functional framework -- with a ton of @Controller methods and only 1 for ServerRequest, is ideal.

Since what is needed for ServerRequest is a trivial one-liner, could we find another solution perhaps? ServerRequest has a uri() method. What about a uriComponentsBuilder next to it?

spring-projects-issues avatar Sep 21 '17 13:09 spring-projects-issues

Arjen Poutsma commented

??Since what is needed for ServerRequest is a trivial one-liner, could we find another solution perhaps? ServerRequest has a uri() method. What about a uriComponentsBuilder next to it???

That sounds like a good idea. I will move the method from WebFluxUriComponentsBuilder to ServerRequest, and remove WebFluxUriComponentsBuilder altogether.

spring-projects-issues avatar Sep 25 '17 08:09 spring-projects-issues

Arjen Poutsma commented

Done, see https://github.com/spring-projects/spring-framework/commit/1a3cc3df94c0f8e504f36e9be8e6f2ded5a12750

spring-projects-issues avatar Sep 25 '17 09:09 spring-projects-issues

Rossen Stoyanchev commented

Now that ServerRequest has an option and #20546 adds the same controllers methods, this is less critical for 5.0 GA. I'm postponing for 5.1.

spring-projects-issues avatar Sep 25 '17 20:09 spring-projects-issues

Closing, as I don't think we need this anymore.

poutsma avatar Jan 29 '19 15:01 poutsma

Spring HATEOAS, which is currently coding reactor support, could use it.

gregturn avatar Jan 29 '19 15:01 gregturn

Without this functionality, is there any way to generate URIs based on controller methods? From @poutsma's comment I assumed the functionality of MvcUriComponentsBuilder would be replicated by the additions that were made in bdde0f1 and 1a3cc3d, but it doesn't seem that way. If a UriComponentsBuilder is injected as an argument to a handler method, there is still no reliable way to construct a link with that to another method on a controller, the way MvcUriComponentsBuilder#fromMethod does.

treuherz avatar Jul 29 '19 14:07 treuherz