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) { diff --git a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfo.java b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfo.java index 9448b72867cf..3d861815e334 100644 --- a/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfo.java +++ b/spring-websocket/src/main/java/org/springframework/web/socket/sockjs/client/SockJsUrlInfo.java @@ -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 @@ * 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;