|
|
|
@ -52,22 +52,20 @@ import org.springframework.web.socket.sockjs.transport.session.StreamingSockJsSe |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* An implementation of {@link WebSocketHandler} that delegates incoming WebSocket |
|
|
|
* An implementation of {@link WebSocketHandler} that delegates incoming WebSocket |
|
|
|
* messages to a {@link SubProtocolHandler} along with a {@link MessageChannel} to |
|
|
|
* messages to a {@link SubProtocolHandler} along with a {@link MessageChannel} to which |
|
|
|
* which the sub-protocol handler can send messages from WebSocket clients to |
|
|
|
* the sub-protocol handler can send messages from WebSocket clients to the application. |
|
|
|
* the application. |
|
|
|
* |
|
|
|
* <p> |
|
|
|
* <p>Also an implementation of {@link MessageHandler} that finds the WebSocket session |
|
|
|
* Also an implementation of {@link MessageHandler} that finds the WebSocket |
|
|
|
* associated with the {@link Message} and passes it, along with the message, to the |
|
|
|
* session associated with the {@link Message} and passes it, along with the message, |
|
|
|
* sub-protocol handler to send messages from the application back to the client. |
|
|
|
* to the sub-protocol handler to send messages from the application back to the |
|
|
|
|
|
|
|
* client. |
|
|
|
|
|
|
|
* |
|
|
|
* |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Rossen Stoyanchev |
|
|
|
* @author Andy Wilkinson |
|
|
|
* @author Andy Wilkinson |
|
|
|
* @author Artem Bilan |
|
|
|
* @author Artem Bilan |
|
|
|
* @since 4.0 |
|
|
|
* @since 4.0 |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public class SubProtocolWebSocketHandler implements WebSocketHandler, |
|
|
|
public class SubProtocolWebSocketHandler |
|
|
|
SubProtocolCapable, MessageHandler, SmartLifecycle { |
|
|
|
implements WebSocketHandler, SubProtocolCapable, MessageHandler, SmartLifecycle { |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Sessions connected to this handler use a sub-protocol. Hence we expect to |
|
|
|
* Sessions connected to this handler use a sub-protocol. Hence we expect to |
|
|
|
@ -109,9 +107,14 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler, |
|
|
|
private volatile boolean running = false; |
|
|
|
private volatile boolean running = false; |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Create a new {@code SubProtocolWebSocketHandler} for the given inbound and outbound channels. |
|
|
|
|
|
|
|
* @param clientInboundChannel the inbound {@code MessageChannel} |
|
|
|
|
|
|
|
* @param clientOutboundChannel the outbound {@code MessageChannel} |
|
|
|
|
|
|
|
*/ |
|
|
|
public SubProtocolWebSocketHandler(MessageChannel clientInboundChannel, SubscribableChannel clientOutboundChannel) { |
|
|
|
public SubProtocolWebSocketHandler(MessageChannel clientInboundChannel, SubscribableChannel clientOutboundChannel) { |
|
|
|
Assert.notNull(clientInboundChannel, "ClientInboundChannel must not be null"); |
|
|
|
Assert.notNull(clientInboundChannel, "Inbound MessageChannel must not be null"); |
|
|
|
Assert.notNull(clientOutboundChannel, "ClientOutboundChannel must not be null"); |
|
|
|
Assert.notNull(clientOutboundChannel, "Outbound MessageChannel must not be null"); |
|
|
|
this.clientInboundChannel = clientInboundChannel; |
|
|
|
this.clientInboundChannel = clientInboundChannel; |
|
|
|
this.clientOutboundChannel = clientOutboundChannel; |
|
|
|
this.clientOutboundChannel = clientOutboundChannel; |
|
|
|
} |
|
|
|
} |
|
|
|
@ -125,7 +128,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler, |
|
|
|
public void setProtocolHandlers(List<SubProtocolHandler> protocolHandlers) { |
|
|
|
public void setProtocolHandlers(List<SubProtocolHandler> protocolHandlers) { |
|
|
|
this.protocolHandlerLookup.clear(); |
|
|
|
this.protocolHandlerLookup.clear(); |
|
|
|
this.protocolHandlers.clear(); |
|
|
|
this.protocolHandlers.clear(); |
|
|
|
for (SubProtocolHandler handler: protocolHandlers) { |
|
|
|
for (SubProtocolHandler handler : protocolHandlers) { |
|
|
|
addProtocolHandler(handler); |
|
|
|
addProtocolHandler(handler); |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
@ -134,7 +137,6 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler, |
|
|
|
return new ArrayList<SubProtocolHandler>(this.protocolHandlers); |
|
|
|
return new ArrayList<SubProtocolHandler>(this.protocolHandlers); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* Register a sub-protocol handler. |
|
|
|
* Register a sub-protocol handler. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
@ -174,7 +176,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler, |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
/** |
|
|
|
* @return the default sub-protocol handler to use |
|
|
|
* Return the default sub-protocol handler to use. |
|
|
|
*/ |
|
|
|
*/ |
|
|
|
public SubProtocolHandler getDefaultProtocolHandler() { |
|
|
|
public SubProtocolHandler getDefaultProtocolHandler() { |
|
|
|
return this.defaultProtocolHandler; |
|
|
|
return this.defaultProtocolHandler; |
|
|
|
@ -187,23 +189,44 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler, |
|
|
|
return new ArrayList<String>(this.protocolHandlerLookup.keySet()); |
|
|
|
return new ArrayList<String>(this.protocolHandlerLookup.keySet()); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Specify the send-time limit (milliseconds). |
|
|
|
|
|
|
|
* @see ConcurrentWebSocketSessionDecorator |
|
|
|
|
|
|
|
*/ |
|
|
|
public void setSendTimeLimit(int sendTimeLimit) { |
|
|
|
public void setSendTimeLimit(int sendTimeLimit) { |
|
|
|
this.sendTimeLimit = sendTimeLimit; |
|
|
|
this.sendTimeLimit = sendTimeLimit; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the send-time limit (milliseconds). |
|
|
|
|
|
|
|
*/ |
|
|
|
public int getSendTimeLimit() { |
|
|
|
public int getSendTimeLimit() { |
|
|
|
return this.sendTimeLimit; |
|
|
|
return this.sendTimeLimit; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Specify the buffer-size limit (number of bytes). |
|
|
|
|
|
|
|
* @see ConcurrentWebSocketSessionDecorator |
|
|
|
|
|
|
|
*/ |
|
|
|
public void setSendBufferSizeLimit(int sendBufferSizeLimit) { |
|
|
|
public void setSendBufferSizeLimit(int sendBufferSizeLimit) { |
|
|
|
this.sendBufferSizeLimit = sendBufferSizeLimit; |
|
|
|
this.sendBufferSizeLimit = sendBufferSizeLimit; |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return the buffer-size limit (number of bytes). |
|
|
|
|
|
|
|
*/ |
|
|
|
public int getSendBufferSizeLimit() { |
|
|
|
public int getSendBufferSizeLimit() { |
|
|
|
return sendBufferSizeLimit; |
|
|
|
return this.sendBufferSizeLimit; |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return a String describing internal state and counters. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public String getStatsInfo() { |
|
|
|
|
|
|
|
return this.stats.toString(); |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public boolean isAutoStartup() { |
|
|
|
public boolean isAutoStartup() { |
|
|
|
return true; |
|
|
|
return true; |
|
|
|
@ -221,14 +244,6 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
/** |
|
|
|
|
|
|
|
* Return a String describing internal state and counters. |
|
|
|
|
|
|
|
*/ |
|
|
|
|
|
|
|
public String getStatsInfo() { |
|
|
|
|
|
|
|
return this.stats.toString(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public final void start() { |
|
|
|
public final void start() { |
|
|
|
Assert.isTrue(this.defaultProtocolHandler != null || !this.protocolHandlers.isEmpty(), "No handlers"); |
|
|
|
Assert.isTrue(this.defaultProtocolHandler != null || !this.protocolHandlers.isEmpty(), "No handlers"); |
|
|
|
@ -262,6 +277,7 @@ public class SubProtocolWebSocketHandler implements WebSocketHandler, |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
@Override |
|
|
|
@Override |
|
|
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception { |
|
|
|
public void afterConnectionEstablished(WebSocketSession session) throws Exception { |
|
|
|
// WebSocketHandlerDecorator could close the session
|
|
|
|
// WebSocketHandlerDecorator could close the session
|
|
|
|
|