Skip to content

Commit

Permalink
Fix NPE when the subprotocal of websocket is null
Browse files Browse the repository at this point in the history
  • Loading branch information
yesunch authored and gsmet committed Sep 29, 2022
1 parent a16d29b commit 4a30be6
Showing 1 changed file with 10 additions and 5 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand All @@ -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 {
Expand Down

0 comments on commit 4a30be6

Please sign in to comment.