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

Java system properties can not be applied to RestTemplate HttpClient connection in some cases #35815

Closed
alex-kormukhin opened this issue Jun 9, 2023 · 4 comments
Assignees
Labels
type: bug A general bug
Milestone

Comments

@alex-kormukhin
Copy link

alex-kormukhin commented Jun 9, 2023

Spring boot 3.1.0 RestTemplateBuilder with apache HTTP client in classpath (org.apache.httpcomponents.client5:httpclient5) ignore java system HTTP proxy command line options like -Dhttp.proxyHost=127.0.0.1 -Dhttp.proxyPort=8888.

Spring boot before 3.1 respects such settings.

For simple RestTemplate restTemplate = restTemplateBuilder.build() spring boot 2.7 instantiate HttpComponentsClientHttpRequestFactory via default constructor, which create HTTP client as HttpClients.createSystem(), i.e. with system proxy support.

image

Spring boot 3.0 (if readTimeout duration is not set) also create HttpComponentsClientHttpRequestFactory via default constructor and HTTP client as HttpClients.createSystem().

image

But spring boot 3.1 create HTTP client as HttpClientBuilder.create().setConnectionManager(connectionManager).build(). Without useSystemProperties() as HttpClients.createSystem() makes.

image

Suggestion: add useSystemProperties() to createHttpClient method like this

return HttpClientBuilder.create()
    .useSystemProperties()
    .setConnectionManager(connectionManager)
    .build();

For compatibility with spring boot 2.x, 3.0, and core spring HttpComponentsClientHttpRequestFactory.

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged label Jun 9, 2023
@scottfrederick
Copy link
Contributor

scottfrederick commented Jun 9, 2023

While it does appear that behavior changed with 3.1 in this regard, the fact that previous releases allowed system properties to be applied in some cases but not others (for example, when readTimeout is set) doesn't seem right to me. We might want to address this in earlier versions, and make sure that system properties can be applied in all cases.

Marking this for team attention to see what other think.

@scottfrederick scottfrederick added the for: team-attention An issue we'd like other members of the team to review label Jun 9, 2023
@mhalbritter
Copy link
Contributor

I agree with you Scott. We should restore old behavior and fix the inconsistencies in earlier versions.

@scottfrederick scottfrederick added type: bug A general bug and removed for: team-attention An issue we'd like other members of the team to review status: waiting-for-triage An issue we've not yet triaged labels Jun 13, 2023
@scottfrederick scottfrederick added this to the 2.7.x milestone Jun 13, 2023
@scottfrederick scottfrederick changed the title RestTemplateBuilder with apache HTTP client ignore java system HTTP proxy settings now Java system properties can not be applied to RestTemplate HttpClient connection in some cases Jun 13, 2023
@scottfrederick scottfrederick modified the milestones: 2.7.x, 3.0.x Jun 14, 2023
@scottfrederick scottfrederick self-assigned this Jun 14, 2023
@p-palanisami
Copy link

I am new to Open Source Contributor. Shall i work on this issue?

@wilkinsona
Copy link
Member

Thanks for the offer, @p-palanisami, but this issue is already assigned to @scottfrederick. I'm not sure if we have any at the moment, but please keep an eye out for unassigned issues labelled with ideal for contribution or, as your haven't contributed before, first-timers only.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
type: bug A general bug
Projects
None yet
Development

No branches or pull requests

6 participants