Skip to content

Commit 5cb3123

Browse files
committed
GH-2749: Deprecate ChannelInterceptorAware
Fixes #2749 The `org.springframework.messaging.support.InterceptableChannel` provides exact functionality as `ChannelInterceptorAware` * Make `ChannelInterceptorAware extends InterceptableChannel` * Suppress deprecation warning whenever we need to keep backward compatibility * Fix all other places to deal with `InterceptableChannel` already
1 parent 53d7a85 commit 5cb3123

File tree

10 files changed

+85
-109
lines changed

10 files changed

+85
-109
lines changed

spring-integration-core/src/main/java/org/springframework/integration/channel/ChannelInterceptorAware.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -33,8 +33,8 @@
3333
*
3434
* @since 4.0
3535
*
36-
* @deprecated since 5.1.3 in favor of {@link InterceptableChannel}.
37-
* Will be removed in the next version
36+
* @deprecated since 5.2 in favor of {@link InterceptableChannel}.
37+
* Will be removed in the next 5.3 version.
3838
*/
3939
@Deprecated
4040
public interface ChannelInterceptorAware extends InterceptableChannel {

spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/VetoCapableInterceptor.java

Lines changed: 8 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,17 @@
1616

1717
package org.springframework.integration.channel.interceptor;
1818

19+
import org.springframework.messaging.support.InterceptableChannel;
20+
1921
/**
2022
* {@link org.springframework.messaging.support.ChannelInterceptor}s implementing this
21-
* interface can veto
22-
* global interception of a particular channel. Could be used, for example,
23-
* when an interceptor itself writes to an output channel (which should
24-
* not be intercepted with this interceptor).
23+
* interface can veto global interception of a particular channel.
24+
* Could be used, for example, when an interceptor itself writes to an output channel
25+
* (which should not be intercepted with this interceptor).
2526
*
2627
* @author Gary Russell
28+
* @author Artem Bilan
29+
*
2730
* @since 4.0
2831
*
2932
*/
@@ -34,7 +37,6 @@ public interface VetoCapableInterceptor {
3437
* @param channel The channel that is about to be intercepted.
3538
* @return false if the intercept wishes to veto the interception.
3639
*/
37-
@SuppressWarnings("deprecation")
38-
boolean shouldIntercept(String beanName, org.springframework.integration.channel.ChannelInterceptorAware channel);
40+
boolean shouldIntercept(String beanName, InterceptableChannel channel);
3941

4042
}

spring-integration-core/src/main/java/org/springframework/integration/channel/interceptor/WireTap.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -31,6 +31,7 @@
3131
import org.springframework.messaging.Message;
3232
import org.springframework.messaging.MessageChannel;
3333
import org.springframework.messaging.support.ChannelInterceptor;
34+
import org.springframework.messaging.support.InterceptableChannel;
3435
import org.springframework.util.Assert;
3536

3637
/**
@@ -172,9 +173,7 @@ public Message<?> preSend(Message<?> message, MessageChannel channel) {
172173
}
173174

174175
@Override
175-
@SuppressWarnings("deprecation")
176-
public boolean shouldIntercept(String beanName,
177-
org.springframework.integration.channel.ChannelInterceptorAware channel) {
176+
public boolean shouldIntercept(String beanName, InterceptableChannel channel) {
178177

179178
return !getChannel().equals(channel);
180179
}

spring-integration-core/src/main/java/org/springframework/integration/config/GlobalChannelInterceptorProcessor.java

Lines changed: 5 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -36,6 +36,7 @@
3636
import org.springframework.integration.channel.interceptor.VetoCapableInterceptor;
3737
import org.springframework.integration.support.utils.PatternMatchUtils;
3838
import org.springframework.messaging.support.ChannelInterceptor;
39+
import org.springframework.messaging.support.InterceptableChannel;
3940
import org.springframework.util.Assert;
4041
import org.springframework.util.CollectionUtils;
4142
import org.springframework.util.StringUtils;
@@ -92,19 +93,17 @@ public void afterSingletonsInstantiated() {
9293
}
9394
});
9495

95-
this.beanFactory.getBeansOfType(org.springframework.integration.channel.ChannelInterceptorAware.class)
96+
this.beanFactory.getBeansOfType(InterceptableChannel.class)
9697
.forEach((key, value) -> addMatchingInterceptors(value, key));
9798
}
9899

99100
this.singletonsInstantiated = true;
100101
}
101102

102103
@Override
103-
@SuppressWarnings("deprecation")
104104
public Object postProcessAfterInitialization(Object bean, String beanName) throws BeansException {
105-
if (this.singletonsInstantiated
106-
&& bean instanceof org.springframework.integration.channel.ChannelInterceptorAware) {
107-
addMatchingInterceptors((org.springframework.integration.channel.ChannelInterceptorAware) bean, beanName);
105+
if (this.singletonsInstantiated && bean instanceof InterceptableChannel) {
106+
addMatchingInterceptors((InterceptableChannel) bean, beanName);
108107
}
109108
return bean;
110109
}
@@ -114,9 +113,7 @@ public Object postProcessAfterInitialization(Object bean, String beanName) throw
114113
* @param channel the message channel to add interceptors.
115114
* @param beanName the message channel bean name to match the pattern.
116115
*/
117-
@SuppressWarnings("deprecation")
118-
public void addMatchingInterceptors(org.springframework.integration.channel.ChannelInterceptorAware channel,
119-
String beanName) {
116+
public void addMatchingInterceptors(InterceptableChannel channel, String beanName) {
120117

121118
if (logger.isDebugEnabled()) {
122119
logger.debug("Applying global interceptors on channel '" + beanName + "'");

spring-integration-core/src/main/java/org/springframework/integration/scattergather/ScatterGatherHandler.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -20,7 +20,6 @@
2020
import org.springframework.beans.factory.BeanFactory;
2121
import org.springframework.beans.factory.BeanInitializationException;
2222
import org.springframework.context.Lifecycle;
23-
import org.springframework.integration.channel.ChannelInterceptorAware;
2423
import org.springframework.integration.channel.FixedSubscriberChannel;
2524
import org.springframework.integration.channel.QueueChannel;
2625
import org.springframework.integration.channel.ReactiveStreamsSubscribableChannel;
@@ -39,6 +38,7 @@
3938
import org.springframework.messaging.PollableChannel;
4039
import org.springframework.messaging.SubscribableChannel;
4140
import org.springframework.messaging.support.ChannelInterceptor;
41+
import org.springframework.messaging.support.InterceptableChannel;
4242
import org.springframework.util.Assert;
4343
import org.springframework.util.ClassUtils;
4444

@@ -150,8 +150,8 @@ protected Object handleRequestMessage(Message<?> requestMessage) {
150150

151151
MessageChannel replyChannel = this.gatherChannel;
152152

153-
if (replyChannel instanceof ChannelInterceptorAware) {
154-
((ChannelInterceptorAware) replyChannel)
153+
if (replyChannel instanceof InterceptableChannel) {
154+
((InterceptableChannel) replyChannel)
155155
.addInterceptor(0,
156156
new ChannelInterceptor() {
157157

spring-integration-core/src/test/java/org/springframework/integration/channel/interceptor/ImplicitConsumerChannelTests.java

Lines changed: 3 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -28,6 +28,7 @@
2828
import org.springframework.messaging.Message;
2929
import org.springframework.messaging.MessageChannel;
3030
import org.springframework.messaging.support.ChannelInterceptor;
31+
import org.springframework.messaging.support.InterceptableChannel;
3132
import org.springframework.test.context.ContextConfiguration;
3233
import org.springframework.test.context.junit4.SpringJUnit4ClassRunner;
3334

@@ -98,10 +99,7 @@ public MessageChannel getChannel() {
9899
}
99100

100101
@Override
101-
@SuppressWarnings("deprecation")
102-
public boolean shouldIntercept(String beanName,
103-
org.springframework.integration.channel.ChannelInterceptorAware channel) {
104-
102+
public boolean shouldIntercept(String beanName, InterceptableChannel channel) {
105103
return !this.channel.equals(channel);
106104
}
107105

@@ -139,10 +137,7 @@ public MessageChannel getChannel() {
139137
}
140138

141139
@Override
142-
@SuppressWarnings("deprecation")
143-
public boolean shouldIntercept(String beanName,
144-
org.springframework.integration.channel.ChannelInterceptorAware channel) {
145-
140+
public boolean shouldIntercept(String beanName, InterceptableChannel channel) {
146141
return !this.channel.equals(channel);
147142
}
148143

spring-integration-core/src/test/java/org/springframework/integration/config/GlobalChannelInterceptorProcessorTests.java

Lines changed: 6 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -63,22 +63,20 @@ public void testProcessorWithNoInterceptor() {
6363
}
6464

6565
@Test
66-
@SuppressWarnings("deprecation")
6766
public void testProcessorWithInterceptorDefaultPattern() {
6867
Map<String, GlobalChannelInterceptorWrapper> interceptors = new HashMap<>();
69-
Map<String, org.springframework.integration.channel.ChannelInterceptorAware> channels = new HashMap<>();
68+
Map<String, InterceptableChannel> channels = new HashMap<>();
7069
ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class);
7170
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper =
7271
new GlobalChannelInterceptorWrapper(channelInterceptor);
7372

74-
org.springframework.integration.channel.ChannelInterceptorAware channel =
75-
Mockito.mock(org.springframework.integration.channel.ChannelInterceptorAware.class);
73+
InterceptableChannel channel = Mockito.mock(InterceptableChannel.class);
7674

7775
interceptors.put("Test-1", globalChannelInterceptorWrapper);
7876
channels.put("Test-1", channel);
7977
when(this.beanFactory.getBeansOfType(GlobalChannelInterceptorWrapper.class))
8078
.thenReturn(interceptors);
81-
when(this.beanFactory.getBeansOfType(org.springframework.integration.channel.ChannelInterceptorAware.class))
79+
when(this.beanFactory.getBeansOfType(InterceptableChannel.class))
8280
.thenReturn(channels);
8381

8482
this.globalChannelInterceptorProcessor.afterSingletonsInstantiated();
@@ -88,23 +86,21 @@ public void testProcessorWithInterceptorDefaultPattern() {
8886
}
8987

9088
@Test
91-
@SuppressWarnings("deprecation")
9289
public void testProcessorWithInterceptorMatchingPattern() {
9390
Map<String, GlobalChannelInterceptorWrapper> interceptors = new HashMap<>();
94-
Map<String, org.springframework.integration.channel.ChannelInterceptorAware> channels = new HashMap<>();
91+
Map<String, InterceptableChannel> channels = new HashMap<>();
9592
ChannelInterceptor channelInterceptor = Mockito.mock(ChannelInterceptor.class);
9693
GlobalChannelInterceptorWrapper globalChannelInterceptorWrapper =
9794
new GlobalChannelInterceptorWrapper(channelInterceptor);
9895

99-
org.springframework.integration.channel.ChannelInterceptorAware channel =
100-
Mockito.mock(org.springframework.integration.channel.ChannelInterceptorAware.class);
96+
InterceptableChannel channel = Mockito.mock(InterceptableChannel.class);
10197

10298
globalChannelInterceptorWrapper.setPatterns(new String[] { "Te*" });
10399
interceptors.put("Test-1", globalChannelInterceptorWrapper);
104100
channels.put("Test-1", channel);
105101
when(this.beanFactory.getBeansOfType(GlobalChannelInterceptorWrapper.class))
106102
.thenReturn(interceptors);
107-
when(this.beanFactory.getBeansOfType(org.springframework.integration.channel.ChannelInterceptorAware.class))
103+
when(this.beanFactory.getBeansOfType(InterceptableChannel.class))
108104
.thenReturn(channels);
109105
this.globalChannelInterceptorProcessor.afterSingletonsInstantiated();
110106

spring-integration-jms/src/test/java/org/springframework/integration/jms/config/GlobalChannelInterceptorTests.java

Lines changed: 10 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -40,18 +40,20 @@ public class GlobalChannelInterceptorTests {
4040
@Test
4141
public void testJmsChannel() {
4242
ActiveMqTestUtils.prepare();
43-
ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
44-
"GlobalChannelInterceptorTests-context.xml", GlobalChannelInterceptorTests.class);
45-
InterceptableChannel jmsChannel = context.getBean("jmsChannel", AbstractMessageChannel.class);
46-
List<ChannelInterceptor> interceptors = jmsChannel.getInterceptors();
47-
assertThat(interceptors).isNotNull();
48-
assertThat(interceptors.size()).isEqualTo(1);
49-
assertThat(interceptors.get(0) instanceof SampleInterceptor).isTrue();
50-
context.close();
43+
try (ConfigurableApplicationContext context = new ClassPathXmlApplicationContext(
44+
"GlobalChannelInterceptorTests-context.xml", GlobalChannelInterceptorTests.class)) {
45+
46+
InterceptableChannel jmsChannel = context.getBean("jmsChannel", AbstractMessageChannel.class);
47+
List<ChannelInterceptor> interceptors = jmsChannel.getInterceptors();
48+
assertThat(interceptors).isNotNull();
49+
assertThat(interceptors.size()).isEqualTo(1);
50+
assertThat(interceptors.get(0) instanceof SampleInterceptor).isTrue();
51+
}
5152
}
5253

5354

5455
public static class SampleInterceptor implements ChannelInterceptor {
56+
5557
}
5658

5759
}

spring-integration-jms/src/test/java/org/springframework/integration/jms/dsl/JmsTests.java

Lines changed: 25 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -160,8 +160,8 @@ public void testPollingFlow() {
160160
}
161161
this.controlBus.send("@'jmsTests.ContextConfiguration.integerMessageSource.inboundChannelAdapter'.stop()");
162162

163-
assertThat(((ChannelInterceptorAware) this.outputChannel).getChannelInterceptors()
164-
.contains(this.testChannelInterceptor)).isTrue();
163+
assertThat(((InterceptableChannel) this.outputChannel).getInterceptors())
164+
.contains(this.testChannelInterceptor);
165165
assertThat(this.testChannelInterceptor.invoked.get()).isGreaterThanOrEqualTo(5);
166166

167167
}
@@ -179,17 +179,21 @@ public void testJmsOutboundInboundFlow() {
179179

180180
Message<?> receive = this.jmsOutboundInboundReplyChannel.receive(10000);
181181

182-
assertThat(receive).isNotNull();
183-
assertThat(receive.getPayload()).isEqualTo("HELLO THROUGH THE JMS");
182+
assertThat(receive)
183+
.isNotNull()
184+
.extracting(Message::getPayload)
185+
.isEqualTo("HELLO THROUGH THE JMS");
184186

185187
this.jmsOutboundInboundChannel.send(MessageBuilder.withPayload("hello THROUGH the JMS")
186188
.setHeader(SimpMessageHeaderAccessor.DESTINATION_HEADER, "jmsMessageDriven")
187189
.build());
188190

189191
receive = this.jmsOutboundInboundReplyChannel.receive(10000);
190192

191-
assertThat(receive).isNotNull();
192-
assertThat(receive.getPayload()).isEqualTo("hello through the jms");
193+
assertThat(receive)
194+
.isNotNull()
195+
.extracting(Message::getPayload)
196+
.isEqualTo("hello through the jms");
193197

194198
assertThat(this.jmsMessageDrivenChannelCalled.get()).isTrue();
195199

@@ -199,8 +203,10 @@ public void testJmsOutboundInboundFlow() {
199203

200204
receive = this.jmsOutboundInboundReplyChannel.receive(10000);
201205

202-
assertThat(receive).isNotNull();
203-
assertThat(receive.getPayload()).isEqualTo("foo");
206+
assertThat(receive)
207+
.isNotNull()
208+
.extracting(Message::getPayload)
209+
.isEqualTo("foo");
204210

205211
assertThat(this.jmsOutboundFlowTemplate).isNotNull();
206212
}
@@ -218,8 +224,10 @@ public void testJmsPipelineFlow() {
218224

219225
Message<?> receive = replyChannel.receive(5000);
220226

221-
assertThat(receive).isNotNull();
222-
assertThat(receive.getPayload()).isEqualTo("HELLO THROUGH THE JMS PIPELINE");
227+
assertThat(receive)
228+
.isNotNull()
229+
.extracting(Message::getPayload)
230+
.isEqualTo("HELLO THROUGH THE JMS PIPELINE");
223231

224232
assertThat(this.jmsInboundGatewayChannelCalled.get()).isTrue();
225233
}
@@ -231,8 +239,10 @@ public void testPubSubFlow() {
231239
template.setDefaultDestinationName("pubsub");
232240
template.convertAndSend("foo");
233241
Message<?> received = this.jmsPubSubBridgeChannel.receive(5000);
234-
assertThat(received).isNotNull();
235-
assertThat(received.getPayload()).isEqualTo("foo");
242+
assertThat(received)
243+
.isNotNull()
244+
.extracting(Message::getPayload)
245+
.isEqualTo("foo");
236246
}
237247

238248
@Test
@@ -340,10 +350,11 @@ public IntegrationFlow pubSubFlow() {
340350
@Bean
341351
public IntegrationFlow jmsMessageDrivenFlow() {
342352
return IntegrationFlows
343-
.from(Jms.messageDrivenChannelAdapter(jmsConnectionFactory(), DefaultMessageListenerContainer.class)
353+
.from(Jms.messageDrivenChannelAdapter(jmsConnectionFactory(),
354+
DefaultMessageListenerContainer.class)
344355
.outputChannel(jmsMessageDrivenInputChannel())
345356
.destination("jmsMessageDriven")
346-
.configureListenerContainer(c -> c.clientId("foo")))
357+
.configureListenerContainer(c -> c.clientId("foo")))
347358
.<String, String>transform(String::toLowerCase)
348359
.channel(jmsOutboundInboundReplyChannel())
349360
.get();

0 commit comments

Comments
 (0)