Browse Source

Polish

pull/1386/head
Rossen Stoyanchev 8 years ago
parent
commit
190408d1dc
  1. 7
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistration.java
  2. 7
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistry.java
  3. 30
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java
  4. 31
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java
  5. 2
      spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java

7
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistration.java

@ -40,6 +40,7 @@ import org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler;
public class ServletWebSocketHandlerRegistration public class ServletWebSocketHandlerRegistration
extends AbstractWebSocketHandlerRegistration<MultiValueMap<HttpRequestHandler, String>> { extends AbstractWebSocketHandlerRegistration<MultiValueMap<HttpRequestHandler, String>> {
public ServletWebSocketHandlerRegistration(TaskScheduler sockJsTaskScheduler) { public ServletWebSocketHandlerRegistration(TaskScheduler sockJsTaskScheduler) {
super(sockJsTaskScheduler); super(sockJsTaskScheduler);
} }
@ -60,10 +61,12 @@ public class ServletWebSocketHandlerRegistration
@Override @Override
protected void addWebSocketHandlerMapping(MultiValueMap<HttpRequestHandler, String> mappings, protected void addWebSocketHandlerMapping(MultiValueMap<HttpRequestHandler, String> mappings,
WebSocketHandler wsHandler, HandshakeHandler handshakeHandler, WebSocketHandler webSocketHandler, HandshakeHandler handshakeHandler,
HandshakeInterceptor[] interceptors, String path) { HandshakeInterceptor[] interceptors, String path) {
WebSocketHttpRequestHandler httpHandler = new WebSocketHttpRequestHandler(wsHandler, handshakeHandler); WebSocketHttpRequestHandler httpHandler =
new WebSocketHttpRequestHandler(webSocketHandler, handshakeHandler);
if (!ObjectUtils.isEmpty(interceptors)) { if (!ObjectUtils.isEmpty(interceptors)) {
httpHandler.setHandshakeInterceptors(Arrays.asList(interceptors)); httpHandler.setHandshakeInterceptors(Arrays.asList(interceptors));
} }

7
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/ServletWebSocketHandlerRegistry.java

@ -41,8 +41,7 @@ import org.springframework.web.util.UrlPathHelper;
*/ */
public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry { public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry {
private final List<ServletWebSocketHandlerRegistration> registrations = private final List<ServletWebSocketHandlerRegistration> registrations = new ArrayList<>(4);
new ArrayList<>();
private TaskScheduler sockJsTaskScheduler; private TaskScheduler sockJsTaskScheduler;
@ -56,10 +55,10 @@ public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry
} }
@Override @Override
public WebSocketHandlerRegistration addHandler(WebSocketHandler webSocketHandler, String... paths) { public WebSocketHandlerRegistration addHandler(WebSocketHandler handler, String... paths) {
ServletWebSocketHandlerRegistration registration = ServletWebSocketHandlerRegistration registration =
new ServletWebSocketHandlerRegistration(this.sockJsTaskScheduler); new ServletWebSocketHandlerRegistration(this.sockJsTaskScheduler);
registration.addHandler(webSocketHandler, paths); registration.addHandler(handler, paths);
this.registrations.add(registration); this.registrations.add(registration);
return registration; return registration;
} }

30
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/SockJsServiceRegistration.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -30,17 +30,18 @@ import org.springframework.web.socket.sockjs.transport.TransportHandler;
import org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService; import org.springframework.web.socket.sockjs.transport.TransportHandlingSockJsService;
import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService; import org.springframework.web.socket.sockjs.transport.handler.DefaultSockJsService;
/** /**
* A helper class for configuring SockJS fallback options, typically used indirectly, in * A helper class for configuring SockJS fallback options for use with an
* conjunction with {@link org.springframework.web.socket.config.annotation.EnableWebSocket @EnableWebSocket} and * {@link org.springframework.web.socket.config.annotation.EnableWebSocket} and
* {@link WebSocketConfigurer}. * {@link WebSocketConfigurer} setup.
* *
* @author Rossen Stoyanchev * @author Rossen Stoyanchev
* @since 4.0 * @since 4.0
*/ */
public class SockJsServiceRegistration { public class SockJsServiceRegistration {
private TaskScheduler taskScheduler; private TaskScheduler scheduler;
private String clientLibraryUrl; private String clientLibraryUrl;
@ -70,12 +71,12 @@ public class SockJsServiceRegistration {
public SockJsServiceRegistration(TaskScheduler defaultTaskScheduler) { public SockJsServiceRegistration(TaskScheduler defaultTaskScheduler) {
this.taskScheduler = defaultTaskScheduler; this.scheduler = defaultTaskScheduler;
} }
public SockJsServiceRegistration setTaskScheduler(TaskScheduler taskScheduler) { public SockJsServiceRegistration setTaskScheduler(TaskScheduler taskScheduler) {
this.taskScheduler = taskScheduler; this.scheduler = taskScheduler;
return this; return this;
} }
@ -277,14 +278,13 @@ public class SockJsServiceRegistration {
} }
private TransportHandlingSockJsService createSockJsService() { private TransportHandlingSockJsService createSockJsService() {
if (!this.transportHandlers.isEmpty()) {
Assert.state(this.transportHandlerOverrides.isEmpty(), Assert.state(this.transportHandlers.isEmpty() || this.transportHandlerOverrides.isEmpty(),
"Specify either TransportHandlers or TransportHandler overrides, not both"); "Specify either TransportHandlers or TransportHandler overrides, not both");
return new TransportHandlingSockJsService(this.taskScheduler, this.transportHandlers);
} return !this.transportHandlers.isEmpty() ?
else { new TransportHandlingSockJsService(this.scheduler, this.transportHandlers) :
return new DefaultSockJsService(this.taskScheduler, this.transportHandlerOverrides); new DefaultSockJsService(this.scheduler, this.transportHandlerOverrides);
}
} }
} }

31
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebMvcStompWebSocketEndpointRegistration.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2016 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.
@ -16,7 +16,9 @@
package org.springframework.web.socket.config.annotation; package org.springframework.web.socket.config.annotation;
import java.util.ArrayList;
import java.util.Arrays; import java.util.Arrays;
import java.util.List;
import org.springframework.scheduling.TaskScheduler; import org.springframework.scheduling.TaskScheduler;
import org.springframework.util.Assert; import org.springframework.util.Assert;
@ -33,8 +35,7 @@ import org.springframework.web.socket.sockjs.SockJsService;
import org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler; import org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler;
import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler; import org.springframework.web.socket.sockjs.transport.handler.WebSocketTransportHandler;
import java.util.ArrayList;
import java.util.List;
/** /**
* An abstract base class for configuring STOMP over WebSocket/SockJS endpoints. * An abstract base class for configuring STOMP over WebSocket/SockJS endpoints.
* *
@ -55,7 +56,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
private final List<String> allowedOrigins = new ArrayList<>(); private final List<String> allowedOrigins = new ArrayList<>();
private StompSockJsServiceRegistration registration; private SockJsServiceRegistration registration;
public WebMvcStompWebSocketEndpointRegistration(String[] paths, WebSocketHandler webSocketHandler, public WebMvcStompWebSocketEndpointRegistration(String[] paths, WebSocketHandler webSocketHandler,
@ -69,6 +70,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
this.sockJsTaskScheduler = sockJsTaskScheduler; this.sockJsTaskScheduler = sockJsTaskScheduler;
} }
@Override @Override
public StompWebSocketEndpointRegistration setHandshakeHandler(HandshakeHandler handshakeHandler) { public StompWebSocketEndpointRegistration setHandshakeHandler(HandshakeHandler handshakeHandler) {
Assert.notNull(handshakeHandler, "'handshakeHandler' must not be null"); Assert.notNull(handshakeHandler, "'handshakeHandler' must not be null");
@ -95,17 +97,18 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
@Override @Override
public SockJsServiceRegistration withSockJS() { public SockJsServiceRegistration withSockJS() {
this.registration = new StompSockJsServiceRegistration(this.sockJsTaskScheduler); this.registration = new SockJsServiceRegistration(this.sockJsTaskScheduler);
HandshakeInterceptor[] interceptors = getInterceptors(); HandshakeInterceptor[] interceptors = getInterceptors();
if (interceptors.length > 0) { if (interceptors.length > 0) {
this.registration.setInterceptors(interceptors); this.registration.setInterceptors(interceptors);
} }
if (this.handshakeHandler != null) { if (this.handshakeHandler != null) {
WebSocketTransportHandler transportHandler = new WebSocketTransportHandler(this.handshakeHandler); WebSocketTransportHandler handler = new WebSocketTransportHandler(this.handshakeHandler);
this.registration.setTransportHandlerOverrides(transportHandler); this.registration.setTransportHandlerOverrides(handler);
} }
if (!this.allowedOrigins.isEmpty()) { if (!this.allowedOrigins.isEmpty()) {
this.registration.setAllowedOrigins(this.allowedOrigins.toArray(new String[this.allowedOrigins.size()])); this.registration.setAllowedOrigins(
this.allowedOrigins.toArray(new String[this.allowedOrigins.size()]));
} }
return this.registration; return this.registration;
} }
@ -146,16 +149,4 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
return mappings; return mappings;
} }
private static class StompSockJsServiceRegistration extends SockJsServiceRegistration {
public StompSockJsServiceRegistration(TaskScheduler defaultTaskScheduler) {
super(defaultTaskScheduler);
}
protected SockJsService getSockJsService() {
return super.getSockJsService();
}
}
} }

2
spring-websocket/src/main/java/org/springframework/web/socket/config/annotation/WebSocketConfigurationSupport.java

@ -1,5 +1,5 @@
/* /*
* Copyright 2002-2014 the original author or authors. * Copyright 2002-2017 the original author or authors.
* *
* Licensed under the Apache License, Version 2.0 (the "License"); * Licensed under the Apache License, Version 2.0 (the "License");
* you may not use this file except in compliance with the License. * you may not use this file except in compliance with the License.

Loading…
Cancel
Save