You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
It is possible to reject the handshake as a server to make sure specific additional values are set in the handshake.
Reject a handshake
If you want to reject a handshake, you have to override the method onWebsocketHandshakeReceivedAsServer() in your WebSocketServer class.
In this method you have to throw an InvalidDataException to indicate that this handshake should be rejected.
@OverridepublicServerHandshakeBuilderonWebsocketHandshakeReceivedAsServer( WebSocketconn, Draftdraft, ClientHandshakerequest) throwsInvalidDataException {
ServerHandshakeBuilderbuilder = super.onWebsocketHandshakeReceivedAsServer( conn, draft, request );
//To your checks and throw an InvalidDataException to indicate that you reject this handshake.returnbuilder;
}
After you throw the InvalidDataException the server will send a http code 404 to the client resulting in a close.
You can also find an example on how to reject a handshake in the examples folder. The class is called ServerRejectHandshakeExample