|
25 | 25 | import java.util.UUID;
|
26 | 26 | import java.util.function.Function;
|
27 | 27 | import org.apache.qpid.proton.amqp.*;
|
28 |
| -import org.apache.qpid.proton.amqp.messaging.AmqpValue; |
29 |
| -import org.apache.qpid.proton.amqp.messaging.ApplicationProperties; |
30 |
| -import org.apache.qpid.proton.amqp.messaging.Data; |
31 |
| -import org.apache.qpid.proton.amqp.messaging.MessageAnnotations; |
| 28 | +import org.apache.qpid.proton.amqp.messaging.*; |
32 | 29 | import org.apache.qpid.proton.codec.ReadableBuffer;
|
33 | 30 | import org.apache.qpid.proton.codec.WritableBuffer;
|
34 | 31 |
|
35 | 32 | public class QpidProtonCodec implements Codec {
|
36 | 33 |
|
| 34 | + static final Section EMPTY_BODY = new Data(new Binary(new byte[0])); |
| 35 | + |
37 | 36 | private static final Function<String, String> MESSAGE_ANNOTATIONS_STRING_KEY_EXTRACTOR = k -> k;
|
38 | 37 | private static final Function<Symbol, String> MESSAGE_ANNOTATIONS_SYMBOL_KEY_EXTRACTOR =
|
39 | 38 | Symbol::toString;
|
@@ -233,13 +232,16 @@ public EncodedMessage encode(Message message) {
|
233 | 232 | qpidMessage.setMessageAnnotations(new MessageAnnotations(messageAnnotations));
|
234 | 233 | }
|
235 | 234 |
|
236 |
| - if (message.getBodyAsBinary() != null) { |
| 235 | + if (message.getBodyAsBinary() == null) { |
| 236 | + qpidMessage.setBody(EMPTY_BODY); |
| 237 | + } else { |
237 | 238 | qpidMessage.setBody(new Data(new Binary(message.getBodyAsBinary())));
|
238 | 239 | }
|
239 | 240 | }
|
240 | 241 | int bufferSize;
|
241 | 242 | if (qpidMessage.getBody() instanceof Data) {
|
242 | 243 | bufferSize = (int) (((Data) qpidMessage.getBody()).getValue().getLength() * 1.5);
|
| 244 | + bufferSize = bufferSize == 0 ? 128 : bufferSize; |
243 | 245 | } else {
|
244 | 246 | bufferSize = 8192;
|
245 | 247 | }
|
|
0 commit comments