camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From davscl...@apache.org
Subject [4/4] camel git commit: CAMEL-11594: rest configuration in spring boot should use map instead of list
Date Wed, 26 Jul 2017 18:39:47 GMT
CAMEL-11594: rest configuration in spring boot should use map instead of list


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

Branch: refs/heads/camel-2.19.x
Commit: 76de7f99b8ea421b37f98ae2a324dcd6af7d8738
Parents: 7709f71
Author: Claus Ibsen <davsclaus@apache.org>
Authored: Wed Jul 26 20:35:30 2017 +0200
Committer: Claus Ibsen <davsclaus@apache.org>
Committed: Wed Jul 26 20:38:45 2017 +0200

----------------------------------------------------------------------
 .../main/java/org/apache/camel/util/CollectionHelper.java   | 6 +++---
 .../src/main/resources/application.properties               | 2 ++
 .../RestConfigurationDefinitionAutoConfiguration.java       | 7 +++++++
 .../apache/camel/model/rest/springboot/CamelRestTest.java   | 6 +++++-
 .../maven/packaging/SpringBootAutoConfigurationMojo.java    | 9 ++++++---
 5 files changed, 23 insertions(+), 7 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/76de7f99/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java b/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
index f5001e6..68f3820 100644
--- a/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
+++ b/camel-core/src/main/java/org/apache/camel/util/CollectionHelper.java
@@ -5,9 +5,9 @@
  * The ASF licenses this file to You under the Apache License, Version 2.0
  * (the "License"); you may not use this file except in compliance with
  * the License.  You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
+ *
+ *      http://www.apache.org/licenses/LICENSE-2.0
+ *
  * Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.

http://git-wip-us.apache.org/repos/asf/camel/blob/76de7f99/examples/camel-example-spring-boot-geocoder/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-geocoder/src/main/resources/application.properties
b/examples/camel-example-spring-boot-geocoder/src/main/resources/application.properties
index 221789b..d694863 100644
--- a/examples/camel-example-spring-boot-geocoder/src/main/resources/application.properties
+++ b/examples/camel-example-spring-boot-geocoder/src/main/resources/application.properties
@@ -34,3 +34,5 @@ camel.rest.api-property.api.title=Geocoder API
 camel.rest.api-property.api.version=1.0.0
 camel.rest.api-property.cors=true
 
+camel.rest.cors-headers.foo=bar
+

http://git-wip-us.apache.org/repos/asf/camel/blob/76de7f99/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/rest/springboot/RestConfigurationDefinitionAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/rest/springboot/RestConfigurationDefinitionAutoConfiguration.java
b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/rest/springboot/RestConfigurationDefinitionAutoConfiguration.java
index 92d49b8..804946f 100644
--- a/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/rest/springboot/RestConfigurationDefinitionAutoConfiguration.java
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/main/java/org/apache/camel/model/rest/springboot/RestConfigurationDefinitionAutoConfiguration.java
@@ -83,6 +83,13 @@ public class RestConfigurationDefinitionAutoConfiguration {
             definition.setEndpointProperties(new HashMap<>(CollectionHelper
                     .flatternKeysInMap(config.getEndpointProperty(), ".")));
         }
+        if (config.getCorsHeaders() != null) {
+            Map<String, Object> map = CollectionHelper.flatternKeysInMap(
+                    config.getCorsHeaders(), ".");
+            Map<String, String> target = new HashMap<>();
+            map.forEach((k, v) -> target.put(k, v.toString()));
+            definition.setCorsHeaders(target);
+        }
         return definition;
     }
 }
\ No newline at end of file

http://git-wip-us.apache.org/repos/asf/camel/blob/76de7f99/platforms/spring-boot/components-starter/camel-core-starter/src/test/java/org/apache/camel/model/rest/springboot/CamelRestTest.java
----------------------------------------------------------------------
diff --git a/platforms/spring-boot/components-starter/camel-core-starter/src/test/java/org/apache/camel/model/rest/springboot/CamelRestTest.java
b/platforms/spring-boot/components-starter/camel-core-starter/src/test/java/org/apache/camel/model/rest/springboot/CamelRestTest.java
index 70f23e3..374240c 100644
--- a/platforms/spring-boot/components-starter/camel-core-starter/src/test/java/org/apache/camel/model/rest/springboot/CamelRestTest.java
+++ b/platforms/spring-boot/components-starter/camel-core-starter/src/test/java/org/apache/camel/model/rest/springboot/CamelRestTest.java
@@ -58,7 +58,9 @@ import org.springframework.test.context.junit4.SpringRunner;
         "camel.rest.data-format-property.prettyPrint=true",
         "camel.rest.api-property.api.title=My cool API",
         "camel.rest.api-property.api.version=1.0.0",
-        "camel.rest.api-property.cors=true"
+        "camel.rest.api-property.cors=true",
+        "camel.rest.cors-headers.foo=123",
+        "camel.rest.cors-headers.bar=456"
     }
 )
 public class CamelRestTest {
@@ -77,6 +79,8 @@ public class CamelRestTest {
         Assert.assertEquals("My cool API", context.getRestConfiguration().getApiProperties().get("api.title"));
         Assert.assertEquals("1.0.0", context.getRestConfiguration().getApiProperties().get("api.version"));
         Assert.assertEquals("true", context.getRestConfiguration().getApiProperties().get("cors"));
+        Assert.assertEquals("123", context.getRestConfiguration().getCorsHeaders().get("foo"));
+        Assert.assertEquals("456", context.getRestConfiguration().getCorsHeaders().get("bar"));
     }
 
     // ***********************************

http://git-wip-us.apache.org/repos/asf/camel/blob/76de7f99/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
----------------------------------------------------------------------
diff --git a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
index 0f3f3d2..2e3785b 100644
--- a/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
+++ b/tooling/maven/camel-package-maven-plugin/src/main/java/org/apache/camel/maven/packaging/SpringBootAutoConfigurationMojo.java
@@ -524,15 +524,18 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             + "if (config.getConsumerProperty() != null) {\n"
             + "    definition.setConsumerProperties(new HashMap<>(CollectionHelper.flatternKeysInMap(config.getConsumerProperty(),
\".\")));\n"
             + "}\n"
-//            + "if (config.getCorsHeaders() != null) {\n"
-//            + "    definition.setCorsHeaders(new HashMap<>(config.getCorsHeaders()));\n"
-//            + "}\n"
             + "if (config.getDataFormatProperty() != null) {\n"
             + "    definition.setDataFormatProperties(new HashMap<>(CollectionHelper.flatternKeysInMap(config.getDataFormatProperty(),
\".\")));\n"
             + "}\n"
             + "if (config.getEndpointProperty() != null) {\n"
             + "    definition.setEndpointProperties(new HashMap<>(CollectionHelper.flatternKeysInMap(config.getEndpointProperty(),
\".\")));\n"
             + "}\n"
+            + "if (config.getCorsHeaders() != null) {\n"
+            + "    Map<String, Object> map = CollectionHelper.flatternKeysInMap(config.getCorsHeaders(),
\".\");\n"
+            + "    Map<String, String> target = new HashMap<>();\n"
+            + "    map.forEach((k, v) -> target.put(k, v.toString()));\n"
+            + "    definition.setCorsHeaders(target);\n"
+            + "}\n"
             + "return definition;"
         );
 


Mime
View raw message