diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/AbstractSockJsSession.java b/spring-websocket/src/main/java/org/springframework/sockjs/AbstractSockJsSession.java index c7dd7a4875..8c8a28406b 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/AbstractSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/AbstractSockJsSession.java @@ -55,7 +55,7 @@ public abstract class AbstractSockJsSession implements WebSocketSession { * @param sessionId * @param webSocketHandler the recipient of SockJS messages */ - public AbstractSockJsSession(String sessionId, WebSocketHandler webSocketHandler) { + public AbstractSockJsSession(String sessionId, WebSocketHandler webSocketHandler) { Assert.notNull(sessionId, "sessionId is required"); Assert.notNull(webSocketHandler, "webSocketHandler is required"); this.sessionId = sessionId; diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/SockJsSessionFactory.java b/spring-websocket/src/main/java/org/springframework/sockjs/SockJsSessionFactory.java index c9bc94519c..977cc9f0a3 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/SockJsSessionFactory.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/SockJsSessionFactory.java @@ -34,6 +34,6 @@ public interface SockJsSessionFactory{ * @param webSocketHandler the underlying {@link WebSocketHandler} * @return a new non-null session */ - S createSession(String sessionId, WebSocketHandler webSocketHandler); + S createSession(String sessionId, WebSocketHandler webSocketHandler); } diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractServerSockJsSession.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractServerSockJsSession.java index f9e57a9487..fdd9f15330 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractServerSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractServerSockJsSession.java @@ -43,7 +43,7 @@ public abstract class AbstractServerSockJsSession extends AbstractSockJsSession private ScheduledFuture heartbeatTask; - public AbstractServerSockJsSession(String sessionId, SockJsConfiguration config, WebSocketHandler handler) { + public AbstractServerSockJsSession(String sessionId, SockJsConfiguration config, WebSocketHandler handler) { super(sessionId, handler); this.sockJsConfig = config; } diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractSockJsService.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractSockJsService.java index 6e0504847b..16fdfc4214 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractSockJsService.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractSockJsService.java @@ -199,7 +199,7 @@ public abstract class AbstractSockJsService implements SockJsService, SockJsConf * @throws Exception */ public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response, - String sockJsPath, WebSocketHandler webSocketHandler) throws IOException, TransportErrorException { + String sockJsPath, WebSocketHandler webSocketHandler) throws IOException, TransportErrorException { logger.debug(request.getMethod() + " [" + sockJsPath + "]"); @@ -253,10 +253,10 @@ public abstract class AbstractSockJsService implements SockJsService, SockJsConf } protected abstract void handleRawWebSocketRequest(ServerHttpRequest request, - ServerHttpResponse response, WebSocketHandler webSocketHandler) throws IOException; + ServerHttpResponse response, WebSocketHandler webSocketHandler) throws IOException; protected abstract void handleTransportRequest(ServerHttpRequest request, ServerHttpResponse response, - String sessionId, TransportType transportType, WebSocketHandler webSocketHandler) + String sessionId, TransportType transportType, WebSocketHandler webSocketHandler) throws IOException, TransportErrorException; diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/SockJsService.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/SockJsService.java index 580d2afec6..91c8a3d52e 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/SockJsService.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/SockJsService.java @@ -30,6 +30,6 @@ public interface SockJsService { void handleRequest(ServerHttpRequest request, ServerHttpResponse response, - String sockJsPath, WebSocketHandler webSocketHandler) throws IOException, TransportErrorException; + String sockJsPath, WebSocketHandler webSocketHandler) throws IOException, TransportErrorException; } diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/TransportHandler.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/TransportHandler.java index af05a34357..e01af545be 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/TransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/TransportHandler.java @@ -30,6 +30,6 @@ public interface TransportHandler { TransportType getTransportType(); void handleRequest(ServerHttpRequest request, ServerHttpResponse response, - WebSocketHandler handler, AbstractSockJsSession session) throws TransportErrorException; + WebSocketHandler handler, AbstractSockJsSession session) throws TransportErrorException; } diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/support/DefaultSockJsService.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/support/DefaultSockJsService.java index f070c1b94d..92dddbed59 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/support/DefaultSockJsService.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/support/DefaultSockJsService.java @@ -142,7 +142,7 @@ public class DefaultSockJsService extends AbstractSockJsService { @Override protected void handleRawWebSocketRequest(ServerHttpRequest request, ServerHttpResponse response, - WebSocketHandler webSocketHandler) throws IOException { + WebSocketHandler webSocketHandler) throws IOException { if (isWebSocketEnabled()) { TransportHandler transportHandler = this.transportHandlers.get(TransportType.WEBSOCKET); @@ -159,7 +159,7 @@ public class DefaultSockJsService extends AbstractSockJsService { @Override protected void handleTransportRequest(ServerHttpRequest request, ServerHttpResponse response, - String sessionId, TransportType transportType, WebSocketHandler webSocketHandler) + String sessionId, TransportType transportType, WebSocketHandler webSocketHandler) throws IOException, TransportErrorException { TransportHandler transportHandler = this.transportHandlers.get(transportType); @@ -210,7 +210,7 @@ public class DefaultSockJsService extends AbstractSockJsService { } public AbstractSockJsSession getSockJsSession(String sessionId, - WebSocketHandler webSocketHandler, TransportHandler transportHandler) { + WebSocketHandler webSocketHandler, TransportHandler transportHandler) { AbstractSockJsSession session = this.sessions.get(sessionId); if (session != null) { diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/support/SockJsHttpRequestHandler.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/support/SockJsHttpRequestHandler.java index ebf38e4cd7..3c90f9db6d 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/support/SockJsHttpRequestHandler.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/support/SockJsHttpRequestHandler.java @@ -43,7 +43,7 @@ public class SockJsHttpRequestHandler implements HttpRequestHandler { private final SockJsService sockJsService; - private final WebSocketHandler webSocketHandler; + private final WebSocketHandler webSocketHandler; private final UrlPathHelper urlPathHelper = new UrlPathHelper(); diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpReceivingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpReceivingTransportHandler.java index 832ba537ba..0f8d492eb1 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpReceivingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpReceivingTransportHandler.java @@ -54,7 +54,7 @@ public abstract class AbstractHttpReceivingTransportHandler implements Transport @Override public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response, - WebSocketHandler webSocketHandler, AbstractSockJsSession session) + WebSocketHandler webSocketHandler, AbstractSockJsSession session) throws TransportErrorException { if (session == null) { diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpSendingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpSendingTransportHandler.java index 917b71b655..f0c92e72f8 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpSendingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpSendingTransportHandler.java @@ -57,7 +57,7 @@ public abstract class AbstractHttpSendingTransportHandler @Override public final void handleRequest(ServerHttpRequest request, ServerHttpResponse response, - WebSocketHandler webSocketHandler, AbstractSockJsSession session) + WebSocketHandler webSocketHandler, AbstractSockJsSession session) throws TransportErrorException { // Set content type before writing diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpServerSockJsSession.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpServerSockJsSession.java index d5ab1a09e9..055102b681 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpServerSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpServerSockJsSession.java @@ -49,7 +49,7 @@ public abstract class AbstractHttpServerSockJsSession extends AbstractServerSock private ServerHttpResponse response; - public AbstractHttpServerSockJsSession(String sessionId, SockJsConfiguration config, WebSocketHandler handler) { + public AbstractHttpServerSockJsSession(String sessionId, SockJsConfiguration config, WebSocketHandler handler) { super(sessionId, config, handler); } diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/EventSourceTransportHandler.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/EventSourceTransportHandler.java index 07fcaa8123..bae88528b8 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/EventSourceTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/EventSourceTransportHandler.java @@ -46,7 +46,7 @@ public class EventSourceTransportHandler extends AbstractHttpSendingTransportHan } @Override - public StreamingServerSockJsSession createSession(String sessionId, WebSocketHandler handler) { + public StreamingServerSockJsSession createSession(String sessionId, WebSocketHandler handler) { Assert.notNull(getSockJsConfig(), "This transport requires SockJsConfiguration"); return new StreamingServerSockJsSession(sessionId, getSockJsConfig(), handler) { @Override diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/HtmlFileTransportHandler.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/HtmlFileTransportHandler.java index 88dc77a1f1..7070a88fea 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/HtmlFileTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/HtmlFileTransportHandler.java @@ -80,7 +80,7 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle } @Override - public StreamingServerSockJsSession createSession(String sessionId, WebSocketHandler handler) { + public StreamingServerSockJsSession createSession(String sessionId, WebSocketHandler handler) { Assert.notNull(getSockJsConfig(), "This transport requires SockJsConfiguration"); return new StreamingServerSockJsSession(sessionId, getSockJsConfig(), handler) { diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/JsonpPollingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/JsonpPollingTransportHandler.java index d098148b09..fde554f0d1 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/JsonpPollingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/JsonpPollingTransportHandler.java @@ -50,7 +50,7 @@ public class JsonpPollingTransportHandler extends AbstractHttpSendingTransportHa } @Override - public PollingServerSockJsSession createSession(String sessionId, WebSocketHandler handler) { + public PollingServerSockJsSession createSession(String sessionId, WebSocketHandler handler) { Assert.notNull(getSockJsConfig(), "This transport requires SockJsConfiguration"); return new PollingServerSockJsSession(sessionId, getSockJsConfig(), handler); } diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/PollingServerSockJsSession.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/PollingServerSockJsSession.java index b8dffe7e33..7a70a5791f 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/PollingServerSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/PollingServerSockJsSession.java @@ -24,7 +24,7 @@ import org.springframework.websocket.WebSocketHandler; public class PollingServerSockJsSession extends AbstractHttpServerSockJsSession { - public PollingServerSockJsSession(String sessionId, SockJsConfiguration config, WebSocketHandler handler) { + public PollingServerSockJsSession(String sessionId, SockJsConfiguration config, WebSocketHandler handler) { super(sessionId, config, handler); } diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/SockJsWebSocketHandler.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/SockJsWebSocketHandler.java index 5a79779be2..13a0b9e12e 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/SockJsWebSocketHandler.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/SockJsWebSocketHandler.java @@ -44,7 +44,7 @@ public class SockJsWebSocketHandler extends TextWebSocketHandlerAdapter { private final SockJsConfiguration sockJsConfig; - private final WebSocketHandler webSocketHandler; + private final WebSocketHandler webSocketHandler; private WebSocketServerSockJsSession sockJsSession; @@ -54,7 +54,7 @@ public class SockJsWebSocketHandler extends TextWebSocketHandlerAdapter { private final ObjectMapper objectMapper = new ObjectMapper(); - public SockJsWebSocketHandler(SockJsConfiguration config, WebSocketHandler webSocketHandler) { + public SockJsWebSocketHandler(SockJsConfiguration config, WebSocketHandler webSocketHandler) { Assert.notNull(config, "sockJsConfig is required"); Assert.notNull(webSocketHandler, "webSocketHandler is required"); this.sockJsConfig = config; @@ -73,7 +73,7 @@ public class SockJsWebSocketHandler extends TextWebSocketHandlerAdapter { } @Override - public void handleMessage(WebSocketSession wsSession, TextMessage message) { + public void handleTextMessage(WebSocketSession wsSession, TextMessage message) { this.sockJsSession.handleMessage(message, wsSession); } diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/StreamingServerSockJsSession.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/StreamingServerSockJsSession.java index 8e147c3091..bc5be9cab8 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/StreamingServerSockJsSession.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/StreamingServerSockJsSession.java @@ -31,7 +31,7 @@ public class StreamingServerSockJsSession extends AbstractHttpServerSockJsSessio private int byteCount; - public StreamingServerSockJsSession(String sessionId, SockJsConfiguration config, WebSocketHandler handler) { + public StreamingServerSockJsSession(String sessionId, SockJsConfiguration config, WebSocketHandler handler) { super(sessionId, config, handler); } diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/WebSocketTransportHandler.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/WebSocketTransportHandler.java index 12554ff676..81d82c4833 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/WebSocketTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/WebSocketTransportHandler.java @@ -63,10 +63,10 @@ public class WebSocketTransportHandler implements ConfigurableTransportHandler, @Override public void handleRequest(ServerHttpRequest request, ServerHttpResponse response, - WebSocketHandler webSocketHandler, AbstractSockJsSession session) throws TransportErrorException { + WebSocketHandler webSocketHandler, AbstractSockJsSession session) throws TransportErrorException { try { - WebSocketHandler sockJsWrapper = new SockJsWebSocketHandler(this.sockJsConfig, webSocketHandler); + WebSocketHandler sockJsWrapper = new SockJsWebSocketHandler(this.sockJsConfig, webSocketHandler); this.handshakeHandler.doHandshake(request, response, sockJsWrapper); } catch (Throwable t) { @@ -77,7 +77,7 @@ public class WebSocketTransportHandler implements ConfigurableTransportHandler, // HandshakeHandler methods @Override - public boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler) + public boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler handler) throws IOException { return this.handshakeHandler.doHandshake(request, response, handler); diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrPollingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrPollingTransportHandler.java index b1640a1eb0..b25818c67f 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrPollingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrPollingTransportHandler.java @@ -50,7 +50,7 @@ public class XhrPollingTransportHandler extends AbstractHttpSendingTransportHand return new DefaultFrameFormat("%s\n"); } - public PollingServerSockJsSession createSession(String sessionId, WebSocketHandler handler) { + public PollingServerSockJsSession createSession(String sessionId, WebSocketHandler handler) { Assert.notNull(getSockJsConfig(), "This transport requires SockJsConfiguration"); return new PollingServerSockJsSession(sessionId, getSockJsConfig(), handler); } diff --git a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrStreamingTransportHandler.java b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrStreamingTransportHandler.java index 642b719dff..84228029ab 100644 --- a/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrStreamingTransportHandler.java +++ b/spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrStreamingTransportHandler.java @@ -47,7 +47,7 @@ public class XhrStreamingTransportHandler extends AbstractHttpSendingTransportHa } @Override - public StreamingServerSockJsSession createSession(String sessionId, WebSocketHandler handler) { + public StreamingServerSockJsSession createSession(String sessionId, WebSocketHandler handler) { Assert.notNull(getSockJsConfig(), "This transport requires SockJsConfiguration"); return new StreamingServerSockJsSession(sessionId, getSockJsConfig(), handler) { diff --git a/spring-websocket/src/main/java/org/springframework/websocket/WebSocketHandler.java b/spring-websocket/src/main/java/org/springframework/websocket/WebSocketHandler.java index 3b0b9476f9..1ea26cd3fe 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/WebSocketHandler.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/WebSocketHandler.java @@ -26,7 +26,7 @@ package org.springframework.websocket; * @author Phillip Webb * @since 4.0 */ -public interface WebSocketHandler> { +public interface WebSocketHandler { /** * A new WebSocket connection has been opened and is ready to be used. @@ -36,7 +36,7 @@ public interface WebSocketHandler> { /** * Handle an incoming WebSocket message. */ - void handleMessage(WebSocketSession session, T message); + void handleMessage(WebSocketSession session, WebSocketMessage message); /** * Handle an error from the underlying WebSocket message transport. diff --git a/spring-websocket/src/main/java/org/springframework/websocket/adapter/BinaryWebSocketHandlerAdapter.java b/spring-websocket/src/main/java/org/springframework/websocket/adapter/BinaryWebSocketHandlerAdapter.java index d136dc9012..7e467593e9 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/adapter/BinaryWebSocketHandlerAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/adapter/BinaryWebSocketHandlerAdapter.java @@ -16,8 +16,10 @@ package org.springframework.websocket.adapter; -import org.springframework.websocket.BinaryMessage; +import java.io.IOException; + import org.springframework.websocket.CloseStatus; +import org.springframework.websocket.TextMessage; import org.springframework.websocket.WebSocketHandler; import org.springframework.websocket.WebSocketSession; @@ -29,22 +31,17 @@ import org.springframework.websocket.WebSocketSession; * @author Phillip Webb * @since 4.0 */ -public class BinaryWebSocketHandlerAdapter implements WebSocketHandler { +public class BinaryWebSocketHandlerAdapter extends WebSocketHandlerAdapter { - @Override - public void afterConnectionEstablished(WebSocketSession session) { - } - - @Override - public void handleMessage(WebSocketSession session, BinaryMessage message) { - } - - @Override - public void handleTransportError(WebSocketSession session, Throwable exception) { - } @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { + protected void handleTextMessage(WebSocketSession session, TextMessage message) { + try { + session.close(CloseStatus.NOT_ACCEPTABLE.withReason("Text messages not supported")); + } + catch (IOException e) { + // ignore + } } } diff --git a/spring-websocket/src/main/java/org/springframework/websocket/adapter/JettyWebSocketListenerAdapter.java b/spring-websocket/src/main/java/org/springframework/websocket/adapter/JettyWebSocketListenerAdapter.java index 3bf095785e..d8aa4f2d13 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/adapter/JettyWebSocketListenerAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/adapter/JettyWebSocketListenerAdapter.java @@ -25,7 +25,6 @@ import org.springframework.websocket.BinaryMessage; import org.springframework.websocket.CloseStatus; import org.springframework.websocket.TextMessage; import org.springframework.websocket.WebSocketHandler; -import org.springframework.websocket.WebSocketMessage; import org.springframework.websocket.WebSocketSession; /** @@ -38,12 +37,12 @@ public class JettyWebSocketListenerAdapter implements WebSocketListener { private static Log logger = LogFactory.getLog(JettyWebSocketListenerAdapter.class); - private final WebSocketHandler> webSocketHandler; + private final WebSocketHandler webSocketHandler; private WebSocketSession wsSession; - public JettyWebSocketListenerAdapter(WebSocketHandler webSocketHandler) { + public JettyWebSocketListenerAdapter(WebSocketHandler webSocketHandler) { Assert.notNull(webSocketHandler, "webSocketHandler is required"); this.webSocketHandler = new WebSocketHandlerInvoker(webSocketHandler).setLogger(logger); } diff --git a/spring-websocket/src/main/java/org/springframework/websocket/adapter/StandardEndpointAdapter.java b/spring-websocket/src/main/java/org/springframework/websocket/adapter/StandardEndpointAdapter.java index cb9047a79f..c076eebe42 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/adapter/StandardEndpointAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/adapter/StandardEndpointAdapter.java @@ -52,7 +52,7 @@ public class StandardEndpointAdapter extends Endpoint { - public StandardEndpointAdapter(WebSocketHandler webSocketHandler) { + public StandardEndpointAdapter(WebSocketHandler webSocketHandler) { Assert.notNull(webSocketHandler, "webSocketHandler is required"); this.handler = new WebSocketHandlerInvoker(webSocketHandler).setLogger(logger); this.handlerClass= webSocketHandler.getClass(); diff --git a/spring-websocket/src/main/java/org/springframework/websocket/adapter/TextWebSocketHandlerAdapter.java b/spring-websocket/src/main/java/org/springframework/websocket/adapter/TextWebSocketHandlerAdapter.java index 6c54f653e8..6fe21f7725 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/adapter/TextWebSocketHandlerAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/adapter/TextWebSocketHandlerAdapter.java @@ -16,8 +16,10 @@ package org.springframework.websocket.adapter; +import java.io.IOException; + +import org.springframework.websocket.BinaryMessage; import org.springframework.websocket.CloseStatus; -import org.springframework.websocket.TextMessage; import org.springframework.websocket.WebSocketHandler; import org.springframework.websocket.WebSocketSession; @@ -29,22 +31,17 @@ import org.springframework.websocket.WebSocketSession; * @author Phillip Webb * @since 4.0 */ -public class TextWebSocketHandlerAdapter implements WebSocketHandler { +public class TextWebSocketHandlerAdapter extends WebSocketHandlerAdapter { - @Override - public void afterConnectionEstablished(WebSocketSession session) { - } - - @Override - public void handleMessage(WebSocketSession session, TextMessage message) { - } - - @Override - public void handleTransportError(WebSocketSession session, Throwable exception) { - } @Override - public void afterConnectionClosed(WebSocketSession session, CloseStatus status) { + protected void handleBinaryMessage(WebSocketSession session, BinaryMessage message) { + try { + session.close(CloseStatus.NOT_ACCEPTABLE.withReason("Binary messages not supported")); + } + catch (IOException e) { + // ignore + } } } diff --git a/spring-websocket/src/main/java/org/springframework/websocket/adapter/WebSocketHandlerAdapter.java b/spring-websocket/src/main/java/org/springframework/websocket/adapter/WebSocketHandlerAdapter.java index 8a4c64f630..a9b464f015 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/adapter/WebSocketHandlerAdapter.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/adapter/WebSocketHandlerAdapter.java @@ -34,7 +34,7 @@ import org.springframework.websocket.WebSocketSession; * @see TextWebSocketHandlerAdapter * @see BinaryWebSocketHandlerAdapter */ -public class WebSocketHandlerAdapter implements WebSocketHandler> { +public class WebSocketHandlerAdapter implements WebSocketHandler { @Override public void afterConnectionEstablished(WebSocketSession session) { @@ -49,6 +49,7 @@ public class WebSocketHandlerAdapter implements WebSocketHandler> { +public class WebSocketHandlerInvoker implements WebSocketHandler { private Log logger = LogFactory.getLog(WebSocketHandlerInvoker.class); - private final WebSocketHandler handler; - - private final Class supportedMessageType; + private final WebSocketHandler handler; private final AtomicInteger sessionCount = new AtomicInteger(0); - public WebSocketHandlerInvoker(WebSocketHandler webSocketHandler) { + public WebSocketHandlerInvoker(WebSocketHandler webSocketHandler) { Assert.notNull(webSocketHandler, "webSocketHandler is required"); this.handler = webSocketHandler; - Class handlerType = webSocketHandler.getClass(); - this.supportedMessageType = GenericTypeResolver.resolveTypeArgument(handlerType, WebSocketHandler.class); } public WebSocketHandlerInvoker setLogger(Log logger) { @@ -79,9 +74,7 @@ public class WebSocketHandlerInvoker implements WebSocketHandler message) { if (logger.isTraceEnabled()) { logger.trace("Received " + message + ", " + session); } - if (!this.supportedMessageType.isAssignableFrom(message.getClass())) { - tryCloseWithError(session, null, CloseStatus.NOT_ACCEPTABLE.withReason("Message type not supported")); - return; - } try { - ((WebSocketHandler) this.handler).handleMessage(session, message); + this.handler.handleMessage(session, message); } catch (Throwable ex) { tryCloseWithError(session,ex); diff --git a/spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketClient.java b/spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketClient.java index e1d3dc6eb0..5aaa0380f9 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketClient.java @@ -38,7 +38,7 @@ public interface WebSocketClient { WebSocketSession doHandshake(WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables) throws WebSocketConnectFailureException; - WebSocketSession doHandshake(WebSocketHandler webSocketHandler, HttpHeaders headers, URI uri) + WebSocketSession doHandshake(WebSocketHandler webSocketHandler, HttpHeaders headers, URI uri) throws WebSocketConnectFailureException; } diff --git a/spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketConnectionManager.java b/spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketConnectionManager.java index bb3fb63f1e..0e5090e584 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketConnectionManager.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketConnectionManager.java @@ -32,7 +32,7 @@ public class WebSocketConnectionManager extends AbstractWebSocketConnectionManag private final WebSocketClient client; - private final WebSocketHandler webSocketHandler; + private final WebSocketHandler webSocketHandler; private WebSocketSession webSocketSession; diff --git a/spring-websocket/src/main/java/org/springframework/websocket/client/endpoint/StandardWebSocketClient.java b/spring-websocket/src/main/java/org/springframework/websocket/client/endpoint/StandardWebSocketClient.java index cadd72cb7c..ffb043c340 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/client/endpoint/StandardWebSocketClient.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/client/endpoint/StandardWebSocketClient.java @@ -67,7 +67,7 @@ public class StandardWebSocketClient implements WebSocketClient { } @Override - public WebSocketSession doHandshake(WebSocketHandler webSocketHandler, + public WebSocketSession doHandshake(WebSocketHandler webSocketHandler, final HttpHeaders httpHeaders, URI uri) throws WebSocketConnectFailureException { Endpoint endpoint = new StandardEndpointAdapter(webSocketHandler); diff --git a/spring-websocket/src/main/java/org/springframework/websocket/server/DefaultHandshakeHandler.java b/spring-websocket/src/main/java/org/springframework/websocket/server/DefaultHandshakeHandler.java index 9995881883..e557a0cc12 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/server/DefaultHandshakeHandler.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/server/DefaultHandshakeHandler.java @@ -87,7 +87,7 @@ public class DefaultHandshakeHandler implements HandshakeHandler { @Override public final boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, - WebSocketHandler webSocketHandler) throws IOException { + WebSocketHandler webSocketHandler) throws IOException { logger.debug("Starting handshake for " + request.getURI()); diff --git a/spring-websocket/src/main/java/org/springframework/websocket/server/HandshakeHandler.java b/spring-websocket/src/main/java/org/springframework/websocket/server/HandshakeHandler.java index 368568d6b0..fbdf2ca1a6 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/server/HandshakeHandler.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/server/HandshakeHandler.java @@ -31,7 +31,7 @@ import org.springframework.websocket.WebSocketHandler; public interface HandshakeHandler { - boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, - WebSocketHandler webSocketHandler) throws IOException; + boolean doHandshake(ServerHttpRequest request, ServerHttpResponse response, WebSocketHandler webSocketHandler) + throws IOException; } diff --git a/spring-websocket/src/main/java/org/springframework/websocket/server/RequestUpgradeStrategy.java b/spring-websocket/src/main/java/org/springframework/websocket/server/RequestUpgradeStrategy.java index c99835165e..70a7653af4 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/server/RequestUpgradeStrategy.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/server/RequestUpgradeStrategy.java @@ -40,9 +40,9 @@ public interface RequestUpgradeStrategy { * Perform runtime specific steps to complete the upgrade. * Invoked only if the handshake is successful. * - * @param handler the handler for WebSocket messages + * @param webSocketHandler the handler for WebSocket messages */ void upgrade(ServerHttpRequest request, ServerHttpResponse response, String selectedProtocol, - WebSocketHandler webSocketHandler) throws IOException; + WebSocketHandler webSocketHandler) throws IOException; } diff --git a/spring-websocket/src/main/java/org/springframework/websocket/server/support/AbstractEndpointUpgradeStrategy.java b/spring-websocket/src/main/java/org/springframework/websocket/server/support/AbstractEndpointUpgradeStrategy.java index 71e2d5fbaf..096ab251e8 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/server/support/AbstractEndpointUpgradeStrategy.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/server/support/AbstractEndpointUpgradeStrategy.java @@ -42,7 +42,7 @@ public abstract class AbstractEndpointUpgradeStrategy implements RequestUpgradeS @Override public void upgrade(ServerHttpRequest request, ServerHttpResponse response, - String protocol, WebSocketHandler webSocketHandler) throws IOException { + String protocol, WebSocketHandler webSocketHandler) throws IOException { upgradeInternal(request, response, protocol, new StandardEndpointAdapter(webSocketHandler)); } diff --git a/spring-websocket/src/main/java/org/springframework/websocket/server/support/JettyRequestUpgradeStrategy.java b/spring-websocket/src/main/java/org/springframework/websocket/server/support/JettyRequestUpgradeStrategy.java index 7704196f6f..9819a63991 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/server/support/JettyRequestUpgradeStrategy.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/server/support/JettyRequestUpgradeStrategy.java @@ -65,8 +65,8 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy { public Object createWebSocket(UpgradeRequest request, UpgradeResponse response) { Assert.isInstanceOf(ServletWebSocketRequest.class, request); ServletWebSocketRequest servletRequest = (ServletWebSocketRequest) request; - WebSocketHandler webSocketHandler = - (WebSocketHandler) servletRequest.getServletAttributes().get(HANDLER_PROVIDER_ATTR_NAME); + WebSocketHandler webSocketHandler = + (WebSocketHandler) servletRequest.getServletAttributes().get(HANDLER_PROVIDER_ATTR_NAME); return new JettyWebSocketListenerAdapter(webSocketHandler); } }); @@ -86,7 +86,7 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy { @Override public void upgrade(ServerHttpRequest request, ServerHttpResponse response, - String selectedProtocol, WebSocketHandler webSocketHandler) throws IOException { + String selectedProtocol, WebSocketHandler webSocketHandler) throws IOException { Assert.isInstanceOf(ServletServerHttpRequest.class, request); HttpServletRequest servletRequest = ((ServletServerHttpRequest) request).getServletRequest(); @@ -98,7 +98,7 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy { } private void upgrade(HttpServletRequest request, HttpServletResponse response, - String selectedProtocol, final WebSocketHandler webSocketHandler) throws IOException { + String selectedProtocol, final WebSocketHandler webSocketHandler) throws IOException { Assert.state(this.factory.isUpgradeRequest(request, response), "Not a suitable WebSocket upgrade request"); Assert.state(this.factory.acceptWebSocket(request, response), "Unable to accept WebSocket"); diff --git a/spring-websocket/src/main/java/org/springframework/websocket/server/support/WebSocketHttpRequestHandler.java b/spring-websocket/src/main/java/org/springframework/websocket/server/support/WebSocketHttpRequestHandler.java index eb82dd6b7c..5d3b815810 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/server/support/WebSocketHttpRequestHandler.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/server/support/WebSocketHttpRequestHandler.java @@ -43,14 +43,14 @@ public class WebSocketHttpRequestHandler implements HttpRequestHandler { private final HandshakeHandler handshakeHandler; - private final WebSocketHandler webSocketHandler; + private final WebSocketHandler webSocketHandler; public WebSocketHttpRequestHandler(WebSocketHandler webSocketHandler) { this(webSocketHandler, new DefaultHandshakeHandler()); } - public WebSocketHttpRequestHandler( WebSocketHandler webSocketHandler, HandshakeHandler handshakeHandler) { + public WebSocketHttpRequestHandler( WebSocketHandler webSocketHandler, HandshakeHandler handshakeHandler) { Assert.notNull(webSocketHandler, "webSocketHandler is required"); Assert.notNull(handshakeHandler, "handshakeHandler is required"); this.webSocketHandler = webSocketHandler; diff --git a/spring-websocket/src/main/java/org/springframework/websocket/support/PerConnectionWebSocketHandlerProxy.java b/spring-websocket/src/main/java/org/springframework/websocket/support/PerConnectionWebSocketHandlerProxy.java index 01e259fb9b..ee4091178f 100644 --- a/spring-websocket/src/main/java/org/springframework/websocket/support/PerConnectionWebSocketHandlerProxy.java +++ b/spring-websocket/src/main/java/org/springframework/websocket/support/PerConnectionWebSocketHandlerProxy.java @@ -16,7 +16,6 @@ package org.springframework.websocket.support; -import java.io.IOException; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; @@ -25,7 +24,6 @@ import org.apache.commons.logging.LogFactory; import org.springframework.beans.BeansException; import org.springframework.beans.factory.BeanFactory; import org.springframework.beans.factory.BeanFactoryAware; -import org.springframework.core.GenericTypeResolver; import org.springframework.util.Assert; import org.springframework.websocket.CloseStatus; import org.springframework.websocket.WebSocketHandler; @@ -50,21 +48,18 @@ import org.springframework.websocket.WebSocketSession; * @author Rossen Stoyanchev * @since 4.0 */ -public class PerConnectionWebSocketHandlerProxy implements WebSocketHandler>, BeanFactoryAware { +public class PerConnectionWebSocketHandlerProxy implements WebSocketHandler, BeanFactoryAware { private Log logger = LogFactory.getLog(PerConnectionWebSocketHandlerProxy.class); - private final BeanCreatingHandlerProvider> provider; + private final BeanCreatingHandlerProvider provider; - private Map> handlers = - new ConcurrentHashMap>(); + private Map handlers = + new ConcurrentHashMap(); - private final Class supportedMessageType; - - public PerConnectionWebSocketHandlerProxy(Class> handlerType) { - this.provider = new BeanCreatingHandlerProvider>(handlerType); - this.supportedMessageType = GenericTypeResolver.resolveTypeArgument(handlerType, WebSocketHandler.class); + public PerConnectionWebSocketHandlerProxy(Class handlerType) { + this.provider = new BeanCreatingHandlerProvider(handlerType); } @@ -75,29 +70,18 @@ public class PerConnectionWebSocketHandlerProxy implements WebSocketHandler handler = this.provider.getHandler(); + WebSocketHandler handler = this.provider.getHandler(); this.handlers.put(session, handler); handler.afterConnectionEstablished(session); } - @SuppressWarnings("unchecked") @Override public void handleMessage(WebSocketSession session, WebSocketMessage message) { - if (!this.supportedMessageType.isAssignableFrom(message.getClass())) { - try { - session.close(CloseStatus.NOT_ACCEPTABLE.withReason("Message type not supported")); - } - catch (IOException e) { - destroy(session); - } - } - else { - ((WebSocketHandler) getHandler(session)).handleMessage(session, message); - } + getHandler(session).handleMessage(session, message); } - private WebSocketHandler getHandler(WebSocketSession session) { - WebSocketHandler handler = this.handlers.get(session); + private WebSocketHandler getHandler(WebSocketSession session) { + WebSocketHandler handler = this.handlers.get(session); Assert.isTrue(handler != null, "WebSocketHandler not found for " + session); return handler; } @@ -118,7 +102,7 @@ public class PerConnectionWebSocketHandlerProxy implements WebSocketHandler handler = this.handlers.remove(session); + WebSocketHandler handler = this.handlers.remove(session); try { if (handler != null) { this.provider.destroy(handler);