Skip to content

Commit

Permalink
Fixed log for exceptions
Browse files Browse the repository at this point in the history
I quess I need more coffee...
  • Loading branch information
marci4 committed Aug 15, 2018
1 parent 2c7246c commit 23487ed
Show file tree
Hide file tree
Showing 6 changed files with 28 additions and 26 deletions.
2 changes: 2 additions & 0 deletions src/main/example/ChatServer.java
Expand Up @@ -105,6 +105,8 @@ public void onError( WebSocket conn, Exception ex ) {
@Override
public void onStart() {
System.out.println("Server started!");
setConnectionLostTimeout(0);
setConnectionLostTimeout(100);
}

}
6 changes: 3 additions & 3 deletions src/main/java/org/java_websocket/AbstractWebSocket.java
Expand Up @@ -119,7 +119,7 @@ public void setConnectionLostTimeout( int connectionLostTimeout ) {
}
}
} catch (Exception e) {
log.error("Exception during connection lost restart: {}", e);
log.error("Exception during connection lost restart", e);
}
restartConnectionLostTimer();
}
Expand Down Expand Up @@ -174,13 +174,13 @@ public void run() {
if( conn instanceof WebSocketImpl ) {
webSocketImpl = ( WebSocketImpl ) conn;
if( webSocketImpl.getLastPong() < current ) {
log.warn("Closing connection due to no pong received: {}", conn);
log.trace("Closing connection due to no pong received: {}", conn);
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" );
} else {
if( webSocketImpl.isOpen() ) {
webSocketImpl.sendPing();
} else {
log.warn("Trying to ping a non open connection: {}", conn);
log.trace("Trying to ping a non open connection: {}", conn);
}
}
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/java_websocket/SSLSocketChannel.java
Expand Up @@ -138,7 +138,7 @@ public SSLSocketChannel( SocketChannel inputSocketChannel, SSLEngine inputEngine
try {
socketChannel.close();
} catch ( IOException e ) {
log.error("Exception during the closing of the channel: {}", e);
log.error("Exception during the closing of the channel", e);
}
}
}
Expand Down Expand Up @@ -166,7 +166,7 @@ public synchronized int read( ByteBuffer dst ) throws IOException {
try {
result = engine.unwrap( peerNetData, peerAppData );
} catch ( SSLException e ) {
log.error("SSLExcpetion during unwrap: {}", e);
log.error("SSLExcpetion during unwrap", e);
throw e;
}
switch(result.getStatus()) {
Expand Down
22 changes: 11 additions & 11 deletions src/main/java/org/java_websocket/WebSocketImpl.java
Expand Up @@ -263,11 +263,11 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
try {
response = wsl.onWebsocketHandshakeReceivedAsServer( this, d, handshake );
} catch ( InvalidDataException e ) {
log.trace("Closing due to wrong handshake. Possible handshake rejection: {}", e);
log.trace("Closing due to wrong handshake. Possible handshake rejection", e);
closeConnectionDueToWrongHandshake( e );
return false;
} catch ( RuntimeException e ) {
log.error("Closing due to internal server error; {}", e);
log.error("Closing due to internal server error", e);
wsl.onWebsocketError( this, e );
closeConnectionDueToInternalServerError( e );
return false;
Expand Down Expand Up @@ -320,11 +320,11 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
try {
wsl.onWebsocketHandshakeReceivedAsClient( this, handshakerequest, handshake );
} catch ( InvalidDataException e ) {
log.trace("Closing due to invalid data exception. Possible handshake rejection: {}", e);
log.trace("Closing due to invalid data exception. Possible handshake rejection", e);
flushAndClose( e.getCloseCode(), e.getMessage(), false );
return false;
} catch ( RuntimeException e ) {
log.error("Closing since client was never connected: {}", e);
log.error("Closing since client was never connected", e);
wsl.onWebsocketError( this, e );
flushAndClose( CloseFrame.NEVER_CONNECTED, e.getMessage(), false );
return false;
Expand All @@ -337,7 +337,7 @@ private boolean decodeHandshake( ByteBuffer socketBufferNew ) {
}
}
} catch ( InvalidHandshakeException e ) {
log.trace("Closing due to invalid handshake: {}", e);
log.trace("Closing due to invalid handshake", e);
close( e );
}
} catch ( IncompleteHandshakeException e ) {
Expand Down Expand Up @@ -370,7 +370,7 @@ private void decodeFrames( ByteBuffer socketBuffer ) {
draft.processFrame( this, f );
}
} catch ( InvalidDataException e ) {
log.error("Closing due to invalid data in frame: {}", e);
log.error("Closing due to invalid data in frame", e);
wsl.onWebsocketError( this, e );
close(e);
}
Expand Down Expand Up @@ -441,7 +441,7 @@ public synchronized void close( int code, String message, boolean remote ) {
sendFrame( closeFrame );
}
} catch ( InvalidDataException e ) {
log.error("generated frame is invalid: {}", e);
log.error("generated frame is invalid", e);
wsl.onWebsocketError( this, e );
flushAndClose( CloseFrame.ABNORMAL_CLOSE, "generated frame is invalid", false );
}
Expand Down Expand Up @@ -496,9 +496,9 @@ public synchronized void closeConnection( int code, String message, boolean remo
channel.close();
} catch ( IOException e ) {
if( e.getMessage().equals( "Broken pipe" ) ) {
log.warn( "Caught IOException: Broken pipe during closeConnection(): {}", e );
log.trace( "Caught IOException: Broken pipe during closeConnection()", e );
} else {
log.error("Exception during channel.close(); {}", e);
log.error("Exception during channel.close()", e);
wsl.onWebsocketError( this, e );
}
}
Expand Down Expand Up @@ -544,7 +544,7 @@ public synchronized void flushAndClose( int code, String message, boolean remote
try {
wsl.onWebsocketClosing( this, code, message, remote );
} catch ( RuntimeException e ) {
log.error("Exception in onWebsocketClosing: {}", e);
log.error("Exception in onWebsocketClosing", e);
wsl.onWebsocketError( this, e );
}
if( draft != null )
Expand Down Expand Up @@ -664,7 +664,7 @@ public void startHandshake( ClientHandshakeBuilder handshakedata ) throws Invali
// Stop if the client code throws an exception
throw new InvalidHandshakeException( "Handshake data rejected by client." );
} catch ( RuntimeException e ) {
log.error("Exception in startHandshake: {}", e);
log.error("Exception in startHandshake", e);
wsl.onWebsocketError( this, e );
throw new InvalidHandshakeException( "rejected because of " + e );
}
Expand Down
4 changes: 2 additions & 2 deletions src/main/java/org/java_websocket/drafts/Draft_6455.java
Expand Up @@ -695,7 +695,7 @@ public void processFrame( WebSocketImpl webSocketImpl, Framedata frame ) throws
try {
webSocketImpl.getWebSocketListener().onWebsocketMessage( webSocketImpl, Charsetfunctions.stringUtf8( current_continuous_frame.getPayloadData() ) );
} catch ( RuntimeException e ) {
log.error( "Runtime exception during onWebsocketMessage: {}", e );
log.error( "Runtime exception during onWebsocketMessage", e );
webSocketImpl.getWebSocketListener().onWebsocketError( webSocketImpl, e );
}
} else if( current_continuous_frame.getOpcode() == Opcode.BINARY ) {
Expand All @@ -704,7 +704,7 @@ public void processFrame( WebSocketImpl webSocketImpl, Framedata frame ) throws
try {
webSocketImpl.getWebSocketListener().onWebsocketMessage( webSocketImpl, current_continuous_frame.getPayloadData() );
} catch ( RuntimeException e ) {
log.error( "Runtime exception during onWebsocketMessage: {}", e );
log.error( "Runtime exception during onWebsocketMessage", e );
webSocketImpl.getWebSocketListener().onWebsocketError( webSocketImpl, e );
}
}
Expand Down
16 changes: 8 additions & 8 deletions src/main/java/org/java_websocket/server/WebSocketServer.java
Expand Up @@ -471,15 +471,15 @@ public void run() {
try {
selector.close();
} catch ( IOException e ) {
log.error( "IOException during selector.close: {}", e );
log.error( "IOException during selector.close", e );
onError( null, e );
}
}
if( server != null ) {
try {
server.close();
} catch ( IOException e ) {
log.error( "IOException during server.close: {}", e );
log.error( "IOException during server.close", e );
onError( null, e );
}
}
Expand Down Expand Up @@ -532,13 +532,13 @@ private void handleIOException( SelectionKey key, WebSocket conn, IOException ex
} catch ( IOException e ) {
// there is nothing that must be done here
}
log.warn("Connection closed because of exception: {}",ex);
log.trace("Connection closed because of exception",ex);
}
}
}

private void handleFatal( WebSocket conn, Exception e ) {
log.error( "Shutdown due to fatal error: {}", e );
log.error( "Shutdown due to fatal error", e );
onError( conn, e );
//Shutting down WebSocketWorkers, see #222
if( decoders != null ) {
Expand All @@ -552,11 +552,11 @@ private void handleFatal( WebSocket conn, Exception e ) {
try {
stop();
} catch ( IOException e1 ) {
log.error( "Error during shutdown: {}", e1 );
log.error( "Error during shutdown", e1 );
onError( null, e1 );
} catch ( InterruptedException e1 ) {
Thread.currentThread().interrupt();
log.error( "Interrupt during stop: {}", e );
log.error( "Interrupt during stop", e );
onError( null, e1 );
}
}
Expand Down Expand Up @@ -611,7 +611,7 @@ protected boolean removeConnection( WebSocket ws ) {
removed = this.connections.remove( ws );
} else {
//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
log.warn("Removing connection which is not in the connections collection! Possible no handshake recieved! {}", ws);
log.trace("Removing connection which is not in the connections collection! Possible no handshake recieved! {}", ws);
}
}
if( isclosed.get() && connections.size() == 0 ) {
Expand Down Expand Up @@ -911,7 +911,7 @@ public void run() {
try {
ws.decode( buf );
} catch(Exception e){
log.error("Error while reading from remote connection: {}", e);
log.error("Error while reading from remote connection", e);
}

finally {
Expand Down

0 comments on commit 23487ed

Please sign in to comment.