diff --git a/extensions/websockets-next/deployment/src/main/java/io/quarkus/websockets/next/deployment/devui/WebSocketServerDevUIProcessor.java b/extensions/websockets-next/deployment/src/main/java/io/quarkus/websockets/next/deployment/devui/WebSocketServerDevUIProcessor.java index 5f89d5cfd0482..2785efe1fbdd4 100644 --- a/extensions/websockets-next/deployment/src/main/java/io/quarkus/websockets/next/deployment/devui/WebSocketServerDevUIProcessor.java +++ b/extensions/websockets-next/deployment/src/main/java/io/quarkus/websockets/next/deployment/devui/WebSocketServerDevUIProcessor.java @@ -40,7 +40,7 @@ public void pages(List endpoints, List root + .addClass(MyBean.class)); + + @Test + public void testConnectorIsInjected() { + assertEquals("1", RestAssured.get("mybeantest").then().statusCode(200).extract().body().asString()); + } + + @Singleton + public static class MyBean { + + @Inject + BasicWebSocketConnector connector; + + void addRoute(@Observes Router router) { + router.get("/mybeantest").handler(rc -> { + rc.end(connector != null ? "1" : "0"); + }); + } + + } + +} diff --git a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/devui/WebSocketNextJsonRPCService.java b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/devui/WebSocketNextJsonRPCService.java index 5df2e1d395b28..b54992fae08bd 100644 --- a/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/devui/WebSocketNextJsonRPCService.java +++ b/extensions/websockets-next/runtime/src/main/java/io/quarkus/websockets/next/runtime/devui/WebSocketNextJsonRPCService.java @@ -12,6 +12,7 @@ import java.util.concurrent.ConcurrentMap; import jakarta.enterprise.context.ApplicationScoped; +import jakarta.enterprise.inject.Instance; import org.jboss.logging.Logger; @@ -53,16 +54,18 @@ public class WebSocketNextJsonRPCService implements ConnectionListener { private final WebSocketsServerRuntimeConfig.DevMode devModeConfig; - WebSocketNextJsonRPCService(ConnectionManager connectionManager, Vertx vertx, HttpConfiguration httpConfig, + WebSocketNextJsonRPCService(Instance connectionManager, Vertx vertx, HttpConfiguration httpConfig, WebSocketsServerRuntimeConfig config) { this.connectionStatus = BroadcastProcessor.create(); this.connectionMessages = BroadcastProcessor.create(); - this.connectionManager = connectionManager; + this.connectionManager = connectionManager.isResolvable() ? connectionManager.get() : null; this.vertx = vertx; this.httpConfig = httpConfig; this.devModeConfig = config.devMode(); this.sockets = new ConcurrentHashMap<>(); - connectionManager.addListener(this); + if (this.connectionManager != null) { + this.connectionManager.addListener(this); + } } public Multi connectionStatus() { @@ -75,14 +78,16 @@ public Multi connectionMessages() { public JsonObject getConnections(List endpoints) { JsonObject json = new JsonObject(); - for (String endpoint : endpoints) { - List connections = new ArrayList<>(connectionManager.getConnections(endpoint)); - connections.sort(Comparator.comparing(WebSocketConnection::creationTime)); - JsonArray array = new JsonArray(); - for (WebSocketConnection c : connections) { - array.add(toJsonObject(endpoint, c)); + if (connectionManager != null) { + for (String endpoint : endpoints) { + List connections = new ArrayList<>(connectionManager.getConnections(endpoint)); + connections.sort(Comparator.comparing(WebSocketConnection::creationTime)); + JsonArray array = new JsonArray(); + for (WebSocketConnection c : connections) { + array.add(toJsonObject(endpoint, c)); + } + json.put(endpoint, array); } - json.put(endpoint, array); } json.put("connectionMessagesLimit", devModeConfig.connectionMessagesLimit()); return json; @@ -104,6 +109,9 @@ public JsonArray getMessages(String connectionKey) { } public Uni openDevConnection(String path, String endpointPath) { + if (connectionManager == null) { + return failureUni(); + } if (isInvalidPath(path, endpointPath)) { LOG.errorf("Invalid path %s; original endpoint path %s", path, endpointPath); return failureUni(); @@ -179,6 +187,9 @@ private static String normalize(String path) { } public Uni closeDevConnection(String connectionKey) { + if (connectionManager == null) { + return failureUni(); + } DevWebSocket socket = sockets.remove(connectionKey); if (socket != null) { Uni uni = UniHelper.toUni(socket.socket.close());