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

WebClient no longer encodes query parameters [SPR-17532] #22064

Closed
spring-issuemaster opened this issue Nov 22, 2018 · 1 comment
Closed

WebClient no longer encodes query parameters [SPR-17532] #22064

spring-issuemaster opened this issue Nov 22, 2018 · 1 comment
Assignees

Comments

@spring-issuemaster
Copy link
Collaborator

@spring-issuemaster spring-issuemaster commented Nov 22, 2018

ShaManHFel opened SPR-17532 and commented

The following sample code used to work in 5.0.8 but stopped working in 5.1.2:

 

WebClient.builder()
.baseUrl("https://www.google.com")
.build()
.get()
.uri(builder -> builder
.path("search")
*.queryParam("q", "some spaces in the value")*
.build())
.retrieve()
.bodyToMono(String.class)
.block();{color}

 

In 5.0.8 the result from this code was the following call:

GET /search?q=some%20spaces%20in%20the%20value HTTP/1.1
user-agent: ReactorNetty/0.7.8.RELEASE
host: [www.google.com](http://www.google.com/)

In 5.1.2 the result is:

Exception in thread "main" java.lang.IllegalArgumentException: Illegal character in query at index 36: https://www.google.com/search?q=some spaces in the value
at java.net.URI.create(URI.java:852)
at org.springframework.web.util.DefaultUriBuilderFactory$DefaultUriBuilder.createUri(DefaultUriBuilderFactory.java:391)
at org.springframework.web.util.DefaultUriBuilderFactory$DefaultUriBuilder.build(DefaultUriBuilderFactory.java:384)
at com.vmware.identity.SpringBug.lambda$main$0(SpringBug.java:19)
at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.uri(DefaultWebClient.java:189)
at org.springframework.web.reactive.function.client.DefaultWebClient$DefaultRequestBodyUriSpec.uri(DefaultWebClient.java:153)
at com.vmware.identity.SpringBug.main(SpringBug.java:16)
Caused by: java.net.URISyntaxException: Illegal character in query at index 36: https://www.google.com/search?q=some spaces in the value
at java.net.URI$Parser.fail(URI.java:2848)
at java.net.URI$Parser.checkChars(URI.java:3021)
at java.net.URI$Parser.parseHierarchical(URI.java:3111)
at java.net.URI$Parser.parse(URI.java:3053)
at java.net.URI.<init>(URI.java:588)
at java.net.URI.create(URI.java:850)
... 6 more

As evident from the error, the queryParam() method no longer encodes the query parameter values. This seems to be caused by a change in DefaultUriBuilderFactory where the default encoding mode was changed ``to EncodingMode.TEMPLATE_AND_VALUES.


Affects: 5.1.2

Issue Links:

  • #21997 WebClient's UriBuilder option should encode path parameters passed into build ("duplicates")
@spring-issuemaster

This comment has been minimized.

Copy link
Collaborator Author

@spring-issuemaster spring-issuemaster commented Nov 23, 2018

Rossen Stoyanchev commented

This is another variation on the same root cause as #21997. It works as expected with the current 5.1.3 snapshots.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Projects
None yet
2 participants
You can’t perform that action at this time.