List of usage examples for org.springframework.web.socket.messaging SubProtocolHandler getSupportedProtocols
List<String> getSupportedProtocols();
From source file:org.springframework.integration.websocket.support.SubProtocolHandlerRegistry.java
public SubProtocolHandlerRegistry(List<SubProtocolHandler> protocolHandlers, SubProtocolHandler defaultProtocolHandler) { Assert.state(!CollectionUtils.isEmpty(protocolHandlers) || defaultProtocolHandler != null, "One of 'protocolHandlers' or 'defaultProtocolHandler' must be provided"); if (!CollectionUtils.isEmpty(protocolHandlers)) { for (SubProtocolHandler handler : protocolHandlers) { List<String> protocols = handler.getSupportedProtocols(); if (CollectionUtils.isEmpty(protocols)) { logger.warn("No sub-protocols, ignoring handler " + handler); continue; }/*w ww . j av a2 s .com*/ for (String protocol : protocols) { SubProtocolHandler replaced = this.protocolHandlers.put(protocol, handler); if (replaced != null) { throw new IllegalStateException("Failed to map handler " + handler + " to protocol '" + protocol + "', it is already mapped to handler " + replaced); } } } } if (this.protocolHandlers.size() == 1 && defaultProtocolHandler == null) { this.defaultProtocolHandler = this.protocolHandlers.values().iterator().next(); } else { 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); if (replaced != null) { throw new IllegalStateException("Failed to map handler " + this.defaultProtocolHandler + " to protocol '" + protocol + "', it is already mapped to handler " + replaced); } } } } }
From source file:org.springframework.web.socket.messaging.SubProtocolWebSocketHandler.java
/** * Register a sub-protocol handler.//from w ww. jav a2 s.com */ 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); }