Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

UriComponentsBuilder controller method argument has no path #25822

Closed
EtienneMiret opened this issue Sep 26, 2020 · 1 comment
Closed

UriComponentsBuilder controller method argument has no path #25822

EtienneMiret opened this issue Sep 26, 2020 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Milestone

Comments

@EtienneMiret
Copy link

Affects: Spring WebFlux 5.2.9

From the documentation about Spring WebFlux controller annotated method arguments:

UriComponentsBuilder | For preparing a URL relative to the current request’s host, port, scheme, and path.

When reading this, I understood that the injected builder would include the full path to my controller method, which seemed confirmed by #20546 stating that an injected builder should behave like UriComponentsBuilder.fromHttpRequest(request).

However, when building a war that is deployed to tomcat 9.0.27 under the application context "/context":

@Controller
@RequestMapping ("/controller")
public class MyController {

  private static final Logger logger = LoggerFactory.getLogger (MyController.class);

  @GetMapping ("/method")
  public void method (
      UriComponentsBuilder builder,
      ServerHttpRequest request
  ) {
   logger.info ("Injected: {}", builder.build (emptyMap ())); // -> http://localhost:8080/
   logger.info ("Constructed: {}", UriComponentsBuilder.fromHttpRequest (request).build (emptyMap ())); // -> http://localhost:8080/context/controller/method
  }
}

Note that I’m fine if the spec changed after #20546 was drafted. The documentation however should be updated.

Interestingly, answers to #21449 state that the injected builder should be "application relative". My understanding of this sentence is that it should include the application context path, but not the controller path. This would have been exactly what I need, but isn’t what I see.

I haven’t tested what happens with non-reactive controllers. Obviously, we want the behavior to match in all three places:

  • WebFlux
  • Web MVC
  • latest documentation.
@EtienneMiret EtienneMiret changed the title UriComponentsBuilder controller method arguments has no path UriComponentsBuilder controller method argument has no path Sep 26, 2020
@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Sep 26, 2020
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Sep 27, 2020
@rstoyanchev rstoyanchev self-assigned this Oct 15, 2020
@rstoyanchev rstoyanchev added type: bug A general bug and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Oct 15, 2020
@rstoyanchev rstoyanchev added this to the 5.3 GA milestone Oct 15, 2020
@rstoyanchev
Copy link
Contributor

Thanks for pointing this out. The intent with #21353 was to align with Spring MVC which uses ServletUriComponentsBuilder#fromServletMapping and the docs there do say:

For preparing a URL relative to the current request’s host, port, scheme, context path, and the literal part of the servlet mapping

So to align all 3 I'll make sure the path in WebFlux is application relative.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: bug A general bug
Projects
None yet
Development

No branches or pull requests

4 participants