camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject svn commit: r1095623 - in /camel/trunk: components/camel-cache/src/main/java/org/apache/camel/component/cache/ components/camel-cache/src/main/java/org/apache/camel/processor/cache/ components/camel-cache/src/test/java/org/apache/camel/component/cache/...
Date Thu, 21 Apr 2011 07:50:29 GMT
Author: davsclaus
Date: Thu Apr 21 07:50:29 2011
New Revision: 1095623

URL: http://svn.apache.org/viewvc?rev=1095623&view=rev
Log:
CAMEL-3852: camel-cache uses Camel style header keys. Also the control keys are removed after
usage to not keep propagating them during routing. Thanks to Ben O'Day for the patch.

Modified:
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConstants.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
    camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
    camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java
    camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedBodyReplacerTest.java
    camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedTokenReplacerTest.java
    camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedXPathElementReplacerTest.java
    camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheTest.java

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConstants.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConstants.java?rev=1095623&r1=1095622&r2=1095623&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConstants.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheConstants.java
Thu Apr 21 07:50:29 2011
@@ -21,14 +21,14 @@ package org.apache.camel.component.cache
  */
 public interface CacheConstants {
 
-    String CACHE_OPERATION = "CACHE_OPERATION";
-    String CACHE_KEY = "CACHE_KEY";
-    String CACHE_ELEMENT_WAS_FOUND = "CACHE_ELEMENT_WAS_FOUND";
+    String CACHE_OPERATION = "CamelCacheOperation";
+    String CACHE_KEY = "CamelCacheKey";
+    String CACHE_ELEMENT_WAS_FOUND = "CamelCacheElementWasFound";
 
-    String CACHE_OPERATION_ADD = "ADD";
-    String CACHE_OPERATION_UPDATE = "UPDATE";
-    String CACHE_OPERATION_DELETE = "DELETE";
-    String CACHE_OPERATION_DELETEALL = "DELETEALL";
-    String CACHE_OPERATION_GET = "GET";
-    String CACHE_OPERATION_CHECK = "CHECK";
+    String CACHE_OPERATION_ADD = "CamelCacheAdd";
+    String CACHE_OPERATION_UPDATE = "CamelCacheUpdate";
+    String CACHE_OPERATION_DELETE = "CamelCacheDelete";
+    String CACHE_OPERATION_DELETEALL = "CamelCacheDeleteAll";
+    String CACHE_OPERATION_GET = "CamelCacheGet";
+    String CACHE_OPERATION_CHECK = "CamelCacheCheck";
 }

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java?rev=1095623&r1=1095622&r2=1095623&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheEndpoint.java
Thu Apr 21 07:50:29 2011
@@ -76,8 +76,8 @@ public class CacheEndpoint extends Defau
     public Exchange createCacheExchange(String operation, String key, Object value) {
         Exchange exchange = new DefaultExchange(this.getCamelContext(), getExchangePattern());
         Message message = new DefaultMessage();
-        message.setHeader("CACHE_OPERATION", operation);
-        message.setHeader("CACHE_KEY", key);
+        message.setHeader(CacheConstants.CACHE_OPERATION, operation);
+        message.setHeader(CacheConstants.CACHE_KEY, key);
         message.setBody(value);
         exchange.setIn(message);
         return exchange;

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java?rev=1095623&r1=1095622&r2=1095623&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/component/cache/CacheProducer.java
Thu Apr 21 07:50:29 2011
@@ -85,13 +85,17 @@ public class CacheProducer extends Defau
         String operation = exchange.getIn().getHeader(CacheConstants.CACHE_OPERATION, String.class);
 
         if (operation == null) {
-            throw new CacheException("Operation not specified in the message header [" +
CacheConstants.CACHE_KEY + "]");
+            throw new CacheException(CacheConstants.CACHE_OPERATION + " not specified in
the message header [" + CacheConstants.CACHE_KEY + "]");
         }
         if ((key == null) && (!operation.equalsIgnoreCase(CacheConstants.CACHE_OPERATION_DELETEALL)))
{
-            throw new CacheException("Cache Key is not specified in message header header
or endpoint URL.");
+            throw new CacheException(CacheConstants.CACHE_KEY + " is not specified in message
header or endpoint URL.");
         }
 
         performCacheOperation(exchange, operation, key);
+        
+        //cleanup the cache headers
+        exchange.getIn().removeHeader(CacheConstants.CACHE_KEY);
+        exchange.getIn().removeHeader(CacheConstants.CACHE_OPERATION);
     }
 
     private void performCacheOperation(Exchange exchange, String operation, String key) throws
Exception {
@@ -139,7 +143,7 @@ public class CacheProducer extends Defau
                 exchange.getIn().removeHeader(CacheConstants.CACHE_ELEMENT_WAS_FOUND);
             }
         } else {
-            throw new CacheException("Operation " + operation + " is not supported.");
+            throw new CacheException(CacheConstants.CACHE_OPERATION + " " + operation + "
is not supported.");
         }
     }
 

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java?rev=1095623&r1=1095622&r2=1095623&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedMessageBodyReplacer.java
Thu Apr 21 07:50:29 2011
@@ -21,6 +21,7 @@ import net.sf.ehcache.Ehcache;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.component.cache.CacheConstants;
 import org.apache.camel.component.cache.DefaultCacheManagerFactory;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -51,7 +52,7 @@ public class CacheBasedMessageBodyReplac
             if (LOG.isDebugEnabled()) {
                 LOG.debug("Replacing Message Body from CacheName " + cacheName + " for key
" + key);
             }
-            exchange.getIn().setHeader("CACHE_KEY", key);
+            exchange.getIn().setHeader(CacheConstants.CACHE_KEY, key);
             exchange.getIn().setBody(cache.get(key).getObjectValue());
         }
 

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java?rev=1095623&r1=1095622&r2=1095623&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedTokenReplacer.java
Thu Apr 21 07:50:29 2011
@@ -23,6 +23,7 @@ import net.sf.ehcache.Ehcache;
 
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.component.cache.CacheConstants;
 import org.apache.camel.component.cache.DefaultCacheManagerFactory;
 import org.apache.camel.converter.IOConverter;
 import org.apache.camel.util.IOHelper;
@@ -59,7 +60,7 @@ public class CacheBasedTokenReplacer ext
                 LOG.debug("Replacing Token " + replacementToken + "in Message with value
stored against key "
                          + key + " in CacheName " + cacheName);
             }
-            exchange.getIn().setHeader("CACHE_KEY", key);
+            exchange.getIn().setHeader(CacheConstants.CACHE_KEY, key);
 
             Object body = exchange.getIn().getBody();
             InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class,
body);

Modified: camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java?rev=1095623&r1=1095622&r2=1095623&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
(original)
+++ camel/trunk/components/camel-cache/src/main/java/org/apache/camel/processor/cache/CacheBasedXPathReplacer.java
Thu Apr 21 07:50:29 2011
@@ -32,6 +32,7 @@ import net.sf.ehcache.CacheManager;
 import net.sf.ehcache.Ehcache;
 import org.apache.camel.Exchange;
 import org.apache.camel.Processor;
+import org.apache.camel.component.cache.CacheConstants;
 import org.apache.camel.component.cache.DefaultCacheManagerFactory;
 import org.apache.camel.converter.IOConverter;
 import org.apache.camel.converter.jaxp.XmlConverter;
@@ -72,7 +73,7 @@ public class CacheBasedXPathReplacer ext
                 LOG.debug("Replacing XPath value " + xpath + "in Message with value stored
against key " + key
                         + " in CacheName " + cacheName);
             }
-            exchange.getIn().setHeader("CACHE_KEY", key);
+            exchange.getIn().setHeader(CacheConstants.CACHE_KEY, key);
             Object body = exchange.getIn().getBody();
             InputStream is = exchange.getContext().getTypeConverter().convertTo(InputStream.class,
body);
             try {

Modified: camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java?rev=1095623&r1=1095622&r2=1095623&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java
(original)
+++ camel/trunk/components/camel-cache/src/test/java/org/apache/camel/component/cache/CacheProducerTest.java
Thu Apr 21 07:50:29 2011
@@ -307,7 +307,7 @@ public class CacheProducerTest extends C
             public void configure() {
                 onException(CacheException.class).
                         handled(true).
-                        choice().when(exceptionMessage().isEqualTo("Operation UNKNOWN is
not supported.")).
+                        choice().when(exceptionMessage().isEqualTo(CacheConstants.CACHE_OPERATION
+ " UNKNOWN is not supported.")).
                         to("log:*** LOGGER").
                         to("mock:CacheProducerTest.cacheException").end();
 

Modified: camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedBodyReplacerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedBodyReplacerTest.java?rev=1095623&r1=1095622&r2=1095623&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedBodyReplacerTest.java
(original)
+++ camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedBodyReplacerTest.java
Thu Apr 21 07:50:29 2011
@@ -27,6 +27,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.cache.CacheConstants;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
@@ -56,8 +57,8 @@ public class CacheBasedBodyReplacerTest 
                 public void process(Exchange exchange) throws Exception {
                     exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
                     Message in = exchange.getIn();
-                    in.setHeader("CACHE_OPERATION", "ADD");
-                    in.setHeader("CACHE_KEY", key);
+                    in.setHeader(CacheConstants.CACHE_OPERATION, CacheConstants.CACHE_OPERATION_ADD);
+                    in.setHeader(CacheConstants.CACHE_KEY, key);
                     if (key.equalsIgnoreCase("greeting")) {
                         in.setBody("Hello World");
                     } else {
@@ -76,13 +77,13 @@ public class CacheBasedBodyReplacerTest 
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-                from("cache://TestCache1").filter(header("CACHE_KEY").isEqualTo("greeting"))
+                from("cache://TestCache1").filter(header(CacheConstants.CACHE_KEY).isEqualTo("greeting"))
                     .process(new CacheBasedMessageBodyReplacer("cache://TestCache1", "farewell"))
                     .to("direct:next");
 
                 from("direct:next").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
-                        String key = (String)exchange.getIn().getHeader("CACHE_KEY");
+                        String key = (String)exchange.getIn().getHeader(CacheConstants.CACHE_KEY);
                         Object body = exchange.getIn().getBody();
                         String data = exchange.getContext().getTypeConverter().convertTo(String.class,
body);
 

Modified: camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedTokenReplacerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedTokenReplacerTest.java?rev=1095623&r1=1095622&r2=1095623&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedTokenReplacerTest.java
(original)
+++ camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedTokenReplacerTest.java
Thu Apr 21 07:50:29 2011
@@ -27,6 +27,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.cache.CacheConstants;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
@@ -63,8 +64,8 @@ public class CacheBasedTokenReplacerTest
                 public void process(Exchange exchange) throws Exception {
                     exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
                     Message in = exchange.getIn();
-                    in.setHeader("CACHE_OPERATION", "ADD");
-                    in.setHeader("CACHE_KEY", key);
+                    in.setHeader(CacheConstants.CACHE_OPERATION, CacheConstants.CACHE_OPERATION_ADD);
+                    in.setHeader(CacheConstants.CACHE_KEY, key);
                     if (key.equalsIgnoreCase("novel")) {
                         in.setBody("Rubaiyat");
                     } else if (key.equalsIgnoreCase("author")) {
@@ -87,7 +88,7 @@ public class CacheBasedTokenReplacerTest
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-                from("cache://TestCache1").filter(header("CACHE_KEY").isEqualTo("quote"))
+                from("cache://TestCache1").filter(header(CacheConstants.CACHE_KEY).isEqualTo("quote"))
                     .process(new CacheBasedTokenReplacer("cache://TestCache1", "novel", "#novel#"))
                     .process(new CacheBasedTokenReplacer("cache://TestCache1", "author",
"#author#"))
                     .process(new CacheBasedTokenReplacer("cache://TestCache1", "number",
"#number#"))
@@ -95,7 +96,7 @@ public class CacheBasedTokenReplacerTest
 
                 from("direct:next").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
-                        String key = (String)exchange.getIn().getHeader("CACHE_KEY");
+                        String key = (String)exchange.getIn().getHeader(CacheConstants.CACHE_KEY);
                         Object body = exchange.getIn().getBody();
                         String data = exchange.getContext().getTypeConverter().convertTo(String.class,
body);
 

Modified: camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedXPathElementReplacerTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedXPathElementReplacerTest.java?rev=1095623&r1=1095622&r2=1095623&view=diff
==============================================================================
--- camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedXPathElementReplacerTest.java
(original)
+++ camel/trunk/components/camel-cache/src/test/java/org/apache/camel/processor/cache/CacheBasedXPathElementReplacerTest.java
Thu Apr 21 07:50:29 2011
@@ -27,6 +27,7 @@ import org.apache.camel.Processor;
 import org.apache.camel.Produce;
 import org.apache.camel.ProducerTemplate;
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.cache.CacheConstants;
 import org.apache.camel.component.mock.MockEndpoint;
 import org.apache.camel.test.junit4.CamelTestSupport;
 import org.junit.Test;
@@ -68,8 +69,8 @@ public class CacheBasedXPathElementRepla
                 public void process(Exchange exchange) throws Exception {
                     exchange.setProperty(Exchange.CHARSET_NAME, "UTF-8");
                     Message in = exchange.getIn();
-                    in.setHeader("CACHE_OPERATION", "ADD");
-                    in.setHeader("CACHE_KEY", key);
+                    in.setHeader(CacheConstants.CACHE_OPERATION, CacheConstants.CACHE_OPERATION_ADD);
+                    in.setHeader(CacheConstants.CACHE_KEY, key);
                     if (key.equalsIgnoreCase("book1")) {
                         in.setBody(book1);
                     } else if (key.equalsIgnoreCase("book2")) {
@@ -90,14 +91,14 @@ public class CacheBasedXPathElementRepla
     protected RouteBuilder createRouteBuilder() throws Exception {
         return new RouteBuilder() {
             public void configure() {
-                from("cache://TestCache1").filter(header("CACHE_KEY").isEqualTo("XML_FRAGMENT"))
+                from("cache://TestCache1").filter(header(CacheConstants.CACHE_KEY).isEqualTo("XML_FRAGMENT"))
                     .process(new CacheBasedXPathReplacer("cache://TestCache1", "book1", "/books/book1"))
                     .process(new CacheBasedXPathReplacer("cache://TestCache1", "book2", "/books/book2"))
                     .to("direct:next");
 
                 from("direct:next").process(new Processor() {
                     public void process(Exchange exchange) throws Exception {
-                        String key = (String)exchange.getIn().getHeader("CACHE_KEY");
+                        String key = (String)exchange.getIn().getHeader(CacheConstants.CACHE_KEY);
                         Object body = exchange.getIn().getBody();
                         String data = exchange.getContext().getTypeConverter().convertTo(String.class,
body);
 

Modified: camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheTest.java
URL: http://svn.apache.org/viewvc/camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheTest.java?rev=1095623&r1=1095622&r2=1095623&view=diff
==============================================================================
--- camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheTest.java
(original)
+++ camel/trunk/tests/camel-itest-osgi/src/test/java/org/apache/camel/itest/osgi/cache/CacheTest.java
Thu Apr 21 07:50:29 2011
@@ -17,6 +17,7 @@
 package org.apache.camel.itest.osgi.cache;
 
 import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.component.cache.CacheConstants;
 import org.apache.camel.itest.osgi.OSGiIntegrationTestSupport;
 import org.apache.karaf.testing.Helper;
 import org.junit.Test;
@@ -50,13 +51,13 @@ public class CacheTest extends OSGiInteg
         return new RouteBuilder() {
             public void configure() {
                 from("direct:add")
-                    .setHeader("CACHE_OPERATION", constant("ADD"))
-                    .setHeader("CACHE_KEY", constant("foo"))
+                    .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_ADD))
+                    .setHeader(CacheConstants.CACHE_KEY, constant("foo"))
                     .to("cache:foo");
 
                 from("direct:get")
-                    .setHeader("CACHE_OPERATION", constant("GET"))
-                    .setHeader("CACHE_KEY", constant("foo"))
+                    .setHeader(CacheConstants.CACHE_OPERATION, constant(CacheConstants.CACHE_OPERATION_GET))
+                    .setHeader(CacheConstants.CACHE_KEY, constant("foo"))
                     .to("cache:foo")
                     .to("mock:result");
             }



Mime
View raw message