You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ni...@apache.org on 2015/03/11 02:50:05 UTC

[1/2] camel git commit: [CAMEL-8468] Usage of camel-xstream depends on TCCL

Repository: camel
Updated Branches:
  refs/heads/camel-2.14.x d05bd3552 -> 55633081a
  refs/heads/camel-2.15.x 3170993f9 -> 3dab2d812


[CAMEL-8468] Usage of camel-xstream depends on TCCL


Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/3dab2d81
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/3dab2d81
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/3dab2d81

Branch: refs/heads/camel-2.15.x
Commit: 3dab2d812baabc72efd06cc4820d222bd5afea98
Parents: 3170993
Author: Thomas Diesler <th...@jboss.com>
Authored: Tue Mar 10 09:40:44 2015 +0100
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Mar 11 09:49:06 2015 +0800

----------------------------------------------------------------------
 .../xstream/AbstractXStreamWrapper.java         | 45 ++++++++++++++++----
 .../dataformat/xstream/JsonDataFormat.java      | 12 +++---
 2 files changed, 42 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3dab2d81/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
index a3f5fab..b4e6423 100644
--- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
+++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
@@ -31,6 +31,8 @@ import com.thoughtworks.xstream.converters.Converter;
 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.converter.jaxp.StaxConverter;
 import org.apache.camel.spi.ClassResolver;
@@ -42,7 +44,7 @@ import org.apache.camel.util.ObjectHelper;
  * ({@link DataFormat}) interface which leverage the XStream library for XML or JSON's marshaling and unmarshaling
  */
 public abstract class AbstractXStreamWrapper implements DataFormat {
-    
+
     private XStream xstream;
     private HierarchicalStreamDriver xstreamDriver;
     private StaxConverter staxConverter;
@@ -54,7 +56,7 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
 
     public AbstractXStreamWrapper() {
     }
-    
+
     public AbstractXStreamWrapper(XStream xstream) {
         this.xstream = xstream;
     }
@@ -73,11 +75,32 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
         return xstream;
     }
 
+    /**
+     * Resolves the XStream instance to be used by this data format. If XStream is not explicitly set, new instance will
+     * be created and cached.
+     *
+     * @param context to be used during a configuration of the XStream instance
+     * @return XStream instance used by this data format.
+     */
+    public XStream getXStream(CamelContext context) {
+        if (xstream == null) {
+            xstream = createXStream(context.getClassResolver(), context.getApplicationContextClassLoader());
+        }
+        return xstream;
+    }
+
     public void setXStream(XStream xstream) {
         this.xstream = xstream;
     }
 
+    /**
+     * @deprecated Use {@link #createXStream(ClassResolver, ClassLoader)}
+     */
     protected XStream createXStream(ClassResolver resolver) {
+        return createXStream(resolver, null);
+    }
+
+    protected XStream createXStream(ClassResolver resolver, ClassLoader classLoader) {
         if (xstreamDriver != null) {
             xstream = new XStream(xstreamDriver);
         } else {
@@ -88,6 +111,10 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
             xstream.setMode(getModeFromString(mode));
         }
 
+        if (classLoader != null) {
+            xstream.setClassLoader(classLoader);
+        }
+
         try {
             if (this.implicitCollections != null) {
                 for (Entry<String, String[]> entry : this.implicitCollections.entrySet()) {
@@ -141,14 +168,14 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
                     xstream.registerConverter(converter);
                 }
             }
-                
+
         } catch (Exception e) {
             throw new RuntimeException("Unable to build XStream instance", e);
         }
 
         return xstream;
-    } 
-    
+    }
+
     protected int getModeFromString(String modeString) {
         int result;
         if ("NO_REFERENCES".equalsIgnoreCase(modeString)) {
@@ -219,11 +246,11 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
     public void setXstreamDriver(HierarchicalStreamDriver xstreamDriver) {
         this.xstreamDriver = xstreamDriver;
     }
-    
+
     public String getMode() {
         return mode;
     }
-    
+
     public void setMode(String mode) {
         this.mode = mode;
     }
@@ -239,7 +266,7 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
     public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception {
         HierarchicalStreamWriter writer = createHierarchicalStreamWriter(exchange, body, stream);
         try {
-            getXStream(exchange.getContext().getClassResolver()).marshal(body, writer);
+            getXStream(exchange.getContext()).marshal(body, writer);
         } finally {
             writer.close();
         }
@@ -248,7 +275,7 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
     public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
         HierarchicalStreamReader reader = createHierarchicalStreamReader(exchange, stream);
         try {
-            return getXStream(exchange.getContext().getClassResolver()).unmarshal(reader);
+            return getXStream(exchange.getContext()).unmarshal(reader);
         } finally {
             reader.close();
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/3dab2d81/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
index 238bef7..7f6d714 100644
--- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
+++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
@@ -39,13 +39,13 @@ import org.codehaus.jettison.mapped.MappedXMLOutputFactory;
  * A <a href="http://camel.apache.org/data-format.html">data format</a>
  * ({@link DataFormat}) using XStream and Jettison to marshal to and from JSON
  *
- * @version 
+ * @version
  */
 
 public class JsonDataFormat extends AbstractXStreamWrapper {
     private final MappedXMLOutputFactory mof;
     private final MappedXMLInputFactory mif;
-    
+
     public JsonDataFormat() {
         final Map<?, ?> nstjsons = new HashMap<Object, Object>();
         mof = new MappedXMLOutputFactory(nstjsons);
@@ -53,8 +53,8 @@ public class JsonDataFormat extends AbstractXStreamWrapper {
     }
 
     @Override
-    protected XStream createXStream(ClassResolver resolver) {
-        XStream xs = super.createXStream(resolver);
+    protected XStream createXStream(ClassResolver resolver, ClassLoader classLoader) {
+        XStream xs = super.createXStream(resolver, classLoader);
         if (getMode() != null) {
             xs.setMode(getModeFromString(getMode()));
         } else {
@@ -63,11 +63,11 @@ public class JsonDataFormat extends AbstractXStreamWrapper {
         return xs;
     }
 
-    protected HierarchicalStreamWriter createHierarchicalStreamWriter(Exchange exchange, Object body, OutputStream stream) throws XMLStreamException {        
+    protected HierarchicalStreamWriter createHierarchicalStreamWriter(Exchange exchange, Object body, OutputStream stream) throws XMLStreamException {
         return new StaxWriter(new QNameMap(), mof.createXMLStreamWriter(stream));
     }
 
-    protected HierarchicalStreamReader createHierarchicalStreamReader(Exchange exchange, InputStream stream) throws XMLStreamException {        
+    protected HierarchicalStreamReader createHierarchicalStreamReader(Exchange exchange, InputStream stream) throws XMLStreamException {
         return new StaxReader(new QNameMap(), mif.createXMLStreamReader(stream));
     }
 }


[2/2] camel git commit: [CAMEL-8468] Usage of camel-xstream depends on TCCL

Posted by ni...@apache.org.
[CAMEL-8468] Usage of camel-xstream depends on TCCL


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

Branch: refs/heads/camel-2.14.x
Commit: 55633081adf66ffa99cab39edf0f0b1818a59fb0
Parents: d05bd35
Author: Thomas Diesler <th...@jboss.com>
Authored: Tue Mar 10 09:40:44 2015 +0100
Committer: Willem Jiang <wi...@gmail.com>
Committed: Wed Mar 11 09:49:38 2015 +0800

----------------------------------------------------------------------
 .../xstream/AbstractXStreamWrapper.java         | 45 ++++++++++++++++----
 .../dataformat/xstream/JsonDataFormat.java      | 12 +++---
 2 files changed, 42 insertions(+), 15 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/55633081/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
index a3f5fab..b4e6423 100644
--- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
+++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/AbstractXStreamWrapper.java
@@ -31,6 +31,8 @@ import com.thoughtworks.xstream.converters.Converter;
 import com.thoughtworks.xstream.io.HierarchicalStreamDriver;
 import com.thoughtworks.xstream.io.HierarchicalStreamReader;
 import com.thoughtworks.xstream.io.HierarchicalStreamWriter;
+
+import org.apache.camel.CamelContext;
 import org.apache.camel.Exchange;
 import org.apache.camel.converter.jaxp.StaxConverter;
 import org.apache.camel.spi.ClassResolver;
@@ -42,7 +44,7 @@ import org.apache.camel.util.ObjectHelper;
  * ({@link DataFormat}) interface which leverage the XStream library for XML or JSON's marshaling and unmarshaling
  */
 public abstract class AbstractXStreamWrapper implements DataFormat {
-    
+
     private XStream xstream;
     private HierarchicalStreamDriver xstreamDriver;
     private StaxConverter staxConverter;
@@ -54,7 +56,7 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
 
     public AbstractXStreamWrapper() {
     }
-    
+
     public AbstractXStreamWrapper(XStream xstream) {
         this.xstream = xstream;
     }
@@ -73,11 +75,32 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
         return xstream;
     }
 
+    /**
+     * Resolves the XStream instance to be used by this data format. If XStream is not explicitly set, new instance will
+     * be created and cached.
+     *
+     * @param context to be used during a configuration of the XStream instance
+     * @return XStream instance used by this data format.
+     */
+    public XStream getXStream(CamelContext context) {
+        if (xstream == null) {
+            xstream = createXStream(context.getClassResolver(), context.getApplicationContextClassLoader());
+        }
+        return xstream;
+    }
+
     public void setXStream(XStream xstream) {
         this.xstream = xstream;
     }
 
+    /**
+     * @deprecated Use {@link #createXStream(ClassResolver, ClassLoader)}
+     */
     protected XStream createXStream(ClassResolver resolver) {
+        return createXStream(resolver, null);
+    }
+
+    protected XStream createXStream(ClassResolver resolver, ClassLoader classLoader) {
         if (xstreamDriver != null) {
             xstream = new XStream(xstreamDriver);
         } else {
@@ -88,6 +111,10 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
             xstream.setMode(getModeFromString(mode));
         }
 
+        if (classLoader != null) {
+            xstream.setClassLoader(classLoader);
+        }
+
         try {
             if (this.implicitCollections != null) {
                 for (Entry<String, String[]> entry : this.implicitCollections.entrySet()) {
@@ -141,14 +168,14 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
                     xstream.registerConverter(converter);
                 }
             }
-                
+
         } catch (Exception e) {
             throw new RuntimeException("Unable to build XStream instance", e);
         }
 
         return xstream;
-    } 
-    
+    }
+
     protected int getModeFromString(String modeString) {
         int result;
         if ("NO_REFERENCES".equalsIgnoreCase(modeString)) {
@@ -219,11 +246,11 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
     public void setXstreamDriver(HierarchicalStreamDriver xstreamDriver) {
         this.xstreamDriver = xstreamDriver;
     }
-    
+
     public String getMode() {
         return mode;
     }
-    
+
     public void setMode(String mode) {
         this.mode = mode;
     }
@@ -239,7 +266,7 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
     public void marshal(Exchange exchange, Object body, OutputStream stream) throws Exception {
         HierarchicalStreamWriter writer = createHierarchicalStreamWriter(exchange, body, stream);
         try {
-            getXStream(exchange.getContext().getClassResolver()).marshal(body, writer);
+            getXStream(exchange.getContext()).marshal(body, writer);
         } finally {
             writer.close();
         }
@@ -248,7 +275,7 @@ public abstract class AbstractXStreamWrapper implements DataFormat {
     public Object unmarshal(Exchange exchange, InputStream stream) throws Exception {
         HierarchicalStreamReader reader = createHierarchicalStreamReader(exchange, stream);
         try {
-            return getXStream(exchange.getContext().getClassResolver()).unmarshal(reader);
+            return getXStream(exchange.getContext()).unmarshal(reader);
         } finally {
             reader.close();
         }

http://git-wip-us.apache.org/repos/asf/camel/blob/55633081/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
----------------------------------------------------------------------
diff --git a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
index 238bef7..7f6d714 100644
--- a/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
+++ b/components/camel-xstream/src/main/java/org/apache/camel/dataformat/xstream/JsonDataFormat.java
@@ -39,13 +39,13 @@ import org.codehaus.jettison.mapped.MappedXMLOutputFactory;
  * A <a href="http://camel.apache.org/data-format.html">data format</a>
  * ({@link DataFormat}) using XStream and Jettison to marshal to and from JSON
  *
- * @version 
+ * @version
  */
 
 public class JsonDataFormat extends AbstractXStreamWrapper {
     private final MappedXMLOutputFactory mof;
     private final MappedXMLInputFactory mif;
-    
+
     public JsonDataFormat() {
         final Map<?, ?> nstjsons = new HashMap<Object, Object>();
         mof = new MappedXMLOutputFactory(nstjsons);
@@ -53,8 +53,8 @@ public class JsonDataFormat extends AbstractXStreamWrapper {
     }
 
     @Override
-    protected XStream createXStream(ClassResolver resolver) {
-        XStream xs = super.createXStream(resolver);
+    protected XStream createXStream(ClassResolver resolver, ClassLoader classLoader) {
+        XStream xs = super.createXStream(resolver, classLoader);
         if (getMode() != null) {
             xs.setMode(getModeFromString(getMode()));
         } else {
@@ -63,11 +63,11 @@ public class JsonDataFormat extends AbstractXStreamWrapper {
         return xs;
     }
 
-    protected HierarchicalStreamWriter createHierarchicalStreamWriter(Exchange exchange, Object body, OutputStream stream) throws XMLStreamException {        
+    protected HierarchicalStreamWriter createHierarchicalStreamWriter(Exchange exchange, Object body, OutputStream stream) throws XMLStreamException {
         return new StaxWriter(new QNameMap(), mof.createXMLStreamWriter(stream));
     }
 
-    protected HierarchicalStreamReader createHierarchicalStreamReader(Exchange exchange, InputStream stream) throws XMLStreamException {        
+    protected HierarchicalStreamReader createHierarchicalStreamReader(Exchange exchange, InputStream stream) throws XMLStreamException {
         return new StaxReader(new QNameMap(), mif.createXMLStreamReader(stream));
     }
 }