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

Using a URI variable for port in WebClient causes an IllegalStateException #32003

Closed
lkleeven opened this issue Jan 10, 2024 · 1 comment
Closed
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) type: regression A bug that is also a regression
Milestone

Comments

@lkleeven
Copy link

lkleeven commented Jan 10, 2024

Affects: 6.1.2

In Spring Framework 6.1.1, the following little code snippet worked without any problems:

var uriSpec = WebClient.create()
            .get()
            .uri("http://localhost:{port}/first", 8080);

Now this same code causes the following IllegalStateException:

java.lang.IllegalStateException: The port contains a URI variable but has not been expanded yet: {port}

	at org.springframework.web.util.HierarchicalUriComponents.getPort(HierarchicalUriComponents.java:193)
	at org.springframework.web.util.HierarchicalUriComponents.toUriString(HierarchicalUriComponents.java:488)
	at org.springframework.web.util.DefaultUriBuilderFactory$DefaultUriBuilder.toUriString(DefaultUriBuilderFactory.java:416)
	at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.uri(DefaultWebClient.java:230)
	at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.uri(DefaultWebClient.java:199)

This seems related to the changes made in #30027 and the already mentioned #31882.

Is this a bug, or are we no longer allowed to use URI variables inside the base URL?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Jan 10, 2024
@sbrannen sbrannen changed the title Using a URI variable for port in WebClient causes an IllegalStateException Using a URI variable for port in WebClient causes an IllegalStateException Jan 10, 2024
@sbrannen sbrannen added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Jan 10, 2024
@rstoyanchev rstoyanchev self-assigned this Jan 10, 2024
@rstoyanchev rstoyanchev added type: regression A bug that is also a regression and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Jan 10, 2024
@rstoyanchev rstoyanchev added this to the 6.1.3 milestone Jan 10, 2024
@rstoyanchev
Copy link
Contributor

Thanks for the report. This is a regression as a result of the changes for #30027. The assumption there was that toUriString in HierarchicalUriComponents is just simple concatenation, but it's not the case for the port, which attempts to parse.

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: regression A bug that is also a regression
Projects
None yet
Development

No branches or pull requests

4 participants