11package info .unterrainer .websocketserver ;
22
3+ import java .io .EOFException ;
4+ import java .io .IOException ;
5+
6+ import info .unterrainer .oauthtokenmanager .OauthTokenManager ;
37import io .javalin .websocket .WsCloseContext ;
48import io .javalin .websocket .WsConnectContext ;
59import io .javalin .websocket .WsErrorContext ;
913@ Slf4j
1014public class WsOauthHandlerBase extends WsHandlerBase {
1115
12- private JwtTokenHandler tokenHandler ;
16+ private OauthTokenManager tokenHandler ;
1317
14- void setTokenHandler (JwtTokenHandler tokenHandler ) {
18+ void setTokenHandler (OauthTokenManager tokenHandler ) {
1519 this .tokenHandler = tokenHandler ;
1620 }
1721
1822 @ Override
1923 public void onConnect (WsConnectContext ctx ) throws Exception {
2024 log .debug ("New client tries to connect: [{}]" , ctx .session .getRemoteAddress ());
21- String token = ctx .queryParam ( "token " );
25+ String token = ctx .header ( "Authorization " );
2226 log .debug ("New client token: [{}]" , token );
2327 try {
2428 tokenHandler .checkAccess (token );
@@ -40,6 +44,11 @@ public void onClose(WsCloseContext ctx) throws Exception {
4044
4145 @ Override
4246 public void onError (WsErrorContext ctx ) throws Exception {
43- log .error ("Error on [{}]: [{}]" , ctx .session .getRemoteAddress (), ctx .error ());
47+ Throwable t = ctx .error ();
48+ if (t instanceof EOFException || t instanceof IOException ) {
49+ log .debug ("Client disconnected [{}]." , ctx .session .getRemoteAddress ());
50+ } else {
51+ log .error ("Unexpected error on [{}]." , ctx .session .getRemoteAddress (), t );
52+ }
4453 }
4554}
0 commit comments