Skip to content

Commit 308bbd1

Browse files
committed
Add support for RSocket Interface Clients Autoconfiguration.
1 parent 0883162 commit 308bbd1

16 files changed

+321
-10
lines changed
Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@
1414
* limitations under the License.
1515
*/
1616

17-
package org.springframework.boot.autoconfigure.interfaceclients.http;
17+
package org.springframework.boot.autoconfigure.interfaceclients;
1818

1919
import java.util.HashMap;
2020
import java.util.Map;
@@ -31,11 +31,11 @@
3131
* @author Josh Long
3232
* @author Olga Maciaszek-Sharma
3333
*/
34-
final class QualifiedBeanProvider {
34+
public final class QualifiedBeanProvider {
3535

3636
private static final Log logger = LogFactory.getLog(QualifiedBeanProvider.class);
3737

38-
static <T> T qualifiedBean(ConfigurableListableBeanFactory beanFactory, Class<T> type, String clientId) {
38+
public static <T> T qualifiedBean(ConfigurableListableBeanFactory beanFactory, Class<T> type, String clientId) {
3939
Map<String, T> matchingClientBeans = getQualifiedBeansOfType(beanFactory, type, clientId);
4040
if (matchingClientBeans.size() > 1) {
4141
throw new NoUniqueBeanDefinitionException(type, matchingClientBeans.keySet());

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

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -20,6 +20,7 @@
2020
import org.apache.commons.logging.LogFactory;
2121

2222
import org.springframework.boot.autoconfigure.interfaceclients.AbstractInterfaceClientsFactoryBean;
23+
import org.springframework.boot.autoconfigure.interfaceclients.QualifiedBeanProvider;
2324
import org.springframework.web.service.invoker.HttpExchangeAdapter;
2425
import org.springframework.web.service.invoker.HttpServiceProxyFactory;
2526

@@ -43,6 +44,8 @@ protected String getBaseUrl() {
4344
return properties.getProperties(this.clientId).getBaseUrl();
4445
}
4546

47+
protected abstract HttpExchangeAdapter exchangeAdapter();
48+
4649
private HttpServiceProxyFactory proxyFactory() {
4750
HttpServiceProxyFactory userProvidedProxyFactory = QualifiedBeanProvider
4851
.qualifiedBean(this.applicationContext.getBeanFactory(), HttpServiceProxyFactory.class, this.clientId);
@@ -57,6 +60,4 @@ private HttpServiceProxyFactory proxyFactory() {
5760
return HttpServiceProxyFactory.builderFor(adapter).build();
5861
}
5962

60-
protected abstract HttpExchangeAdapter exchangeAdapter();
61-
6263
}

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

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -48,7 +48,7 @@ public class HttpInterfaceClientsAutoConfiguration {
4848
@Configuration(proxyBeanMethods = false)
4949
@ConditionalOnClass({ RestClient.class, RestClientAdapter.class, HttpServiceProxyFactory.class })
5050
@Conditional(NotReactiveWebApplicationCondition.class)
51-
@ConditionalOnProperty(value = "spring.interfaceclients.resttemplate.enabled", havingValue = "false",
51+
@ConditionalOnProperty(value = "spring.interfaceclients.http.resttemplate.enabled", havingValue = "false",
5252
matchIfMissing = true)
5353
@Import(RestClientInterfaceClientsImportRegistrar.class)
5454
protected static class RestClientAdapterProviderConfiguration {
@@ -58,7 +58,7 @@ protected static class RestClientAdapterProviderConfiguration {
5858
@Configuration(proxyBeanMethods = false)
5959
@ConditionalOnClass({ RestTemplate.class, RestTemplateAdapter.class, HttpServiceProxyFactory.class })
6060
@Conditional(NotReactiveWebApplicationCondition.class)
61-
@ConditionalOnProperty(value = "spring.interfaceclients.resttemplate.enabled", havingValue = "true")
61+
@ConditionalOnProperty(value = "spring.interfaceclients.http.resttemplate.enabled", havingValue = "true")
6262
@Import(RestTemplateInterfaceClientsImportRegistrar.class)
6363
protected static class RestTemplateAdapterProviderConfiguration {
6464

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -27,7 +27,7 @@
2727
*
2828
* @author Olga Maciaszek-Sharma
2929
*/
30-
@ConfigurationProperties("spring.interfaceclients")
30+
@ConfigurationProperties("spring.interfaceclients.http")
3131
public class HttpInterfaceClientsProperties extends HttpInterfaceClientsBaseProperties {
3232

3333
/**

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
2121

22+
import org.springframework.boot.autoconfigure.interfaceclients.QualifiedBeanProvider;
2223
import org.springframework.web.client.RestClient;
2324
import org.springframework.web.client.support.RestClientAdapter;
2425
import org.springframework.web.service.invoker.HttpExchangeAdapter;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
2121

22+
import org.springframework.boot.autoconfigure.interfaceclients.QualifiedBeanProvider;
2223
import org.springframework.boot.web.client.RestTemplateBuilder;
2324
import org.springframework.web.client.RestTemplate;
2425
import org.springframework.web.client.support.RestTemplateAdapter;

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -19,6 +19,7 @@
1919
import org.apache.commons.logging.Log;
2020
import org.apache.commons.logging.LogFactory;
2121

22+
import org.springframework.boot.autoconfigure.interfaceclients.QualifiedBeanProvider;
2223
import org.springframework.web.reactive.function.client.WebClient;
2324
import org.springframework.web.reactive.function.client.support.WebClientAdapter;
2425
import org.springframework.web.service.invoker.HttpExchangeAdapter;
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,37 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.interfaceclients.rsocket;
18+
19+
import java.lang.annotation.Documented;
20+
import java.lang.annotation.ElementType;
21+
import java.lang.annotation.Retention;
22+
import java.lang.annotation.RetentionPolicy;
23+
import java.lang.annotation.Target;
24+
25+
/**
26+
* @author Olga Maciaszek-Sharma
27+
*/
28+
@Target(ElementType.TYPE)
29+
@Retention(RetentionPolicy.RUNTIME)
30+
@Documented
31+
public @interface RSocketClient {
32+
33+
String value();
34+
35+
String beanName() default "";
36+
37+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,41 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.interfaceclients.rsocket;
18+
19+
import io.rsocket.transport.netty.server.TcpServerTransport;
20+
import reactor.netty.http.server.HttpServer;
21+
22+
import org.springframework.boot.autoconfigure.AutoConfiguration;
23+
import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
24+
import org.springframework.boot.autoconfigure.condition.ConditionalOnProperty;
25+
import org.springframework.boot.autoconfigure.rsocket.RSocketRequesterAutoConfiguration;
26+
import org.springframework.boot.context.properties.EnableConfigurationProperties;
27+
import org.springframework.context.annotation.Import;
28+
import org.springframework.messaging.rsocket.RSocketRequester;
29+
import org.springframework.messaging.rsocket.service.RSocketServiceProxyFactory;
30+
31+
/**
32+
* @author Olga Maciaszek-Sharma
33+
*/
34+
@AutoConfiguration(after = RSocketRequesterAutoConfiguration.class)
35+
@ConditionalOnClass({ RSocketRequester.class, io.rsocket.RSocket.class, HttpServer.class,
36+
TcpServerTransport.class, RSocketServiceProxyFactory.class })
37+
@EnableConfigurationProperties(RSocketInterfaceClientsProperties.class)
38+
@ConditionalOnProperty(value = "spring.interfaceclients.enabled", havingValue = "true")
39+
@Import(RSocketInterfaceClientsImportRegistrar.class)
40+
public class RSocketInterfaceClientsAutoConfiguration {
41+
}
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,67 @@
1+
/*
2+
* Copyright 2012-2024 the original author or authors.
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
*
8+
* https://www.apache.org/licenses/LICENSE-2.0
9+
*
10+
* Unless required by applicable law or agreed to in writing, software
11+
* distributed under the License is distributed on an "AS IS" BASIS,
12+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
13+
* See the License for the specific language governing permissions and
14+
* limitations under the License.
15+
*/
16+
17+
package org.springframework.boot.autoconfigure.interfaceclients.rsocket;
18+
19+
import java.net.URI;
20+
21+
/**
22+
* @author Olga Maciaszek-Sharma
23+
*/
24+
public class RSocketInterfaceClientsBaseProperties {
25+
26+
/**
27+
* Host used to create a TCP connection for RSocketRequester. By default, set to null.
28+
* Both host and port are required for a TCP connection.
29+
*/
30+
private String host;
31+
32+
/**
33+
* Port used to create a TCP connection for RSocketRequester. By default, set to null.
34+
* Both host and port are required for a TCP connection.
35+
*/
36+
private Integer port;
37+
38+
39+
/**
40+
* URI used to create a Websocket connection for RSocketRequester. By default, set to null.
41+
*/
42+
private URI uri;
43+
44+
public String getHost() {
45+
return this.host;
46+
}
47+
48+
public void setHost(String host) {
49+
this.host = host;
50+
}
51+
52+
public Integer getPort() {
53+
return this.port;
54+
}
55+
56+
public void setPort(Integer port) {
57+
this.port = port;
58+
}
59+
60+
public URI getUri() {
61+
return this.uri;
62+
}
63+
64+
public void setUri(URI uri) {
65+
this.uri = uri;
66+
}
67+
}

0 commit comments

Comments
 (0)