Skip to content

Commit

Permalink
Error handling improvement in AbstractSockJsSession
Browse files Browse the repository at this point in the history
Closes gh-24986
  • Loading branch information
rstoyanchev committed May 1, 2020
1 parent c2cce0c commit e17736d
Showing 1 changed file with 18 additions and 9 deletions.
Expand Up @@ -380,23 +380,32 @@ public void delegateConnectionEstablished() throws Exception {
public void delegateMessages(String... messages) throws SockJsMessageDeliveryException {
for (int i = 0; i < messages.length; i++) {
try {
if (!isClosed()) {
this.handler.handleMessage(this, new TextMessage(messages[i]));
}
else {
List<String> undelivered = getUndelivered(messages, i);
if (undelivered.isEmpty()) {
return;
}
throw new SockJsMessageDeliveryException(this.id, undelivered, "Session closed");
if (isClosed()) {
logUndeliveredMessages(i, messages);
return;
}
this.handler.handleMessage(this, new TextMessage(messages[i]));
}
catch (Exception ex) {
if (isClosed()) {
if (logger.isTraceEnabled()) {
logger.trace("Failed to handle message '" + messages[i] + "'", ex);
}
logUndeliveredMessages(i, messages);
return;
}
throw new SockJsMessageDeliveryException(this.id, getUndelivered(messages, i), ex);
}
}
}

private void logUndeliveredMessages(int index, String[] messages) {
List<String> undelivered = getUndelivered(messages, index);
if (logger.isTraceEnabled() && !undelivered.isEmpty()) {
logger.trace("Dropped inbound message(s) due to closed session: " + undelivered);
}
}

private static List<String> getUndelivered(String[] messages, int i) {
switch (messages.length - i) {
case 0:
Expand Down

0 comments on commit e17736d

Please sign in to comment.