Improve HttpServiceClientAutoConfiguration conditions
See gh-18366 Co-authored-by: Phillip Webb <phil.webb@broadcom.com>
This commit is contained in:
committed by
Phillip Webb
parent
2ae354d6ec
commit
5bdb0ecbb4
@@ -73,10 +73,12 @@ public final class ClientHttpRequestFactories {
|
||||
private <P, T> T getProperty(Function<AbstractHttpRequestFactoryProperties, P> accessor, Function<P, T> extractor,
|
||||
Predicate<T> predicate) {
|
||||
for (AbstractHttpRequestFactoryProperties properties : this.orderedProperties) {
|
||||
P value = accessor.apply(properties);
|
||||
T extracted = (value != null) ? extractor.apply(value) : null;
|
||||
if (predicate.test(extracted)) {
|
||||
return extracted;
|
||||
if (properties != null) {
|
||||
P value = accessor.apply(properties);
|
||||
T extracted = (value != null) ? extractor.apply(value) : null;
|
||||
if (predicate.test(extracted)) {
|
||||
return extracted;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -73,10 +73,12 @@ public final class ClientHttpConnectors {
|
||||
private <P, T> T getProperty(Function<AbstractClientHttpConnectorProperties, P> accessor, Function<P, T> extractor,
|
||||
Predicate<T> predicate) {
|
||||
for (AbstractClientHttpConnectorProperties properties : this.orderedProperties) {
|
||||
P value = accessor.apply(properties);
|
||||
T extracted = (value != null) ? extractor.apply(value) : null;
|
||||
if (predicate.test(extracted)) {
|
||||
return extracted;
|
||||
if (properties != null) {
|
||||
P value = accessor.apply(properties);
|
||||
T extracted = (value != null) ? extractor.apply(value) : null;
|
||||
if (predicate.test(extracted)) {
|
||||
return extracted;
|
||||
}
|
||||
}
|
||||
}
|
||||
return null;
|
||||
|
||||
@@ -30,6 +30,7 @@ import org.springframework.boot.http.client.ClientHttpRequestFactorySettings;
|
||||
import org.springframework.boot.ssl.SslBundles;
|
||||
import org.springframework.boot.web.client.RestClientCustomizer;
|
||||
import org.springframework.context.annotation.Bean;
|
||||
import org.springframework.context.annotation.Conditional;
|
||||
import org.springframework.web.client.support.RestClientAdapter;
|
||||
import org.springframework.web.service.registry.HttpServiceProxyRegistry;
|
||||
import org.springframework.web.service.registry.ImportHttpServices;
|
||||
@@ -48,6 +49,7 @@ import org.springframework.web.service.registry.ImportHttpServices;
|
||||
@AutoConfiguration(after = { HttpClientAutoConfiguration.class, RestClientAutoConfiguration.class })
|
||||
@ConditionalOnClass(RestClientAdapter.class)
|
||||
@ConditionalOnBean(HttpServiceProxyRegistry.class)
|
||||
@Conditional(NotReactiveWebApplicationCondition.class)
|
||||
@EnableConfigurationProperties(HttpClientServiceProperties.class)
|
||||
public class HttpServiceClientAutoConfiguration implements BeanClassLoaderAware {
|
||||
|
||||
@@ -63,12 +65,13 @@ public class HttpServiceClientAutoConfiguration implements BeanClassLoaderAware
|
||||
|
||||
@Bean
|
||||
RestClientPropertiesHttpServiceGroupConfigurer restClientPropertiesHttpServiceGroupConfigurer(
|
||||
ObjectProvider<SslBundles> sslBundles, HttpClientProperties httpClientProperties,
|
||||
ObjectProvider<SslBundles> sslBundles, ObjectProvider<HttpClientProperties> httpClientProperties,
|
||||
HttpClientServiceProperties serviceProperties,
|
||||
ObjectProvider<ClientHttpRequestFactoryBuilder<?>> clientFactoryBuilder,
|
||||
ObjectProvider<ClientHttpRequestFactorySettings> clientHttpRequestFactorySettings) {
|
||||
return new RestClientPropertiesHttpServiceGroupConfigurer(this.beanClassLoader, sslBundles,
|
||||
httpClientProperties, serviceProperties, clientFactoryBuilder, clientHttpRequestFactorySettings);
|
||||
httpClientProperties.getIfAvailable(), serviceProperties, clientFactoryBuilder,
|
||||
clientHttpRequestFactorySettings);
|
||||
}
|
||||
|
||||
@Bean
|
||||
|
||||
@@ -0,0 +1,40 @@
|
||||
/*
|
||||
* Copyright 2012-2024 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
* You may obtain a copy of the License at
|
||||
*
|
||||
* https://www.apache.org/licenses/LICENSE-2.0
|
||||
*
|
||||
* Unless required by applicable law or agreed to in writing, software
|
||||
* distributed under the License is distributed on an "AS IS" BASIS,
|
||||
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
|
||||
* See the License for the specific language governing permissions and
|
||||
* limitations under the License.
|
||||
*/
|
||||
|
||||
package org.springframework.boot.autoconfigure.http.client.service;
|
||||
|
||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnWebApplication;
|
||||
import org.springframework.boot.autoconfigure.condition.NoneNestedConditions;
|
||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition;
|
||||
|
||||
/**
|
||||
* {@link SpringBootCondition} that applies only when running in a non-reactive web
|
||||
* application.
|
||||
*
|
||||
* @author Phillip Webb
|
||||
*/
|
||||
class NotReactiveWebApplicationCondition extends NoneNestedConditions {
|
||||
|
||||
NotReactiveWebApplicationCondition() {
|
||||
super(ConfigurationPhase.PARSE_CONFIGURATION);
|
||||
}
|
||||
|
||||
@ConditionalOnWebApplication(type = ConditionalOnWebApplication.Type.REACTIVE)
|
||||
private static final class ReactiveWebApplication {
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
@@ -29,6 +29,7 @@ import org.junit.jupiter.api.Test;
|
||||
import org.springframework.aop.Advisor;
|
||||
import org.springframework.boot.autoconfigure.AutoConfigurations;
|
||||
import org.springframework.boot.autoconfigure.http.client.reactive.ClientHttpConnectorAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.http.client.service.HttpServiceClientAutoConfiguration;
|
||||
import org.springframework.boot.autoconfigure.web.reactive.function.client.WebClientAutoConfiguration;
|
||||
import org.springframework.boot.http.client.HttpRedirects;
|
||||
import org.springframework.boot.http.client.reactive.ClientHttpConnectorBuilder;
|
||||
@@ -58,8 +59,9 @@ import static org.assertj.core.api.Assertions.assertThat;
|
||||
class ReactiveHttpServiceClientAutoConfigurationTests {
|
||||
|
||||
private final ReactiveWebApplicationContextRunner contextRunner = new ReactiveWebApplicationContextRunner()
|
||||
.withConfiguration(AutoConfigurations.of(ReactiveHttpServiceClientAutoConfiguration.class,
|
||||
ClientHttpConnectorAutoConfiguration.class, WebClientAutoConfiguration.class));
|
||||
.withConfiguration(AutoConfigurations.of(HttpServiceClientAutoConfiguration.class,
|
||||
ReactiveHttpServiceClientAutoConfiguration.class, ClientHttpConnectorAutoConfiguration.class,
|
||||
WebClientAutoConfiguration.class));
|
||||
|
||||
@Test
|
||||
void configuresClientFromProperties() {
|
||||
|
||||
Reference in New Issue
Block a user