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/42903358 Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/42903358 Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/42903358 Branch: refs/heads/master Commit: 42903358b4b7191d0844d522cbc7460e5410bbb5 Parents: 52c5fba Author: Claus Ibsen <davscl...@apache.org> Authored: Wed Jul 26 20:35:30 2017 +0200 Committer: Claus Ibsen <davscl...@apache.org> Committed: Wed Jul 26 20:36:58 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/42903358/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/42903358/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/42903358/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/42903358/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/42903358/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 c8b9a18..cf01ab9 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 @@ -520,15 +520,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;" );