diff --git a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLOverWebSocketHandler.java b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLOverWebSocketHandler.java index 7d4c65ba5f2464..f3f71f82f7e16a 100644 --- a/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLOverWebSocketHandler.java +++ b/extensions/smallrye-graphql/runtime/src/main/java/io/quarkus/smallrye/graphql/runtime/SmallRyeGraphQLOverWebSocketHandler.java @@ -30,7 +30,12 @@ protected void doHandle(final RoutingContext ctx) { if (event.succeeded()) { ServerWebSocket serverWebSocket = event.result(); String subprotocol = serverWebSocket.subProtocol(); - GraphQLWebsocketHandler handler = null; + if (subprotocol == null) { + log.warn("Websocket subprotocol is null"); + serverWebSocket.close(); + return; + } + GraphQLWebsocketHandler handler; switch (subprotocol) { case "graphql-transport-ws": handler = new GraphQLTransportWSSubprotocolHandler( @@ -45,14 +50,14 @@ protected void doHandle(final RoutingContext ctx) { serverWebSocket.close(); return; } - log.debug("Starting websocket with subprotocol = " + subprotocol); + log.debugf("Starting websocket with subprotocol = %s", subprotocol); GraphQLWebsocketHandler finalHandler = handler; serverWebSocket.closeHandler(v -> finalHandler.onClose()); serverWebSocket.endHandler(v -> finalHandler.onEnd()); - serverWebSocket.exceptionHandler(t -> finalHandler.onThrowable(t)); - serverWebSocket.textMessageHandler(m -> finalHandler.onMessage(m)); + serverWebSocket.exceptionHandler(finalHandler::onThrowable); + serverWebSocket.textMessageHandler(finalHandler::onMessage); } else { - log.warn("WebSocket failed", event.cause()); + log.warn("Websocket failed", event.cause()); } }); } else {