use of org.springframework.web.socket.server.HandshakeInterceptor in project spring-framework by spring-projects.
the class WebMvcStompWebSocketEndpointRegistration method getMappings.
public final MultiValueMap<HttpRequestHandler, String> getMappings() {
MultiValueMap<HttpRequestHandler, String> mappings = new LinkedMultiValueMap<>();
if (this.registration != null) {
SockJsService sockJsService = this.registration.getSockJsService();
for (String path : this.paths) {
String pattern = path.endsWith("/") ? path + "**" : path + "/**";
SockJsHttpRequestHandler handler = new SockJsHttpRequestHandler(sockJsService, this.webSocketHandler);
mappings.add(handler, pattern);
}
} else {
for (String path : this.paths) {
WebSocketHttpRequestHandler handler;
if (this.handshakeHandler != null) {
handler = new WebSocketHttpRequestHandler(this.webSocketHandler, this.handshakeHandler);
} else {
handler = new WebSocketHttpRequestHandler(this.webSocketHandler);
}
HandshakeInterceptor[] interceptors = getInterceptors();
if (interceptors.length > 0) {
handler.setHandshakeInterceptors(Arrays.asList(interceptors));
}
mappings.add(handler, path);
}
}
return mappings;
}
use of org.springframework.web.socket.server.HandshakeInterceptor in project spring-framework by spring-projects.
the class WebMvcStompWebSocketEndpointRegistration method getInterceptors.
protected HandshakeInterceptor[] getInterceptors() {
List<HandshakeInterceptor> interceptors = new ArrayList<>();
interceptors.addAll(this.interceptors);
interceptors.add(new OriginHandshakeInterceptor(this.allowedOrigins));
return interceptors.toArray(new HandshakeInterceptor[interceptors.size()]);
}
use of org.springframework.web.socket.server.HandshakeInterceptor in project spring-framework by spring-projects.
the class HandshakeInterceptorChain method applyBeforeHandshake.
public boolean applyBeforeHandshake(ServerHttpRequest request, ServerHttpResponse response, Map<String, Object> attributes) throws Exception {
for (int i = 0; i < this.interceptors.size(); i++) {
HandshakeInterceptor interceptor = this.interceptors.get(i);
if (!interceptor.beforeHandshake(request, response, this.wsHandler, attributes)) {
if (logger.isDebugEnabled()) {
logger.debug(interceptor + " returns false from beforeHandshake - precluding handshake");
}
applyAfterHandshake(request, response, null);
return false;
}
this.interceptorIndex = i;
}
return true;
}
use of org.springframework.web.socket.server.HandshakeInterceptor in project spring-framework by spring-projects.
the class AbstractWebSocketHandlerRegistration method withSockJS.
@Override
public SockJsServiceRegistration withSockJS() {
this.sockJsServiceRegistration = new SockJsServiceRegistration(this.sockJsTaskScheduler);
HandshakeInterceptor[] interceptors = getInterceptors();
if (interceptors.length > 0) {
this.sockJsServiceRegistration.setInterceptors(interceptors);
}
if (this.handshakeHandler != null) {
WebSocketTransportHandler transportHandler = new WebSocketTransportHandler(this.handshakeHandler);
this.sockJsServiceRegistration.setTransportHandlerOverrides(transportHandler);
}
if (!this.allowedOrigins.isEmpty()) {
this.sockJsServiceRegistration.setAllowedOrigins(this.allowedOrigins.toArray(new String[this.allowedOrigins.size()]));
}
return this.sockJsServiceRegistration;
}
use of org.springframework.web.socket.server.HandshakeInterceptor in project spring-framework by spring-projects.
the class WebMvcStompWebSocketEndpointRegistration method withSockJS.
@Override
public SockJsServiceRegistration withSockJS() {
this.registration = new StompSockJsServiceRegistration(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);
}
if (!this.allowedOrigins.isEmpty()) {
this.registration.setAllowedOrigins(this.allowedOrigins.toArray(new String[this.allowedOrigins.size()]));
}
return this.registration;
}
Aggregations