camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From cmuel...@apache.org
Subject svn commit: r1324976 - in /camel/branches/camel-2.9.x/components/camel-jaxb/src: main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java test/java/org/apache/camel/example/DataFormatConcurrentTest.java
Date Wed, 11 Apr 2012 20:14:50 GMT
Author: cmueller
Date: Wed Apr 11 20:14:49 2012
New Revision: 1324976

URL: http://svn.apache.org/viewvc?rev=1324976&view=rev
Log:
CAMEL-3776: Add pooling support for JAXB data format

Modified:
    camel/branches/camel-2.9.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
    camel/branches/camel-2.9.x/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java

Modified: camel/branches/camel-2.9.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java?rev=1324976&r1=1324975&r2=1324976&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-jaxb/src/main/java/org/apache/camel/converter/jaxb/FallbackTypeConverter.java
Wed Apr 11 20:14:49 2012
@@ -36,6 +36,7 @@ import javax.xml.bind.annotation.XmlRoot
 import javax.xml.stream.FactoryConfigurationError;
 import javax.xml.stream.XMLOutputFactory;
 import javax.xml.stream.XMLStreamException;
+import javax.xml.stream.XMLStreamReader;
 import javax.xml.stream.XMLStreamWriter;
 import javax.xml.transform.Source;
 
@@ -137,6 +138,14 @@ public class FallbackTypeConverter imple
         Unmarshaller unmarshaller = getOrCreateUnmarshaller(type);
 
         if (parentTypeConverter != null) {
+            if (!needFiltering(exchange)) {
+                // we cannot filter the XMLStreamReader if necessary
+                XMLStreamReader xmlReader = parentTypeConverter.convertTo(XMLStreamReader.class,
value);
+                if (xmlReader != null) {
+                    Object unmarshalled = unmarshal(unmarshaller, exchange, xmlReader);
+                    return type.cast(unmarshalled);
+                }
+            }
             InputStream inputStream = parentTypeConverter.convertTo(InputStream.class, value);
             if (inputStream != null) {
                 Object unmarshalled = unmarshal(unmarshaller, exchange, inputStream);
@@ -195,10 +204,13 @@ public class FallbackTypeConverter imple
         return answer;
     }
 
-    protected Object unmarshal(Unmarshaller unmarshaller, Exchange exchange, Object value)
throws JAXBException, UnsupportedEncodingException {
+    protected Object unmarshal(Unmarshaller unmarshaller, Exchange exchange, Object value)
throws JAXBException, UnsupportedEncodingException, XMLStreamException {
         unmarshallerLock.lock();
         try {
-            if (value instanceof InputStream) {
+            if (value instanceof XMLStreamReader) {
+                XMLStreamReader xmlReader = (XMLStreamReader) value;
+                return unmarshaller.unmarshal(xmlReader);
+            } else if (value instanceof InputStream) {
                 if (needFiltering(exchange)) {
                     return unmarshaller.unmarshal(new NonXmlFilterReader(new InputStreamReader((InputStream)value,
IOHelper.getCharsetName(exchange))));
                 }

Modified: camel/branches/camel-2.9.x/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.9.x/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java?rev=1324976&r1=1324975&r2=1324976&view=diff
==============================================================================
--- camel/branches/camel-2.9.x/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java
(original)
+++ camel/branches/camel-2.9.x/components/camel-jaxb/src/test/java/org/apache/camel/example/DataFormatConcurrentTest.java
Wed Apr 11 20:14:49 2012
@@ -67,7 +67,7 @@ public class DataFormatConcurrentTest ex
         template.setDefaultEndpointUri("direct:unmarshalFallback");
 
         ExecutorService pool = Executors.newFixedThreadPool(20);
-        //long start = System.currentTimeMillis();
+        long start = System.currentTimeMillis();
         for (int i = 0; i < counter; i++) {
             pool.execute(new Runnable() {
                 public void run() {
@@ -79,8 +79,8 @@ public class DataFormatConcurrentTest ex
 
         // should finish on fast machines in less than 3 seconds
         assertTrue(latch.await(10, TimeUnit.SECONDS));
-        //long end = System.currentTimeMillis();
-        //System.out.println("took " + (end - start) + "ms");
+        long end = System.currentTimeMillis();
+        System.out.println("took " + (end - start) + "ms");
     }
 
     @Test



Mime
View raw message