|
|
@ -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(); |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
} |
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
} |
|
|
|
} |
|
|
|