AMQP-124: make Message.toString() more informative if byte[] body
This commit is contained in:
@@ -13,6 +13,8 @@
|
||||
|
||||
package org.springframework.amqp.core;
|
||||
|
||||
import java.nio.charset.Charset;
|
||||
|
||||
import org.springframework.amqp.utils.SerializationUtils;
|
||||
|
||||
/**
|
||||
@@ -74,17 +76,15 @@ public class Message {
|
||||
return SerializationUtils.deserialize(body).toString();
|
||||
}
|
||||
if (MessageProperties.CONTENT_TYPE_TEXT_PLAIN.equals(contentType)) {
|
||||
// TODO: use charset
|
||||
return new String(body);
|
||||
return new String(body, Charset.defaultCharset());
|
||||
}
|
||||
if (MessageProperties.CONTENT_TYPE_JSON.equals(contentType)) {
|
||||
// TODO: use charset
|
||||
return new String(body);
|
||||
return new String(body, Charset.defaultCharset());
|
||||
}
|
||||
return body.toString();
|
||||
} catch (Exception e) {
|
||||
return "Undeserializable body of length: " + body.length;
|
||||
// ignore
|
||||
}
|
||||
return body.toString()+"(byte["+body.length+"])"; // Comes out as '[B@....b' (so harmless)
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@@ -60,6 +60,7 @@ public class MessageTests {
|
||||
MessageProperties messageProperties = new MessageProperties();
|
||||
messageProperties.setContentType(MessageProperties.CONTENT_TYPE_SERIALIZED_OBJECT);
|
||||
Message message = new Message("foo".getBytes(), messageProperties);
|
||||
System.err.println(message);
|
||||
assertNotNull(message.toString());
|
||||
}
|
||||
|
||||
|
||||
Reference in New Issue
Block a user