Add corrupted data exception handling

This commit is contained in:
Manfred Karrer 2016-05-21 21:34:06 +02:00
parent ec63bc40f8
commit 96fce3b5b4
2 changed files with 6 additions and 2 deletions

View file

@ -6,6 +6,7 @@ public enum CloseConnectionReason {
RESET(false, false), RESET(false, false),
SOCKET_TIMEOUT(false, false), SOCKET_TIMEOUT(false, false),
TERMINATED(false, false), // EOFException TERMINATED(false, false), // EOFException
CORRUPTED_DATA(false, false),
UNKNOWN_EXCEPTION(false, false), UNKNOWN_EXCEPTION(false, false),
// Planned // Planned

View file

@ -540,8 +540,10 @@ public class Connection implements MessageListener {
} else if (e instanceof SocketTimeoutException || e instanceof TimeoutException) { } else if (e instanceof SocketTimeoutException || e instanceof TimeoutException) {
closeConnectionReason = CloseConnectionReason.SOCKET_TIMEOUT; closeConnectionReason = CloseConnectionReason.SOCKET_TIMEOUT;
log.debug("SocketTimeoutException at socket " + socket.toString() + "\n\tconnection={}" + this); log.debug("SocketTimeoutException at socket " + socket.toString() + "\n\tconnection={}" + this);
} else if (e instanceof EOFException || e instanceof StreamCorruptedException) { } else if (e instanceof EOFException) {
closeConnectionReason = CloseConnectionReason.TERMINATED; closeConnectionReason = CloseConnectionReason.TERMINATED;
} else if (e instanceof OptionalDataException || e instanceof StreamCorruptedException) {
closeConnectionReason = CloseConnectionReason.CORRUPTED_DATA;
} else { } else {
// TODO sometimes we get StreamCorruptedException, OptionalDataException, IllegalStateException // TODO sometimes we get StreamCorruptedException, OptionalDataException, IllegalStateException
closeConnectionReason = CloseConnectionReason.UNKNOWN_EXCEPTION; closeConnectionReason = CloseConnectionReason.UNKNOWN_EXCEPTION;
@ -788,6 +790,7 @@ public class Connection implements MessageListener {
} }
} }
} catch (Throwable t) { } catch (Throwable t) {
if (!(t instanceof OptionalDataException))
t.printStackTrace(); t.printStackTrace();
stop(); stop();
sharedModel.handleConnectionException(new Exception(t)); sharedModel.handleConnectionException(new Exception(t));