Prevent crash when route IDs contain dollar signs

Spring Boot configured route get names like 
`UpdateRelationCamelRoute$$EnhancerBySpringCGLIB$$24c87b04`. The dollar signs 
are interpreted as group references since the `java.lang.String#replaceFirst()` 
method works with regular expressions. An alternative to the proposed change is 
to use the `java.lang.String#replace()` method, assuming users of 
`MetricsRoutePolicy` don't put the `##routeId##` token multiple places in the 
name pattern and really want to keep all but the first literal occurrence.

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

Branch: refs/heads/camel-2.19.x
Commit: 726dadcc99603b84fe3ad2bd0cf54ec9890b3a1a
Parents: 0a03e9a
Author: Sune Keller <sune.kel...@gmail.com>
Authored: Tue Jun 6 13:26:41 2017 +0200
Committer: Claus Ibsen <davscl...@apache.org>
Committed: Tue Jun 6 16:57:40 2017 +0200

----------------------------------------------------------------------
 .../camel/component/metrics/routepolicy/MetricsRoutePolicy.java    | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/726dadcc/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
----------------------------------------------------------------------
diff --git 
a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
 
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
index f39b33d..7eaa655 100644
--- 
a/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
+++ 
b/components/camel-metrics/src/main/java/org/apache/camel/component/metrics/routepolicy/MetricsRoutePolicy.java
@@ -171,7 +171,7 @@ public class MetricsRoutePolicy extends RoutePolicySupport 
implements NonManaged
 
         String answer = namePattern;
         answer = answer.replaceFirst("##name##", name);
-        answer = answer.replaceFirst("##routeId##", route.getId());
+        answer = answer.replaceFirst("##routeId##", 
java.util.regex.Matcher.quoteReplacement(route.getId()));
         answer = answer.replaceFirst("##type##", type);
         return answer;
     }

Reply via email to