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 committed Sep 28, 2022
1 parent a16d29b commit 99ee13b
Showing 1 changed file with 8 additions and 3 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 subprotocal is null");
serverWebSocket.close();
return;
}
GraphQLWebsocketHandler handler;
switch (subprotocol) {
case "graphql-transport-ws":
handler = new GraphQLTransportWSSubprotocolHandler(
Expand All @@ -49,8 +54,8 @@ protected void doHandle(final RoutingContext ctx) {
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());
}
Expand Down

0 comments on commit 99ee13b

Please sign in to comment.