camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [1/3] camel git commit: CAMEL-9793: Fixed Swagger Java when using property placeholders in Rest DSL could cause invalid parameters to be included that was from the placeholder.
Date Sat, 02 Apr 2016 07:05:01 GMT
Repository: camel
Updated Branches:
  refs/heads/camel-2.16.x 2f1be0549 -> 1a5cb8859
  refs/heads/camel-2.17.x 8720947b9 -> aba716ce3
  refs/heads/master ae2c751e5 -> 41a851893


CAMEL-9793: Fixed Swagger Java when using property placeholders in Rest DSL could cause invalid
parameters to be included that was from the placeholder.


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

Branch: refs/heads/master
Commit: 41a851893eaf3bf81c642c03f24c46d362f61ca1
Parents: ae2c751
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Sat Apr 2 09:04:09 2016 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Sat Apr 2 09:04:09 2016 +0200

----------------------------------------------------------------------
 .../apache/camel/model/rest/RestDefinition.java  | 19 ++++++++++++++++---
 .../apache/camel/swagger/RestSwaggerSupport.java |  1 +
 ...RestSwaggerReaderPropertyPlaceholderTest.java |  2 ++
 3 files changed, 19 insertions(+), 3 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/41a85189/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
index 2af693b..85ddc08 100644
--- a/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
+++ b/camel-core/src/main/java/org/apache/camel/model/rest/RestDefinition.java
@@ -780,17 +780,30 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
                 allPath = verb.getUri();
             }
 
-            // each {} is a parameter
+            // each {} is a parameter (url templating)
             String[] arr = allPath.split("\\/");
             for (String a : arr) {
+                // need to resolve property placeholders first
+                try {
+                    a = camelContext.resolvePropertyPlaceholders(a);
+                } catch (Exception e) {
+                    throw ObjectHelper.wrapRuntimeCamelException(e);
+                }
                 if (a.startsWith("{") && a.endsWith("}")) {
                     String key = a.substring(1, a.length() - 1);
                     //  merge if exists
                     boolean found = false;
                     for (RestOperationParamDefinition param : verb.getParams()) {
                         // name is mandatory
-                        ObjectHelper.notEmpty(param.getName(), "parameter name");
-                        if (param.getName().equalsIgnoreCase(key)) {
+                        String name = param.getName();
+                        ObjectHelper.notEmpty(name, "parameter name");
+                        // need to resolve property placeholders first
+                        try {
+                            name = camelContext.resolvePropertyPlaceholders(name);
+                        } catch (Exception e) {
+                            throw ObjectHelper.wrapRuntimeCamelException(e);
+                        }
+                        if (name.equalsIgnoreCase(key)) {
                             param.type(RestParamType.path);
                             found = true;
                             break;

http://git-wip-us.apache.org/repos/asf/camel/blob/41a85189/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerSupport.java
----------------------------------------------------------------------
diff --git a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerSupport.java
b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerSupport.java
index 982d8f3..abef77d 100644
--- a/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerSupport.java
+++ b/components/camel-swagger-java/src/main/java/org/apache/camel/swagger/RestSwaggerSupport.java
@@ -155,6 +155,7 @@ public class RestSwaggerSupport {
                 xml = (String) server.invoke(found, "dumpRestsAsXml", null, null);
             }
             if (xml != null) {
+                LOG.debug("DumpRestAsXml:\n{}", xml);
                 RestsDefinition rests = ModelHelper.createModelFromXml(null, xml, RestsDefinition.class);
                 if (rests != null) {
                     return rests.getRests();

http://git-wip-us.apache.org/repos/asf/camel/blob/41a85189/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderPropertyPlaceholderTest.java
----------------------------------------------------------------------
diff --git a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderPropertyPlaceholderTest.java
b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderPropertyPlaceholderTest.java
index a4ec368..d2b3417 100644
--- a/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderPropertyPlaceholderTest.java
+++ b/components/camel-swagger-java/src/test/java/org/apache/camel/swagger/RestSwaggerReaderPropertyPlaceholderTest.java
@@ -101,6 +101,8 @@ public class RestSwaggerReaderPropertyPlaceholderTest extends CamelTestSupport
{
         assertTrue(json.contains("\"summary\" : \"To update the greeting message\""));
         assertTrue(json.contains("\"/hello/bye/{name}\""));
         assertTrue(json.contains("\"/hello/hi/{name}\""));
+        assertFalse(json.contains("{foo}"));
+        assertFalse(json.contains("{bar}"));
 
         context.stop();
     }


Mime
View raw message