use of org.springframework.integration.websocket.support.SubProtocolHandlerRegistry in project spring-integration by spring-projects.
the class WebSocketParserTests method testCustomOutboundChannelAdapter.
@Test
public void testCustomOutboundChannelAdapter() throws URISyntaxException {
assertSame(this.clientWebSocketContainer, TestUtils.getPropertyValue(this.customOutboundAdapter, "webSocketContainer"));
SubProtocolHandlerRegistry subProtocolHandlerRegistry = TestUtils.getPropertyValue(this.customOutboundAdapter, "subProtocolHandlerRegistry", SubProtocolHandlerRegistry.class);
assertSame(this.stompSubProtocolHandler, TestUtils.getPropertyValue(subProtocolHandlerRegistry, "defaultProtocolHandler"));
Map<?, ?> protocolHandlers = TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class);
assertEquals(3, protocolHandlers.size());
// See warn log message.
for (Object handler : protocolHandlers.values()) {
assertSame(this.stompSubProtocolHandler, handler);
}
assertTrue(TestUtils.getPropertyValue(this.customOutboundAdapter, "mergeWithDefaultConverters", Boolean.class));
CompositeMessageConverter compositeMessageConverter = TestUtils.getPropertyValue(this.customOutboundAdapter, "messageConverter", CompositeMessageConverter.class);
List<MessageConverter> converters = compositeMessageConverter.getConverters();
assertEquals(5, converters.size());
assertSame(this.simpleMessageConverter, converters.get(0));
assertSame(this.mapMessageConverter, converters.get(1));
assertThat(converters.get(2), instanceOf(StringMessageConverter.class));
assertTrue(TestUtils.getPropertyValue(this.customOutboundAdapter, "client", Boolean.class));
}
use of org.springframework.integration.websocket.support.SubProtocolHandlerRegistry in project spring-integration by spring-projects.
the class WebSocketParserTests method testDefaultInboundChannelAdapterAndServerContainer.
@Test
@SuppressWarnings("unckecked")
public void testDefaultInboundChannelAdapterAndServerContainer() {
Map<?, ?> urlMap = TestUtils.getPropertyValue(this.handlerMapping, "urlMap", Map.class);
assertEquals(1, urlMap.size());
assertTrue(urlMap.containsKey("/ws/**"));
Object mappedHandler = urlMap.get("/ws/**");
// WebSocketHttpRequestHandler -> ExceptionWebSocketHandlerDecorator - > LoggingWebSocketHandlerDecorator
// -> IntegrationWebSocketContainer$IntegrationWebSocketHandler
assertSame(TestUtils.getPropertyValue(this.serverWebSocketContainer, "webSocketHandler"), TestUtils.getPropertyValue(mappedHandler, "webSocketHandler.delegate.delegate"));
assertSame(this.handshakeHandler, TestUtils.getPropertyValue(this.serverWebSocketContainer, "handshakeHandler"));
HandshakeInterceptor[] interceptors = TestUtils.getPropertyValue(this.serverWebSocketContainer, "interceptors", HandshakeInterceptor[].class);
assertNotNull(interceptors);
assertEquals(1, interceptors.length);
assertSame(this.handshakeInterceptor, interceptors[0]);
assertEquals(100, TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendTimeLimit"));
assertEquals(100000, TestUtils.getPropertyValue(this.serverWebSocketContainer, "sendBufferSizeLimit"));
assertArrayEquals(new String[] { "http://foo.com" }, TestUtils.getPropertyValue(this.serverWebSocketContainer, "origins", String[].class));
WebSocketHandlerDecoratorFactory[] decoratorFactories = TestUtils.getPropertyValue(this.serverWebSocketContainer, "decoratorFactories", WebSocketHandlerDecoratorFactory[].class);
assertNotNull(decoratorFactories);
assertEquals(1, decoratorFactories.length);
assertSame(this.decoratorFactory, decoratorFactories[0]);
TransportHandlingSockJsService sockJsService = TestUtils.getPropertyValue(mappedHandler, "sockJsService", TransportHandlingSockJsService.class);
assertSame(this.taskScheduler, sockJsService.getTaskScheduler());
assertSame(this.sockJsMessageCodec, sockJsService.getMessageCodec());
Map<TransportType, TransportHandler> transportHandlers = sockJsService.getTransportHandlers();
// If "handshake-handler" is provided, "transport-handlers" isn't allowed
assertEquals(8, transportHandlers.size());
assertSame(this.handshakeHandler, TestUtils.getPropertyValue(transportHandlers.get(TransportType.WEBSOCKET), "handshakeHandler"));
assertEquals(4000L, sockJsService.getDisconnectDelay());
assertEquals(30000L, sockJsService.getHeartbeatTime());
assertEquals(10000, sockJsService.getHttpMessageCacheSize());
assertEquals(2000, sockJsService.getStreamBytesLimit());
assertEquals("https://foo.sock.js", sockJsService.getSockJsClientLibraryUrl());
assertFalse(sockJsService.isSessionCookieNeeded());
assertFalse(sockJsService.isWebSocketEnabled());
assertTrue(sockJsService.shouldSuppressCors());
assertSame(this.serverWebSocketContainer, TestUtils.getPropertyValue(this.defaultInboundAdapter, "webSocketContainer"));
assertNull(TestUtils.getPropertyValue(this.defaultInboundAdapter, "messageConverters"));
assertEquals(TestUtils.getPropertyValue(this.defaultInboundAdapter, "messageConverter.converters"), TestUtils.getPropertyValue(this.defaultInboundAdapter, "defaultConverters"));
assertEquals(String.class, TestUtils.getPropertyValue(this.defaultInboundAdapter, "payloadType", AtomicReference.class).get());
assertTrue(TestUtils.getPropertyValue(this.defaultInboundAdapter, "useBroker", Boolean.class));
assertSame(this.brokerHandler, TestUtils.getPropertyValue(this.defaultInboundAdapter, "brokerHandler"));
SubProtocolHandlerRegistry subProtocolHandlerRegistry = TestUtils.getPropertyValue(this.defaultInboundAdapter, "subProtocolHandlerRegistry", SubProtocolHandlerRegistry.class);
assertThat(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "defaultProtocolHandler"), instanceOf(PassThruSubProtocolHandler.class));
assertTrue(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class).isEmpty());
}
use of org.springframework.integration.websocket.support.SubProtocolHandlerRegistry in project spring-integration by spring-projects.
the class WebSocketParserTests method testDefaultOutboundChannelAdapter.
@Test
public void testDefaultOutboundChannelAdapter() {
assertSame(this.serverWebSocketContainer, TestUtils.getPropertyValue(this.defaultOutboundAdapter, "webSocketContainer"));
assertNull(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "messageConverters"));
assertEquals(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "messageConverter.converters"), TestUtils.getPropertyValue(this.defaultOutboundAdapter, "defaultConverters"));
SubProtocolHandlerRegistry subProtocolHandlerRegistry = TestUtils.getPropertyValue(this.defaultOutboundAdapter, "subProtocolHandlerRegistry", SubProtocolHandlerRegistry.class);
assertThat(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "defaultProtocolHandler"), instanceOf(PassThruSubProtocolHandler.class));
assertTrue(TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class).isEmpty());
assertFalse(TestUtils.getPropertyValue(this.defaultOutboundAdapter, "client", Boolean.class));
}
use of org.springframework.integration.websocket.support.SubProtocolHandlerRegistry in project spring-integration by spring-projects.
the class WebSocketParserTests method testCustomInboundChannelAdapterAndClientContainer.
@Test
public void testCustomInboundChannelAdapterAndClientContainer() throws URISyntaxException {
assertSame(this.clientInboundChannel, TestUtils.getPropertyValue(this.customInboundAdapter, "outputChannel"));
assertSame(this.errorChannel, TestUtils.getPropertyValue(this.customInboundAdapter, "errorChannel"));
assertSame(this.clientWebSocketContainer, TestUtils.getPropertyValue(this.customInboundAdapter, "webSocketContainer"));
assertEquals(2000L, TestUtils.getPropertyValue(this.customInboundAdapter, "messagingTemplate.sendTimeout"));
assertEquals(200, TestUtils.getPropertyValue(this.customInboundAdapter, "phase"));
assertFalse(TestUtils.getPropertyValue(this.customInboundAdapter, "autoStartup", Boolean.class));
assertEquals(Integer.class, TestUtils.getPropertyValue(this.customInboundAdapter, "payloadType", AtomicReference.class).get());
SubProtocolHandlerRegistry subProtocolHandlerRegistry = TestUtils.getPropertyValue(this.customInboundAdapter, "subProtocolHandlerRegistry", SubProtocolHandlerRegistry.class);
assertSame(this.stompSubProtocolHandler, TestUtils.getPropertyValue(subProtocolHandlerRegistry, "defaultProtocolHandler"));
Map<?, ?> protocolHandlers = TestUtils.getPropertyValue(subProtocolHandlerRegistry, "protocolHandlers", Map.class);
assertEquals(3, protocolHandlers.size());
// See warn log message.
for (Object handler : protocolHandlers.values()) {
assertSame(this.stompSubProtocolHandler, handler);
}
assertTrue(TestUtils.getPropertyValue(this.customInboundAdapter, "mergeWithDefaultConverters", Boolean.class));
CompositeMessageConverter compositeMessageConverter = TestUtils.getPropertyValue(this.customInboundAdapter, "messageConverter", CompositeMessageConverter.class);
List<MessageConverter> converters = compositeMessageConverter.getConverters();
assertEquals(5, converters.size());
assertSame(this.simpleMessageConverter, converters.get(0));
assertSame(this.mapMessageConverter, converters.get(1));
assertThat(converters.get(2), instanceOf(StringMessageConverter.class));
// Test ClientWebSocketContainer parser
assertSame(this.customInboundAdapter, TestUtils.getPropertyValue(this.clientWebSocketContainer, "messageListener"));
assertEquals(100, TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendTimeLimit"));
assertEquals(1000, TestUtils.getPropertyValue(this.clientWebSocketContainer, "sendBufferSizeLimit"));
assertEquals(new URI("ws://foo.bar/ws?service=user"), TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.uri", URI.class));
assertSame(this.webSocketClient, TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.client"));
assertEquals(100, TestUtils.getPropertyValue(this.clientWebSocketContainer, "connectionManager.phase"));
WebSocketHttpHeaders headers = TestUtils.getPropertyValue(this.clientWebSocketContainer, "headers", WebSocketHttpHeaders.class);
assertEquals("FOO", headers.getOrigin());
assertEquals(Arrays.asList("BAR", "baz"), headers.get("FOO"));
assertEquals(10 * 1000, TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendTimeLimit"));
assertEquals(512 * 1024, TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "sendBufferSizeLimit"));
assertEquals(new URI("ws://foo.bar"), TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.uri", URI.class));
assertSame(this.webSocketClient, TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.client"));
assertEquals(Integer.MAX_VALUE, TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.phase"));
assertFalse(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "connectionManager.autoStartup", Boolean.class));
assertTrue(TestUtils.getPropertyValue(this.simpleClientWebSocketContainer, "headers", WebSocketHttpHeaders.class).isEmpty());
}
use of org.springframework.integration.websocket.support.SubProtocolHandlerRegistry in project faf-java-server by FAForever.
the class WebsocketAdapterConfig method webSocketInboundChannelAdapter.
/**
* WebSocket inbound adapter that accepts connections and messages from clients.
*/
@Bean
public WebSocketInboundChannelAdapter webSocketInboundChannelAdapter(IntegrationWebSocketContainer serverWebSocketContainer) {
WebSocketInboundChannelAdapter adapter = new WebSocketInboundChannelAdapter(serverWebSocketContainer, new SubProtocolHandlerRegistry(new FafSubProtocolHandler(clientConnectionService)));
adapter.setErrorChannelName(IntegrationContextUtils.ERROR_CHANNEL_BEAN_NAME);
return adapter;
}
Aggregations