AMQP-124: make Message.toString() more informative if byte[] body

This commit is contained in:
Dave Syer
2011-03-22 21:57:28 +00:00
parent 175080a2f4
commit 2030e51165
2 changed files with 7 additions and 6 deletions

View File

@@ -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)
}
}

View File

@@ -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());
}