INT-3515: Fix Some WebSockets Issues

JIRA: https://jira.spring.io/browse/INT-3515

Change test suite to the Tomcat according IO

INT-3515: IllegalStateException for the `WebSocketInboundChannelAdapter`, when `useBroker = true`, but there is no Broker Relay in the Context
This commit is contained in:
Artem Bilan
2014-09-10 19:03:37 +03:00
committed by Gary Russell
parent 2587ed6bd0
commit a5bddddac2
16 changed files with 196 additions and 125 deletions

View File

@@ -116,6 +116,10 @@ public abstract class IntegrationWebSocketContainer implements ApplicationEventP
return Collections.unmodifiableList(protocols);
}
public Map<String, WebSocketSession> getSessions() {
return Collections.unmodifiableMap(this.sessions);
}
public WebSocketSession getSession(String sessionId) throws Exception {
WebSocketSession session = this.sessions.get(sessionId);
Assert.notNull(session, "Session not found for id '" + sessionId + "'");

View File

@@ -50,11 +50,9 @@ public class ClientWebSocketContainerParser extends AbstractSingleBeanDefinition
@Override
protected void doParse(Element element, ParserContext parserContext, BeanDefinitionBuilder builder) {
builder.addConstructorArgReference(element.getAttribute("client"))
.addConstructorArgValue(element.getAttribute("uri"));
String uriVariables = element.getAttribute("uri-variables");
if (StringUtils.hasText(uriVariables)) {
builder.addConstructorArgValue(StringUtils.commaDelimitedListToStringArray(uriVariables));
}
.addConstructorArgValue(element.getAttribute("uri"))
.addConstructorArgValue(StringUtils.commaDelimitedListToStringArray(element.getAttribute("uri-variables")));
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-buffer-size-limit");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "send-time-limit");
IntegrationNamespaceUtils.setValueIfAttributeDefined(builder, element, "origin");

View File

@@ -189,10 +189,9 @@ public class WebSocketInboundChannelAdapter extends MessageProducerSupport imple
break;
}
}
if (this.brokerHandler == null) {
logger.warn("'AbstractBrokerMessageHandler' isn't present in the application context. " +
"The non-MESSAGE WebSocketMessages will be ignored.");
}
Assert.state(this.brokerHandler != null,
"WebSocket Broker Relay isn't present in the application context; " +
"it is required when 'useBroker = true'.");
}
}

View File

@@ -27,6 +27,7 @@ import org.apache.commons.logging.LogFactory;
import org.springframework.messaging.Message;
import org.springframework.util.Assert;
import org.springframework.util.CollectionUtils;
import org.springframework.util.StringUtils;
import org.springframework.web.socket.WebSocketSession;
import org.springframework.web.socket.messaging.SubProtocolHandler;
@@ -108,7 +109,7 @@ public final class SubProtocolHandlerRegistry {
public SubProtocolHandler findProtocolHandler(WebSocketSession session) {
SubProtocolHandler handler;
String protocol = session.getAcceptedProtocol();
if (protocol != null) {
if (StringUtils.hasText(protocol)) {
handler = this.protocolHandlers.get(protocol);
Assert.state(handler != null,
"No handler for sub-protocol '" + protocol + "', handlers = " + this.protocolHandlers);