Browse Source

Remove parameterized type from WebSocketHandler

pull/292/head
Rossen Stoyanchev 12 years ago
parent
commit
f347988428
  1. 2
      spring-websocket/src/main/java/org/springframework/sockjs/AbstractSockJsSession.java
  2. 2
      spring-websocket/src/main/java/org/springframework/sockjs/SockJsSessionFactory.java
  3. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractServerSockJsSession.java
  4. 6
      spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractSockJsService.java
  5. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/SockJsService.java
  6. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/TransportHandler.java
  7. 6
      spring-websocket/src/main/java/org/springframework/sockjs/server/support/DefaultSockJsService.java
  8. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/support/SockJsHttpRequestHandler.java
  9. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpReceivingTransportHandler.java
  10. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpSendingTransportHandler.java
  11. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpServerSockJsSession.java
  12. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/EventSourceTransportHandler.java
  13. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/HtmlFileTransportHandler.java
  14. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/JsonpPollingTransportHandler.java
  15. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/PollingServerSockJsSession.java
  16. 6
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/SockJsWebSocketHandler.java
  17. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/StreamingServerSockJsSession.java
  18. 6
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/WebSocketTransportHandler.java
  19. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrPollingTransportHandler.java
  20. 2
      spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrStreamingTransportHandler.java
  21. 4
      spring-websocket/src/main/java/org/springframework/websocket/WebSocketHandler.java
  22. 25
      spring-websocket/src/main/java/org/springframework/websocket/adapter/BinaryWebSocketHandlerAdapter.java
  23. 5
      spring-websocket/src/main/java/org/springframework/websocket/adapter/JettyWebSocketListenerAdapter.java
  24. 2
      spring-websocket/src/main/java/org/springframework/websocket/adapter/StandardEndpointAdapter.java
  25. 25
      spring-websocket/src/main/java/org/springframework/websocket/adapter/TextWebSocketHandlerAdapter.java
  26. 3
      spring-websocket/src/main/java/org/springframework/websocket/adapter/WebSocketHandlerAdapter.java
  27. 22
      spring-websocket/src/main/java/org/springframework/websocket/adapter/WebSocketHandlerInvoker.java
  28. 2
      spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketClient.java
  29. 2
      spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketConnectionManager.java
  30. 2
      spring-websocket/src/main/java/org/springframework/websocket/client/endpoint/StandardWebSocketClient.java
  31. 2
      spring-websocket/src/main/java/org/springframework/websocket/server/DefaultHandshakeHandler.java
  32. 4
      spring-websocket/src/main/java/org/springframework/websocket/server/HandshakeHandler.java
  33. 4
      spring-websocket/src/main/java/org/springframework/websocket/server/RequestUpgradeStrategy.java
  34. 2
      spring-websocket/src/main/java/org/springframework/websocket/server/support/AbstractEndpointUpgradeStrategy.java
  35. 8
      spring-websocket/src/main/java/org/springframework/websocket/server/support/JettyRequestUpgradeStrategy.java
  36. 4
      spring-websocket/src/main/java/org/springframework/websocket/server/support/WebSocketHttpRequestHandler.java
  37. 38
      spring-websocket/src/main/java/org/springframework/websocket/support/PerConnectionWebSocketHandlerProxy.java

2
spring-websocket/src/main/java/org/springframework/sockjs/AbstractSockJsSession.java

@ -55,7 +55,7 @@ public abstract class AbstractSockJsSession implements WebSocketSession { @@ -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;

2
spring-websocket/src/main/java/org/springframework/sockjs/SockJsSessionFactory.java

@ -34,6 +34,6 @@ public interface SockJsSessionFactory<S extends WebSocketSession>{ @@ -34,6 +34,6 @@ public interface SockJsSessionFactory<S extends WebSocketSession>{
* @param webSocketHandler the underlying {@link WebSocketHandler}
* @return a new non-null session
*/
S createSession(String sessionId, WebSocketHandler<?> webSocketHandler);
S createSession(String sessionId, WebSocketHandler webSocketHandler);
}

2
spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractServerSockJsSession.java

@ -43,7 +43,7 @@ public abstract class AbstractServerSockJsSession extends AbstractSockJsSession @@ -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;
}

6
spring-websocket/src/main/java/org/springframework/sockjs/server/AbstractSockJsService.java

@ -199,7 +199,7 @@ public abstract class AbstractSockJsService implements SockJsService, SockJsConf @@ -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 @@ -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;

2
spring-websocket/src/main/java/org/springframework/sockjs/server/SockJsService.java

@ -30,6 +30,6 @@ public interface SockJsService { @@ -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;
}

2
spring-websocket/src/main/java/org/springframework/sockjs/server/TransportHandler.java

@ -30,6 +30,6 @@ public interface TransportHandler { @@ -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;
}

6
spring-websocket/src/main/java/org/springframework/sockjs/server/support/DefaultSockJsService.java

@ -142,7 +142,7 @@ public class DefaultSockJsService extends AbstractSockJsService { @@ -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 { @@ -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 { @@ -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) {

2
spring-websocket/src/main/java/org/springframework/sockjs/server/support/SockJsHttpRequestHandler.java

@ -43,7 +43,7 @@ public class SockJsHttpRequestHandler implements HttpRequestHandler { @@ -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();

2
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpReceivingTransportHandler.java

@ -54,7 +54,7 @@ public abstract class AbstractHttpReceivingTransportHandler implements Transport @@ -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) {

2
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpSendingTransportHandler.java

@ -57,7 +57,7 @@ public abstract class AbstractHttpSendingTransportHandler @@ -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

2
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/AbstractHttpServerSockJsSession.java

@ -49,7 +49,7 @@ public abstract class AbstractHttpServerSockJsSession extends AbstractServerSock @@ -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);
}

2
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/EventSourceTransportHandler.java

@ -46,7 +46,7 @@ public class EventSourceTransportHandler extends AbstractHttpSendingTransportHan @@ -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

2
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/HtmlFileTransportHandler.java

@ -80,7 +80,7 @@ public class HtmlFileTransportHandler extends AbstractHttpSendingTransportHandle @@ -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) {

2
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/JsonpPollingTransportHandler.java

@ -50,7 +50,7 @@ public class JsonpPollingTransportHandler extends AbstractHttpSendingTransportHa @@ -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);
}

2
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/PollingServerSockJsSession.java

@ -24,7 +24,7 @@ import org.springframework.websocket.WebSocketHandler; @@ -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);
}

6
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/SockJsWebSocketHandler.java

@ -44,7 +44,7 @@ public class SockJsWebSocketHandler extends TextWebSocketHandlerAdapter { @@ -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 { @@ -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 { @@ -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);
}

2
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/StreamingServerSockJsSession.java

@ -31,7 +31,7 @@ public class StreamingServerSockJsSession extends AbstractHttpServerSockJsSessio @@ -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);
}

6
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/WebSocketTransportHandler.java

@ -63,10 +63,10 @@ public class WebSocketTransportHandler implements ConfigurableTransportHandler, @@ -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, @@ -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);

2
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrPollingTransportHandler.java

@ -50,7 +50,7 @@ public class XhrPollingTransportHandler extends AbstractHttpSendingTransportHand @@ -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);
}

2
spring-websocket/src/main/java/org/springframework/sockjs/server/transport/XhrStreamingTransportHandler.java

@ -47,7 +47,7 @@ public class XhrStreamingTransportHandler extends AbstractHttpSendingTransportHa @@ -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) {

4
spring-websocket/src/main/java/org/springframework/websocket/WebSocketHandler.java

@ -26,7 +26,7 @@ package org.springframework.websocket; @@ -26,7 +26,7 @@ package org.springframework.websocket;
* @author Phillip Webb
* @since 4.0
*/
public interface WebSocketHandler<T extends WebSocketMessage<?>> {
public interface WebSocketHandler {
/**
* A new WebSocket connection has been opened and is ready to be used.
@ -36,7 +36,7 @@ public interface WebSocketHandler<T extends WebSocketMessage<?>> { @@ -36,7 +36,7 @@ public interface WebSocketHandler<T extends WebSocketMessage<?>> {
/**
* 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.

25
spring-websocket/src/main/java/org/springframework/websocket/adapter/BinaryWebSocketHandlerAdapter.java

@ -16,8 +16,10 @@ @@ -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; @@ -29,22 +31,17 @@ import org.springframework.websocket.WebSocketSession;
* @author Phillip Webb
* @since 4.0
*/
public class BinaryWebSocketHandlerAdapter implements WebSocketHandler<BinaryMessage> {
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
}
}
}

5
spring-websocket/src/main/java/org/springframework/websocket/adapter/JettyWebSocketListenerAdapter.java

@ -25,7 +25,6 @@ import org.springframework.websocket.BinaryMessage; @@ -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 { @@ -38,12 +37,12 @@ public class JettyWebSocketListenerAdapter implements WebSocketListener {
private static Log logger = LogFactory.getLog(JettyWebSocketListenerAdapter.class);
private final WebSocketHandler<WebSocketMessage<?>> 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);
}

2
spring-websocket/src/main/java/org/springframework/websocket/adapter/StandardEndpointAdapter.java

@ -52,7 +52,7 @@ public class StandardEndpointAdapter extends Endpoint { @@ -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();

25
spring-websocket/src/main/java/org/springframework/websocket/adapter/TextWebSocketHandlerAdapter.java

@ -16,8 +16,10 @@ @@ -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; @@ -29,22 +31,17 @@ import org.springframework.websocket.WebSocketSession;
* @author Phillip Webb
* @since 4.0
*/
public class TextWebSocketHandlerAdapter implements WebSocketHandler<TextMessage> {
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
}
}
}

3
spring-websocket/src/main/java/org/springframework/websocket/adapter/WebSocketHandlerAdapter.java

@ -34,7 +34,7 @@ import org.springframework.websocket.WebSocketSession; @@ -34,7 +34,7 @@ import org.springframework.websocket.WebSocketSession;
* @see TextWebSocketHandlerAdapter
* @see BinaryWebSocketHandlerAdapter
*/
public class WebSocketHandlerAdapter implements WebSocketHandler<WebSocketMessage<?>> {
public class WebSocketHandlerAdapter implements WebSocketHandler {
@Override
public void afterConnectionEstablished(WebSocketSession session) {
@ -49,6 +49,7 @@ public class WebSocketHandlerAdapter implements WebSocketHandler<WebSocketMessag @@ -49,6 +49,7 @@ public class WebSocketHandlerAdapter implements WebSocketHandler<WebSocketMessag
handleBinaryMessage(session, (BinaryMessage) message);
}
else {
// should not happen
throw new IllegalStateException("Unexpected WebSocket message type: " + message);
}
}

22
spring-websocket/src/main/java/org/springframework/websocket/adapter/WebSocketHandlerInvoker.java

@ -20,7 +20,6 @@ import java.util.concurrent.atomic.AtomicInteger; @@ -20,7 +20,6 @@ import java.util.concurrent.atomic.AtomicInteger;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.springframework.core.GenericTypeResolver;
import org.springframework.util.Assert;
import org.springframework.websocket.CloseStatus;
import org.springframework.websocket.WebSocketHandler;
@ -36,22 +35,18 @@ import org.springframework.websocket.WebSocketSession; @@ -36,22 +35,18 @@ import org.springframework.websocket.WebSocketSession;
* @author Phillip Webb
* @since 4.0
*/
public class WebSocketHandlerInvoker implements WebSocketHandler<WebSocketMessage<?>> {
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<WebSocketMessag @@ -79,9 +74,7 @@ public class WebSocketHandlerInvoker implements WebSocketHandler<WebSocketMessag
}
public void tryCloseWithError(WebSocketSession session, Throwable exeption, CloseStatus status) {
if (exeption != null) {
logger.error("Closing due to exception for " + session, exeption);
}
logger.error("Closing due to exception for " + session, exeption);
if (session.isOpen()) {
try {
session.close((status != null) ? status : CloseStatus.SERVER_ERROR);
@ -92,18 +85,13 @@ public class WebSocketHandlerInvoker implements WebSocketHandler<WebSocketMessag @@ -92,18 +85,13 @@ public class WebSocketHandlerInvoker implements WebSocketHandler<WebSocketMessag
}
}
@SuppressWarnings("unchecked")
@Override
public void handleMessage(WebSocketSession session, WebSocketMessage<?> 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);

2
spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketClient.java

@ -38,7 +38,7 @@ public interface WebSocketClient { @@ -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;
}

2
spring-websocket/src/main/java/org/springframework/websocket/client/WebSocketConnectionManager.java

@ -32,7 +32,7 @@ public class WebSocketConnectionManager extends AbstractWebSocketConnectionManag @@ -32,7 +32,7 @@ public class WebSocketConnectionManager extends AbstractWebSocketConnectionManag
private final WebSocketClient client;
private final WebSocketHandler<?> webSocketHandler;
private final WebSocketHandler webSocketHandler;
private WebSocketSession webSocketSession;

2
spring-websocket/src/main/java/org/springframework/websocket/client/endpoint/StandardWebSocketClient.java

@ -67,7 +67,7 @@ public class StandardWebSocketClient implements WebSocketClient { @@ -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);

2
spring-websocket/src/main/java/org/springframework/websocket/server/DefaultHandshakeHandler.java

@ -87,7 +87,7 @@ public class DefaultHandshakeHandler implements HandshakeHandler { @@ -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());

4
spring-websocket/src/main/java/org/springframework/websocket/server/HandshakeHandler.java

@ -31,7 +31,7 @@ import org.springframework.websocket.WebSocketHandler; @@ -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;
}

4
spring-websocket/src/main/java/org/springframework/websocket/server/RequestUpgradeStrategy.java

@ -40,9 +40,9 @@ public interface RequestUpgradeStrategy { @@ -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;
}

2
spring-websocket/src/main/java/org/springframework/websocket/server/support/AbstractEndpointUpgradeStrategy.java

@ -42,7 +42,7 @@ public abstract class AbstractEndpointUpgradeStrategy implements RequestUpgradeS @@ -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));
}

8
spring-websocket/src/main/java/org/springframework/websocket/server/support/JettyRequestUpgradeStrategy.java

@ -65,8 +65,8 @@ public class JettyRequestUpgradeStrategy implements RequestUpgradeStrategy { @@ -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 { @@ -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 { @@ -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");

4
spring-websocket/src/main/java/org/springframework/websocket/server/support/WebSocketHttpRequestHandler.java

@ -43,14 +43,14 @@ public class WebSocketHttpRequestHandler implements HttpRequestHandler { @@ -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;

38
spring-websocket/src/main/java/org/springframework/websocket/support/PerConnectionWebSocketHandlerProxy.java

@ -16,7 +16,6 @@ @@ -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; @@ -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; @@ -50,21 +48,18 @@ import org.springframework.websocket.WebSocketSession;
* @author Rossen Stoyanchev
* @since 4.0
*/
public class PerConnectionWebSocketHandlerProxy implements WebSocketHandler<WebSocketMessage<?>>, BeanFactoryAware {
public class PerConnectionWebSocketHandlerProxy implements WebSocketHandler, BeanFactoryAware {
private Log logger = LogFactory.getLog(PerConnectionWebSocketHandlerProxy.class);
private final BeanCreatingHandlerProvider<WebSocketHandler<?>> provider;
private final BeanCreatingHandlerProvider<WebSocketHandler> provider;
private Map<WebSocketSession, WebSocketHandler<?>> handlers =
new ConcurrentHashMap<WebSocketSession, WebSocketHandler<?>>();
private Map<WebSocketSession, WebSocketHandler> handlers =
new ConcurrentHashMap<WebSocketSession, WebSocketHandler>();
private final Class<?> supportedMessageType;
public PerConnectionWebSocketHandlerProxy(Class<? extends WebSocketHandler<?>> handlerType) {
this.provider = new BeanCreatingHandlerProvider<WebSocketHandler<?>>(handlerType);
this.supportedMessageType = GenericTypeResolver.resolveTypeArgument(handlerType, WebSocketHandler.class);
public PerConnectionWebSocketHandlerProxy(Class<? extends WebSocketHandler> handlerType) {
this.provider = new BeanCreatingHandlerProvider<WebSocketHandler>(handlerType);
}
@ -75,29 +70,18 @@ public class PerConnectionWebSocketHandlerProxy implements WebSocketHandler<WebS @@ -75,29 +70,18 @@ public class PerConnectionWebSocketHandlerProxy implements WebSocketHandler<WebS
@Override
public void afterConnectionEstablished(WebSocketSession session) {
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<WebS @@ -118,7 +102,7 @@ public class PerConnectionWebSocketHandlerProxy implements WebSocketHandler<WebS
}
private void destroy(WebSocketSession session) {
WebSocketHandler<?> handler = this.handlers.remove(session);
WebSocketHandler handler = this.handlers.remove(session);
try {
if (handler != null) {
this.provider.destroy(handler);

Loading…
Cancel
Save