mirror of https://github.com/apache/activemq.git
fix for AMQ-1978
git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@706299 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
parent
c761823613
commit
1f01c94d24
|
@ -21,6 +21,7 @@ import java.io.DataOutputStream;
|
|||
import java.io.IOException;
|
||||
import java.io.InputStream;
|
||||
import java.io.OutputStream;
|
||||
import java.util.HashMap;
|
||||
import java.util.zip.DeflaterOutputStream;
|
||||
import java.util.zip.InflaterInputStream;
|
||||
|
||||
|
@ -149,7 +150,13 @@ public class ActiveMQTextMessage extends ActiveMQMessage implements TextMessage
|
|||
|
||||
public String toString() {
|
||||
try {
|
||||
getText();
|
||||
String text = getText();
|
||||
if (text.length() > 63) {
|
||||
text = text.substring(0, 45) + "..." + text.substring(text.length() - 12);
|
||||
HashMap<String, Object> overrideFields = new HashMap<String, Object>();
|
||||
overrideFields.put("text", text);
|
||||
return super.toString(overrideFields);
|
||||
}
|
||||
} catch (JMSException e) {
|
||||
}
|
||||
return super.toString();
|
||||
|
|
|
@ -16,6 +16,8 @@
|
|||
*/
|
||||
package org.apache.activemq.command;
|
||||
|
||||
import java.util.Map;
|
||||
|
||||
import org.apache.activemq.util.IntrospectionSupport;
|
||||
|
||||
|
||||
|
@ -60,7 +62,11 @@ public abstract class BaseCommand implements Command {
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return IntrospectionSupport.toString(this, BaseCommand.class);
|
||||
return toString(null);
|
||||
}
|
||||
|
||||
public String toString(Map<String, Object>overrideFields) {
|
||||
return IntrospectionSupport.toString(this, BaseCommand.class, overrideFields);
|
||||
}
|
||||
|
||||
public boolean isWireFormatInfo() {
|
||||
|
|
|
@ -721,10 +721,14 @@ public abstract class Message extends BaseCommand implements MarshallAware, Mess
|
|||
}
|
||||
|
||||
public String toString() {
|
||||
return toString(null);
|
||||
}
|
||||
|
||||
public String toString(Map<String, Object>overrideFields) {
|
||||
try {
|
||||
getProperties();
|
||||
} catch (IOException e) {
|
||||
}
|
||||
return super.toString();
|
||||
return super.toString(overrideFields);
|
||||
}
|
||||
}
|
||||
|
|
|
@ -28,8 +28,8 @@ import java.util.HashMap;
|
|||
import java.util.Iterator;
|
||||
import java.util.LinkedHashMap;
|
||||
import java.util.Map;
|
||||
import java.util.Map.Entry;
|
||||
import java.util.Set;
|
||||
import java.util.Map.Entry;
|
||||
|
||||
import org.apache.activemq.command.ActiveMQDestination;
|
||||
|
||||
|
@ -229,12 +229,23 @@ public final class IntrospectionSupport {
|
|||
}
|
||||
|
||||
public static String toString(Object target) {
|
||||
return toString(target, Object.class);
|
||||
return toString(target, Object.class, null);
|
||||
}
|
||||
|
||||
public static String toString(Object target, Class stopClass) {
|
||||
return toString(target, stopClass, null);
|
||||
}
|
||||
|
||||
public static String toString(Object target, Class stopClass) {
|
||||
public static String toString(Object target, Class stopClass, Map<String, Object> overrideFields) {
|
||||
LinkedHashMap<String, Object> map = new LinkedHashMap<String, Object>();
|
||||
addFields(target, target.getClass(), stopClass, map);
|
||||
if (overrideFields != null) {
|
||||
for(String key : overrideFields.keySet()) {
|
||||
Object value = overrideFields.get(key);
|
||||
map.put(key, value);
|
||||
}
|
||||
|
||||
}
|
||||
StringBuffer buffer = new StringBuffer(simpleName(target.getClass()));
|
||||
buffer.append(" {");
|
||||
Set entrySet = map.entrySet();
|
||||
|
|
|
@ -16,6 +16,7 @@
|
|||
*/
|
||||
package org.apache.activemq.command;
|
||||
|
||||
import java.io.DataOutputStream;
|
||||
import java.io.IOException;
|
||||
|
||||
import javax.jms.JMSException;
|
||||
|
@ -25,7 +26,9 @@ import javax.jms.MessageNotWriteableException;
|
|||
import junit.framework.TestCase;
|
||||
import junit.textui.TestRunner;
|
||||
|
||||
import org.apache.activemq.util.ByteArrayOutputStream;
|
||||
import org.apache.activemq.util.ByteSequence;
|
||||
import org.apache.activemq.util.MarshallingSupport;
|
||||
|
||||
/**
|
||||
* @version $Revision$
|
||||
|
@ -124,4 +127,27 @@ public class ActiveMQTextMessageTest extends TestCase {
|
|||
} catch (MessageNotWriteableException mnwe) {
|
||||
}
|
||||
}
|
||||
|
||||
public void testShortText() throws Exception {
|
||||
String shortText = "Content";
|
||||
ActiveMQTextMessage shortMessage = new ActiveMQTextMessage();
|
||||
setContent(shortMessage, shortText);
|
||||
assertTrue(shortMessage.toString().contains("text = " + shortText));
|
||||
assertTrue(shortMessage.getText().equals(shortText));
|
||||
|
||||
String longText = "Very very very very veeeeeeery loooooooooooooooooooooooooooooooooong text";
|
||||
String longExpectedText = "Very very very very veeeeeeery looooooooooooo...ooooong text";
|
||||
ActiveMQTextMessage longMessage = new ActiveMQTextMessage();
|
||||
setContent(longMessage, longText);
|
||||
assertTrue(longMessage.toString().contains("text = " + longExpectedText));
|
||||
assertTrue(longMessage.getText().equals(longText));
|
||||
}
|
||||
|
||||
protected void setContent(Message message, String text) throws Exception {
|
||||
ByteArrayOutputStream baos = new ByteArrayOutputStream();
|
||||
DataOutputStream dataOut = new DataOutputStream(baos);
|
||||
MarshallingSupport.writeUTF8(dataOut, text);
|
||||
dataOut.close();
|
||||
message.setContent(baos.toByteSequence());
|
||||
}
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue