diff --git a/src/main/example/ChatServer.java b/src/main/example/ChatServer.java index f4a3e2cf..3ebc50bc 100644 --- a/src/main/example/ChatServer.java +++ b/src/main/example/ChatServer.java @@ -105,6 +105,8 @@ public void onError( WebSocket conn, Exception ex ) { @Override public void onStart() { System.out.println("Server started!"); + setConnectionLostTimeout(0); + setConnectionLostTimeout(100); } } diff --git a/src/main/java/org/java_websocket/AbstractWebSocket.java b/src/main/java/org/java_websocket/AbstractWebSocket.java index 59abdc26..a9fd67ad 100644 --- a/src/main/java/org/java_websocket/AbstractWebSocket.java +++ b/src/main/java/org/java_websocket/AbstractWebSocket.java @@ -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(); } @@ -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); } } } diff --git a/src/main/java/org/java_websocket/SSLSocketChannel.java b/src/main/java/org/java_websocket/SSLSocketChannel.java index 7ef6f74d..6fb21dd6 100644 --- a/src/main/java/org/java_websocket/SSLSocketChannel.java +++ b/src/main/java/org/java_websocket/SSLSocketChannel.java @@ -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); } } } @@ -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()) { diff --git a/src/main/java/org/java_websocket/WebSocketImpl.java b/src/main/java/org/java_websocket/WebSocketImpl.java index 9f585c56..89e1c8a9 100644 --- a/src/main/java/org/java_websocket/WebSocketImpl.java +++ b/src/main/java/org/java_websocket/WebSocketImpl.java @@ -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; @@ -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; @@ -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 ) { @@ -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); } @@ -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 ); } @@ -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 ); } } @@ -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 ) @@ -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 ); } diff --git a/src/main/java/org/java_websocket/drafts/Draft_6455.java b/src/main/java/org/java_websocket/drafts/Draft_6455.java index 4b443437..17e2e6da 100644 --- a/src/main/java/org/java_websocket/drafts/Draft_6455.java +++ b/src/main/java/org/java_websocket/drafts/Draft_6455.java @@ -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 ) { @@ -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 ); } } diff --git a/src/main/java/org/java_websocket/server/WebSocketServer.java b/src/main/java/org/java_websocket/server/WebSocketServer.java index 8af93e7d..21182aac 100644 --- a/src/main/java/org/java_websocket/server/WebSocketServer.java +++ b/src/main/java/org/java_websocket/server/WebSocketServer.java @@ -471,7 +471,7 @@ 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 ); } } @@ -479,7 +479,7 @@ public void run() { try { server.close(); } catch ( IOException e ) { - log.error( "IOException during server.close: {}", e ); + log.error( "IOException during server.close", e ); onError( null, e ); } } @@ -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 ) { @@ -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 ); } } @@ -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 ) { @@ -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 {