|
1 | 1 | /* |
2 | | - * Copyright 2002-2020 the original author or authors. |
| 2 | + * Copyright 2002-2021 the original author or authors. |
3 | 3 | * |
4 | 4 | * Licensed under the Apache License, Version 2.0 (the "License"); |
5 | 5 | * you may not use this file except in compliance with the License. |
@@ -57,7 +57,23 @@ public class Message implements Serializable { |
57 | 57 |
|
58 | 58 | private final byte[] body; |
59 | 59 |
|
| 60 | + /** |
| 61 | + * Construct an instance with the provided body and default {@link MessageProperties}. |
| 62 | + * @param body the body. |
| 63 | + * @since 2.2.17 |
| 64 | + */ |
| 65 | + public Message(byte[] body) { |
| 66 | + this(body, new MessageProperties()); |
| 67 | + } |
| 68 | + |
| 69 | + /** |
| 70 | + * Construct an instance with the provided body and properties. |
| 71 | + * @param body the body. |
| 72 | + * @param messageProperties the properties. |
| 73 | + */ |
60 | 74 | public Message(byte[] body, MessageProperties messageProperties) { //NOSONAR |
| 75 | + Assert.notNull(body, "'body' cannot be null"); |
| 76 | + Assert.notNull(messageProperties, "'messageProperties' cannot be null"); |
61 | 77 | this.body = body; //NOSONAR |
62 | 78 | this.messageProperties = messageProperties; |
63 | 79 | } |
@@ -103,9 +119,7 @@ public String toString() { |
103 | 119 | StringBuilder buffer = new StringBuilder(); |
104 | 120 | buffer.append("("); |
105 | 121 | buffer.append("Body:'").append(this.getBodyContentAsString()).append("'"); |
106 | | - if (this.messageProperties != null) { |
107 | | - buffer.append(" ").append(this.messageProperties.toString()); |
108 | | - } |
| 122 | + buffer.append(" ").append(this.messageProperties.toString()); |
109 | 123 | buffer.append(")"); |
110 | 124 | return buffer.toString(); |
111 | 125 | } |
|
0 commit comments