camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [3/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:03 GMT
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/1a5cb885
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/1a5cb885
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/1a5cb885

Branch: refs/heads/camel-2.16.x
Commit: 1a5cb885954beef86d83b45dd13d2bd81d8834ea
Parents: 2f1be05
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:51 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/1a5cb885/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 88e06f9..365a7db 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
@@ -753,17 +753,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/1a5cb885/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 a7cbc06..cbbbef0 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
@@ -149,6 +149,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/1a5cb885/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