-
Notifications
You must be signed in to change notification settings - Fork 1.1k
GH-3154: Support UriBuilderFactory.EncodingMode
#3162
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
Conversation
Fixes spring-projects#3154 Spring Framework now provides a `DefaultUriBuilderFactory.EncodingMode` for encoding URIs in the `RestTemplate` before and after uri template enrichment with uri variables. Therefore `encodeUri` and manual uri variables substitution is not necessary in Spring Integration HTTP components * Deprecate `AbstractHttpRequestExecutingMessageHandler.encodeUri` in favor of `DefaultUriBuilderFactory.EncodingMode` and respective configuration on the `RestTemplate` in HTTP module and `WebClient` in WebFlux module
UriBuilderFactory.EncodingMode
UriBuilderFactory.EncodingMode
TODO:
Will address them lately, but you can review now. Thanks |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
A few issues/questions.
@@ -118,6 +115,7 @@ | |||
public AbstractHttpRequestExecutingMessageHandler(Expression uriExpression) { | |||
Assert.notNull(uriExpression, "URI Expression is required"); | |||
this.uriExpression = uriExpression; | |||
this.uriFactory.setEncodingMode(DefaultUriBuilderFactory.EncodingMode.TEMPLATE_AND_VALUES); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why is this needed? This is the default.
@@ -85,6 +82,8 @@ | |||
private static final List<HttpMethod> NO_BODY_HTTP_METHODS = | |||
Arrays.asList(HttpMethod.GET, HttpMethod.HEAD, HttpMethod.TRACE); | |||
|
|||
DefaultUriBuilderFactory uriFactory = new DefaultUriBuilderFactory(); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why package visibility?
Why not UriBuilderFactory
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
The UriBuilderFactory
doesn't have a setEncodingMode()
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
and package?
* @param encodingMode the mode to use for uri encoding | ||
* @since 5.3 | ||
*/ | ||
public void setEncodingMode(DefaultUriBuilderFactory.EncodingMode encodingMode) { |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Why not setUriBuilderFactory
?
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Right. I'm going to document that for more complex scenarios it would be better to configure an external RestTemplate
and already use its setUriTemplateHandler()
.
I would even go with all the RestTempalte
options as an external reference. I'm not a fun of mutating internal objects.
But that would be too drastic even in the point release...
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Ok, makes sense; proceed with the remaining work 😄
* Ensure in tests that `encoding-mode` is populated properly into an internal `RestTemplate` * Clean up affected HTTP tests for AssertJ and JUnit 5
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler); | ||
assertThat(handlerAccessor.getPropertyValue("expectReply")).isEqualTo(false); | ||
assertThat(endpointAccessor.getPropertyValue("inputChannel")) | ||
.isEqualTo(this.applicationContext.getBean("requests")); | ||
assertThat(handlerAccessor.getPropertyValue("outputChannel")).isNull(); | ||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate")); | ||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate" | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Unusual formatting.
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler); | ||
assertThat(handlerAccessor.getPropertyValue("expectReply")).isEqualTo(false); | ||
assertThat(endpointAccessor.getPropertyValue("inputChannel")) | ||
.isEqualTo(this.applicationContext.getBean("requests")); | ||
assertThat(handlerAccessor.getPropertyValue("outputChannel")).isNull(); | ||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate")); | ||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate" | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Here too.
DirectFieldAccessor handlerAccessor = new DirectFieldAccessor(handler); | ||
assertThat(handlerAccessor.getPropertyValue("expectReply")).isEqualTo(false); | ||
assertThat(endpointAccessor.getPropertyValue("inputChannel")) | ||
.isEqualTo(this.applicationContext.getBean("requests")); | ||
assertThat(handlerAccessor.getPropertyValue("outputChannel")).isNull(); | ||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate")); | ||
DirectFieldAccessor templateAccessor = new DirectFieldAccessor(handlerAccessor.getPropertyValue("restTemplate" | ||
)); |
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
And here
* Add docs for new `encoding-mode` option
UriBuilderFactory.EncodingMode
UriBuilderFactory.EncodingMode
|
Fixes #3154
Spring Framework now provides a
DefaultUriBuilderFactory.EncodingMode
for encoding URIs in the
RestTemplate
before and after uri templateenrichment with uri variables.
Therefore
encodeUri
and manual uri variables substitution is not necessaryin Spring Integration HTTP components
AbstractHttpRequestExecutingMessageHandler.encodeUri
in favor ofDefaultUriBuilderFactory.EncodingMode
and respective configurationon the
RestTemplate
in HTTP module andWebClient
in WebFlux module