Skip to content

Commit

Permalink
Allow SockJsUrlInfo to be overridden in SockJsClient
Browse files Browse the repository at this point in the history
Closes gh-25888
  • Loading branch information
jhoeller committed Dec 28, 2023
1 parent 28e5468 commit 989625d
Show file tree
Hide file tree
Showing 2 changed files with 35 additions and 3 deletions.
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -55,6 +55,7 @@
*
* @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
Expand Down Expand Up @@ -242,7 +243,7 @@ public final CompletableFuture<WebSocketSession> execute(

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);
}
Expand All @@ -255,6 +256,18 @@ public final CompletableFuture<WebSocketSession> execute(
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) {
Expand Down
Original file line number Diff line number Diff line change
@@ -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.
Expand Down Expand Up @@ -32,6 +32,7 @@
* and {@link #getTransportUrl(TransportType) transport} URLs.
*
* @author Rossen Stoyanchev
* @author Juergen Hoeller
* @since 4.1
*/
public class SockJsUrlInfo {
Expand All @@ -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;
Expand Down

0 comments on commit 989625d

Please sign in to comment.