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

Consider using a configured WebClient in the application context instead of creating a new one on each component #16549

Open
dlemoing opened this issue Feb 7, 2025 · 0 comments
Labels
status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement

Comments

@dlemoing
Copy link

dlemoing commented Feb 7, 2025

Context

When using Spring Gateway with Spring Security on GCP, I have to connect to an external Identity Provider. The problem is that the connections are closed by the NAT. One solution is to configure the connection pool. For this, I am using this configuration:

spring:
    cloud:
        gateway:
            httpclient:
                pool:
                    eviction-interval: 1m
                    max-idle-time: 1m
                    max-life-time: 5m

The configuration creates a HttpClient that can be used to configure a WebClient:

@Bean
WebClient webClient(HttpClient httpClient) {
    return WebClient.builder()
        .clientConnector(new ReactorClientHttpConnector(httpClient))
        .build();
}

Current Behavior

Unfortunately, the WebClient is never used "automatically" by the autoconfiguration and in some cases, you are even forced to reimplement some interfaces just to make it possible to share the WebClient:

    @Bean
    ReactiveOAuth2AccessTokenResponseClient<OAuth2AuthorizationCodeGrantRequest> accessTokenResponseClient(WebClient webClient) {
        var authorizationCodeTokenResponseClient = new WebClientReactiveAuthorizationCodeTokenResponseClient();
        // the WebClient in the application context is not set automatically
        authorizationCodeTokenResponseClient.setWebClient(webClient);
        return authorizationCodeTokenResponseClient;
    }

    @Bean
    ReactiveJwtDecoderFactory<ClientRegistration> jwtDecoderFactory(WebClient webClient) {
        // I had to replace the ReactiveOidcIdTokenDecoderFactory to be able to set a configured WebClient
        return new JwtDecoderFactory(webClient);
    }
    ...

Expected Behavior

When a WebClient is in the application context, it should be used by the auto configuration.

Additionally, the factories should be able to fully configure the created beans. This is not the case of the ReactiveOidcIdTokenDecoderFactory which cannot be configured with a WebClient and force NimbusReactiveJwtDecoder to create a new one.

@dlemoing dlemoing added status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement labels Feb 7, 2025
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
status: waiting-for-triage An issue we've not yet triaged type: enhancement A general enhancement
Projects
None yet
Development

No branches or pull requests

1 participant