Skip to content

RestClient requestInterceptor not invoked after Spring Boot upgrade. #34743

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
rpapeters opened this issue Apr 11, 2025 · 3 comments
Closed

RestClient requestInterceptor not invoked after Spring Boot upgrade. #34743

rpapeters opened this issue Apr 11, 2025 · 3 comments
Assignees
Labels
in: web Issues in web modules (web, webmvc, webflux, websocket) status: invalid An issue that we don't feel is valid

Comments

@rpapeters
Copy link

rpapeters commented Apr 11, 2025

Since upgrading Spring Boot from 3.3.x to 3.4.x (spring-web from 6.1.x to 6.2.x) any registered request interceptors are not invoked.

For example we have this RestClient:

        final var restClient = RestClient.builder()
                .baseUrl(integralityUrl + "/api")
                .requestInterceptor((HttpRequest request, byte[] body, ClientHttpRequestExecution execution) -> {
                    System.out.println("THIS WILL NOT BE EXECUTED");
                    return execution.execute(request, body);
                })
                .build();

        restClient.get().uri("/some-endpoint").retrieve();

In this example the requestInterceptor is never invoked.

When looking into the code of spring-web 6.1.18 and 6.2.0 there is a difference in the retrieve function:

6.1.18

        public RestClient.ResponseSpec retrieve() {
            RestClient.ResponseSpec responseSpec = (RestClient.ResponseSpec)this.exchangeInternal((x$0, x$1) -> {
                return DefaultRestClient.this.new DefaultResponseSpec(x$0, x$1);
            }, false);
            Assert.state(responseSpec != null, "No ResponseSpec");
            return responseSpec;
        }

this.exchangeInternal will invoke createRequest which will invoke the interceptors.

6.2.0

        public RestClient.ResponseSpec retrieve() {
            return DefaultRestClient.this.new DefaultResponseSpec(this);
        }

this.exchangeInternal is not invoked.

Is this a bug or should it be configured differently?

@spring-projects-issues spring-projects-issues added the status: waiting-for-triage An issue we've not yet triaged or decided on label Apr 11, 2025
@jhoeller jhoeller added the in: web Issues in web modules (web, webmvc, webflux, websocket) label Apr 11, 2025
@sbrannen sbrannen self-assigned this Apr 11, 2025
@sbrannen
Copy link
Member

Hi @rpapeters,

Congratulations on submitting your first issue for the Spring Framework! 👍

Is this a bug or should it be configured differently?

This change in behavior is to be expected.

See:

As documented in the HTTP clients section of the 6.2 release notes, you'll need to invoke a terminal operation on the ResponseSpec.

For example:

restClient.get().uri("/some-endpoint").retrieve().toBodilessEntity();

In light of the above, I am closing this issue.

@sbrannen sbrannen closed this as not planned Won't fix, can't repro, duplicate, stale Apr 11, 2025
@sbrannen sbrannen added status: invalid An issue that we don't feel is valid and removed status: waiting-for-triage An issue we've not yet triaged or decided on labels Apr 11, 2025
@taarh

This comment has been minimized.

@rpapeters
Copy link
Author

rpapeters commented Apr 11, 2025 via email

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
Projects
None yet
Development

No branches or pull requests

5 participants