Polish
This commit is contained in:
parent
4d9144132e
commit
190408d1dc
|
|
@ -40,6 +40,7 @@ import org.springframework.web.socket.sockjs.support.SockJsHttpRequestHandler;
|
|||
public class ServletWebSocketHandlerRegistration
|
||||
extends AbstractWebSocketHandlerRegistration<MultiValueMap<HttpRequestHandler, String>> {
|
||||
|
||||
|
||||
public ServletWebSocketHandlerRegistration(TaskScheduler sockJsTaskScheduler) {
|
||||
super(sockJsTaskScheduler);
|
||||
}
|
||||
|
|
@ -60,10 +61,12 @@ public class ServletWebSocketHandlerRegistration
|
|||
|
||||
@Override
|
||||
protected void addWebSocketHandlerMapping(MultiValueMap<HttpRequestHandler, String> mappings,
|
||||
WebSocketHandler wsHandler, HandshakeHandler handshakeHandler,
|
||||
WebSocketHandler webSocketHandler, HandshakeHandler handshakeHandler,
|
||||
HandshakeInterceptor[] interceptors, String path) {
|
||||
|
||||
WebSocketHttpRequestHandler httpHandler = new WebSocketHttpRequestHandler(wsHandler, handshakeHandler);
|
||||
WebSocketHttpRequestHandler httpHandler =
|
||||
new WebSocketHttpRequestHandler(webSocketHandler, handshakeHandler);
|
||||
|
||||
if (!ObjectUtils.isEmpty(interceptors)) {
|
||||
httpHandler.setHandshakeInterceptors(Arrays.asList(interceptors));
|
||||
}
|
||||
|
|
|
|||
|
|
@ -41,8 +41,7 @@ import org.springframework.web.util.UrlPathHelper;
|
|||
*/
|
||||
public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry {
|
||||
|
||||
private final List<ServletWebSocketHandlerRegistration> registrations =
|
||||
new ArrayList<>();
|
||||
private final List<ServletWebSocketHandlerRegistration> registrations = new ArrayList<>(4);
|
||||
|
||||
private TaskScheduler sockJsTaskScheduler;
|
||||
|
||||
|
|
@ -56,10 +55,10 @@ public class ServletWebSocketHandlerRegistry implements WebSocketHandlerRegistry
|
|||
}
|
||||
|
||||
@Override
|
||||
public WebSocketHandlerRegistration addHandler(WebSocketHandler webSocketHandler, String... paths) {
|
||||
public WebSocketHandlerRegistration addHandler(WebSocketHandler handler, String... paths) {
|
||||
ServletWebSocketHandlerRegistration registration =
|
||||
new ServletWebSocketHandlerRegistration(this.sockJsTaskScheduler);
|
||||
registration.addHandler(webSocketHandler, paths);
|
||||
registration.addHandler(handler, paths);
|
||||
this.registrations.add(registration);
|
||||
return registration;
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
* 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.handler.DefaultSockJsService;
|
||||
|
||||
|
||||
/**
|
||||
* A helper class for configuring SockJS fallback options, typically used indirectly, in
|
||||
* conjunction with {@link org.springframework.web.socket.config.annotation.EnableWebSocket @EnableWebSocket} and
|
||||
* {@link WebSocketConfigurer}.
|
||||
* A helper class for configuring SockJS fallback options for use with an
|
||||
* {@link org.springframework.web.socket.config.annotation.EnableWebSocket} and
|
||||
* {@link WebSocketConfigurer} setup.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @since 4.0
|
||||
*/
|
||||
public class SockJsServiceRegistration {
|
||||
|
||||
private TaskScheduler taskScheduler;
|
||||
private TaskScheduler scheduler;
|
||||
|
||||
private String clientLibraryUrl;
|
||||
|
||||
|
|
@ -70,12 +71,12 @@ public class SockJsServiceRegistration {
|
|||
|
||||
|
||||
public SockJsServiceRegistration(TaskScheduler defaultTaskScheduler) {
|
||||
this.taskScheduler = defaultTaskScheduler;
|
||||
this.scheduler = defaultTaskScheduler;
|
||||
}
|
||||
|
||||
|
||||
public SockJsServiceRegistration setTaskScheduler(TaskScheduler taskScheduler) {
|
||||
this.taskScheduler = taskScheduler;
|
||||
this.scheduler = taskScheduler;
|
||||
return this;
|
||||
}
|
||||
|
||||
|
|
@ -277,14 +278,13 @@ public class SockJsServiceRegistration {
|
|||
}
|
||||
|
||||
private TransportHandlingSockJsService createSockJsService() {
|
||||
if (!this.transportHandlers.isEmpty()) {
|
||||
Assert.state(this.transportHandlerOverrides.isEmpty(),
|
||||
"Specify either TransportHandlers or TransportHandler overrides, not both");
|
||||
return new TransportHandlingSockJsService(this.taskScheduler, this.transportHandlers);
|
||||
}
|
||||
else {
|
||||
return new DefaultSockJsService(this.taskScheduler, this.transportHandlerOverrides);
|
||||
}
|
||||
|
||||
Assert.state(this.transportHandlers.isEmpty() || this.transportHandlerOverrides.isEmpty(),
|
||||
"Specify either TransportHandlers or TransportHandler overrides, not both");
|
||||
|
||||
return !this.transportHandlers.isEmpty() ?
|
||||
new TransportHandlingSockJsService(this.scheduler, this.transportHandlers) :
|
||||
new DefaultSockJsService(this.scheduler, this.transportHandlerOverrides);
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
@ -16,7 +16,9 @@
|
|||
|
||||
package org.springframework.web.socket.config.annotation;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
|
||||
import org.springframework.scheduling.TaskScheduler;
|
||||
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.transport.handler.WebSocketTransportHandler;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.List;
|
||||
|
||||
/**
|
||||
* 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 StompSockJsServiceRegistration registration;
|
||||
private SockJsServiceRegistration registration;
|
||||
|
||||
|
||||
public WebMvcStompWebSocketEndpointRegistration(String[] paths, WebSocketHandler webSocketHandler,
|
||||
|
|
@ -69,6 +70,7 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
|
|||
this.sockJsTaskScheduler = sockJsTaskScheduler;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public StompWebSocketEndpointRegistration setHandshakeHandler(HandshakeHandler handshakeHandler) {
|
||||
Assert.notNull(handshakeHandler, "'handshakeHandler' must not be null");
|
||||
|
|
@ -95,17 +97,18 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
|
|||
|
||||
@Override
|
||||
public SockJsServiceRegistration withSockJS() {
|
||||
this.registration = new StompSockJsServiceRegistration(this.sockJsTaskScheduler);
|
||||
this.registration = new SockJsServiceRegistration(this.sockJsTaskScheduler);
|
||||
HandshakeInterceptor[] interceptors = getInterceptors();
|
||||
if (interceptors.length > 0) {
|
||||
this.registration.setInterceptors(interceptors);
|
||||
}
|
||||
if (this.handshakeHandler != null) {
|
||||
WebSocketTransportHandler transportHandler = new WebSocketTransportHandler(this.handshakeHandler);
|
||||
this.registration.setTransportHandlerOverrides(transportHandler);
|
||||
WebSocketTransportHandler handler = new WebSocketTransportHandler(this.handshakeHandler);
|
||||
this.registration.setTransportHandlerOverrides(handler);
|
||||
}
|
||||
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;
|
||||
}
|
||||
|
|
@ -146,16 +149,4 @@ public class WebMvcStompWebSocketEndpointRegistration implements StompWebSocketE
|
|||
return mappings;
|
||||
}
|
||||
|
||||
|
||||
private static class StompSockJsServiceRegistration extends SockJsServiceRegistration {
|
||||
|
||||
public StompSockJsServiceRegistration(TaskScheduler defaultTaskScheduler) {
|
||||
super(defaultTaskScheduler);
|
||||
}
|
||||
|
||||
protected SockJsService getSockJsService() {
|
||||
return super.getSockJsService();
|
||||
}
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
|||
|
|
@ -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");
|
||||
* you may not use this file except in compliance with the License.
|
||||
|
|
|
|||
Loading…
Reference in New Issue