Browse Source

SubProtocolWebSocketHandler checks if session is open

Issue: SPR-12812
pull/759/head
Rossen Stoyanchev 10 years ago
parent
commit
0c9cd4cc32
  1. 6
      spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java
  2. 11
      spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java
  3. 5
      spring-websocket/src/test/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandlerTests.java

6
spring-websocket/src/main/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandler.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -264,6 +264,10 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler, @@ -264,6 +264,10 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler,
@Override
public void afterConnectionEstablished(WebSocketSession session) throws Exception {
// WebSocketHandlerDecorator could close the session
if (!session.isOpen()) {
return;
}
this.stats.incrementSessionCount(session);
session = new ConcurrentWebSocketSessionDecorator(session, getSendTimeLimit(), getSendBufferSizeLimit());
this.sessions.put(session.getId(), new WebSocketSessionHolder(session));

11
spring-websocket/src/test/java/org/springframework/web/socket/config/annotation/WebSocketMessageBrokerConfigurationSupportTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -16,10 +16,7 @@ @@ -16,10 +16,7 @@
package org.springframework.web.socket.config.annotation;
import static org.junit.Assert.assertEquals;
import static org.junit.Assert.assertFalse;
import static org.junit.Assert.assertNotNull;
import static org.junit.Assert.assertTrue;
import static org.junit.Assert.*;
import java.util.ArrayList;
import java.util.List;
@ -28,6 +25,7 @@ import java.util.Set; @@ -28,6 +25,7 @@ import java.util.Set;
import java.util.concurrent.ScheduledThreadPoolExecutor;
import org.junit.Test;
import org.springframework.context.ApplicationContext;
import org.springframework.context.annotation.AnnotationConfigApplicationContext;
import org.springframework.context.annotation.Bean;
@ -92,7 +90,8 @@ public class WebSocketMessageBrokerConfigurationSupportTests { @@ -92,7 +90,8 @@ public class WebSocketMessageBrokerConfigurationSupportTests {
List<ChannelInterceptor> interceptors = channel.getInterceptors();
assertEquals(ImmutableMessageChannelInterceptor.class, interceptors.get(interceptors.size()-1).getClass());
WebSocketSession session = new TestWebSocketSession("s1");
TestWebSocketSession session = new TestWebSocketSession("s1");
session.setOpen(true);
webSocketHandler.afterConnectionEstablished(session);
TextMessage textMessage = StompTextMessageBuilder.create(StompCommand.SEND).headers("destination:/foo").build();

5
spring-websocket/src/test/java/org/springframework/web/socket/messaging/SubProtocolWebSocketHandlerTests.java

@ -1,5 +1,5 @@ @@ -1,5 +1,5 @@
/*
* Copyright 2002-2014 the original author or authors.
* Copyright 2002-2015 the original author or authors.
*
* Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License.
@ -66,6 +66,7 @@ public class SubProtocolWebSocketHandlerTests { @@ -66,6 +66,7 @@ public class SubProtocolWebSocketHandlerTests {
given(mqttHandler.getSupportedProtocols()).willReturn(Arrays.asList("MQTT"));
this.session = new TestWebSocketSession();
this.session.setId("1");
this.session.setOpen(true);
}
@ -148,6 +149,8 @@ public class SubProtocolWebSocketHandlerTests { @@ -148,6 +149,8 @@ public class SubProtocolWebSocketHandlerTests {
public void checkSession() throws Exception {
TestWebSocketSession session1 = new TestWebSocketSession("id1");
TestWebSocketSession session2 = new TestWebSocketSession("id2");
session1.setOpen(true);
session2.setOpen(true);
session1.setAcceptedProtocol("v12.stomp");
session2.setAcceptedProtocol("v12.stomp");

Loading…
Cancel
Save