camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From ningji...@apache.org
Subject svn commit: r689399 - in /activemq/camel/trunk: camel-core/src/main/java/org/apache/camel/component/log/ camel-core/src/main/java/org/apache/camel/converter/stream/ camel-core/src/main/java/org/apache/camel/processor/interceptor/ tests/camel-itest/src/...
Date Wed, 27 Aug 2008 07:31:19 GMT
Author: ningjiang
Date: Wed Aug 27 00:31:18 2008
New Revision: 689399

URL: http://svn.apache.org/viewvc?rev=689399&view=rev
Log:
CAMEL-782 CAMEL-858 caching the inputStream when taking the message body as String

Modified:
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
    activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceFormatter.java
    activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsTest.java
    activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/SetExchangeProcessor.java
    activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsTest-context.xml

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java?rev=689399&r1=689398&r2=689399&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/component/log/LogFormatter.java
Wed Aug 27 00:31:18 2008
@@ -16,8 +16,12 @@
  */
 package org.apache.camel.component.log;
 
+import java.io.InputStream;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
+import org.apache.camel.converter.stream.StreamCache;
+import org.apache.camel.converter.stream.StreamCacheConverter.InputStreamCache;
 import org.apache.camel.processor.interceptor.ExchangeFormatter;
 import org.apache.camel.util.ObjectHelper;
 
@@ -173,10 +177,23 @@
     // Implementation methods
     //-------------------------------------------------------------------------
     protected Object getBodyAsString(Message message) {
+        Object newBody = null;
+        InputStreamCache cache = null;
+        if (message.getBody() instanceof InputStream) {
+            newBody = message.getBody(StreamCache.class);
+            if (newBody != null) {
+                cache = (InputStreamCache) newBody;
+                message.setBody(cache);
+            }
+        }
         Object answer = message.getBody(String.class);
         if (answer == null) {
             answer = message.getBody();
         }
+        if (cache != null) {
+            // Reset the inputStreamCache
+            cache.reset();
+        }
         return answer;
     }
 

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java?rev=689399&r1=689398&r2=689399&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/converter/stream/StreamCacheConverter.java
Wed Aug 27 00:31:18 2008
@@ -57,7 +57,7 @@
         }
     }
     
-    private class InputStreamCache extends ByteArrayInputStream implements StreamCache {
+    public class InputStreamCache extends ByteArrayInputStream implements StreamCache {
      
         public InputStreamCache(byte[] data) {
             super(data);

Modified: activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceFormatter.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceFormatter.java?rev=689399&r1=689398&r2=689399&view=diff
==============================================================================
--- activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceFormatter.java
(original)
+++ activemq/camel/trunk/camel-core/src/main/java/org/apache/camel/processor/interceptor/TraceFormatter.java
Wed Aug 27 00:31:18 2008
@@ -16,8 +16,13 @@
  */
 package org.apache.camel.processor.interceptor;
 
+import java.io.InputStream;
+
 import org.apache.camel.Exchange;
 import org.apache.camel.Message;
+import org.apache.camel.converter.stream.StreamCache;
+import org.apache.camel.converter.stream.StreamCacheConverter;
+import org.apache.camel.converter.stream.StreamCacheConverter.InputStreamCache;
 import org.apache.camel.spi.UnitOfWork;
 import org.apache.camel.util.ObjectHelper;
 
@@ -112,10 +117,23 @@
     }
 
     protected Object getBodyAsString(Message in) {
+        Object newBody = null;
+        InputStreamCache cache = null;
+        if (in.getBody() instanceof InputStream) {
+            newBody = in.getBody(StreamCache.class);
+            if (newBody != null) {
+                cache = (InputStreamCache) newBody;
+                in.setBody(cache);
+            }
+        }
         Object answer = in.getBody(String.class);
         if (answer == null) {
             answer = in.getBody();
         }
+        if (cache != null) {
+            // Reset the InputStreamCache
+            cache.reset();
+        }
         return answer;
     }
 

Modified: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsTest.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsTest.java?rev=689399&r1=689398&r2=689399&view=diff
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsTest.java
(original)
+++ activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/JettyJmsTest.java
Wed Aug 27 00:31:18 2008
@@ -24,6 +24,7 @@
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.component.cxf.CxfConstants;
 import org.apache.camel.component.mock.MockEndpoint;
+import org.apache.camel.processor.interceptor.Tracer;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.test.context.ContextConfiguration;
 import org.springframework.test.context.junit38.AbstractJUnit38SpringContextTests;
@@ -37,8 +38,24 @@
     @EndpointInject(uri = "mock:resultEndpoint")
     protected MockEndpoint resultEndpoint;
 
-    public void testMocksAreValid() throws Exception {
+    public void testMocksAreValidWithTracerEnabled() throws Exception {
         assertNotNull(camelContext);
+        Tracer tracer = Tracer.getTracer(camelContext);
+        assertNotNull(tracer);
+        assertTrue("The tracer should be enabled", tracer.isEnabled());
+        validMockes();
+    }
+
+    public void testMocksAreValidWithTracerDisabled() throws Exception {
+        assertNotNull(camelContext);
+        Tracer tracer = Tracer.getTracer(camelContext);
+        assertNotNull(tracer);
+        tracer.setEnabled(false);
+        validMockes();
+    }
+
+    private void validMockes() throws Exception {
+        resultEndpoint.reset();
         assertNotNull(resultEndpoint);
 
         ProducerTemplate<Exchange> template = camelContext.createProducerTemplate();
@@ -59,4 +76,8 @@
 
     }
 
+
+
+
+
 }

Modified: activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/SetExchangeProcessor.java
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/SetExchangeProcessor.java?rev=689399&r1=689398&r2=689399&view=diff
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/SetExchangeProcessor.java
(original)
+++ activemq/camel/trunk/tests/camel-itest/src/test/java/org/apache/camel/itest/jetty/SetExchangeProcessor.java
Wed Aug 27 00:31:18 2008
@@ -19,17 +19,17 @@
 import org.apache.camel.Exchange;
 import org.apache.camel.ExchangePattern;
 import org.apache.camel.Processor;
+import org.apache.camel.converter.stream.StreamCache;
 
 public class SetExchangeProcessor implements Processor {
 
     public void process(Exchange exchange) throws Exception {
         // Override the exchange pattern
         exchange.setPattern(ExchangePattern.InOnly);
+
         // Convert the input stream into a string
         String result = exchange.getIn().getBody(String.class);
-        // Copy the message header
-        exchange.getOut().setHeaders(exchange.getIn().getHeaders());
-        exchange.getOut().setBody(result);
+        exchange.getIn().setBody(result);
 
     }
 

Modified: activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsTest-context.xml
URL: http://svn.apache.org/viewvc/activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsTest-context.xml?rev=689399&r1=689398&r2=689399&view=diff
==============================================================================
--- activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsTest-context.xml
(original)
+++ activemq/camel/trunk/tests/camel-itest/src/test/resources/org/apache/camel/itest/jetty/JettyJmsTest-context.xml
Wed Aug 27 00:31:18 2008
@@ -37,9 +37,10 @@
   <bean id="setExchangeProcessor" class="org.apache.camel.itest.jetty.SetExchangeProcessor"/>
 
   <!-- START SNIPPET: example -->
-  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring">
+  <camelContext xmlns="http://activemq.apache.org/camel/schema/spring" trace="true">
     <route>
         <from uri="jetty:http://localhost:9000/test"/>
+        <to uri="log:MyCategory?level=INFO"/>
         <process ref="setExchangeProcessor"/>
         <to uri="jms:responseQueue"/>
     </route>



Mime
View raw message