qpid-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From rgodf...@apache.org
Subject [2/4] qpid-broker-j git commit: QPID-7940 : [Java Broker] JSON context substitution does not work with nested variables
Date Sat, 30 Sep 2017 20:31:48 GMT
QPID-7940 : [Java Broker] JSON context substitution does not work with nested variables


Project: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/repo
Commit: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/commit/03c35771
Tree: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/tree/03c35771
Diff: http://git-wip-us.apache.org/repos/asf/qpid-broker-j/diff/03c35771

Branch: refs/heads/master
Commit: 03c357718525711c2e3cb5ce6f68841beefe63b9
Parents: 3745dd9
Author: rgodfrey <rgodfrey@apache.org>
Authored: Sat Sep 30 22:17:29 2017 +0200
Committer: rgodfrey <rgodfrey@apache.org>
Committed: Sat Sep 30 22:30:17 2017 +0200

----------------------------------------------------------------------
 .../server/model/AttributeValueConverter.java   |  2 +-
 .../org/apache/qpid/server/util/Strings.java    |  5 +++-
 .../apache/qpid/server/util/StringsTest.java    | 24 ++++++++++++++++++++
 3 files changed, 29 insertions(+), 2 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/03c35771/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java
b/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java
index 9b2df6e..c8a9177 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/model/AttributeValueConverter.java
@@ -1359,7 +1359,7 @@ abstract class AttributeValueConverter<T>
                 }
                 catch (IOException e)
                 {
-
+                    throw new IllegalArgumentException("Cannot convert type " + value.getClass()
+ " to a " + _klazz.getName(), e);
                 }
 
             }

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/03c35771/broker-core/src/main/java/org/apache/qpid/server/util/Strings.java
----------------------------------------------------------------------
diff --git a/broker-core/src/main/java/org/apache/qpid/server/util/Strings.java b/broker-core/src/main/java/org/apache/qpid/server/util/Strings.java
index 7a8692a..60edbd0 100644
--- a/broker-core/src/main/java/org/apache/qpid/server/util/Strings.java
+++ b/broker-core/src/main/java/org/apache/qpid/server/util/Strings.java
@@ -404,7 +404,10 @@ public final class Strings
                 if (variable.startsWith(_prefix))
                 {
                     currentStack.add(variable);
-                    String expanded = resolver.resolve(variable.substring(_prefix.length()),
resolver);
+                    final Stack<String> stack = new Stack<>();
+                    stack.add(variable);
+                    String expanded = Strings.expand("${" + variable.substring(_prefix.length())
+ "}", resolver,
+                                                     stack, false);
                     currentStack.remove(variable);
                     if(expanded != null)
                     {

http://git-wip-us.apache.org/repos/asf/qpid-broker-j/blob/03c35771/broker-core/src/test/java/org/apache/qpid/server/util/StringsTest.java
----------------------------------------------------------------------
diff --git a/broker-core/src/test/java/org/apache/qpid/server/util/StringsTest.java b/broker-core/src/test/java/org/apache/qpid/server/util/StringsTest.java
index 2b0d3f1..4047d6a 100644
--- a/broker-core/src/test/java/org/apache/qpid/server/util/StringsTest.java
+++ b/broker-core/src/test/java/org/apache/qpid/server/util/StringsTest.java
@@ -21,7 +21,9 @@
 package org.apache.qpid.server.util;
 
 import java.util.Collections;
+import java.util.HashMap;
 import java.util.LinkedHashMap;
+import java.util.Map;
 
 import org.apache.qpid.test.utils.QpidTestCase;
 
@@ -45,4 +47,26 @@ public class StringsTest extends QpidTestCase
                      Strings.expand("{ \"path\" : \"${json:test}\\foo\" }",Strings.chain(jsonResolver,mapResolver)));
 
     }
+
+    public void testNestedSubstitutionResolver()
+    {
+        Map<String,String> context = new HashMap<>();
+        context.put("test", "C:\\TEMP\\\"Hello World\"");
+        context.put("nestedTest", "${test}");
+        Strings.MapResolver mapResolver =
+                new Strings.MapResolver(context);
+
+        Strings.Resolver jsonResolver = Strings.createSubstitutionResolver("json:",
+                                                                           new LinkedHashMap<String,
String>()
+                                                                           {
+                                                                               {
+                                                                                   put("\\",
"\\\\");
+                                                                                   put("\"",
"\\\"");
+                                                                               }
+                                                                           });
+
+        assertEquals("{ \"path\" : \"C:\\\\TEMP\\\\\\\"Hello World\\\"\\foo\" }",
+                     Strings.expand("{ \"path\" : \"${json:nestedTest}\\foo\" }",Strings.chain(jsonResolver,mapResolver)));
+
+    }
 }


---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@qpid.apache.org
For additional commands, e-mail: commits-help@qpid.apache.org


Mime
View raw message