-
Notifications
You must be signed in to change notification settings - Fork 2.6k
Rejecting a handshake
Marcel Prestel edited this page Sep 11, 2017
·
2 revisions
It is possible to reject the handshake as a server to make sure specific additional values are set in the 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.
@Override
public ServerHandshakeBuilder onWebsocketHandshakeReceivedAsServer( WebSocket conn, Draft draft, ClientHandshake request) throws InvalidDataException {
ServerHandshakeBuilder builder = super.onWebsocketHandshakeReceivedAsServer( conn, draft, request );
//To your checks and throw an InvalidDataException to indicate that you reject this handshake.
return builder;
}
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