Skip to content

Commit

Permalink
Merge pull request quarkusio#28268 from yesunch/main
Browse files Browse the repository at this point in the history
Fix NPE when the subprotocol of websocket is null
  • Loading branch information
gsmet authored Sep 29, 2022
2 parents 0e24a41 + 47350db commit a472f55
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -34,7 +34,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(
Expand All @@ -49,14 +54,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 {
Expand Down

0 comments on commit a472f55

Please sign in to comment.