Make URI template variables nullable

Closes gh-34221
This commit is contained in:
Sébastien Deleuze
2025-01-10 11:39:21 +01:00
parent bce7d87151
commit ec48c47886
33 changed files with 172 additions and 165 deletions

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2024 the original author or authors.
* Copyright 2002-2025 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.
@@ -61,7 +61,7 @@ public abstract class AbstractWebSocketClient implements WebSocketClient {
@Override
public CompletableFuture<WebSocketSession> execute(WebSocketHandler webSocketHandler,
String uriTemplate, Object... uriVars) {
String uriTemplate, @Nullable Object... uriVars) {
Assert.notNull(uriTemplate, "'uriTemplate' must not be null");
URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVars).encode().toUri();

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2023 the original author or authors.
* Copyright 2002-2025 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.
@@ -20,6 +20,7 @@ import java.net.URI;
import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import org.jspecify.annotations.Nullable;
import org.springframework.context.SmartLifecycle;
import org.springframework.web.util.UriComponentsBuilder;
@@ -52,7 +53,7 @@ public abstract class ConnectionManagerSupport implements SmartLifecycle {
/**
* Constructor with a URI template and variables.
*/
public ConnectionManagerSupport(String uriTemplate, Object... uriVariables) {
public ConnectionManagerSupport(String uriTemplate, @Nullable Object... uriVariables) {
this.uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVariables).encode().toUri();
}

View File

@@ -46,7 +46,7 @@ public interface WebSocketClient {
* @since 6.0
*/
CompletableFuture<WebSocketSession> execute(WebSocketHandler webSocketHandler,
String uriTemplate, Object... uriVariables);
String uriTemplate, @Nullable Object... uriVariables);
/**
* Execute a handshake request to the given url and handle the resulting

View File

@@ -53,7 +53,7 @@ public class WebSocketConnectionManager extends ConnectionManagerSupport {
* Constructor with the client to use and a handler to handle messages with.
*/
public WebSocketConnectionManager(WebSocketClient client,
WebSocketHandler webSocketHandler, String uriTemplate, Object... uriVariables) {
WebSocketHandler webSocketHandler, String uriTemplate, @Nullable Object... uriVariables) {
super(uriTemplate, uriVariables);
this.client = client;

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2024 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.
@@ -51,13 +51,13 @@ public class AnnotatedEndpointConnectionManager extends ConnectionManagerSupport
private volatile @Nullable Session session;
public AnnotatedEndpointConnectionManager(Object endpoint, String uriTemplate, Object... uriVariables) {
public AnnotatedEndpointConnectionManager(Object endpoint, String uriTemplate, @Nullable Object... uriVariables) {
super(uriTemplate, uriVariables);
this.endpoint = endpoint;
this.endpointProvider = null;
}
public AnnotatedEndpointConnectionManager(Class<?> endpointClass, String uriTemplate, Object... uriVariables) {
public AnnotatedEndpointConnectionManager(Class<?> endpointClass, String uriTemplate, @Nullable Object... uriVariables) {
super(uriTemplate, uriVariables);
this.endpoint = null;
this.endpointProvider = new BeanCreatingHandlerProvider<>(endpointClass);

View File

@@ -1,5 +1,5 @@
/*
* Copyright 2002-2022 the original author or authors.
* Copyright 2002-2025 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.
@@ -62,14 +62,14 @@ public class EndpointConnectionManager extends ConnectionManagerSupport implemen
private volatile @Nullable Session session;
public EndpointConnectionManager(Endpoint endpoint, String uriTemplate, Object... uriVariables) {
public EndpointConnectionManager(Endpoint endpoint, String uriTemplate, @Nullable Object... uriVariables) {
super(uriTemplate, uriVariables);
Assert.notNull(endpoint, "endpoint must not be null");
this.endpoint = endpoint;
this.endpointProvider = null;
}
public EndpointConnectionManager(Class<? extends Endpoint> endpointClass, String uriTemplate, Object... uriVars) {
public EndpointConnectionManager(Class<? extends Endpoint> endpointClass, String uriTemplate, @Nullable Object... uriVars) {
super(uriTemplate, uriVars);
Assert.notNull(endpointClass, "endpointClass must not be null");
this.endpoint = null;

View File

@@ -235,7 +235,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
* @return a CompletableFuture for access to the session when ready for use
* @since 6.0
*/
public CompletableFuture<StompSession> connectAsync(String url, StompSessionHandler handler, Object... uriVars) {
public CompletableFuture<StompSession> connectAsync(String url, StompSessionHandler handler, @Nullable Object... uriVars) {
return connectAsync(url, null, handler, uriVars);
}
@@ -251,7 +251,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
* @since 6.0
*/
public CompletableFuture<StompSession> connectAsync(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
StompSessionHandler handler, Object... uriVariables) {
StompSessionHandler handler, @Nullable Object... uriVariables) {
return connectAsync(url, handshakeHeaders, null, handler, uriVariables);
}
@@ -270,7 +270,7 @@ public class WebSocketStompClient extends StompClientSupport implements SmartLif
* @since 6.0
*/
public CompletableFuture<StompSession> connectAsync(String url, @Nullable WebSocketHttpHeaders handshakeHeaders,
@Nullable StompHeaders connectHeaders, StompSessionHandler handler, Object... uriVariables) {
@Nullable StompHeaders connectHeaders, StompSessionHandler handler, @Nullable Object... uriVariables) {
Assert.notNull(url, "'url' must not be null");
URI uri = UriComponentsBuilder.fromUriString(url).buildAndExpand(uriVariables).encode().toUri();

View File

@@ -218,7 +218,7 @@ public class SockJsClient implements WebSocketClient, Lifecycle {
@Override
public CompletableFuture<WebSocketSession> execute(
WebSocketHandler handler, String uriTemplate, Object... uriVars) {
WebSocketHandler handler, String uriTemplate, @Nullable Object... uriVars) {
Assert.notNull(uriTemplate, "uriTemplate must not be null");
URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVars).encode().toUri();

View File

@@ -20,6 +20,7 @@ import java.net.URI;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import org.jspecify.annotations.Nullable;
import org.junit.jupiter.api.Test;
import org.springframework.context.Lifecycle;
@@ -110,7 +111,7 @@ class WebSocketConnectionManagerTests {
@Override
public CompletableFuture<WebSocketSession> execute(WebSocketHandler handler,
String uriTemplate, Object... uriVars) {
String uriTemplate, @Nullable Object... uriVars) {
URI uri = UriComponentsBuilder.fromUriString(uriTemplate).buildAndExpand(uriVars).encode().toUri();
return execute(handler, null, uri);