use of org.springframework.web.socket.messaging.SubProtocolWebSocketHandler in project spring-framework by spring-projects.
the class WebSocketMessageBrokerConfigurationSupport method stompWebSocketHandlerMapping.
@Bean
public HandlerMapping stompWebSocketHandlerMapping() {
WebSocketHandler handler = decorateWebSocketHandler(subProtocolWebSocketHandler());
WebMvcStompEndpointRegistry registry = new WebMvcStompEndpointRegistry(handler, getTransportRegistration(), messageBrokerTaskScheduler());
registry.setApplicationContext(getApplicationContext());
registerStompEndpoints(registry);
return registry.getHandlerMapping();
}
use of org.springframework.web.socket.messaging.SubProtocolWebSocketHandler in project spring-framework by spring-projects.
the class WebSocketMessageBrokerConfigurationSupportTests method clientInboundChannelSendMessage.
@Test
void clientInboundChannelSendMessage() throws Exception {
ApplicationContext context = createContext(TestChannelConfig.class, TestConfigurer.class);
TestChannel channel = context.getBean("clientInboundChannel", TestChannel.class);
SubProtocolWebSocketHandler webSocketHandler = context.getBean(SubProtocolWebSocketHandler.class);
List<ChannelInterceptor> interceptors = channel.getInterceptors();
assertThat(interceptors.get(interceptors.size() - 1).getClass()).isEqualTo(ImmutableMessageChannelInterceptor.class);
TestWebSocketSession session = new TestWebSocketSession("s1");
session.setOpen(true);
webSocketHandler.afterConnectionEstablished(session);
webSocketHandler.handleMessage(session, StompTextMessageBuilder.create(StompCommand.SEND).headers("destination:/foo").build());
Message<?> message = channel.messages.get(0);
StompHeaderAccessor accessor = StompHeaderAccessor.getAccessor(message, StompHeaderAccessor.class);
assertThat(accessor).isNotNull();
assertThat(accessor.isMutable()).isFalse();
assertThat(accessor.getMessageType()).isEqualTo(SimpMessageType.MESSAGE);
assertThat(accessor.getDestination()).isEqualTo("/foo");
}
use of org.springframework.web.socket.messaging.SubProtocolWebSocketHandler in project spring-framework by spring-projects.
the class SockJsWebSocketHandlerTests method getSubProtocols.
@Test
public void getSubProtocols() throws Exception {
SubscribableChannel channel = mock(SubscribableChannel.class);
SubProtocolWebSocketHandler handler = new SubProtocolWebSocketHandler(channel, channel);
StompSubProtocolHandler stompHandler = new StompSubProtocolHandler();
handler.addProtocolHandler(stompHandler);
TaskScheduler scheduler = mock(TaskScheduler.class);
DefaultSockJsService service = new DefaultSockJsService(scheduler);
WebSocketServerSockJsSession session = new WebSocketServerSockJsSession("1", service, handler, null);
SockJsWebSocketHandler sockJsHandler = new SockJsWebSocketHandler(service, handler, session);
assertThat(sockJsHandler.getSubProtocols()).isEqualTo(stompHandler.getSupportedProtocols());
}
use of org.springframework.web.socket.messaging.SubProtocolWebSocketHandler in project spring-integration by spring-projects.
the class TestServerConfig method subProtocolWebSocketHandler.
@Bean
public WebSocketHandler subProtocolWebSocketHandler() {
SubProtocolWebSocketHandler webSocketHandler = new SubProtocolWebSocketHandler(clientInboundChannel(), clientOutboundChannel());
webSocketHandler.setDefaultProtocolHandler(stompSubProtocolHandler());
return webSocketHandler;
}
use of org.springframework.web.socket.messaging.SubProtocolWebSocketHandler in project spring-framework by spring-projects.
the class WebSocketMessageBrokerConfigurationSupport method stompWebSocketHandlerMapping.
@Bean
public HandlerMapping stompWebSocketHandlerMapping(WebSocketHandler subProtocolWebSocketHandler, TaskScheduler messageBrokerTaskScheduler) {
WebSocketHandler handler = decorateWebSocketHandler(subProtocolWebSocketHandler);
WebMvcStompEndpointRegistry registry = new WebMvcStompEndpointRegistry(handler, getTransportRegistration(), messageBrokerTaskScheduler);
ApplicationContext applicationContext = getApplicationContext();
if (applicationContext != null) {
registry.setApplicationContext(applicationContext);
}
registerStompEndpoints(registry);
return registry.getHandlerMapping();
}
Aggregations