Skip to content
This repository was archived by the owner on Dec 19, 2023. It is now read-only.

Commit bc3c878

Browse files
refactor: use Spring URI builder for building test subscription path
1 parent 6215678 commit bc3c878

File tree

1 file changed

+5
-1
lines changed

1 file changed

+5
-1
lines changed

graphql-spring-boot-test/src/main/java/com/graphql/spring/boot/test/GraphQLTestSubscription.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212
import org.springframework.http.ResponseEntity;
1313
import org.springframework.lang.Nullable;
1414
import org.springframework.util.ResourceUtils;
15+
import org.springframework.web.util.DefaultUriBuilderFactory;
16+
import org.springframework.web.util.UriBuilderFactory;
1517

1618
import javax.websocket.ClientEndpointConfig;
1719
import javax.websocket.ContainerProvider;
@@ -46,6 +48,7 @@ public class GraphQLTestSubscription {
4648

4749
private static final int SLEEP_INTERVAL_MS = 100;
4850
private static final AtomicInteger ID_COUNTER = new AtomicInteger(1);
51+
private static final UriBuilderFactory URI_BUILDER_FACTORY = new DefaultUriBuilderFactory();
4952

5053
@Getter
5154
private Session session;
@@ -339,7 +342,8 @@ public List<GraphQLResponse> getRemainingResponses() {
339342
private void initClient() throws Exception {
340343
final WebSocketContainer webSocketContainer = ContainerProvider.getWebSocketContainer();
341344
final String port = environment.getProperty("local.server.port");
342-
final URI uri = URI.create(String.format("ws://localhost:%s/%s", port, subscriptionPath));
345+
final URI uri = URI_BUILDER_FACTORY.builder().scheme("ws").host("localhost").port(port).path(subscriptionPath)
346+
.build();
343347
log.debug("Connecting to client at {}", uri);
344348
final ClientEndpointConfig clientEndpointConfig = ClientEndpointConfig.Builder.create()
345349
.configurator(new TestWebSocketClientConfigurator())

0 commit comments

Comments
 (0)