git-svn-id: https://svn.apache.org/repos/asf/activemq/trunk@964087 13f79535-47bb-0310-9956-ffa450edef68
This commit is contained in:
Bosanac Dejan 2010-07-14 15:51:37 +00:00
parent 54a1520393
commit 3817ed9a97
4 changed files with 123 additions and 20 deletions

View File

@ -33,6 +33,8 @@
<properties>
<activemq.osgi.import.pkg>
com.thoughtworks.xstream*;resolution:=optional,
javax.xml.stream*;resolution:=optional,
org.codehaus.jettison*;resolution:=optional,
org.apache.activeio*;resolution:=optional,
org.apache.camel*;resolution:=optional,
org.apache.commons.pool*;resolution:=optional,
@ -155,6 +157,11 @@
<artifactId>xstream</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<optional>true</optional>
</dependency>
<!-- for XML parsing -->
<dependency>
@ -162,6 +169,11 @@
<artifactId>xbean-spring</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<optional>true</optional>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
@ -219,27 +231,17 @@
<optional>false</optional>
<type>test-jar</type>
</dependency>
<dependency>
<groupId>org.codehaus.jettison</groupId>
<artifactId>jettison</artifactId>
<version>1.0</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-jms</artifactId>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>org.springframework</groupId>
<artifactId>spring-test</artifactId>
<scope>test</scope>
</dependency>
</dependency>
<dependency>
<groupId>commons-io</groupId>
<artifactId>commons-io</artifactId>

View File

@ -29,18 +29,16 @@ import org.apache.activemq.advisory.AdvisorySupport;
import org.apache.activemq.command.ActiveMQMapMessage;
import org.apache.activemq.command.ActiveMQMessage;
import org.apache.activemq.command.ActiveMQObjectMessage;
import org.apache.activemq.command.ConsumerId;
import org.apache.activemq.command.DataStructure;
import org.apache.activemq.util.JettisonMappedXmlDriver;
import org.codehaus.jettison.mapped.Configuration;
import org.springframework.beans.BeansException;
import org.springframework.context.ApplicationContext;
import org.springframework.context.ApplicationContextAware;
import com.sun.tools.javac.util.Log;
import com.thoughtworks.xstream.XStream;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
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.XppReader;
@ -174,7 +172,7 @@ public class JmsFrameTranslator extends LegacyFrameTranslator implements
StringWriter buffer = new StringWriter();
HierarchicalStreamWriter out;
if (transformation.toLowerCase().endsWith("json")) {
out = new JettisonMappedXmlDriver().createWriter(buffer);
out = new JettisonMappedXmlDriver(new Configuration(), false).createWriter(buffer);
} else {
out = new PrettyPrintWriter(buffer);
}

View File

@ -0,0 +1,102 @@
/*
* Copyright (c) 2007, 2008 XStream Committers.
* All rights reserved.
*
* The software in this package is published under the terms of the BSD
* style license a copy of which has been included with this distribution in
* the LICENSE.txt file.
*
* Created on 30. March 2007 by Joerg Schaible
*/
package org.apache.activemq.util;
import java.io.InputStream;
import java.io.OutputStream;
import java.io.Reader;
import java.io.Writer;
import javax.xml.stream.XMLStreamException;
import org.codehaus.jettison.mapped.Configuration;
import org.codehaus.jettison.mapped.MappedNamespaceConvention;
import org.codehaus.jettison.mapped.MappedXMLInputFactory;
import org.codehaus.jettison.mapped.MappedXMLOutputFactory;
import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
import com.thoughtworks.xstream.io.HierarchicalStreamReader;
import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
import com.thoughtworks.xstream.io.StreamException;
import com.thoughtworks.xstream.io.json.JettisonStaxWriter;
import com.thoughtworks.xstream.io.xml.QNameMap;
import com.thoughtworks.xstream.io.xml.StaxReader;
import com.thoughtworks.xstream.io.xml.StaxWriter;
/**
*
* Temporary used until XStream 1.3.2 is released
*
* Simple XStream driver wrapping Jettison's Mapped reader and writer. Serializes object from
* and to JSON.
*
* @author Dejan Bosanac
*/
public class JettisonMappedXmlDriver implements HierarchicalStreamDriver {
private final MappedXMLOutputFactory mof;
private final MappedXMLInputFactory mif;
private final MappedNamespaceConvention convention;
private boolean useSerializeAsArray = true;
public JettisonMappedXmlDriver() {
this(new Configuration(), true);
}
public JettisonMappedXmlDriver(final Configuration config, final boolean useSerializeAsArray) {
mof = new MappedXMLOutputFactory(config);
mif = new MappedXMLInputFactory(config);
convention = new MappedNamespaceConvention(config);
this.useSerializeAsArray = useSerializeAsArray;
}
public HierarchicalStreamReader createReader(final Reader reader) {
try {
return new StaxReader(new QNameMap(), mif.createXMLStreamReader(reader));
} catch (final XMLStreamException e) {
throw new StreamException(e);
}
}
public HierarchicalStreamReader createReader(final InputStream input) {
try {
return new StaxReader(new QNameMap(), mif.createXMLStreamReader(input));
} catch (final XMLStreamException e) {
throw new StreamException(e);
}
}
public HierarchicalStreamWriter createWriter(final Writer writer) {
try {
if (useSerializeAsArray) {
return new JettisonStaxWriter(new QNameMap(), mof.createXMLStreamWriter(writer), convention);
} else {
return new StaxWriter(new QNameMap(), mof.createXMLStreamWriter(writer));
}
} catch (final XMLStreamException e) {
throw new StreamException(e);
}
}
public HierarchicalStreamWriter createWriter(final OutputStream output) {
try {
if (useSerializeAsArray) {
return new JettisonStaxWriter(new QNameMap(), mof.createXMLStreamWriter(output), convention);
} else {
return new StaxWriter(new QNameMap(), mof.createXMLStreamWriter(output));
}
} catch (final XMLStreamException e) {
throw new StreamException(e);
}
}
}

View File

@ -63,7 +63,7 @@
<jdom-version>1.0</jdom-version>
<jetty-version>7.0.1.v20091125</jetty-version>
<jsp-version>2.1.v20100127</jsp-version>
<jettison-version>1.1</jettison-version>
<jettison-version>1.2</jettison-version>
<jmock-version>2.5.1</jmock-version>
<junit-version>4.5</junit-version>
<jxta-version>2.0</jxta-version>
@ -76,6 +76,7 @@
<rome-version>0.8</rome-version>
<slf4j-version>1.5.0</slf4j-version>
<spring-oxm-version>1.5.8</spring-oxm-version>
<stax-api-version>1.0.1</stax-api-version>
<stax-version>1.2.0</stax-version>
<xalan-version>2.6.0</xalan-version>
<xmlbeans-version>2.0.0-beta1</xmlbeans-version>
@ -744,7 +745,7 @@
<dependency>
<groupId>stax</groupId>
<artifactId>stax-api</artifactId>
<version>1.0.1</version>
<version>${stax-api-version}</version>
</dependency>
<dependency>
<groupId>stax</groupId>