Skip to content

Commit 10839a6

Browse files
committed
Polish "Add client interceptor filter support"
Signed-off-by: Chris Bono <[email protected]>
1 parent 161ad69 commit 10839a6

File tree

2 files changed

+13
-2
lines changed

2 files changed

+13
-2
lines changed

spring-grpc-core/src/main/java/org/springframework/grpc/client/ClientInterceptorsConfigurer.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,7 +22,9 @@
2222

2323
import org.springframework.beans.factory.InitializingBean;
2424
import org.springframework.beans.factory.NoSuchBeanDefinitionException;
25+
import org.springframework.beans.factory.NoUniqueBeanDefinitionException;
2526
import org.springframework.context.ApplicationContext;
27+
import org.springframework.core.log.LogAccessor;
2628
import org.springframework.grpc.internal.ApplicationContextBeanLookupUtils;
2729

2830
import io.grpc.ClientInterceptor;
@@ -36,6 +38,8 @@
3638
*/
3739
public class ClientInterceptorsConfigurer implements InitializingBean {
3840

41+
private final LogAccessor log = new LogAccessor(getClass());
42+
3943
private final ApplicationContext applicationContext;
4044

4145
private List<ClientInterceptor> globalInterceptors;
@@ -87,7 +91,14 @@ private ClientInterceptorFilter findInterceptorFilter() {
8791
try {
8892
return this.applicationContext.getBean(ClientInterceptorFilter.class);
8993
}
94+
catch (NoUniqueBeanDefinitionException noUniqueBeanEx) {
95+
this.log.warn(noUniqueBeanEx,
96+
() -> "No unique ClientInterceptorFilter bean found. Consider defining a single bean or marking one as @Primary");
97+
return null;
98+
}
9099
catch (NoSuchBeanDefinitionException ignored) {
100+
this.log.debug(
101+
() -> "No ClientInterceptorFilter bean found - filtering will not be applied to client interceptors.");
91102
return null;
92103
}
93104
}

spring-grpc-core/src/test/java/org/springframework/grpc/client/ClientInterceptorsConfigurerTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -173,7 +173,7 @@ void whenBlendInterceptorsTrueThenGlobalInterceptorsBlended() {
173173
}
174174

175175
@Nested
176-
class WithInterceptorFilters {
176+
class WithInterceptorFilter {
177177

178178
@Test
179179
void whenFilterExcludesOneGlobalInterceptor_thenBuilderGetsOnlyAllowedOnes() {
@@ -196,7 +196,7 @@ void whenFilterIncludesAllGlobalInterceptors_thenBuilderGetsOnlyAllowedOnes() {
196196
ManagedChannelBuilder<?> builder = Mockito.mock();
197197
ClientInterceptorsConfigurerTests.this.contextRunner()
198198
.withUserConfiguration(GlobalClientInterceptorsConfig.class)
199-
.withBean(ClientInterceptorFilter.class, () -> (interceptor, __) -> true)
199+
.withBean(ClientInterceptorFilter.class, () -> (__, ___) -> true)
200200
.run(context -> {
201201
var factory = Mockito.mock(GrpcChannelFactory.class);
202202
var configurer = context.getBean(ClientInterceptorsConfigurer.class);

0 commit comments

Comments
 (0)