Skip to content

Commit

Permalink
INT-3515: Fix some WebSockets issues
Browse files Browse the repository at this point in the history
  • Loading branch information
artembilan committed Sep 10, 2014
1 parent 443dd9f commit cfc2551
Show file tree
Hide file tree
Showing 6 changed files with 35 additions and 7 deletions.
Expand Up @@ -116,6 +116,10 @@ public List<String> getSubProtocols() {
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 + "'");
Expand Down
Expand Up @@ -50,11 +50,9 @@ protected boolean shouldGenerateIdAsFallback() {
@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");
Expand Down
Expand Up @@ -27,6 +27,7 @@
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;

Expand Down Expand Up @@ -108,7 +109,7 @@ public SubProtocolHandlerRegistry(List<SubProtocolHandler> protocolHandlers,
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);
Expand Down
Expand Up @@ -101,4 +101,8 @@

<int:channel id="clientOutboundChannel"/>

<int-websocket:client-container id="simpleClientWebSocketContainer"
client="webSocketClient"
uri="ws://foo.bar"/>

</beans>
Expand Up @@ -104,6 +104,10 @@ public class WebSocketParserTests {
@Qualifier("clientWebSocketContainer")
private IntegrationWebSocketContainer clientWebSocketContainer;

@Autowired
@Qualifier("simpleClientWebSocketContainer")
private IntegrationWebSocketContainer simpleClientWebSocketContainer;

@Autowired
@Qualifier("customInboundAdapter")
private WebSocketInboundChannelAdapter customInboundAdapter;
Expand Down Expand Up @@ -235,6 +239,19 @@ public void testCustomInboundChannelAdapterAndClientContainer() throws URISyntax
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());
}

@Test
Expand Down
Expand Up @@ -87,7 +87,7 @@ public void testHandlerSelection() {
SubProtocolHandlerRegistry subProtocolHandlerRegistry =
new SubProtocolHandlerRegistry(testProtocolHandler);
WebSocketSession session = mock(WebSocketSession.class);
when(session.getAcceptedProtocol()).thenReturn("foo", (String) null);
when(session.getAcceptedProtocol()).thenReturn("foo", "", null);

try {
subProtocolHandlerRegistry.findProtocolHandler(session);
Expand All @@ -101,6 +101,10 @@ public void testHandlerSelection() {
SubProtocolHandler protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
assertNotNull(protocolHandler);
assertSame(protocolHandler, testProtocolHandler);

protocolHandler = subProtocolHandlerRegistry.findProtocolHandler(session);
assertNotNull(protocolHandler);
assertSame(protocolHandler, testProtocolHandler);
}

@Test
Expand Down

0 comments on commit cfc2551

Please sign in to comment.