14 changed files with 82 additions and 594 deletions
@ -1,40 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-present 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.http.client.autoconfigure.service; |
|
||||||
|
|
||||||
import java.lang.annotation.Documented; |
|
||||||
import java.lang.annotation.ElementType; |
|
||||||
import java.lang.annotation.Retention; |
|
||||||
import java.lang.annotation.RetentionPolicy; |
|
||||||
import java.lang.annotation.Target; |
|
||||||
|
|
||||||
import org.springframework.context.annotation.Conditional; |
|
||||||
|
|
||||||
/** |
|
||||||
* {@link Conditional @Conditional} that matches when one or more HTTP Service bean has |
|
||||||
* been registered. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
* @since 4.0.0 |
|
||||||
*/ |
|
||||||
@Target({ ElementType.TYPE, ElementType.METHOD }) |
|
||||||
@Retention(RetentionPolicy.RUNTIME) |
|
||||||
@Documented |
|
||||||
@Conditional(OnMissingHttpServiceProxyBeanCondition.class) |
|
||||||
public @interface ConditionalOnMissingHttpServiceProxyBean { |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,73 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-present 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.http.client.autoconfigure.service; |
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory; |
|
||||||
import org.springframework.beans.factory.HierarchicalBeanFactory; |
|
||||||
import org.springframework.beans.factory.config.BeanDefinition; |
|
||||||
import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionMessage; |
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionOutcome; |
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnJava; |
|
||||||
import org.springframework.boot.autoconfigure.condition.SpringBootCondition; |
|
||||||
import org.springframework.context.annotation.Condition; |
|
||||||
import org.springframework.context.annotation.ConditionContext; |
|
||||||
import org.springframework.context.annotation.ConfigurationCondition; |
|
||||||
import org.springframework.core.type.AnnotatedTypeMetadata; |
|
||||||
|
|
||||||
/** |
|
||||||
* {@link Condition} that checks for any HTTP Service proxy bean. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
* @see ConditionalOnJava |
|
||||||
*/ |
|
||||||
class OnMissingHttpServiceProxyBeanCondition extends SpringBootCondition implements ConfigurationCondition { |
|
||||||
|
|
||||||
static final String HTTP_SERVICE_GROUP_NAME_ATTRIBUTE = "httpServiceGroupName"; |
|
||||||
|
|
||||||
@Override |
|
||||||
public ConfigurationPhase getConfigurationPhase() { |
|
||||||
return ConfigurationPhase.REGISTER_BEAN; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
public ConditionOutcome getMatchOutcome(ConditionContext context, AnnotatedTypeMetadata metadata) { |
|
||||||
ConditionMessage.Builder message = ConditionMessage |
|
||||||
.forCondition(ConditionalOnMissingHttpServiceProxyBean.class); |
|
||||||
BeanFactory beanFactory = context.getBeanFactory(); |
|
||||||
while (beanFactory != null) { |
|
||||||
if (beanFactory instanceof ConfigurableListableBeanFactory configurableListableBeanFactory |
|
||||||
&& hasHttpServiceProxyBeanDefinition(configurableListableBeanFactory)) { |
|
||||||
return ConditionOutcome.noMatch(message.foundExactly("HTTP Service proxy bean")); |
|
||||||
} |
|
||||||
beanFactory = (beanFactory instanceof HierarchicalBeanFactory hierarchicalBeanFactory) |
|
||||||
? hierarchicalBeanFactory.getParentBeanFactory() : null; |
|
||||||
} |
|
||||||
return ConditionOutcome.match(message.didNotFind("").items("HTTP Service proxy beans")); |
|
||||||
} |
|
||||||
|
|
||||||
private boolean hasHttpServiceProxyBeanDefinition(ConfigurableListableBeanFactory beanFactory) { |
|
||||||
for (String beanName : beanFactory.getBeanDefinitionNames()) { |
|
||||||
BeanDefinition beanDefinition = beanFactory.getBeanDefinition(beanName); |
|
||||||
if (beanDefinition.hasAttribute(HTTP_SERVICE_GROUP_NAME_ATTRIBUTE)) { |
|
||||||
return true; |
|
||||||
} |
|
||||||
} |
|
||||||
return false; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,23 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-present 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. |
|
||||||
*/ |
|
||||||
|
|
||||||
/** |
|
||||||
* Common support code for HTTP Service Clients. |
|
||||||
*/ |
|
||||||
@NullMarked |
|
||||||
package org.springframework.boot.http.client.autoconfigure.service; |
|
||||||
|
|
||||||
import org.jspecify.annotations.NullMarked; |
|
||||||
@ -1,82 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-present 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.http.client.autoconfigure.service; |
|
||||||
|
|
||||||
import org.junit.jupiter.api.Test; |
|
||||||
|
|
||||||
import org.springframework.boot.test.context.runner.ApplicationContextRunner; |
|
||||||
import org.springframework.context.annotation.Bean; |
|
||||||
import org.springframework.context.annotation.Configuration; |
|
||||||
import org.springframework.test.util.ReflectionTestUtils; |
|
||||||
import org.springframework.web.service.annotation.GetExchange; |
|
||||||
import org.springframework.web.service.registry.AbstractHttpServiceRegistrar; |
|
||||||
import org.springframework.web.service.registry.ImportHttpServices; |
|
||||||
|
|
||||||
import static org.assertj.core.api.Assertions.assertThat; |
|
||||||
|
|
||||||
/** |
|
||||||
* Tests for |
|
||||||
* {@link ConditionalOnMissingHttpServiceProxyBean @ConditionalOnMissingHttpServiceProxyBean}. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
class ConditionalOnMissingHttpServiceProxyBeanTests { |
|
||||||
|
|
||||||
@Test |
|
||||||
void attributeNameMatchesSpringFramework() { |
|
||||||
assertThat(OnMissingHttpServiceProxyBeanCondition.HTTP_SERVICE_GROUP_NAME_ATTRIBUTE).isEqualTo( |
|
||||||
ReflectionTestUtils.getField(AbstractHttpServiceRegistrar.class, "HTTP_SERVICE_GROUP_NAME_ATTRIBUTE")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
void getOutcomeWhenNoHttpServiceProxyMatches() { |
|
||||||
new ApplicationContextRunner().withUserConfiguration(TestConfiguration.class) |
|
||||||
.run((context) -> assertThat(context).hasBean("test")); |
|
||||||
} |
|
||||||
|
|
||||||
@Test |
|
||||||
void getOutcomeWhenHasHttpServiceProxyDoesNotMatch() { |
|
||||||
new ApplicationContextRunner() |
|
||||||
.withUserConfiguration(HttpServiceProxyConfiguration.class, TestConfiguration.class) |
|
||||||
.run((context) -> assertThat(context).hasSingleBean(TestHttpService.class).doesNotHaveBean("test")); |
|
||||||
} |
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false) |
|
||||||
@ImportHttpServices(TestHttpService.class) |
|
||||||
static class HttpServiceProxyConfiguration { |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
@Configuration(proxyBeanMethods = false) |
|
||||||
static class TestConfiguration { |
|
||||||
|
|
||||||
@Bean |
|
||||||
@ConditionalOnMissingHttpServiceProxyBean |
|
||||||
String test() { |
|
||||||
return "test"; |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
interface TestHttpService { |
|
||||||
|
|
||||||
@GetExchange("/test") |
|
||||||
String test(); |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,62 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-present 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.restclient.autoconfigure.service; |
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory; |
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages; |
|
||||||
import org.springframework.boot.http.client.autoconfigure.service.ConditionalOnMissingHttpServiceProxyBean; |
|
||||||
import org.springframework.boot.restclient.autoconfigure.service.ImportHttpServiceClientsConfiguration.ImportHttpServiceClients; |
|
||||||
import org.springframework.context.annotation.Configuration; |
|
||||||
import org.springframework.context.annotation.Import; |
|
||||||
import org.springframework.core.type.AnnotationMetadata; |
|
||||||
import org.springframework.web.service.registry.AbstractClientHttpServiceRegistrar; |
|
||||||
import org.springframework.web.service.registry.HttpServiceClient; |
|
||||||
|
|
||||||
/** |
|
||||||
* {@link Configuration @Configuration} to import {@link ImportHttpServiceClients} when no |
|
||||||
* user-defined HTTP service client beans are found. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
@Configuration(proxyBeanMethods = false) |
|
||||||
@ConditionalOnMissingHttpServiceProxyBean |
|
||||||
@Import(ImportHttpServiceClients.class) |
|
||||||
class ImportHttpServiceClientsConfiguration { |
|
||||||
|
|
||||||
/** |
|
||||||
* {@link AbstractClientHttpServiceRegistrar} to import
|
|
||||||
* {@link HttpServiceClient @HttpServiceClient} annotated classes from |
|
||||||
* {@link AutoConfigurationPackages}. |
|
||||||
*/ |
|
||||||
static class ImportHttpServiceClients extends AbstractClientHttpServiceRegistrar { |
|
||||||
|
|
||||||
private final BeanFactory beanFactory; |
|
||||||
|
|
||||||
ImportHttpServiceClients(BeanFactory beanFactory) { |
|
||||||
this.beanFactory = beanFactory; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void registerHttpServices(GroupRegistry registry, AnnotationMetadata importingClassMetadata) { |
|
||||||
if (AutoConfigurationPackages.has(this.beanFactory)) { |
|
||||||
findAndRegisterHttpServiceClients(registry, AutoConfigurationPackages.get(this.beanFactory)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,70 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-present 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.restclient.autoconfigure.service; |
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanClassLoaderAware; |
|
||||||
import org.springframework.beans.factory.ObjectProvider; |
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
|
||||||
import org.springframework.boot.http.client.ClientHttpRequestFactoryBuilder; |
|
||||||
import org.springframework.boot.http.client.ClientHttpRequestFactorySettings; |
|
||||||
import org.springframework.boot.restclient.RestClientCustomizer; |
|
||||||
import org.springframework.boot.ssl.SslBundles; |
|
||||||
import org.springframework.context.annotation.Bean; |
|
||||||
import org.springframework.context.annotation.Configuration; |
|
||||||
import org.springframework.web.client.ApiVersionFormatter; |
|
||||||
import org.springframework.web.client.ApiVersionInserter; |
|
||||||
import org.springframework.web.client.RestClient; |
|
||||||
import org.springframework.web.client.support.RestClientHttpServiceGroupConfigurer; |
|
||||||
import org.springframework.web.service.registry.HttpServiceProxyRegistry; |
|
||||||
|
|
||||||
/** |
|
||||||
* {@link Configuration @Configuration} to register |
|
||||||
* {@link RestClientHttpServiceGroupConfigurer} beans to support HTTP service clients |
|
||||||
* backed by a {@link RestClient}. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
@Configuration(proxyBeanMethods = false) |
|
||||||
@ConditionalOnBean(HttpServiceProxyRegistry.class) |
|
||||||
class RestClientHttpServiceClientConfiguration implements BeanClassLoaderAware { |
|
||||||
|
|
||||||
@SuppressWarnings("NullAway.Init") |
|
||||||
private ClassLoader beanClassLoader; |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setBeanClassLoader(ClassLoader classLoader) { |
|
||||||
this.beanClassLoader = classLoader; |
|
||||||
} |
|
||||||
|
|
||||||
@Bean |
|
||||||
RestClientPropertiesHttpServiceGroupConfigurer restClientPropertiesHttpServiceGroupConfigurer( |
|
||||||
ObjectProvider<SslBundles> sslBundles, HttpClientServiceProperties serviceProperties, |
|
||||||
ObjectProvider<ClientHttpRequestFactoryBuilder<?>> clientFactoryBuilder, |
|
||||||
ObjectProvider<ClientHttpRequestFactorySettings> clientHttpRequestFactorySettings, |
|
||||||
ObjectProvider<ApiVersionInserter> apiVersionInserter, |
|
||||||
ObjectProvider<ApiVersionFormatter> apiVersionFormatter) { |
|
||||||
return new RestClientPropertiesHttpServiceGroupConfigurer(this.beanClassLoader, sslBundles, serviceProperties, |
|
||||||
clientFactoryBuilder, clientHttpRequestFactorySettings, apiVersionInserter, apiVersionFormatter); |
|
||||||
} |
|
||||||
|
|
||||||
@Bean |
|
||||||
RestClientCustomizerHttpServiceGroupConfigurer restClientCustomizerHttpServiceGroupConfigurer( |
|
||||||
ObjectProvider<RestClientCustomizer> customizers) { |
|
||||||
return new RestClientCustomizerHttpServiceGroupConfigurer(customizers); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,33 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-present 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.restclient.autoconfigure.service.scan; |
|
||||||
|
|
||||||
import org.springframework.web.service.annotation.GetExchange; |
|
||||||
import org.springframework.web.service.registry.HttpServiceClient; |
|
||||||
|
|
||||||
/** |
|
||||||
* Test HTTP service used with scanning. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
@HttpServiceClient("test") |
|
||||||
public interface TestHttpServiceClient { |
|
||||||
|
|
||||||
@GetExchange("/hello") |
|
||||||
String hello(); |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,62 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-present 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.webclient.autoconfigure.service; |
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanFactory; |
|
||||||
import org.springframework.boot.autoconfigure.AutoConfigurationPackages; |
|
||||||
import org.springframework.boot.http.client.autoconfigure.service.ConditionalOnMissingHttpServiceProxyBean; |
|
||||||
import org.springframework.boot.webclient.autoconfigure.service.ImportHttpServiceClientsConfiguration.ImportHttpServiceClients; |
|
||||||
import org.springframework.context.annotation.Configuration; |
|
||||||
import org.springframework.context.annotation.Import; |
|
||||||
import org.springframework.core.type.AnnotationMetadata; |
|
||||||
import org.springframework.web.service.registry.AbstractClientHttpServiceRegistrar; |
|
||||||
import org.springframework.web.service.registry.HttpServiceClient; |
|
||||||
|
|
||||||
/** |
|
||||||
* {@link Configuration @Configuration} to import {@link ImportHttpServiceClients} when no |
|
||||||
* user-defined HTTP service client beans are found. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
@Configuration(proxyBeanMethods = false) |
|
||||||
@ConditionalOnMissingHttpServiceProxyBean |
|
||||||
@Import(ImportHttpServiceClients.class) |
|
||||||
class ImportHttpServiceClientsConfiguration { |
|
||||||
|
|
||||||
/** |
|
||||||
* {@link AbstractClientHttpServiceRegistrar} to import
|
|
||||||
* {@link HttpServiceClient @HttpServiceClient} annotated classes from |
|
||||||
* {@link AutoConfigurationPackages}. |
|
||||||
*/ |
|
||||||
static class ImportHttpServiceClients extends AbstractClientHttpServiceRegistrar { |
|
||||||
|
|
||||||
private final BeanFactory beanFactory; |
|
||||||
|
|
||||||
ImportHttpServiceClients(BeanFactory beanFactory) { |
|
||||||
this.beanFactory = beanFactory; |
|
||||||
} |
|
||||||
|
|
||||||
@Override |
|
||||||
protected void registerHttpServices(GroupRegistry registry, AnnotationMetadata importingClassMetadata) { |
|
||||||
if (AutoConfigurationPackages.has(this.beanFactory)) { |
|
||||||
findAndRegisterHttpServiceClients(registry, AutoConfigurationPackages.get(this.beanFactory)); |
|
||||||
} |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,70 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-present 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.webclient.autoconfigure.service; |
|
||||||
|
|
||||||
import org.springframework.beans.factory.BeanClassLoaderAware; |
|
||||||
import org.springframework.beans.factory.ObjectProvider; |
|
||||||
import org.springframework.boot.autoconfigure.condition.ConditionalOnBean; |
|
||||||
import org.springframework.boot.http.client.reactive.ClientHttpConnectorBuilder; |
|
||||||
import org.springframework.boot.http.client.reactive.ClientHttpConnectorSettings; |
|
||||||
import org.springframework.boot.ssl.SslBundles; |
|
||||||
import org.springframework.boot.webclient.WebClientCustomizer; |
|
||||||
import org.springframework.context.annotation.Bean; |
|
||||||
import org.springframework.context.annotation.Configuration; |
|
||||||
import org.springframework.web.client.ApiVersionFormatter; |
|
||||||
import org.springframework.web.client.ApiVersionInserter; |
|
||||||
import org.springframework.web.reactive.function.client.WebClient; |
|
||||||
import org.springframework.web.reactive.function.client.support.WebClientHttpServiceGroupConfigurer; |
|
||||||
import org.springframework.web.service.registry.HttpServiceProxyRegistry; |
|
||||||
|
|
||||||
/** |
|
||||||
* {@link Configuration @Configuration} to register |
|
||||||
* {@link WebClientHttpServiceGroupConfigurer} beans to support HTTP service clients |
|
||||||
* backed by a {@link WebClient}. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
@Configuration(proxyBeanMethods = false) |
|
||||||
@ConditionalOnBean(HttpServiceProxyRegistry.class) |
|
||||||
final class WebClientHttpServiceClientConfiguration implements BeanClassLoaderAware { |
|
||||||
|
|
||||||
@SuppressWarnings("NullAway.Init") |
|
||||||
private ClassLoader beanClassLoader; |
|
||||||
|
|
||||||
@Override |
|
||||||
public void setBeanClassLoader(ClassLoader classLoader) { |
|
||||||
this.beanClassLoader = classLoader; |
|
||||||
} |
|
||||||
|
|
||||||
@Bean |
|
||||||
WebClientPropertiesHttpServiceGroupConfigurer webClientPropertiesHttpServiceGroupConfigurer( |
|
||||||
ObjectProvider<SslBundles> sslBundles, ReactiveHttpClientServiceProperties serviceProperties, |
|
||||||
ObjectProvider<ClientHttpConnectorBuilder<?>> clientConnectorBuilder, |
|
||||||
ObjectProvider<ClientHttpConnectorSettings> clientConnectorSettings, |
|
||||||
ObjectProvider<ApiVersionInserter> apiVersionInserter, |
|
||||||
ObjectProvider<ApiVersionFormatter> apiVersionFormatter) { |
|
||||||
return new WebClientPropertiesHttpServiceGroupConfigurer(this.beanClassLoader, sslBundles, serviceProperties, |
|
||||||
clientConnectorBuilder, clientConnectorSettings, apiVersionInserter, apiVersionFormatter); |
|
||||||
} |
|
||||||
|
|
||||||
@Bean |
|
||||||
WebClientCustomizerHttpServiceGroupConfigurer webClientCustomizerHttpServiceGroupConfigurer( |
|
||||||
ObjectProvider<WebClientCustomizer> customizers) { |
|
||||||
return new WebClientCustomizerHttpServiceGroupConfigurer(customizers); |
|
||||||
} |
|
||||||
|
|
||||||
} |
|
||||||
@ -1,33 +0,0 @@ |
|||||||
/* |
|
||||||
* Copyright 2012-present 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.webclient.autoconfigure.service.scan; |
|
||||||
|
|
||||||
import org.springframework.web.service.annotation.GetExchange; |
|
||||||
import org.springframework.web.service.registry.HttpServiceClient; |
|
||||||
|
|
||||||
/** |
|
||||||
* Test HTTP service used with scanning. |
|
||||||
* |
|
||||||
* @author Phillip Webb |
|
||||||
*/ |
|
||||||
@HttpServiceClient("test") |
|
||||||
public interface TestHttpServiceClient { |
|
||||||
|
|
||||||
@GetExchange("/hello") |
|
||||||
String hello(); |
|
||||||
|
|
||||||
} |
|
||||||
Loading…
Reference in new issue