use of org.springframework.messaging.support.ImmutableMessageChannelInterceptor in project spring-framework by spring-projects.
the class AbstractMessageBrokerConfiguration method brokerChannel.
@Bean
public AbstractSubscribableChannel brokerChannel() {
ChannelRegistration reg = getBrokerRegistry().getBrokerChannelRegistration();
ExecutorSubscribableChannel channel = reg.hasTaskExecutor() ? new ExecutorSubscribableChannel(brokerChannelExecutor()) : new ExecutorSubscribableChannel();
reg.setInterceptors(new ImmutableMessageChannelInterceptor());
channel.setInterceptors(reg.getInterceptors());
return channel;
}
use of org.springframework.messaging.support.ImmutableMessageChannelInterceptor in project spring-cloud-stream by spring-cloud.
the class BinderAwareChannelResolverTests method resolveChannel.
@Test
public void resolveChannel() {
Map<String, Bindable> bindables = context.getBeansOfType(Bindable.class);
assertThat(bindables).hasSize(1);
for (Bindable bindable : bindables.values()) {
// producer
assertEquals(0, bindable.getInputs().size());
// consumer
assertEquals(0, bindable.getOutputs().size());
}
MessageChannel registered = resolver.resolveDestination("foo");
assertEquals(2, ((AbstractMessageChannel) registered).getChannelInterceptors().size());
assertTrue(((AbstractMessageChannel) registered).getChannelInterceptors().get(1) instanceof ImmutableMessageChannelInterceptor);
bindables = context.getBeansOfType(Bindable.class);
assertThat(bindables).hasSize(1);
for (Bindable bindable : bindables.values()) {
// producer
assertEquals(0, bindable.getInputs().size());
// consumer
assertEquals(1, bindable.getOutputs().size());
}
DirectChannel testChannel = new DirectChannel();
testChannel.setComponentName("INPUT");
final CountDownLatch latch = new CountDownLatch(1);
final List<Message<?>> received = new ArrayList<>();
testChannel.subscribe(new MessageHandler() {
@Override
public void handleMessage(Message<?> message) throws MessagingException {
received.add(message);
latch.countDown();
}
});
this.binder.bindConsumer("foo", null, testChannel, new ConsumerProperties());
assertThat(received).hasSize(0);
registered.send(MessageBuilder.withPayload("hello").build());
try {
assertThat(latch.await(1, TimeUnit.SECONDS)).describedAs("Latch timed out");
} catch (InterruptedException e) {
Thread.currentThread().interrupt();
fail("interrupted while awaiting latch");
}
assertThat(received).hasSize(1);
assertThat(new String((byte[]) received.get(0).getPayload())).isEqualTo("hello");
this.context.close();
for (Bindable bindable : bindables.values()) {
assertEquals(0, bindable.getInputs().size());
// Must not be bound"
assertEquals(0, bindable.getOutputs().size());
}
}
use of org.springframework.messaging.support.ImmutableMessageChannelInterceptor in project spring-framework by spring-projects.
the class StompSubProtocolHandlerTests method handleMessageFromClientWithTokenAuthentication.
// SPR-14690
@Test
public void handleMessageFromClientWithTokenAuthentication() {
ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
channel.addInterceptor(new AuthenticationInterceptor("__pete__@gmail.com"));
channel.addInterceptor(new ImmutableMessageChannelInterceptor());
TestMessageHandler messageHandler = new TestMessageHandler();
channel.subscribe(messageHandler);
StompSubProtocolHandler handler = new StompSubProtocolHandler();
handler.afterSessionStarted(this.session, channel);
TextMessage wsMessage = StompTextMessageBuilder.create(StompCommand.CONNECT).build();
handler.handleMessageFromClient(this.session, wsMessage, channel);
assertThat(messageHandler.getMessages().size()).isEqualTo(1);
Message<?> message = messageHandler.getMessages().get(0);
Principal user = SimpMessageHeaderAccessor.getUser(message.getHeaders());
assertThat(user).isNotNull();
assertThat(user.getName()).isEqualTo("__pete__@gmail.com");
StompHeaderAccessor accessor = StompHeaderAccessor.create(StompCommand.CONNECTED);
message = MessageBuilder.createMessage(EMPTY_PAYLOAD, accessor.getMessageHeaders());
handler.handleMessageToClient(this.session, message);
assertThat(this.session.getSentMessages()).hasSize(1);
WebSocketMessage<?> textMessage = this.session.getSentMessages().get(0);
assertThat(textMessage.getPayload()).isEqualTo("CONNECTED\n" + "user-name:__pete__@gmail.com\n" + "\n" + "\u0000");
}
use of org.springframework.messaging.support.ImmutableMessageChannelInterceptor in project spring-framework by spring-projects.
the class AbstractMessageBrokerConfiguration method brokerChannel.
@Bean
public AbstractSubscribableChannel brokerChannel(AbstractSubscribableChannel clientInboundChannel, AbstractSubscribableChannel clientOutboundChannel, TaskExecutor brokerChannelExecutor) {
MessageBrokerRegistry registry = getBrokerRegistry(clientInboundChannel, clientOutboundChannel);
ChannelRegistration registration = registry.getBrokerChannelRegistration();
ExecutorSubscribableChannel channel = (registration.hasTaskExecutor() ? new ExecutorSubscribableChannel(brokerChannelExecutor) : new ExecutorSubscribableChannel());
registration.interceptors(new ImmutableMessageChannelInterceptor());
channel.setLogger(SimpLogging.forLog(channel.getLogger()));
channel.setInterceptors(registration.getInterceptors());
return channel;
}
use of org.springframework.messaging.support.ImmutableMessageChannelInterceptor in project spring-framework by spring-projects.
the class AbstractMessageBrokerConfiguration method getClientOutboundChannelRegistration.
protected final ChannelRegistration getClientOutboundChannelRegistration() {
if (this.clientOutboundChannelRegistration == null) {
ChannelRegistration registration = new ChannelRegistration();
configureClientOutboundChannel(registration);
registration.interceptors(new ImmutableMessageChannelInterceptor());
this.clientOutboundChannelRegistration = registration;
}
return this.clientOutboundChannelRegistration;
}
Aggregations