Polish WebSocketHttpRequestHandler

This commit is contained in:
Rossen Stoyanchev 2013-08-25 13:47:16 -04:00
parent 4447248a83
commit 4b6a9ac180
3 changed files with 6 additions and 27 deletions

View File

@ -505,6 +505,7 @@ project("spring-websocket") {
compile(project(":spring-core")) compile(project(":spring-core"))
compile(project(":spring-context")) compile(project(":spring-context"))
compile(project(":spring-web")) compile(project(":spring-web"))
optional(project(":spring-webmvc"))
optional("javax.servlet:javax.servlet-api:3.1.0") optional("javax.servlet:javax.servlet-api:3.1.0")
optional("javax.websocket:javax.websocket-api:1.0") optional("javax.websocket:javax.websocket-api:1.0")
optional("org.apache.tomcat:tomcat-websocket:8.0-SNAPSHOT") { optional("org.apache.tomcat:tomcat-websocket:8.0-SNAPSHOT") {

View File

@ -49,7 +49,7 @@ import org.springframework.web.socket.support.LoggingWebSocketHandlerDecorator;
* {@link HttpServletResponse} to {@link ServerHttpRequest} and {@link ServerHttpResponse} * {@link HttpServletResponse} to {@link ServerHttpRequest} and {@link ServerHttpResponse}
* respectively. * respectively.
* *
* <p>The {@link #decorateWebSocketHandler(WebSocketHandler)} method decorates the given * <p>The {@link #applyDefaultDecorators(WebSocketHandler)} method decorates the given
* WebSocketHandler with a logging and exception handling decorators. This method can * WebSocketHandler with a logging and exception handling decorators. This method can
* be overridden to change that. * be overridden to change that.
* *
@ -69,10 +69,10 @@ public class WebSocketHttpRequestHandler implements HttpRequestHandler {
this(webSocketHandler, new DefaultHandshakeHandler()); this(webSocketHandler, new DefaultHandshakeHandler());
} }
public WebSocketHttpRequestHandler( WebSocketHandler webSocketHandler, HandshakeHandler handshakeHandler) { public WebSocketHttpRequestHandler(WebSocketHandler wsHandler, HandshakeHandler handshakeHandler) {
Assert.notNull(webSocketHandler, "webSocketHandler must not be null"); Assert.notNull(wsHandler, "wsHandler must not be null");
Assert.notNull(handshakeHandler, "handshakeHandler must not be null"); Assert.notNull(handshakeHandler, "handshakeHandler must not be null");
this.wsHandler = decorateWebSocketHandler(webSocketHandler); this.wsHandler = new ExceptionWebSocketHandlerDecorator(new LoggingWebSocketHandlerDecorator(wsHandler));
this.handshakeHandler = handshakeHandler; this.handshakeHandler = handshakeHandler;
} }
@ -94,17 +94,6 @@ public class WebSocketHttpRequestHandler implements HttpRequestHandler {
return this.interceptors; return this.interceptors;
} }
/**
* Decorate the WebSocketHandler provided to the class constructor.
*
* <p>By default {@link ExceptionWebSocketHandlerDecorator} and
* {@link LoggingWebSocketHandlerDecorator} are applied are added.
*/
protected WebSocketHandler decorateWebSocketHandler(WebSocketHandler wsHandler) {
wsHandler = new ExceptionWebSocketHandlerDecorator(wsHandler);
return new LoggingWebSocketHandlerDecorator(wsHandler);
}
@Override @Override
public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
throws ServletException, IOException { throws ServletException, IOException {

View File

@ -55,21 +55,10 @@ public class SockJsHttpRequestHandler implements HttpRequestHandler {
Assert.notNull(sockJsService, "sockJsService must not be null"); Assert.notNull(sockJsService, "sockJsService must not be null");
Assert.notNull(wsHandler, "webSocketHandler must not be null"); Assert.notNull(wsHandler, "webSocketHandler must not be null");
this.sockJsService = sockJsService; this.sockJsService = sockJsService;
this.wsHandler = decorateWebSocketHandler(wsHandler); this.wsHandler = new ExceptionWebSocketHandlerDecorator(new LoggingWebSocketHandlerDecorator(wsHandler));
} }
/**
* Decorate the WebSocketHandler provided to the class constructor.
*
* <p>By default {@link ExceptionWebSocketHandlerDecorator} and
* {@link LoggingWebSocketHandlerDecorator} are applied are added.
*/
protected WebSocketHandler decorateWebSocketHandler(WebSocketHandler wsHandler) {
wsHandler = new ExceptionWebSocketHandlerDecorator(wsHandler);
return new LoggingWebSocketHandlerDecorator(wsHandler);
}
@Override @Override
public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse) public void handleRequest(HttpServletRequest servletRequest, HttpServletResponse servletResponse)
throws ServletException, IOException { throws ServletException, IOException {