use of org.springframework.messaging.support.ChannelInterceptor in project spring-integration by spring-projects.
the class JmsChannelParserTests method topicChannelWithInterceptors.
@Test
@SuppressWarnings("unchecked")
public void topicChannelWithInterceptors() {
assertEquals(SubscribableJmsChannel.class, topicChannelWithInterceptors.getClass());
SubscribableJmsChannel channel = (SubscribableJmsChannel) topicChannelWithInterceptors;
DirectFieldAccessor accessor = new DirectFieldAccessor(channel);
List<ChannelInterceptor> interceptors = (List<ChannelInterceptor>) new DirectFieldAccessor(accessor.getPropertyValue("interceptors")).getPropertyValue("interceptors");
assertEquals(2, interceptors.size());
assertEquals(TestInterceptor.class, interceptors.get(0).getClass());
assertEquals(TestInterceptor.class, interceptors.get(1).getClass());
}
use of org.springframework.messaging.support.ChannelInterceptor in project spring-integration by spring-projects.
the class PollableJmsChannelTests method queueNameWithTruePreReceiveInterceptors.
@Test
public void queueNameWithTruePreReceiveInterceptors() throws Exception {
JmsChannelFactoryBean factoryBean = new JmsChannelFactoryBean(false);
CachingConnectionFactory ccf = new CachingConnectionFactory(this.connectionFactory);
ccf.setCacheConsumers(false);
factoryBean.setConnectionFactory(ccf);
factoryBean.setDestinationName("someDynamicQueue");
factoryBean.setPubSubDomain(false);
List<ChannelInterceptor> interceptorList = new ArrayList<ChannelInterceptor>();
ChannelInterceptor interceptor = spy(new SampleInterceptor(true));
interceptorList.add(interceptor);
factoryBean.setInterceptors(interceptorList);
factoryBean.setBeanFactory(mock(BeanFactory.class));
factoryBean.afterPropertiesSet();
PollableJmsChannel channel = (PollableJmsChannel) factoryBean.getObject();
boolean sent1 = channel.send(new GenericMessage<String>("foo"));
assertTrue(sent1);
Message<?> result1 = channel.receive(10000);
assertNotNull(result1);
verify(interceptor, times(1)).preReceive(Mockito.any(MessageChannel.class));
verify(interceptor, times(1)).postReceive(Mockito.any(Message.class), Mockito.any(MessageChannel.class));
}
use of org.springframework.messaging.support.ChannelInterceptor in project spring-framework by spring-projects.
the class StompSubProtocolHandlerTests method handleMessageFromClientWithImmutableMessageInterceptor.
@Test
public void handleMessageFromClientWithImmutableMessageInterceptor() {
AtomicReference<Boolean> mutable = new AtomicReference<>();
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
channel.addInterceptor(new ChannelInterceptor() {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
mutable.set(MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class).isMutable());
return message;
}
});
channel.addInterceptor(new ImmutableMessageChannelInterceptor());
StompSubProtocolHandler handler = new StompSubProtocolHandler();
handler.afterSessionStarted(this.session, channel);
TextMessage message = StompTextMessageBuilder.create(StompCommand.CONNECT).build();
handler.handleMessageFromClient(this.session, message, channel);
assertThat(mutable.get()).isNotNull();
assertThat(mutable.get()).isTrue();
}
use of org.springframework.messaging.support.ChannelInterceptor in project spring-framework by spring-projects.
the class StompSubProtocolHandlerTests method handleMessageFromClientWithoutImmutableMessageInterceptor.
@Test
public void handleMessageFromClientWithoutImmutableMessageInterceptor() {
AtomicReference<Boolean> mutable = new AtomicReference<>();
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
channel.addInterceptor(new ChannelInterceptor() {
@Override
public Message<?> preSend(Message<?> message, MessageChannel channel) {
mutable.set(MessageHeaderAccessor.getAccessor(message, MessageHeaderAccessor.class).isMutable());
return message;
}
});
StompSubProtocolHandler handler = new StompSubProtocolHandler();
handler.afterSessionStarted(this.session, channel);
TextMessage message = StompTextMessageBuilder.create(StompCommand.CONNECT).build();
handler.handleMessageFromClient(this.session, message, channel);
assertThat(mutable.get()).isNotNull();
assertThat(mutable.get()).isFalse();
}
use of org.springframework.messaging.support.ChannelInterceptor in project spring-framework by spring-projects.
the class WebSocketMessageBrokerConfigurationSupportTests method brokerChannel.
@Test
void brokerChannel() {
ApplicationContext context = createContext(TestChannelConfig.class, TestConfigurer.class);
TestChannel channel = context.getBean("brokerChannel", TestChannel.class);
Set<MessageHandler> handlers = channel.getSubscribers();
List<ChannelInterceptor> interceptors = channel.getInterceptors();
assertThat(interceptors.get(interceptors.size() - 1).getClass()).isEqualTo(ImmutableMessageChannelInterceptor.class);
assertThat(handlers).hasSize(2);
assertThat(handlers).contains(context.getBean(SimpleBrokerMessageHandler.class));
assertThat(handlers).contains(context.getBean(UserDestinationMessageHandler.class));
}
Aggregations