Search in sources :

Example 1 with SubProtocolHandlerRegistry

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));
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) SubProtocolHandlerRegistry(org.springframework.integration.websocket.support.SubProtocolHandlerRegistry) CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) MapMessageConverter(org.springframework.integration.support.converter.MapMessageConverter) MessageConverter(org.springframework.messaging.converter.MessageConverter) SimpleMessageConverter(org.springframework.integration.support.converter.SimpleMessageConverter) StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) Test(org.junit.Test)

Example 2 with SubProtocolHandlerRegistry

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());
}
Also used : TransportHandler(org.springframework.web.socket.sockjs.transport.TransportHandler) TransportHandlingSockJsService(org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService) SubProtocolHandlerRegistry(org.springframework.integration.websocket.support.SubProtocolHandlerRegistry) WebSocketHandlerDecoratorFactory(org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory) HandshakeInterceptor(org.springframework.web.socket.server.HandshakeInterceptor) PassThruSubProtocolHandler(org.springframework.integration.websocket.support.PassThruSubProtocolHandler) TransportType(org.springframework.web.socket.sockjs.transport.TransportType) Test(org.junit.Test)

Example 3 with SubProtocolHandlerRegistry

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));
}
Also used : PassThruSubProtocolHandler(org.springframework.integration.websocket.support.PassThruSubProtocolHandler) SubProtocolHandlerRegistry(org.springframework.integration.websocket.support.SubProtocolHandlerRegistry) Test(org.junit.Test)

Example 4 with SubProtocolHandlerRegistry

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());
}
Also used : StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) WebSocketHttpHeaders(org.springframework.web.socket.WebSocketHttpHeaders) SubProtocolHandlerRegistry(org.springframework.integration.websocket.support.SubProtocolHandlerRegistry) CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) CompositeMessageConverter(org.springframework.messaging.converter.CompositeMessageConverter) MapMessageConverter(org.springframework.integration.support.converter.MapMessageConverter) MessageConverter(org.springframework.messaging.converter.MessageConverter) SimpleMessageConverter(org.springframework.integration.support.converter.SimpleMessageConverter) StringMessageConverter(org.springframework.messaging.converter.StringMessageConverter) URI(java.net.URI) Test(org.junit.Test)

Example 5 with SubProtocolHandlerRegistry

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;
}
Also used : WebSocketInboundChannelAdapter(org.springframework.integration.websocket.inbound.WebSocketInboundChannelAdapter) SubProtocolHandlerRegistry(org.springframework.integration.websocket.support.SubProtocolHandlerRegistry) Bean(org.springframework.context.annotation.Bean)

Aggregations

SubProtocolHandlerRegistry (org.springframework.integration.websocket.support.SubProtocolHandlerRegistry)5 Test (org.junit.Test)4 MapMessageConverter (org.springframework.integration.support.converter.MapMessageConverter)2 SimpleMessageConverter (org.springframework.integration.support.converter.SimpleMessageConverter)2 PassThruSubProtocolHandler (org.springframework.integration.websocket.support.PassThruSubProtocolHandler)2 CompositeMessageConverter (org.springframework.messaging.converter.CompositeMessageConverter)2 MessageConverter (org.springframework.messaging.converter.MessageConverter)2 StringMessageConverter (org.springframework.messaging.converter.StringMessageConverter)2 URI (java.net.URI)1 Bean (org.springframework.context.annotation.Bean)1 WebSocketInboundChannelAdapter (org.springframework.integration.websocket.inbound.WebSocketInboundChannelAdapter)1 WebSocketHttpHeaders (org.springframework.web.socket.WebSocketHttpHeaders)1 WebSocketHandlerDecoratorFactory (org.springframework.web.socket.handler.WebSocketHandlerDecoratorFactory)1 HandshakeInterceptor (org.springframework.web.socket.server.HandshakeInterceptor)1 TransportHandler (org.springframework.web.socket.sockjs.transport.TransportHandler)1 TransportHandlingSockJsService (org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService)1 TransportType (org.springframework.web.socket.sockjs.transport.TransportType)1