/** * Register a sub-protocol handler. */ public void addProtocolHandler(SubProtocolHandler handler) { List<String> protocols = handler.getSupportedProtocols(); if (CollectionUtils.isEmpty(protocols)) { if (logger.isErrorEnabled()) { logger.error("No sub-protocols for " + handler); } return; } for (String protocol : protocols) { SubProtocolHandler replaced = this.protocolHandlerLookup.put(protocol, handler); if (replaced != null && replaced != handler) { throw new IllegalStateException("Cannot map " + handler + " to protocol '" + protocol + "': already mapped to " + replaced + "."); } } this.protocolHandlers.add(handler); }
@Before public void setup() { MockitoAnnotations.initMocks(this); this.webSocketHandler = new SubProtocolWebSocketHandler(this.inClientChannel, this.outClientChannel); given(stompHandler.getSupportedProtocols()).willReturn(Arrays.asList("v10.stomp", "v11.stomp", "v12.stomp")); given(mqttHandler.getSupportedProtocols()).willReturn(Arrays.asList("MQTT")); this.session = new TestWebSocketSession(); this.session.setId("1"); this.session.setOpen(true); }
List<String> protocols = handler.getSupportedProtocols(); if (CollectionUtils.isEmpty(protocols)) { if (LOGGER.isWarnEnabled()) { this.defaultProtocolHandler = defaultProtocolHandler; if (this.protocolHandlers.isEmpty() && this.defaultProtocolHandler != null) { List<String> protocols = this.defaultProtocolHandler.getSupportedProtocols(); for (String protocol : protocols) { SubProtocolHandler replaced = this.protocolHandlers.put(protocol, this.defaultProtocolHandler);
@Test public void testSingleHandler() { SubProtocolHandler testProtocolHandler = spy(new StompSubProtocolHandler()); when(testProtocolHandler.getSupportedProtocols()).thenReturn(Collections.singletonList("foo")); SubProtocolHandlerRegistry subProtocolHandlerRegistry = new SubProtocolHandlerRegistry(Collections.<SubProtocolHandler>singletonList(testProtocolHandler)); WebSocketSession session = mock(WebSocketSession.class); when(session.getAcceptedProtocol()).thenReturn("foo", (String) null); SubProtocolHandler protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session); assertNotNull(protocolHandler); assertSame(protocolHandler, testProtocolHandler); protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session); assertNotNull(protocolHandler); assertSame(protocolHandler, testProtocolHandler); }
/** * Register a sub-protocol handler. */ public void addProtocolHandler(SubProtocolHandler handler) { List<String> protocols = handler.getSupportedProtocols(); if (CollectionUtils.isEmpty(protocols)) { if (logger.isErrorEnabled()) { logger.error("No sub-protocols for " + handler); } return; } for (String protocol : protocols) { SubProtocolHandler replaced = this.protocolHandlerLookup.put(protocol, handler); if (replaced != null && replaced != handler) { throw new IllegalStateException("Cannot map " + handler + " to protocol '" + protocol + "': already mapped to " + replaced + "."); } } this.protocolHandlers.add(handler); }
/** * Register a sub-protocol handler. */ public void addProtocolHandler(SubProtocolHandler handler) { List<String> protocols = handler.getSupportedProtocols(); if (CollectionUtils.isEmpty(protocols)) { if (logger.isErrorEnabled()) { logger.error("No sub-protocols for " + handler); } return; } for (String protocol : protocols) { SubProtocolHandler replaced = this.protocolHandlerLookup.put(protocol, handler); if (replaced != null && replaced != handler) { throw new IllegalStateException("Cannot map " + handler + " to protocol '" + protocol + "': already mapped to " + replaced + "."); } } this.protocolHandlers.add(handler); }
List<String> protocols = handler.getSupportedProtocols(); if (CollectionUtils.isEmpty(protocols)) { if (LOGGER.isWarnEnabled()) { this.defaultProtocolHandler = defaultProtocolHandler; if (this.protocolHandlers.isEmpty() && this.defaultProtocolHandler != null) { List<String> protocols = this.defaultProtocolHandler.getSupportedProtocols(); for (String protocol : protocols) { SubProtocolHandler replaced = this.protocolHandlers.put(protocol, this.defaultProtocolHandler);