activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dej...@apache.org
Subject svn commit: r706299 - in /activemq/trunk/activemq-core/src: main/java/org/apache/activemq/command/ main/java/org/apache/activemq/util/ test/java/org/apache/activemq/command/
Date Mon, 20 Oct 2008 14:14:32 GMT
Author: dejanb
Date: Mon Oct 20 07:14:31 2008
New Revision: 706299

URL: http://svn.apache.org/viewvc?rev=706299&view=rev
Log:
fix for AMQ-1978

Modified:
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQTextMessage.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/BaseCommand.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/Message.java
    activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java
    activemq/trunk/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQTextMessageTest.java

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQTextMessage.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQTextMessage.java?rev=706299&r1=706298&r2=706299&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQTextMessage.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/ActiveMQTextMessage.java
Mon Oct 20 07:14:31 2008
@@ -21,6 +21,7 @@
 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 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();

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/BaseCommand.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/BaseCommand.java?rev=706299&r1=706298&r2=706299&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/BaseCommand.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/BaseCommand.java
Mon Oct 20 07:14:31 2008
@@ -16,6 +16,8 @@
  */
 package org.apache.activemq.command;
 
+import java.util.Map;
+
 import org.apache.activemq.util.IntrospectionSupport;
 
 
@@ -60,7 +62,11 @@
     }
 
     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() {

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/Message.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/Message.java?rev=706299&r1=706298&r2=706299&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/Message.java (original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/command/Message.java Mon
Oct 20 07:14:31 2008
@@ -721,10 +721,14 @@
     }
     
     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);
     }    
 }

Modified: activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java?rev=706299&r1=706298&r2=706299&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java
(original)
+++ activemq/trunk/activemq-core/src/main/java/org/apache/activemq/util/IntrospectionSupport.java
Mon Oct 20 07:14:31 2008
@@ -28,8 +28,8 @@
 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 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, 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();

Modified: activemq/trunk/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQTextMessageTest.java
URL: http://svn.apache.org/viewvc/activemq/trunk/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQTextMessageTest.java?rev=706299&r1=706298&r2=706299&view=diff
==============================================================================
--- activemq/trunk/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQTextMessageTest.java
(original)
+++ activemq/trunk/activemq-core/src/test/java/org/apache/activemq/command/ActiveMQTextMessageTest.java
Mon Oct 20 07:14:31 2008
@@ -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 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 @@
         } 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());
+    }
 }



Mime
View raw message