|
19 | 19 | import org.apache.commons.logging.Log;
|
20 | 20 | import org.apache.commons.logging.LogFactory;
|
21 | 21 |
|
22 |
| -import org.springframework.beans.factory.ListableBeanFactory; |
23 |
| -import org.springframework.beans.factory.ObjectProvider; |
24 |
| -import org.springframework.beans.factory.config.ConfigurableListableBeanFactory; |
25 | 22 | import org.springframework.web.reactive.function.client.WebClient;
|
26 | 23 | import org.springframework.web.reactive.function.client.support.WebClientAdapter;
|
27 | 24 | import org.springframework.web.service.invoker.HttpExchangeAdapter;
|
28 | 25 |
|
29 | 26 | /**
|
30 | 27 | * @author Olga Maciaszek-Sharma
|
31 | 28 | */
|
32 |
| -public class WebClientAdapterProvider implements HttpExchangeAdapterProvider { |
| 29 | +public class WebClientInterfaceClientsFactoryBean extends AbstractHttpInterfaceClientsFactoryBean { |
33 | 30 |
|
34 |
| - private static final Log logger = LogFactory.getLog(WebClientAdapterProvider.class); |
35 |
| - |
36 |
| - private final WebClient.Builder builder; |
37 |
| - |
38 |
| - private final ObjectProvider<HttpInterfaceClientsProperties> propertiesProvider; |
39 |
| - |
40 |
| - public WebClientAdapterProvider(WebClient.Builder builder, |
41 |
| - ObjectProvider<HttpInterfaceClientsProperties> propertiesProvider) { |
42 |
| - this.builder = builder; |
43 |
| - this.propertiesProvider = propertiesProvider; |
44 |
| - } |
| 31 | + private static final Log logger = LogFactory.getLog(WebClientInterfaceClientsFactoryBean.class); |
45 | 32 |
|
46 | 33 | @Override
|
47 |
| - public HttpExchangeAdapter get(ConfigurableListableBeanFactory beanFactory, String clientId) { |
48 |
| - WebClient userProvidedWebClient = QualifiedBeanProvider.qualifiedBean(beanFactory, WebClient.class, clientId); |
| 34 | + protected HttpExchangeAdapter exchangeAdapter() { |
| 35 | + String baseUrl = getBaseUrl(); |
| 36 | + |
| 37 | + WebClient userProvidedWebClient = QualifiedBeanProvider.qualifiedBean(this.applicationContext.getBeanFactory(), |
| 38 | + WebClient.class, this.clientId); |
49 | 39 | if (userProvidedWebClient != null) {
|
| 40 | + // If the user wants to set the baseUrl directly on the builder, |
| 41 | + // it should not be set in properties. |
| 42 | + if (baseUrl != null) { |
| 43 | + userProvidedWebClient = userProvidedWebClient.mutate().baseUrl(baseUrl).build(); |
| 44 | + } |
50 | 45 | return WebClientAdapter.create(userProvidedWebClient);
|
51 | 46 | }
|
52 |
| - HttpInterfaceClientsProperties properties = this.propertiesProvider.getObject(); |
53 |
| - String baseUrl = properties.getProperties(clientId).getBaseUrl(); |
54 |
| - WebClient.Builder userProvidedWebClientBuilder = QualifiedBeanProvider.qualifiedBean(beanFactory, |
55 |
| - WebClient.Builder.class, clientId); |
| 47 | + |
| 48 | + WebClient.Builder userProvidedWebClientBuilder = QualifiedBeanProvider |
| 49 | + .qualifiedBean(this.applicationContext.getBeanFactory(), WebClient.Builder.class, this.clientId); |
56 | 50 | if (userProvidedWebClientBuilder != null) {
|
57 |
| - // If the user wants to set the baseUrl directly on the builder, |
58 |
| - // it should not be set in properties. |
| 51 | + |
59 | 52 | if (baseUrl != null) {
|
60 | 53 | userProvidedWebClientBuilder.baseUrl(baseUrl);
|
61 | 54 | }
|
62 | 55 | return WebClientAdapter.create(userProvidedWebClientBuilder.build());
|
63 | 56 | }
|
| 57 | + |
64 | 58 | // create a WebClientAdapter bean with default implementation
|
65 | 59 | if (logger.isDebugEnabled()) {
|
66 |
| - logger.debug("Creating WebClientAdapter for '" + clientId + "'"); |
| 60 | + logger.debug("Creating WebClientAdapter for '" + this.clientId + "'"); |
67 | 61 | }
|
68 |
| - WebClient webClient = this.builder.baseUrl(baseUrl).build(); |
| 62 | + WebClient.Builder builder = this.applicationContext.getBean(WebClient.Builder.class); |
| 63 | + WebClient webClient = builder.baseUrl(baseUrl).build(); |
69 | 64 | return WebClientAdapter.create(webClient);
|
70 | 65 | }
|
71 | 66 |
|
|
0 commit comments