23
23
24
24
/**
25
25
* A {@link GenericMessage} with a {@link Throwable} payload.
26
- * The payload is typically a {@link org.springframework.messaging.MessagingException}
26
+ *
27
+ * <p>The payload is typically a {@link org.springframework.messaging.MessagingException}
27
28
* with the message at the point of failure in its {@code failedMessage} property.
28
29
* An optional {@code originalMessage} may be provided, which represents the message
29
30
* that existed at the point in the stack where the error message is created.
31
+ *
30
32
* <p>Consider some code that starts with a message, invokes some process that performs
31
33
* transformation on that message and then fails for some reason, throwing the exception.
32
34
* The exception is caught and an error message produced that contains both the original
@@ -44,6 +46,7 @@ public class ErrorMessage extends GenericMessage<Throwable> {
44
46
45
47
private final Message <?> originalMessage ;
46
48
49
+
47
50
/**
48
51
* Create a new message with the given payload.
49
52
* @param payload the message payload (never {@code null})
@@ -79,8 +82,8 @@ public ErrorMessage(Throwable payload, MessageHeaders headers) {
79
82
/**
80
83
* Create a new message with the given payload and original message.
81
84
* @param payload the message payload (never {@code null})
82
- * @param originalMessage the original message (if present) at the point in the stack
83
- * where the ErrorMessage was created
85
+ * @param originalMessage the original message (if present) at the point
86
+ * in the stack where the ErrorMessage was created
84
87
* @since 5.0
85
88
*/
86
89
public ErrorMessage (Throwable payload , Message <?> originalMessage ) {
@@ -93,8 +96,8 @@ public ErrorMessage(Throwable payload, Message<?> originalMessage) {
93
96
* The content of the given header map is copied.
94
97
* @param payload the message payload (never {@code null})
95
98
* @param headers message headers to use for initialization
96
- * @param originalMessage the original message (if present) at the point in the stack
97
- * where the ErrorMessage was created
99
+ * @param originalMessage the original message (if present) at the point
100
+ * in the stack where the ErrorMessage was created
98
101
* @since 5.0
99
102
*/
100
103
public ErrorMessage (Throwable payload , Map <String , Object > headers , Message <?> originalMessage ) {
@@ -108,37 +111,34 @@ public ErrorMessage(Throwable payload, Map<String, Object> headers, Message<?> o
108
111
* is used directly in the new message, i.e. it is not copied.
109
112
* @param payload the message payload (never {@code null})
110
113
* @param headers message headers
111
- * @param originalMessage the original message (if present) at the point in the stack
112
- * where the ErrorMessage was created
114
+ * @param originalMessage the original message (if present) at the point
115
+ * in the stack where the ErrorMessage was created
113
116
* @since 5.0
114
117
*/
115
118
public ErrorMessage (Throwable payload , MessageHeaders headers , Message <?> originalMessage ) {
116
119
super (payload , headers );
117
120
this .originalMessage = originalMessage ;
118
121
}
119
122
123
+
120
124
/**
121
- * The original message (if present ) at the point in the stack where the
122
- * ErrorMessage was created.
123
- * @return the originalMessage
125
+ * Return the original message (if available ) at the point in the stack
126
+ * where the ErrorMessage was created.
127
+ * @since 5.0
124
128
*/
125
129
public Message <?> getOriginalMessage () {
126
- return originalMessage ;
130
+ return this . originalMessage ;
127
131
}
128
132
129
133
@ Override
130
134
public String toString () {
131
135
if (this .originalMessage == null ) {
132
136
return super .toString ();
133
137
}
134
- else {
135
- StringBuilder sb = new StringBuilder (super .toString ());
136
- if (sb .length () > 0 ) {
137
- sb .setLength (sb .length () - 1 );
138
- }
139
- sb .append (", originalMessage=" ).append (this .originalMessage .toString ()).append ("]" );
140
- return sb .toString ();
141
- }
138
+
139
+ StringBuilder sb = new StringBuilder (super .toString ());
140
+ sb .append (" for original " ).append (this .originalMessage );
141
+ return sb .toString ();
142
142
}
143
143
144
144
}
0 commit comments