Skip to content

Commit db379ca

Browse files
committed
Fix dependencies. Fix naming. Fix exception handling.
1 parent 0608d8e commit db379ca

12 files changed

+67
-52
lines changed

spring-boot-project/spring-boot-autoconfigure/build.gradle

Lines changed: 4 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -23,6 +23,10 @@ configurations.all {
2323
dependencies {
2424
api(project(":spring-boot-project:spring-boot"))
2525

26+
// TODO: Have added it to be able to use CaseUtils and avoid rewriting the code;
27+
// can remove it and duplicate the required method instead
28+
implementation("org.apache.commons:commons-text")
29+
2630
dockerTestImplementation(project(":spring-boot-project:spring-boot-test"))
2731
dockerTestImplementation(project(":spring-boot-project:spring-boot-tools:spring-boot-test-support-docker"))
2832
dockerTestImplementation("org.assertj:assertj-core")
Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -23,10 +23,10 @@
2323
* @author Olga Maciaszek-Sharma
2424
*/
2525
// TODO: remove abstract supertype or move to a shared package
26-
public interface InterfaceClientAdapter extends Ordered {
26+
public interface InterfaceClientsAdapter extends Ordered {
2727

2828
String DEFAULT_QUALIFIER = "interfaceClients";
2929

30-
<T> T createClient(ListableBeanFactory beanFactory, String clientName, Class<T> type);
30+
<T> T createClient(ListableBeanFactory beanFactory, String clientId, Class<T> type);
3131

3232
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/interfaceclients/http/HttpExchangeAdapterProvider.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,6 @@
2626
public interface HttpExchangeAdapterProvider {
2727

2828
// TODO: try a less specific type for the beanFactory
29-
HttpExchangeAdapter get(ListableBeanFactory beanFactory, String clientName);
29+
HttpExchangeAdapter get(ListableBeanFactory beanFactory, String clientId);
3030

3131
}
Lines changed: 10 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -20,41 +20,41 @@
2020
import org.apache.commons.logging.LogFactory;
2121

2222
import org.springframework.beans.factory.ListableBeanFactory;
23-
import org.springframework.boot.autoconfigure.interfaceclients.InterfaceClientAdapter;
23+
import org.springframework.boot.autoconfigure.interfaceclients.InterfaceClientsAdapter;
2424
import org.springframework.web.service.invoker.HttpExchangeAdapter;
2525
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
2626

2727
/**
2828
* @author Olga Maciaszek-Sharma
2929
*/
30-
public class HttpInterfaceClientAdapter implements InterfaceClientAdapter {
30+
public class HttpInterfaceClientsAdapter implements InterfaceClientsAdapter {
3131

32-
private static final Log logger = LogFactory.getLog(HttpInterfaceClientAdapter.class);
32+
private static final Log logger = LogFactory.getLog(HttpInterfaceClientsAdapter.class);
3333

3434
private final HttpExchangeAdapterProvider adapterProvider;
3535

36-
public HttpInterfaceClientAdapter(HttpExchangeAdapterProvider adapterProvider) {
36+
public HttpInterfaceClientsAdapter(HttpExchangeAdapterProvider adapterProvider) {
3737
this.adapterProvider = adapterProvider;
3838
}
3939

4040
@Override
41-
public <T> T createClient(ListableBeanFactory beanFactory, String clientName, Class<T> type) {
42-
HttpServiceProxyFactory proxyFactory = proxyFactory(beanFactory, clientName);
41+
public <T> T createClient(ListableBeanFactory beanFactory, String clientId, Class<T> type) {
42+
HttpServiceProxyFactory proxyFactory = proxyFactory(beanFactory, clientId);
4343

4444
return proxyFactory.createClient(type);
4545
}
4646

47-
private HttpServiceProxyFactory proxyFactory(ListableBeanFactory beanFactory, String clientName) {
47+
private HttpServiceProxyFactory proxyFactory(ListableBeanFactory beanFactory, String clientId) {
4848
HttpServiceProxyFactory userProvidedProxyFactory = QualifiedBeanProvider.qualifiedBean(beanFactory,
49-
HttpServiceProxyFactory.class, clientName);
49+
HttpServiceProxyFactory.class, clientId);
5050
if (userProvidedProxyFactory != null) {
5151
return userProvidedProxyFactory;
5252
}
5353
// create an HttpServiceProxyFactory bean with default implementation
5454
if (logger.isDebugEnabled()) {
55-
logger.debug("Creating HttpServiceProxyFactory for '" + clientName + "'");
55+
logger.debug("Creating HttpServiceProxyFactory for '" + clientId + "'");
5656
}
57-
HttpExchangeAdapter adapter = this.adapterProvider.get(beanFactory, clientName);
57+
HttpExchangeAdapter adapter = this.adapterProvider.get(beanFactory, clientId);
5858
return HttpServiceProxyFactory.builderFor(adapter).build();
5959
}
6060

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/interfaceclients/http/HttpInterfaceClientsAutoConfiguration.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -44,14 +44,14 @@
4444
* @author Olga Maciaszek-Sharma
4545
*/
4646
@AutoConfiguration(after = { RestTemplateAutoConfiguration.class, RestClientAutoConfiguration.class,
47-
WebClientAutoConfiguration.class })
47+
WebClientAutoConfiguration.class})
4848
@Import(HttpInterfaceClientsImportRegistrar.class)
4949
@EnableConfigurationProperties(HttpInterfaceClientsProperties.class)
5050
public class HttpInterfaceClientsAutoConfiguration {
5151

5252
@Bean
53-
HttpInterfaceClientAdapter httpInterfaceClientAdapter(HttpExchangeAdapterProvider adapterProvider) {
54-
return new HttpInterfaceClientAdapter(adapterProvider);
53+
HttpInterfaceClientsAdapter httpInterfaceClientAdapter(HttpExchangeAdapterProvider adapterProvider) {
54+
return new HttpInterfaceClientsAdapter(adapterProvider);
5555
}
5656

5757
@Configuration(proxyBeanMethods = false)

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/interfaceclients/http/HttpInterfaceClientsImportRegistrar.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -42,6 +42,8 @@
4242
// TODO: Handle AOT
4343
public class HttpInterfaceClientsImportRegistrar extends AbstractInterfaceClientsImportRegistrar {
4444

45+
// TODO: work on IntelliJ plugin /other plugins/ to show that the client beans are
46+
// autoconfigured
4547
private static final Log logger = LogFactory.getLog(HttpInterfaceClientsImportRegistrar.class);
4648

4749
private static final String INTERFACE_CLIENT_SUFFIX = "InterfaceClient";
@@ -76,23 +78,23 @@ public void registerBeanDefinitions(AnnotationMetadata metadata, BeanDefinitionR
7678
// qualifier to look for related beans
7779
// TODO: while the actual beanName corresponds to the simple class name
7880
// suffixed with InterfaceClient
79-
String clientQualifier = annotation.getString(MergedAnnotation.VALUE);
81+
String clientId = annotation.getString(MergedAnnotation.VALUE);
8082
String beanName = !ObjectUtils.isEmpty(annotation.getString(BEAN_NAME_ATTRIBUTE_NAME))
81-
? annotation.getString(BEAN_NAME_ATTRIBUTE_NAME) : buildBeanName(clientQualifier);
82-
HttpInterfaceClientAdapter adapter = beanFactory.getBean(HttpInterfaceClientAdapter.class);
83+
? annotation.getString(BEAN_NAME_ATTRIBUTE_NAME) : buildBeanName(clientId);
84+
HttpInterfaceClientsAdapter adapter = beanFactory.getBean(HttpInterfaceClientsAdapter.class);
8385
BeanDefinition definition = BeanDefinitionBuilder
8486
.rootBeanDefinition(ResolvableType.forClass(beanClass),
85-
() -> adapter.createClient(beanFactory, clientQualifier, beanClass))
87+
() -> adapter.createClient(beanFactory, clientId, beanClass))
8688
.getBeanDefinition();
8789
registry.registerBeanDefinition(beanName, definition);
8890

8991
}
9092
}
9193
}
9294

93-
private String buildBeanName(String clientQualifier) {
95+
private String buildBeanName(String clientId) {
9496
// TODO: research Normalizer form types
95-
String normalised = Normalizer.normalize(clientQualifier, Normalizer.Form.NFD);
97+
String normalised = Normalizer.normalize(clientId, Normalizer.Form.NFD);
9698
String camelCased = CaseUtils.toCamelCase(normalised, false, '-', '_');
9799
return camelCased + INTERFACE_CLIENT_SUFFIX;
98100
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/interfaceclients/http/HttpInterfaceClientsProperties.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,14 +39,14 @@ public Map<String, HttpInterfaceClientsBaseProperties> getClients() {
3939
return this.clients;
4040
}
4141

42-
public HttpInterfaceClientsBaseProperties getProperties(String clientName) {
43-
if (clientName == null || !this.getClients().containsKey(clientName)) {
42+
public HttpInterfaceClientsBaseProperties getProperties(String clientId) {
43+
if (clientId == null || !this.getClients().containsKey(clientId)) {
4444
// no specific client properties, return default
4545
return this;
4646
}
4747
// because specifics are overlaid on top of defaults, everything in `properties`,
4848
// unless overridden, is in `clientsProperties`
49-
return this.getClients().get(clientName);
49+
return this.getClients().get(clientId);
5050
}
5151

5252
}

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/interfaceclients/http/QualifiedBeanProvider.java

Lines changed: 8 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,7 @@
2222
import org.springframework.beans.factory.ListableBeanFactory;
2323
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
2424
import org.springframework.beans.factory.annotation.BeanFactoryAnnotationUtils;
25-
import org.springframework.boot.autoconfigure.interfaceclients.InterfaceClientAdapter;
25+
import org.springframework.boot.autoconfigure.interfaceclients.InterfaceClientsAdapter;
2626

2727
/**
2828
* @author Olga Maciaszek-Sharma
@@ -31,24 +31,23 @@ final class QualifiedBeanProvider {
3131

3232
private static final Log logger = LogFactory.getLog(QualifiedBeanProvider.class);
3333

34-
static <T> T qualifiedBean(ListableBeanFactory beanFactory, Class<T> type, String clientName) {
34+
static <T> T qualifiedBean(ListableBeanFactory beanFactory, Class<T> type, String clientId) {
3535
try {
36-
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, type, clientName);
36+
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, type, clientId);
3737
}
38-
catch (NoSuchBeanDefinitionException ex) {
38+
catch (NoSuchBeanDefinitionException ignored) {
3939
if (logger.isDebugEnabled()) {
40-
logger.debug("No qualified bean of type " + type + " found for " + clientName, ex);
40+
logger.debug("No qualified bean of type " + type + " found for " + clientId);
4141
}
4242
}
4343
// Get default-qualified bean
4444
try {
4545
return BeanFactoryAnnotationUtils.qualifiedBeanOfType(beanFactory, type,
46-
InterfaceClientAdapter.DEFAULT_QUALIFIER);
46+
InterfaceClientsAdapter.DEFAULT_QUALIFIER);
4747
}
48-
catch (NoSuchBeanDefinitionException ex) {
48+
catch (NoSuchBeanDefinitionException ignored) {
4949
if (logger.isDebugEnabled()) {
50-
logger.debug("No qualified of type " + type + "found for " + InterfaceClientAdapter.DEFAULT_QUALIFIER,
51-
ex);
50+
logger.debug("No qualified of type " + type + "found for " + InterfaceClientsAdapter.DEFAULT_QUALIFIER);
5251
}
5352
}
5453
return null;

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/interfaceclients/http/RestClientAdapterProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -41,24 +41,24 @@ public RestClientAdapterProvider(RestClient.Builder builder, HttpInterfaceClient
4141
}
4242

4343
@Override
44-
public HttpExchangeAdapter get(ListableBeanFactory beanFactory, String clientName) {
44+
public HttpExchangeAdapter get(ListableBeanFactory beanFactory, String clientId) {
4545
RestClient userProvidedRestClient = QualifiedBeanProvider.qualifiedBean(beanFactory, RestClient.class,
46-
clientName);
46+
clientId);
4747
if (userProvidedRestClient != null) {
4848
return RestClientAdapter.create(userProvidedRestClient);
4949
}
5050
RestClient.Builder userProvidedRestClientBuilder = QualifiedBeanProvider.qualifiedBean(beanFactory,
51-
RestClient.Builder.class, clientName);
51+
RestClient.Builder.class, clientId);
5252
if (userProvidedRestClientBuilder != null) {
5353
// TODO: should we do this or get it from the user?
54-
userProvidedRestClientBuilder.baseUrl(this.properties.getProperties(clientName).getBaseUrl());
54+
userProvidedRestClientBuilder.baseUrl(this.properties.getProperties(clientId).getBaseUrl());
5555
return RestClientAdapter.create(userProvidedRestClientBuilder.build());
5656
}
5757
// create a RestClientAdapter bean with default implementation
5858
if (logger.isDebugEnabled()) {
59-
logger.debug("Creating RestClientAdapter for '" + clientName + "'");
59+
logger.debug("Creating RestClientAdapter for '" + clientId + "'");
6060
}
61-
RestClient restClient = this.builder.baseUrl(this.properties.getProperties(clientName).getBaseUrl()).build();
61+
RestClient restClient = this.builder.baseUrl(this.properties.getProperties(clientId).getBaseUrl()).build();
6262
return RestClientAdapter.create(restClient);
6363
}
6464

spring-boot-project/spring-boot-autoconfigure/src/main/java/org/springframework/boot/autoconfigure/interfaceclients/http/RestTemplateAdapterProvider.java

Lines changed: 6 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -43,25 +43,25 @@ public RestTemplateAdapterProvider(RestTemplateBuilder restTemplateBuilder,
4343
}
4444

4545
@Override
46-
public HttpExchangeAdapter get(ListableBeanFactory beanFactory, String clientName) {
46+
public HttpExchangeAdapter get(ListableBeanFactory beanFactory, String clientId) {
4747
RestTemplate userProvidedRestTemplate = QualifiedBeanProvider.qualifiedBean(beanFactory, RestTemplate.class,
48-
clientName);
48+
clientId);
4949
if (userProvidedRestTemplate != null) {
5050
return RestTemplateAdapter.create(userProvidedRestTemplate);
5151
}
5252
RestTemplateBuilder userProvidedRestTemplateBuilder = QualifiedBeanProvider.qualifiedBean(beanFactory,
53-
RestTemplateBuilder.class, clientName);
53+
RestTemplateBuilder.class, clientId);
5454
if (userProvidedRestTemplateBuilder != null) {
5555
// TODO: should we do this or get it from the user?
56-
userProvidedRestTemplateBuilder.rootUri(this.properties.getProperties(clientName).getBaseUrl());
56+
userProvidedRestTemplateBuilder.rootUri(this.properties.getProperties(clientId).getBaseUrl());
5757
return RestTemplateAdapter.create(userProvidedRestTemplateBuilder.build());
5858
}
5959
// create a RestTemplateAdapter bean with default implementation
6060
if (logger.isDebugEnabled()) {
61-
logger.debug("Creating RestTemplateAdapter for '" + clientName + "'");
61+
logger.debug("Creating RestTemplateAdapter for '" + clientId + "'");
6262
}
6363
RestTemplate restTemplate = this.restTemplateBuilder
64-
.rootUri(this.properties.getProperties(clientName).getBaseUrl())
64+
.rootUri(this.properties.getProperties(clientId).getBaseUrl())
6565
.build();
6666
return RestTemplateAdapter.create(restTemplate);
6767
}

0 commit comments

Comments
 (0)