activemq-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From gtu...@apache.org
Subject [2/2] activemq git commit: compact byteSequence before xstream marshall so that only required bytes are base64 encoded
Date Thu, 27 Aug 2015 10:10:34 GMT
compact byteSequence before xstream marshall so that only required bytes are base64 encoded


Project: http://git-wip-us.apache.org/repos/asf/activemq/repo
Commit: http://git-wip-us.apache.org/repos/asf/activemq/commit/547476d1
Tree: http://git-wip-us.apache.org/repos/asf/activemq/tree/547476d1
Diff: http://git-wip-us.apache.org/repos/asf/activemq/diff/547476d1

Branch: refs/heads/master
Commit: 547476d1bc8bd6d5c824d51bc0dc3cdd5a201f4c
Parents: 950dc92
Author: gtully <gary.tully@gmail.com>
Authored: Wed Aug 26 11:20:18 2015 +0100
Committer: gtully <gary.tully@gmail.com>
Committed: Thu Aug 27 11:10:08 2015 +0100

----------------------------------------------------------------------
 .../transport/xstream/XStreamWireFormat.java    | 28 +++++++++++++++++++-
 .../xstream/XStreamWireFormatTest.java          | 16 ++++++++++-
 2 files changed, 42 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/activemq/blob/547476d1/activemq-http/src/main/java/org/apache/activemq/transport/xstream/XStreamWireFormat.java
----------------------------------------------------------------------
diff --git a/activemq-http/src/main/java/org/apache/activemq/transport/xstream/XStreamWireFormat.java
b/activemq-http/src/main/java/org/apache/activemq/transport/xstream/XStreamWireFormat.java
index de437c9..179f90d 100755
--- a/activemq-http/src/main/java/org/apache/activemq/transport/xstream/XStreamWireFormat.java
+++ b/activemq-http/src/main/java/org/apache/activemq/transport/xstream/XStreamWireFormat.java
@@ -19,9 +19,16 @@ package org.apache.activemq.transport.xstream;
 import java.io.IOException;
 import java.io.Reader;
 
+import com.thoughtworks.xstream.converters.Converter;
+import com.thoughtworks.xstream.converters.ConverterLookup;
+import com.thoughtworks.xstream.converters.MarshallingContext;
+import com.thoughtworks.xstream.converters.UnmarshallingContext;
+import com.thoughtworks.xstream.io.HierarchicalStreamReader;
+import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
 import org.apache.activemq.command.MarshallAware;
 import org.apache.activemq.command.MessageDispatch;
 import org.apache.activemq.transport.util.TextWireFormat;
+import org.apache.activemq.util.ByteSequence;
 import org.apache.activemq.wireformat.WireFormat;
 
 import com.thoughtworks.xstream.XStream;
@@ -110,8 +117,27 @@ public class XStreamWireFormat extends TextWireFormat {
     // Implementation methods
     // -------------------------------------------------------------------------
     protected XStream createXStream() {
-        XStream xstream = new XStream();
+        final XStream xstream = new XStream();
         xstream.ignoreUnknownElements();
+        xstream.registerConverter(new Converter() {
+            final Converter delegate = xstream.getConverterLookup().lookupConverterForType(ByteSequence.class);
+            @Override
+            public void marshal(Object o, HierarchicalStreamWriter hierarchicalStreamWriter,
MarshallingContext marshallingContext) {
+                ByteSequence byteSequence = (ByteSequence)o;
+                byteSequence.compact();
+                delegate.marshal(byteSequence, hierarchicalStreamWriter, marshallingContext);
+            }
+
+            @Override
+            public Object unmarshal(HierarchicalStreamReader hierarchicalStreamReader, UnmarshallingContext
unmarshallingContext) {
+                return delegate.unmarshal(hierarchicalStreamReader, unmarshallingContext);
+            }
+
+            @Override
+            public boolean canConvert(Class aClass) {
+                return aClass == ByteSequence.class;
+            }
+        });
         return xstream;
     }
 

http://git-wip-us.apache.org/repos/asf/activemq/blob/547476d1/activemq-http/src/test/java/org/apache/activemq/transport/xstream/XStreamWireFormatTest.java
----------------------------------------------------------------------
diff --git a/activemq-http/src/test/java/org/apache/activemq/transport/xstream/XStreamWireFormatTest.java
b/activemq-http/src/test/java/org/apache/activemq/transport/xstream/XStreamWireFormatTest.java
index daa1468..5a5e611 100755
--- a/activemq-http/src/test/java/org/apache/activemq/transport/xstream/XStreamWireFormatTest.java
+++ b/activemq-http/src/test/java/org/apache/activemq/transport/xstream/XStreamWireFormatTest.java
@@ -18,6 +18,8 @@ package org.apache.activemq.transport.xstream;
 
 import java.io.IOException;
 
+import junit.framework.Test;
+import org.apache.activemq.command.ActiveMQTextMessage;
 import org.apache.activemq.command.Command;
 import org.apache.activemq.command.MessageTest;
 import org.apache.activemq.wireformat.WireFormat;
@@ -33,7 +35,7 @@ public class XStreamWireFormatTest extends MessageTest {
     public void assertBeanMarshalls(Object original) throws IOException {
         super.assertBeanMarshalls(original);
 
-        String xml = getXStreamWireFormat().marshalText((Command) original);
+        String xml = getXStreamWireFormat().marshalText(original);
         LOG.info(original.getClass().getName() + " as XML is:");
         LOG.info(xml);
     }
@@ -45,4 +47,16 @@ public class XStreamWireFormatTest extends MessageTest {
     protected WireFormat createWireFormat() {
         return new XStreamWireFormat();
     }
+
+    public static Test suite() {
+        return suite(XStreamWireFormatTest.class);
+    }
+
+    public void testXmlPayload() throws Exception {
+        ActiveMQTextMessage message = new ActiveMQTextMessage();
+        message.setText("<body val=\"Hi\"/>");
+        message.setStringProperty("body","Hi");
+
+        assertBeanMarshalls(message);
+    }
 }


Mime
View raw message