Allow SockJsUrlInfo to be overridden in SockJsClient
Closes gh-25888
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -55,6 +55,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Sam Brannen
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.1
|
||||
* @see <a href="https://github.com/sockjs/sockjs-client">https://github.com/sockjs/sockjs-client</a>
|
||||
* @see org.springframework.web.socket.sockjs.client.Transport
|
||||
@@ -242,7 +243,7 @@ public class SockJsClient implements WebSocketClient, Lifecycle {
|
||||
|
||||
CompletableFuture<WebSocketSession> connectFuture = new CompletableFuture<>();
|
||||
try {
|
||||
SockJsUrlInfo sockJsUrlInfo = new SockJsUrlInfo(url);
|
||||
SockJsUrlInfo sockJsUrlInfo = buildSockJsUrlInfo(url);
|
||||
ServerInfo serverInfo = getServerInfo(sockJsUrlInfo, getHttpRequestHeaders(headers));
|
||||
createRequest(sockJsUrlInfo, headers, serverInfo).connect(handler, connectFuture);
|
||||
}
|
||||
@@ -255,6 +256,18 @@ public class SockJsClient implements WebSocketClient, Lifecycle {
|
||||
return connectFuture;
|
||||
}
|
||||
|
||||
/**
|
||||
* Create a new {@link SockJsUrlInfo} for the current client execution.
|
||||
* <p>The default implementation builds a {@code SockJsUrlInfo} which
|
||||
* calculates a random server id and session id if necessary.
|
||||
* @param url the target URL
|
||||
* @since 6.1.3
|
||||
* @see SockJsUrlInfo#SockJsUrlInfo(URI)
|
||||
*/
|
||||
protected SockJsUrlInfo buildSockJsUrlInfo(URI url) {
|
||||
return new SockJsUrlInfo(url);
|
||||
}
|
||||
|
||||
@Nullable
|
||||
private HttpHeaders getHttpRequestHeaders(@Nullable HttpHeaders webSocketHttpHeaders) {
|
||||
if (getHttpHeaderNames() == null || webSocketHttpHeaders == null) {
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2018 the original author or authors.
|
||||
* Copyright 2002-2023 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.
|
||||
@@ -32,6 +32,7 @@ import org.springframework.web.util.UriComponentsBuilder;
|
||||
* and {@link #getTransportUrl(TransportType) transport} URLs.
|
||||
*
|
||||
* @author Rossen Stoyanchev
|
||||
* @author Juergen Hoeller
|
||||
* @since 4.1
|
||||
*/
|
||||
public class SockJsUrlInfo {
|
||||
@@ -51,10 +52,28 @@ public class SockJsUrlInfo {
|
||||
private UUID uuid;
|
||||
|
||||
|
||||
/**
|
||||
* Construct a new {@code SockJsUrlInfo} instance,
|
||||
* calculating a random server id and session id if necessary.
|
||||
* @param sockJsUrl the target URL
|
||||
*/
|
||||
public SockJsUrlInfo(URI sockJsUrl) {
|
||||
this.sockJsUrl = sockJsUrl;
|
||||
}
|
||||
|
||||
/**
|
||||
* Construct a new {@code SockJsUrlInfo} instance.
|
||||
* @param sockJsUrl the target URL
|
||||
* @param serverId a pre-determined server id, if any
|
||||
* @param sessionId a pre-determined session id, if any
|
||||
* @since 6.1.3
|
||||
*/
|
||||
public SockJsUrlInfo(URI sockJsUrl, @Nullable String serverId, @Nullable String sessionId) {
|
||||
this.sockJsUrl = sockJsUrl;
|
||||
this.serverId = serverId;
|
||||
this.sessionId = sessionId;
|
||||
}
|
||||
|
||||
|
||||
public URI getSockJsUrl() {
|
||||
return this.sockJsUrl;
|
||||
|
||||
Reference in New Issue
Block a user