webClient build url wrong when using UriBuilder [probably a bug]

See original GitHub issue

affects

path = "http://a.b/c";
webClient = WebClient.builder().build();
webClient.get()
        .uri(uriBuilder -> uriBuilder.path(path).queryParams(myMutliValuedMapParams).build());

uri becomes: “http:/a.b/c”, the double slash after schema becomes a single slash. And results in an java.net.UnknownHostException: http: But webClient.get().uri(path); does not have the same problem.

possible reason

UriComponentsBuilder.java buildInternal function causes the problem. the var uric is wrong.


private UriComponents buildInternal(EncodingHint hint) {
		UriComponents result;
		if (this.ssp != null) {
			result = new OpaqueUriComponents(this.scheme, this.ssp, this.fragment);
		}
		else {
// The PROBLEM: 
			HierarchicalUriComponents uric = new HierarchicalUriComponents(this.scheme, this.fragment,
					this.userInfo, this.host, this.port, this.pathBuilder.build(), this.queryParams,
					hint == EncodingHint.FULLY_ENCODED); 

			result = hint == EncodingHint.ENCODE_TEMPLATE ? uric.encodeTemplate(this.charset) : uric;
		}
		if (!this.uriVariables.isEmpty()) {
			result = result.expand(name -> this.uriVariables.getOrDefault(name, UriTemplateVariables.SKIP_VALUE));
		}
		return result;
	}

version

spring-web-5.1.8.RELEASE

Issue Analytics

  • State:closed
  • Created 3 years ago
  • Comments:5 (3 by maintainers)

github_iconTop GitHub Comments

1reaction
bclozelcommented, Jan 26, 2022

I believe the : character is illegal in path segment. Maybe this section of the reference documentation on URL encoding is of interest?

0reactions
bclozelcommented, Jan 27, 2022

@miguel-botelho I understand now - we are indeed sanitizing the path and removing duplicate"/". This is a long standing behavior and I’m not sure we can easily change this now. Feel free to create a new issue, giving as much background information about this use case: why APIs are requiring this format, how common they are (any public one is a plus) and also the limitations of this approach as explained in the RFC.

Read more comments on GitHub >

github_iconTop Results From Across the Web

webflux constructs incorrect URL value - java - Stack Overflow
You are building a RestClient with a gateway base url: WebClient.Builder builder = WebClient.builder().baseUrl(gatewayUrl);.
Read more >
Spring Boot WebClient Cheat Sheet | by Stanislav Vain
The first and easiest is to create a client with default settings. With this method, you can also configure the base URL.
Read more >
[Solved]-how to log Spring 5 WebClient call-Springboot
You can easily do it using ExchangeFilterFunction. Just add the custom logRequest filter when you create your WebClient using WebClient.Builder .
Read more >
Chapter 9. Issues Resolved in Fuse 7.0
9.1. Apache Karaf container issues resolved in Fuse 7.0 ; KARAF-1150. admin:create command creates broken org.ops4j.pax.url.mvn.cfg file ; KARAF-1154. Upgrade to ...
Read more >
Avoiding memory leaks with Spring Boot WebClient | bol.com
We've mentioned in the introduction, that by simply not using a URI builder to construct WebClient URLs, you can avoid this memory leak....
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found