Skip to content

MockRestServiceServer to prevent override of ClientHttpRequestFactory in RestClient.Builder #34013

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
rstoyanchev opened this issue Dec 3, 2024 · 1 comment
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid type: enhancement A general enhancement

Comments

@rstoyanchev
Copy link
Contributor

One of the cases in #32338 relates to MockRestServiceServer setting a mock request factory on RestClient.Builder. If that same builder is then passed into an application component that wants to customize the request factory (related to production), it ends up replacing the mock request factory.

It's reasonable to assume that if a RestClient.Builder is passed into MockRestServiceServer then the changes to the request factory should stick, and any further changes can be a no-op.

@rstoyanchev
Copy link
Contributor Author

rstoyanchev commented Jan 10, 2025

On closer look, MockRestServiceServer can't prevent the request factory from being replaced.

Looking back at spring-projects/spring-boot#38832 the goal was to make a global switch from HttpURLConnection to JDK HttpClient, but using the most narrow approach for customization. Therefore the recommendation in spring-projects/spring-boot#38832 (comment) to use a RestClientCustomizer is the more appropriate way to do it for a start.

This case is also very specifically linked to making a choice between two out-of-the-box options in the JDK, and should not be an issue for other client libraries where classpath detection should work fine.

That said the issue was closed in favor of spring-projects/spring-boot#36266 and as of 3.4 there is a first-class way to select the request factory at the earliest point of initialization through an application property:

spring.http.client.factory=jdk

@rstoyanchev rstoyanchev closed this as not planned Won't fix, can't repro, duplicate, stale Jan 10, 2025
@rstoyanchev rstoyanchev removed this from the 7.0.0-M1 milestone Jan 10, 2025
@rstoyanchev rstoyanchev added the status: invalid An issue that we don't feel is valid label Jan 10, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant