Search in sources :

Example 6 with ExecutorSubscribableChannel

use of org.springframework.messaging.support.ExecutorSubscribableChannel 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 ChannelInterceptorAdapter() {

        @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);
    assertNotNull(mutable.get());
    assertTrue(mutable.get());
}
Also used : ExecutorSubscribableChannel(org.springframework.messaging.support.ExecutorSubscribableChannel) ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) TextMessage(org.springframework.web.socket.TextMessage) Message(org.springframework.messaging.Message) WebSocketMessage(org.springframework.web.socket.WebSocketMessage) BinaryMessage(org.springframework.web.socket.BinaryMessage) ImmutableMessageChannelInterceptor(org.springframework.messaging.support.ImmutableMessageChannelInterceptor) AtomicReference(java.util.concurrent.atomic.AtomicReference) MessageChannel(org.springframework.messaging.MessageChannel) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.Test)

Example 7 with ExecutorSubscribableChannel

use of org.springframework.messaging.support.ExecutorSubscribableChannel 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 ChannelInterceptorAdapter() {

        @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);
    assertNotNull(mutable.get());
    assertFalse(mutable.get());
}
Also used : ExecutorSubscribableChannel(org.springframework.messaging.support.ExecutorSubscribableChannel) ChannelInterceptorAdapter(org.springframework.messaging.support.ChannelInterceptorAdapter) MessageChannel(org.springframework.messaging.MessageChannel) TextMessage(org.springframework.web.socket.TextMessage) Message(org.springframework.messaging.Message) WebSocketMessage(org.springframework.web.socket.WebSocketMessage) BinaryMessage(org.springframework.web.socket.BinaryMessage) AtomicReference(java.util.concurrent.atomic.AtomicReference) SimpMessageHeaderAccessor(org.springframework.messaging.simp.SimpMessageHeaderAccessor) MessageHeaderAccessor(org.springframework.messaging.support.MessageHeaderAccessor) TextMessage(org.springframework.web.socket.TextMessage) Test(org.junit.Test)

Example 8 with ExecutorSubscribableChannel

use of org.springframework.messaging.support.ExecutorSubscribableChannel in project spring-security by spring-projects.

the class SyncExecutorSubscribableChannelPostProcessor method postProcessBeforeInitialization.

public Object postProcessBeforeInitialization(Object bean, String beanName) throws BeansException {
    if (bean instanceof ExecutorSubscribableChannel) {
        ExecutorSubscribableChannel original = (ExecutorSubscribableChannel) bean;
        ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel();
        channel.setInterceptors(original.getInterceptors());
        return channel;
    }
    return bean;
}
Also used : ExecutorSubscribableChannel(org.springframework.messaging.support.ExecutorSubscribableChannel)

Example 9 with ExecutorSubscribableChannel

use of org.springframework.messaging.support.ExecutorSubscribableChannel in project spring-framework by spring-projects.

the class AbstractMessageBrokerConfiguration method clientOutboundChannel.

@Bean
public AbstractSubscribableChannel clientOutboundChannel() {
    ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientOutboundChannelExecutor());
    ChannelRegistration reg = getClientOutboundChannelRegistration();
    channel.setInterceptors(reg.getInterceptors());
    return channel;
}
Also used : ExecutorSubscribableChannel(org.springframework.messaging.support.ExecutorSubscribableChannel) Bean(org.springframework.context.annotation.Bean)

Example 10 with ExecutorSubscribableChannel

use of org.springframework.messaging.support.ExecutorSubscribableChannel in project spring-framework by spring-projects.

the class AbstractMessageBrokerConfiguration method clientInboundChannel.

@Bean
public AbstractSubscribableChannel clientInboundChannel() {
    ExecutorSubscribableChannel channel = new ExecutorSubscribableChannel(clientInboundChannelExecutor());
    ChannelRegistration reg = getClientInboundChannelRegistration();
    channel.setInterceptors(reg.getInterceptors());
    return channel;
}
Also used : ExecutorSubscribableChannel(org.springframework.messaging.support.ExecutorSubscribableChannel) Bean(org.springframework.context.annotation.Bean)

Aggregations

ExecutorSubscribableChannel (org.springframework.messaging.support.ExecutorSubscribableChannel)11 Test (org.junit.Test)5 MessageChannel (org.springframework.messaging.MessageChannel)4 AtomicReference (java.util.concurrent.atomic.AtomicReference)3 Bean (org.springframework.context.annotation.Bean)3 ImmutableMessageChannelInterceptor (org.springframework.messaging.support.ImmutableMessageChannelInterceptor)3 TextMessage (org.springframework.web.socket.TextMessage)3 Before (org.junit.Before)2 Message (org.springframework.messaging.Message)2 MessageHandler (org.springframework.messaging.MessageHandler)2 MessagingException (org.springframework.messaging.MessagingException)2 StubMessageChannel (org.springframework.messaging.StubMessageChannel)2 SubscribableChannel (org.springframework.messaging.SubscribableChannel)2 SimpMessageHeaderAccessor (org.springframework.messaging.simp.SimpMessageHeaderAccessor)2 ChannelInterceptorAdapter (org.springframework.messaging.support.ChannelInterceptorAdapter)2 GenericMessage (org.springframework.messaging.support.GenericMessage)2 MessageHeaderAccessor (org.springframework.messaging.support.MessageHeaderAccessor)2 BinaryMessage (org.springframework.web.socket.BinaryMessage)2 WebSocketMessage (org.springframework.web.socket.WebSocketMessage)2 Principal (java.security.Principal)1