Skip to content

Commit 23487ed

Browse files
committed
Fixed log for exceptions
I quess I need more coffee...
1 parent 2c7246c commit 23487ed

File tree

6 files changed

+28
-26
lines changed

6 files changed

+28
-26
lines changed

src/main/example/ChatServer.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -105,6 +105,8 @@ public void onError( WebSocket conn, Exception ex ) {
105105
@Override
106106
public void onStart() {
107107
System.out.println("Server started!");
108+
setConnectionLostTimeout(0);
109+
setConnectionLostTimeout(100);
108110
}
109111

110112
}

src/main/java/org/java_websocket/AbstractWebSocket.java

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -119,7 +119,7 @@ public void setConnectionLostTimeout( int connectionLostTimeout ) {
119119
}
120120
}
121121
} catch (Exception e) {
122-
log.error("Exception during connection lost restart: {}", e);
122+
log.error("Exception during connection lost restart", e);
123123
}
124124
restartConnectionLostTimer();
125125
}
@@ -174,13 +174,13 @@ public void run() {
174174
if( conn instanceof WebSocketImpl ) {
175175
webSocketImpl = ( WebSocketImpl ) conn;
176176
if( webSocketImpl.getLastPong() < current ) {
177-
log.warn("Closing connection due to no pong received: {}", conn);
177+
log.trace("Closing connection due to no pong received: {}", conn);
178178
webSocketImpl.closeConnection( CloseFrame.ABNORMAL_CLOSE, "The connection was closed because the other endpoint did not respond with a pong in time. For more information check: https://github.com/TooTallNate/Java-WebSocket/wiki/Lost-connection-detection" );
179179
} else {
180180
if( webSocketImpl.isOpen() ) {
181181
webSocketImpl.sendPing();
182182
} else {
183-
log.warn("Trying to ping a non open connection: {}", conn);
183+
log.trace("Trying to ping a non open connection: {}", conn);
184184
}
185185
}
186186
}

src/main/java/org/java_websocket/SSLSocketChannel.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -138,7 +138,7 @@ public SSLSocketChannel( SocketChannel inputSocketChannel, SSLEngine inputEngine
138138
try {
139139
socketChannel.close();
140140
} catch ( IOException e ) {
141-
log.error("Exception during the closing of the channel: {}", e);
141+
log.error("Exception during the closing of the channel", e);
142142
}
143143
}
144144
}
@@ -166,7 +166,7 @@ public synchronized int read( ByteBuffer dst ) throws IOException {
166166
try {
167167
result = engine.unwrap( peerNetData, peerAppData );
168168
} catch ( SSLException e ) {
169-
log.error("SSLExcpetion during unwrap: {}", e);
169+
log.error("SSLExcpetion during unwrap", e);
170170
throw e;
171171
}
172172
switch(result.getStatus()) {

src/main/java/org/java_websocket/WebSocketImpl.java

Lines changed: 11 additions & 11 deletions
Original file line numberDiff line numberDiff line change
@@ -263,11 +263,11 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
263263
try {
264264
response = wsl.onWebsocketHandshakeReceivedAsServer( this, d, handshake );
265265
} catch ( InvalidDataException e ) {
266-
log.trace("Closing due to wrong handshake. Possible handshake rejection: {}", e);
266+
log.trace("Closing due to wrong handshake. Possible handshake rejection", e);
267267
closeConnectionDueToWrongHandshake( e );
268268
return false;
269269
} catch ( RuntimeException e ) {
270-
log.error("Closing due to internal server error; {}", e);
270+
log.error("Closing due to internal server error", e);
271271
wsl.onWebsocketError( this, e );
272272
closeConnectionDueToInternalServerError( e );
273273
return false;
@@ -320,11 +320,11 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
320320
try {
321321
wsl.onWebsocketHandshakeReceivedAsClient( this, handshakerequest, handshake );
322322
} catch ( InvalidDataException e ) {
323-
log.trace("Closing due to invalid data exception. Possible handshake rejection: {}", e);
323+
log.trace("Closing due to invalid data exception. Possible handshake rejection", e);
324324
flushAndClose( e.getCloseCode(), e.getMessage(), false );
325325
return false;
326326
} catch ( RuntimeException e ) {
327-
log.error("Closing since client was never connected: {}", e);
327+
log.error("Closing since client was never connected", e);
328328
wsl.onWebsocketError( this, e );
329329
flushAndClose( CloseFrame.NEVER_CONNECTED, e.getMessage(), false );
330330
return false;
@@ -337,7 +337,7 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
337337
}
338338
}
339339
} catch ( InvalidHandshakeException e ) {
340-
log.trace("Closing due to invalid handshake: {}", e);
340+
log.trace("Closing due to invalid handshake", e);
341341
close( e );
342342
}
343343
} catch ( IncompleteHandshakeException e ) {
@@ -370,7 +370,7 @@ private void decodeFrames( ByteBuffer socketBuffer ) {
370370
draft.processFrame( this, f );
371371
}
372372
} catch ( InvalidDataException e ) {
373-
log.error("Closing due to invalid data in frame: {}", e);
373+
log.error("Closing due to invalid data in frame", e);
374374
wsl.onWebsocketError( this, e );
375375
close(e);
376376
}
@@ -441,7 +441,7 @@ public synchronized void close( int code, String message, boolean remote ) {
441441
sendFrame( closeFrame );
442442
}
443443
} catch ( InvalidDataException e ) {
444-
log.error("generated frame is invalid: {}", e);
444+
log.error("generated frame is invalid", e);
445445
wsl.onWebsocketError( this, e );
446446
flushAndClose( CloseFrame.ABNORMAL_CLOSE, "generated frame is invalid", false );
447447
}
@@ -496,9 +496,9 @@ public synchronized void closeConnection( int code, String message, boolean remo
496496
channel.close();
497497
} catch ( IOException e ) {
498498
if( e.getMessage().equals( "Broken pipe" ) ) {
499-
log.warn( "Caught IOException: Broken pipe during closeConnection(): {}", e );
499+
log.trace( "Caught IOException: Broken pipe during closeConnection()", e );
500500
} else {
501-
log.error("Exception during channel.close(); {}", e);
501+
log.error("Exception during channel.close()", e);
502502
wsl.onWebsocketError( this, e );
503503
}
504504
}
@@ -544,7 +544,7 @@ public synchronized void flushAndClose( int code, String message, boolean remote
544544
try {
545545
wsl.onWebsocketClosing( this, code, message, remote );
546546
} catch ( RuntimeException e ) {
547-
log.error("Exception in onWebsocketClosing: {}", e);
547+
log.error("Exception in onWebsocketClosing", e);
548548
wsl.onWebsocketError( this, e );
549549
}
550550
if( draft != null )
@@ -664,7 +664,7 @@ public void startHandshake( ClientHandshakeBuilder handshakedata ) throws Invali
664664
// Stop if the client code throws an exception
665665
throw new InvalidHandshakeException( "Handshake data rejected by client." );
666666
} catch ( RuntimeException e ) {
667-
log.error("Exception in startHandshake: {}", e);
667+
log.error("Exception in startHandshake", e);
668668
wsl.onWebsocketError( this, e );
669669
throw new InvalidHandshakeException( "rejected because of " + e );
670670
}

src/main/java/org/java_websocket/drafts/Draft_6455.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -695,7 +695,7 @@ public void processFrame( WebSocketImpl webSocketImpl, Framedata frame ) throws
695695
try {
696696
webSocketImpl.getWebSocketListener().onWebsocketMessage( webSocketImpl, Charsetfunctions.stringUtf8( current_continuous_frame.getPayloadData() ) );
697697
} catch ( RuntimeException e ) {
698-
log.error( "Runtime exception during onWebsocketMessage: {}", e );
698+
log.error( "Runtime exception during onWebsocketMessage", e );
699699
webSocketImpl.getWebSocketListener().onWebsocketError( webSocketImpl, e );
700700
}
701701
} else if( current_continuous_frame.getOpcode() == Opcode.BINARY ) {
@@ -704,7 +704,7 @@ public void processFrame( WebSocketImpl webSocketImpl, Framedata frame ) throws
704704
try {
705705
webSocketImpl.getWebSocketListener().onWebsocketMessage( webSocketImpl, current_continuous_frame.getPayloadData() );
706706
} catch ( RuntimeException e ) {
707-
log.error( "Runtime exception during onWebsocketMessage: {}", e );
707+
log.error( "Runtime exception during onWebsocketMessage", e );
708708
webSocketImpl.getWebSocketListener().onWebsocketError( webSocketImpl, e );
709709
}
710710
}

src/main/java/org/java_websocket/server/WebSocketServer.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -471,15 +471,15 @@ public void run() {
471471
try {
472472
selector.close();
473473
} catch ( IOException e ) {
474-
log.error( "IOException during selector.close: {}", e );
474+
log.error( "IOException during selector.close", e );
475475
onError( null, e );
476476
}
477477
}
478478
if( server != null ) {
479479
try {
480480
server.close();
481481
} catch ( IOException e ) {
482-
log.error( "IOException during server.close: {}", e );
482+
log.error( "IOException during server.close", e );
483483
onError( null, e );
484484
}
485485
}
@@ -532,13 +532,13 @@ private void handleIOException( SelectionKey key, WebSocket conn, IOException ex
532532
} catch ( IOException e ) {
533533
// there is nothing that must be done here
534534
}
535-
log.warn("Connection closed because of exception: {}",ex);
535+
log.trace("Connection closed because of exception",ex);
536536
}
537537
}
538538
}
539539

540540
private void handleFatal( WebSocket conn, Exception e ) {
541-
log.error( "Shutdown due to fatal error: {}", e );
541+
log.error( "Shutdown due to fatal error", e );
542542
onError( conn, e );
543543
//Shutting down WebSocketWorkers, see #222
544544
if( decoders != null ) {
@@ -552,11 +552,11 @@ private void handleFatal( WebSocket conn, Exception e ) {
552552
try {
553553
stop();
554554
} catch ( IOException e1 ) {
555-
log.error( "Error during shutdown: {}", e1 );
555+
log.error( "Error during shutdown", e1 );
556556
onError( null, e1 );
557557
} catch ( InterruptedException e1 ) {
558558
Thread.currentThread().interrupt();
559-
log.error( "Interrupt during stop: {}", e );
559+
log.error( "Interrupt during stop", e );
560560
onError( null, e1 );
561561
}
562562
}
@@ -611,7 +611,7 @@ protected boolean removeConnection( WebSocket ws ) {
611611
removed = this.connections.remove( ws );
612612
} else {
613613
//Don't throw an assert error if the ws is not in the list. e.g. when the other endpoint did not send any handshake. see #512
614-
log.warn("Removing connection which is not in the connections collection! Possible no handshake recieved! {}", ws);
614+
log.trace("Removing connection which is not in the connections collection! Possible no handshake recieved! {}", ws);
615615
}
616616
}
617617
if( isclosed.get() && connections.size() == 0 ) {
@@ -911,7 +911,7 @@ public void run() {
911911
try {
912912
ws.decode( buf );
913913
} catch(Exception e){
914-
log.error("Error while reading from remote connection: {}", e);
914+
log.error("Error while reading from remote connection", e);
915915
}
916916

917917
finally {

0 commit comments

Comments
 (0)