Skip to content

Setting a RestTemplateBuilder read timeout results in an IllegalStateException due to deprecations in HttpComponentsClientHttpRequestFactory #32857

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

Closed
marcingrzejszczak opened this issue Oct 24, 2022 · 4 comments
Assignees
Labels
type: regression A regression from a previous release
Milestone

Comments

@marcingrzejszczak
Copy link
Contributor

In a project that has micrometer-tracing with Zipkin + RestTemplate and no WebClient dependency, ZipkinRestTemplateSender tries to hook in. The problem is that we're calling setReadTimeout via the RestTemplateBuilder's API. That in effect is calling org.springframework.http.client.HttpComponentsClientHttpRequestFactory#setReadTimeout which is deprecated and the application context fails to start.

Caused by: org.springframework.beans.BeanInstantiationException: Failed to instantiate [org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinRestTemplateSender]: Factory method 'restTemplateSender' threw exception with message: Request factory class org.springframework.http.client.HttpComponentsClientHttpRequestFactory has the setReadTimeout method marked as deprecated
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:171) ~[spring-beans-6.0.0-RC2.jar:6.0.0-RC2]
	at org.springframework.beans.factory.support.ConstructorResolver.instantiate(ConstructorResolver.java:648) ~[spring-beans-6.0.0-RC2.jar:6.0.0-RC2]
	... 203 common frames omitted
Caused by: java.lang.IllegalStateException: Request factory class org.springframework.http.client.HttpComponentsClientHttpRequestFactory has the setReadTimeout method marked as deprecated
	at org.springframework.boot.web.client.RestTemplateBuilder$RequestFactoryCustomizer.findMethod(RestTemplateBuilder.java:791) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
	at org.springframework.boot.web.client.RestTemplateBuilder$RequestFactoryCustomizer.setReadTimeout(RestTemplateBuilder.java:774) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
	at org.springframework.boot.web.client.RestTemplateBuilder$RequestFactoryCustomizer.accept(RestTemplateBuilder.java:746) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
	at org.springframework.boot.web.client.RestTemplateBuilder.buildRequestFactory(RestTemplateBuilder.java:663) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
	at org.springframework.boot.web.client.RestTemplateBuilder.configure(RestTemplateBuilder.java:621) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
	at org.springframework.boot.web.client.RestTemplateBuilder.build(RestTemplateBuilder.java:596) ~[spring-boot-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
	at org.springframework.boot.actuate.autoconfigure.tracing.zipkin.ZipkinConfigurations$RestTemplateSenderConfiguration.restTemplateSender(ZipkinConfigurations.java:82) ~[spring-boot-actuator-autoconfigure-3.0.0-SNAPSHOT.jar:3.0.0-SNAPSHOT]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:na]
	at java.base/jdk.internal.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:77) ~[na:na]
	at java.base/jdk.internal.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:na]
	at java.base/java.lang.reflect.Method.invoke(Method.java:568) ~[na:na]
	at org.springframework.beans.factory.support.SimpleInstantiationStrategy.instantiate(SimpleInstantiationStrategy.java:139) ~[spring-beans-6.0.0-RC2.jar:6.0.0-RC2]
	... 204 common frames omitted


Process finished with exit code 1

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Oct 24, 2022
@wilkinsona wilkinsona added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 24, 2022
@wilkinsona wilkinsona added this to the 3.0.x milestone Oct 24, 2022
@wilkinsona
Copy link
Member

We're apparently missing a test as this has been broken since Framework 6.0.0-RC1 due to the changes for spring-projects/spring-framework#28925.

@wilkinsona wilkinsona added status: waiting-for-triage An issue we've not yet triaged and removed type: regression A regression from a previous release labels Oct 24, 2022
@wilkinsona wilkinsona removed this from the 3.0.x milestone Oct 24, 2022
@wilkinsona
Copy link
Member

The exception is intentional due to these changes. I'm not sure what we can do about this. It feels rather similar to #31496.

@mhalbritter
Copy link
Contributor

Yeah, I agree. I tend to just drop the setReadTimeout in ZipkinConfigurations.RestTemplateSenderConfiguration as there's currently no way from framework side to set that for all possible http clients.

@wilkinsona
Copy link
Member

HttpWebServiceMessageSenderBuilder is also affected so I think we're going to have to try to do something.

@wilkinsona wilkinsona self-assigned this Oct 24, 2022
@philwebb philwebb added type: regression A regression from a previous release and removed status: waiting-for-triage An issue we've not yet triaged labels Oct 24, 2022
@philwebb philwebb added this to the 3.0.x milestone Oct 24, 2022
@philwebb philwebb changed the title RestTemplateBuilder fails on using deprecated API Setting a RestTemplateBuilder read timeout results in an IllegalStateException due to deprecations in HttpComponentsClientHttpRequestFactory Oct 25, 2022
@philwebb philwebb modified the milestones: 3.0.x, 3.0.0-RC2 Oct 25, 2022
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: regression A regression from a previous release
Projects
None yet
Development

No branches or pull requests

5 participants