Skip to content

Commit

Permalink
https://issues.apache.org/jira/browse/AMQ-6169
Browse files Browse the repository at this point in the history
Log actual STOMP frames that cause error at trace level, only log the
command action if it is present and valid.
  • Loading branch information
tabish121 committed Feb 12, 2016
1 parent adf70bc commit b595b8b
Showing 1 changed file with 50 additions and 6 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -279,11 +279,20 @@ public void onStompCommand(StompFrame command) throws IOException, JMSException
}

protected void handleException(Throwable exception, StompFrame command) throws IOException {
LOG.warn("Exception occurred processing: \n" + command + ": " + exception.toString());
if (command == null) {
LOG.warn("Exception occurred while processing a command: {}", exception.toString());
} else {
LOG.warn("Exception occurred processing: {} -> {}", safeGetAction(command), exception.toString());
}

if (LOG.isDebugEnabled()) {
LOG.debug("Exception detail", exception);
}

if (command != null && LOG.isTraceEnabled()) {
LOG.trace("Command that caused the error: {}", command);
}

// Let the stomp client know about any protocol errors.
ByteArrayOutputStream baos = new ByteArrayOutputStream();
PrintWriter stream = new PrintWriter(new OutputStreamWriter(baos, "UTF-8"));
Expand Down Expand Up @@ -703,15 +712,12 @@ protected void onStompUnsubscribe(StompFrame command) throws ProtocolException {
}

if (subscriptionId != null) {

StompSubscription sub = this.subscriptions.remove(subscriptionId);
if (sub != null) {
sendToActiveMQ(sub.getConsumerInfo().createRemoveCommand(), createResponseHandler(command));
return;
}

} else {

// Unsubscribing using a destination is a bit weird if multiple subscriptions
// are created with the same destination.
for (Iterator<StompSubscription> iter = subscriptionsByConsumerId.values().iterator(); iter.hasNext();) {
Expand Down Expand Up @@ -973,7 +979,7 @@ protected void configureInactivityMonitor(String heartBeatConfig) throws Protoco
}

if (LOG.isDebugEnabled()) {
LOG.debug("Stomp Connect heartbeat conf RW[" + hbReadInterval + "," + hbWriteInterval + "]");
LOG.debug("Stomp Connect heartbeat conf RW[{},{}]", hbReadInterval, hbWriteInterval);
}
}
}
Expand All @@ -988,8 +994,46 @@ protected void sendReceipt(StompFrame command) {
try {
sendToStomp(sc);
} catch (IOException e) {
LOG.warn("Could not send a receipt for " + command, e);
LOG.warn("Could not send a receipt for {}", command, e);
}
}
}

/**
* Retrieve the STOMP action value from a frame if the value is valid, otherwise
* return an unknown string to allow for safe log output.
*
* @param command
* The STOMP command to fetch an action from.
*
* @return the command action or a safe string to use in logging.
*/
protected Object safeGetAction(StompFrame command) {
String result = "<Unknown>";
if (command != null) {
String action = command.getAction().trim();

if (action != null) {
switch (action) {
case Stomp.Commands.SEND:
case Stomp.Commands.ACK:
case Stomp.Commands.NACK:
case Stomp.Commands.BEGIN:
case Stomp.Commands.COMMIT:
case Stomp.Commands.ABORT:
case Stomp.Commands.SUBSCRIBE:
case Stomp.Commands.UNSUBSCRIBE:
case Stomp.Commands.CONNECT:
case Stomp.Commands.STOMP:
case Stomp.Commands.DISCONNECT:
result = action;
break;
default:
break;
}
}
}

return result;
}
}

0 comments on commit b595b8b

Please sign in to comment.