ignore unknown fields in openwire commands to allow interop between
openwire versions.
This commit is contained in:
Timothy Bish 2013-11-13 10:36:02 -05:00
parent 6ed8f43d8d
commit 5e5458ec38
2 changed files with 14 additions and 6 deletions

View File

@ -19,13 +19,13 @@ package org.apache.activemq.transport.xstream;
import java.io.IOException; import java.io.IOException;
import java.io.Reader; import java.io.Reader;
import com.thoughtworks.xstream.XStream;
import org.apache.activemq.command.Command;
import org.apache.activemq.command.MarshallAware; import org.apache.activemq.command.MarshallAware;
import org.apache.activemq.command.MessageDispatch; import org.apache.activemq.command.MessageDispatch;
import org.apache.activemq.transport.util.TextWireFormat; import org.apache.activemq.transport.util.TextWireFormat;
import org.apache.activemq.wireformat.WireFormat; import org.apache.activemq.wireformat.WireFormat;
import com.thoughtworks.xstream.XStream;
/** /**
* A {@link WireFormat} implementation which uses the <a * A {@link WireFormat} implementation which uses the <a
* href="http://xstream.codehaus.org/>XStream</a> library to marshall commands * href="http://xstream.codehaus.org/>XStream</a> library to marshall commands
@ -37,10 +37,12 @@ public class XStreamWireFormat extends TextWireFormat {
private XStream xStream; private XStream xStream;
private int version; private int version;
@Override
public int getVersion() { public int getVersion() {
return version; return version;
} }
@Override
public void setVersion(int version) { public void setVersion(int version) {
this.version = version; this.version = version;
} }
@ -49,14 +51,17 @@ public class XStreamWireFormat extends TextWireFormat {
return new XStreamWireFormat(); return new XStreamWireFormat();
} }
@Override
public Object unmarshalText(String text) { public Object unmarshalText(String text) {
return (Command)getXStream().fromXML(text); return getXStream().fromXML(text);
} }
@Override
public Object unmarshalText(Reader reader) { public Object unmarshalText(Reader reader) {
return (Command)getXStream().fromXML(reader); return getXStream().fromXML(reader);
} }
@Override
public String marshalText(Object command) throws IOException { public String marshalText(Object command) throws IOException {
if (command instanceof MarshallAware) { if (command instanceof MarshallAware) {
((MarshallAware)command).beforeMarshall(this); ((MarshallAware)command).beforeMarshall(this);
@ -105,7 +110,9 @@ public class XStreamWireFormat extends TextWireFormat {
// Implementation methods // Implementation methods
// ------------------------------------------------------------------------- // -------------------------------------------------------------------------
protected XStream createXStream() { protected XStream createXStream() {
return new XStream(); XStream xstream = new XStream();
xstream.ignoreUnknownElements();
return xstream;
} }
} }

View File

@ -26,7 +26,6 @@ import java.util.Map;
import javax.jms.JMSException; import javax.jms.JMSException;
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
import org.apache.activemq.advisory.AdvisorySupport; import org.apache.activemq.advisory.AdvisorySupport;
import org.apache.activemq.broker.BrokerContext; import org.apache.activemq.broker.BrokerContext;
import org.apache.activemq.broker.BrokerContextAware; import org.apache.activemq.broker.BrokerContextAware;
@ -42,6 +41,7 @@ import com.thoughtworks.xstream.converters.basic.AbstractSingleValueConverter;
import com.thoughtworks.xstream.io.HierarchicalStreamReader; import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter; import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver; import com.thoughtworks.xstream.io.json.JettisonMappedXmlDriver;
import com.thoughtworks.xstream.io.json.JsonHierarchicalStreamDriver;
import com.thoughtworks.xstream.io.xml.PrettyPrintWriter; import com.thoughtworks.xstream.io.xml.PrettyPrintWriter;
import com.thoughtworks.xstream.io.xml.XppReader; import com.thoughtworks.xstream.io.xml.XppReader;
import com.thoughtworks.xstream.io.xml.xppdom.XppFactory; import com.thoughtworks.xstream.io.xml.xppdom.XppFactory;
@ -253,6 +253,7 @@ public class JmsFrameTranslator extends LegacyFrameTranslator implements
if (xstream == null) { if (xstream == null) {
xstream = new XStream(); xstream = new XStream();
xstream.ignoreUnknownElements();
} }
// For any object whose elements contains an UTF8Buffer instance instead of a String // For any object whose elements contains an UTF8Buffer instance instead of a String