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 2011/08/08 15:59:23 UTC

svn commit: r1154967 - in /camel/branches/camel-2.8.x: ./ camel-core/src/main/java/org/apache/camel/component/properties/ camel-core/src/test/java/org/apache/camel/component/properties/ components/camel-http/

Author: ningjiang
Date: Mon Aug  8 13:59:23 2011
New Revision: 1154967

URL: http://svn.apache.org/viewvc?rev=1154967&view=rev
Log:
Merged revisions 1149488 via svnmerge from 
https://svn.apache.org/repos/asf/camel/trunk

........
  r1149488 | davsclaus | 2011-07-22 15:28:48 +0800 (Fri, 22 Jul 2011) | 1 line
  
  CAMEL-4261: Fixed properties component may contain duplicates in its location cache.
........

Modified:
    camel/branches/camel-2.8.x/   (props changed)
    camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
    camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
    camel/branches/camel-2.8.x/components/camel-http/   (props changed)

Propchange: camel/branches/camel-2.8.x/
------------------------------------------------------------------------------
--- svnmerge-integrated (original)
+++ svnmerge-integrated Mon Aug  8 13:59:23 2011
@@ -1 +1 @@
-/camel/trunk:1-1148091,1153146,1153323
+/camel/trunk:1-1148091,1149488,1153146,1153323

Modified: camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java?rev=1154967&r1=1154966&r2=1154967&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/main/java/org/apache/camel/component/properties/PropertiesComponent.java Mon Aug  8 13:59:23 2011
@@ -16,6 +16,8 @@
  */
 package org.apache.camel.component.properties;
 
+import java.io.Serializable;
+import java.util.Arrays;
 import java.util.Map;
 import java.util.Properties;
 import java.util.regex.Matcher;
@@ -23,7 +25,7 @@ import java.util.regex.Pattern;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.impl.DefaultComponent;
-import org.apache.camel.util.LRUCache;
+import org.apache.camel.util.LRUSoftCache;
 import org.apache.camel.util.ObjectHelper;
 import org.apache.camel.util.ServiceHelper;
 import org.slf4j.Logger;
@@ -44,7 +46,7 @@ public class PropertiesComponent extends
     private static final Pattern SYS_PATTERN = Pattern.compile("\\$\\{(.*?)\\}", Pattern.DOTALL);
 
     private static final transient Logger LOG = LoggerFactory.getLogger(PropertiesComponent.class);
-    private final Map<String[], Properties> cacheMap = new LRUCache<String[], Properties>(1000);
+    private final Map<CacheKey, Properties> cacheMap = new LRUSoftCache<CacheKey, Properties>(1000);
     private PropertiesResolver propertiesResolver = new DefaultPropertiesResolver();
     private PropertiesParser propertiesParser = new DefaultPropertiesParser();
     private String[] locations;
@@ -88,11 +90,12 @@ public class PropertiesComponent extends
         String[] locations = parseLocations(paths);
 
         // check cache first
-        Properties prop = cache ? cacheMap.get(locations) : null;
+        CacheKey key = new CacheKey(locations);
+        Properties prop = cache ? cacheMap.get(key) : null;
         if (prop == null) {
             prop = propertiesResolver.resolveProperties(getCamelContext(), locations);
             if (cache) {
-                cacheMap.put(locations, prop);
+                cacheMap.put(key, prop);
             }
         }
 
@@ -170,7 +173,7 @@ public class PropertiesComponent extends
                 if (ObjectHelper.isEmpty(value)) {
                     throw new IllegalArgumentException("Cannot find system environment with key: " + key);
                 }
-                // must quoute the replacement to have it work as literal replacement
+                // must quote the replacement to have it work as literal replacement
                 value = Matcher.quoteReplacement(value);
                 location = matcher.replaceFirst(value);
                 // must match again as location is changed
@@ -184,7 +187,7 @@ public class PropertiesComponent extends
                 if (ObjectHelper.isEmpty(value)) {
                     throw new IllegalArgumentException("Cannot find JVM system property with key: " + key);
                 }
-                // must quoute the replacement to have it work as literal replacement
+                // must quote the replacement to have it work as literal replacement
                 value = Matcher.quoteReplacement(value);
                 location = matcher.replaceFirst(value);
                 // must match again as location is changed
@@ -198,4 +201,48 @@ public class PropertiesComponent extends
         return answer;
     }
 
+    /**
+     * Key used in the locations cache
+     */
+    private final class CacheKey implements Serializable {
+
+        private final String[] locations;
+
+        private CacheKey(String[] locations) {
+            this.locations = locations;
+        }
+
+        public String[] getLocations() {
+            return locations;
+        }
+
+        @Override
+        public boolean equals(Object o) {
+            if (this == o) {
+                return true;
+            }
+            if (o == null || getClass() != o.getClass()) {
+                return false;
+            }
+
+            CacheKey that = (CacheKey) o;
+
+            if (!Arrays.equals(locations, that.locations)) {
+                return false;
+            }
+
+            return true;
+        }
+
+        @Override
+        public int hashCode() {
+            return locations != null ? Arrays.hashCode(locations) : 0;
+        }
+
+        @Override
+        public String toString() {
+            return "LocationKey[" + Arrays.asList(locations).toString() + "]";
+        }
+    }
+
 }

Modified: camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java
URL: http://svn.apache.org/viewvc/camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java?rev=1154967&r1=1154966&r2=1154967&view=diff
==============================================================================
--- camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java (original)
+++ camel/branches/camel-2.8.x/camel-core/src/test/java/org/apache/camel/component/properties/PropertiesComponentTest.java Mon Aug  8 13:59:23 2011
@@ -48,6 +48,40 @@ public class PropertiesComponentTest ext
         assertMockEndpointsSatisfied();
     }
 
+    public void testPropertiesComponentTwo() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:start").to("properties:{{cool.end}}");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:result").expectedMessageCount(2);
+
+        template.sendBody("direct:start", "Hello World");
+        template.sendBody("direct:start", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
+    public void testPropertiesComponentTemplate() throws Exception {
+        context.addRoutes(new RouteBuilder() {
+            @Override
+            public void configure() throws Exception {
+                from("direct:cool").to("mock:result");
+            }
+        });
+        context.start();
+
+        getMockEndpoint("mock:result").expectedMessageCount(2);
+
+        template.sendBody("{{cool.start}}", "Hello World");
+        template.sendBody("{{cool.start}}", "Bye World");
+
+        assertMockEndpointsSatisfied();
+    }
+
     public void testPropertiesComponentResult() throws Exception {
         context.addRoutes(new RouteBuilder() {
             @Override

Propchange: camel/branches/camel-2.8.x/components/camel-http/
            ('svn:mergeinfo' removed)