Provide best-effort toString for Lazy resolved message
Previously, MessagingMessageListenerAdapter or any adapter relying on the default MessagingMessageConverter would log an incoming message with a toString of the Message that does not provide any extra information. This is due to the default implementation providing a lazy resolution message that only attempts to extract the payload when necessary. This commit implements a toString method that uses the raw JMS message if the payload is not available. If it is, the payload is used instead. Closes gh-21265
This commit is contained in:
@@ -1,5 +1,5 @@
|
||||
/*
|
||||
* Copyright 2002-2022 the original author or authors.
|
||||
* Copyright 2002-2023 the original author or authors.
|
||||
*
|
||||
* Licensed under the Apache License, Version 2.0 (the "License");
|
||||
* you may not use this file except in compliance with the License.
|
||||
@@ -550,6 +550,29 @@ public abstract class AbstractAdaptableMessageListener
|
||||
}
|
||||
return this.headers;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString() {
|
||||
StringBuilder sb = new StringBuilder(getClass().getSimpleName());
|
||||
if (this.payload == null) {
|
||||
sb.append(" [rawMessage=").append(this.message);
|
||||
}
|
||||
else {
|
||||
sb.append(" [payload=");
|
||||
if (this.payload instanceof byte[] bytes) {
|
||||
sb.append("byte[").append(bytes.length).append(']');
|
||||
}
|
||||
else {
|
||||
sb.append(this.payload);
|
||||
}
|
||||
}
|
||||
if (this.headers != null) {
|
||||
sb.append(", headers=").append(this.headers);
|
||||
}
|
||||
sb.append(']');
|
||||
return sb.toString();
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user