You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by da...@apache.org on 2017/07/25 18:53:41 UTC
[2/4] camel git commit: CAMEL-11593: Global rest configuration gets
overridden by default
CAMEL-11593: Global rest configuration gets overridden by default
Project: http://git-wip-us.apache.org/repos/asf/camel/repo
Commit: http://git-wip-us.apache.org/repos/asf/camel/commit/8e412cd0
Tree: http://git-wip-us.apache.org/repos/asf/camel/tree/8e412cd0
Diff: http://git-wip-us.apache.org/repos/asf/camel/diff/8e412cd0
Branch: refs/heads/master
Commit: 8e412cd07ce2a133415ae93cb204c6fd1b6f2c7f
Parents: c88d021
Author: Claus Ibsen <da...@apache.org>
Authored: Tue Jul 25 16:26:48 2017 +0200
Committer: Claus Ibsen <da...@apache.org>
Committed: Tue Jul 25 20:47:27 2017 +0200
----------------------------------------------------------------------
.../camel/component/rest/RestComponent.java | 9 ++--
.../apache/camel/impl/DefaultCamelContext.java | 10 ++--
.../apache/camel/model/rest/RestDefinition.java | 13 ++++-
.../spring/boot/CamelAutoConfiguration.java | 7 +++
.../springboot/geocoder/Application.java | 9 +---
.../springboot/geocoder/CamelGeocoderRoute.java | 47 +++++++++++++++++
.../springboot/geocoder/CamelRouter.java | 55 --------------------
.../src/main/resources/application.properties | 36 +++++++++++++
8 files changed, 113 insertions(+), 73 deletions(-)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/camel/blob/8e412cd0/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
index d1c1963..264750c 100644
--- a/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
+++ b/camel-core/src/main/java/org/apache/camel/component/rest/RestComponent.java
@@ -64,7 +64,7 @@ public class RestComponent extends DefaultComponent implements VerifiableCompone
// if no explicit host was given, then fallback and use default configured host
String h = getAndRemoveOrResolveReferenceParameter(parameters, "host", String.class, host);
- if (h == null && config != null) {
+ if (h == null) {
h = config.getHost();
int port = config.getPort();
// is there a custom port number
@@ -118,7 +118,7 @@ public class RestComponent extends DefaultComponent implements VerifiableCompone
answer.setUriTemplate(uriTemplate);
// if no explicit component name was given, then fallback and use default configured component name
- if (answer.getComponentName() == null && config != null) {
+ if (answer.getComponentName() == null) {
String name = config.getProducerComponent();
if (name == null) {
// fallback and use the consumer name
@@ -127,7 +127,7 @@ public class RestComponent extends DefaultComponent implements VerifiableCompone
answer.setComponentName(name);
}
// if no explicit producer api was given, then fallback and use default configured
- if (answer.getApiDoc() == null && config != null) {
+ if (answer.getApiDoc() == null) {
answer.setApiDoc(config.getProducerApiDoc());
}
@@ -188,6 +188,9 @@ public class RestComponent extends DefaultComponent implements VerifiableCompone
}
private RestConfiguration mergeConfigurations(RestConfiguration conf, RestConfiguration from) throws Exception {
+ if (conf == from) {
+ return conf;
+ }
if (from != null) {
Map<String, Object> map = IntrospectionSupport.getNonNullProperties(from);
http://git-wip-us.apache.org/repos/asf/camel/blob/8e412cd0/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
----------------------------------------------------------------------
diff --git a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
index 061263a..b46b6c2 100644
--- a/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
+++ b/camel-core/src/main/java/org/apache/camel/impl/DefaultCamelContext.java
@@ -2733,12 +2733,7 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
}
public RestConfiguration getRestConfiguration() {
- RestConfiguration config = restConfigurations.get("");
- if (config == null) {
- config = new RestConfiguration();
- setRestConfiguration(config);
- }
- return config;
+ return restConfigurations.get("");
}
public void setRestConfiguration(RestConfiguration restConfiguration) {
@@ -2759,8 +2754,9 @@ public class DefaultCamelContext extends ServiceSupport implements ModelCamelCon
}
RestConfiguration config = restConfigurations.get(component);
if (config == null && defaultIfNotExist) {
+ // grab the default configuration
config = getRestConfiguration();
- if (config != null && config.getComponent() != null && !config.getComponent().equals(component)) {
+ if (config == null || (config.getComponent() != null && !config.getComponent().equals(component))) {
config = new RestConfiguration();
restConfigurations.put(component, config);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/8e412cd0/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 6973f8c..b668f48 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
@@ -37,6 +37,7 @@ import org.apache.camel.model.ToDefinition;
import org.apache.camel.model.ToDynamicDefinition;
import org.apache.camel.spi.Metadata;
import org.apache.camel.spi.RestConfiguration;
+import org.apache.camel.util.CamelContextHelper;
import org.apache.camel.util.FileUtil;
import org.apache.camel.util.ObjectHelper;
import org.apache.camel.util.URISupport;
@@ -615,7 +616,17 @@ public class RestDefinition extends OptionalIdentifiedDefinition<RestDefinition>
List<RouteDefinition> answer = new ArrayList<RouteDefinition>();
if (camelContext.getRestConfigurations().isEmpty()) {
- camelContext.getRestConfiguration();
+ // make sure to initialize a rest configuration when its empty
+ // lookup a global which may have been setup via camel-spring-boot etc
+ RestConfiguration conf = CamelContextHelper.lookup(camelContext, RestConstants.DEFAULT_REST_CONFIGURATION_ID, RestConfiguration.class);
+ if (conf == null) {
+ conf = CamelContextHelper.findByType(camelContext, RestConfiguration.class);
+ }
+ if (conf != null) {
+ camelContext.setRestConfiguration(conf);
+ } else {
+ camelContext.setRestConfiguration(new RestConfiguration());
+ }
}
for (RestConfiguration config : camelContext.getRestConfigurations()) {
addRouteDefinition(camelContext, answer, config.getComponent());
http://git-wip-us.apache.org/repos/asf/camel/blob/8e412cd0/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
index 6605029..7363704 100644
--- a/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
+++ b/components/camel-spring-boot/src/main/java/org/apache/camel/spring/boot/CamelAutoConfiguration.java
@@ -46,6 +46,7 @@ import org.apache.camel.spi.LifecycleStrategy;
import org.apache.camel.spi.ManagementNamingStrategy;
import org.apache.camel.spi.ManagementStrategy;
import org.apache.camel.spi.ReloadStrategy;
+import org.apache.camel.spi.RestConfiguration;
import org.apache.camel.spi.RouteController;
import org.apache.camel.spi.RoutePolicyFactory;
import org.apache.camel.spi.RuntimeEndpointRegistry;
@@ -447,6 +448,12 @@ public class CamelAutoConfiguration {
camelContext.setRouteController(routeController);
}
+ // rest-dsl global configuration
+ RestConfiguration restConfiguration = getSingleBeanOfType(applicationContext, RestConfiguration.class);
+ if (restConfiguration != null) {
+ camelContext.setRestConfiguration(restConfiguration);
+ }
+
// set the default thread pool profile if defined
initThreadPoolProfiles(applicationContext, camelContext);
}
http://git-wip-us.apache.org/repos/asf/camel/blob/8e412cd0/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/Application.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/Application.java b/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/Application.java
index 25f5f1f..c4735ff 100644
--- a/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/Application.java
+++ b/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/Application.java
@@ -19,16 +19,10 @@ package org.apache.camel.example.springboot.geocoder;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
+// CHECKSTYLE:OFF
@SpringBootApplication
public class Application {
- /*
- * For PMD HideUtilityClassConstructorCheck
- */
- private void noop() {
-
- }
-
/**
* Main method to start the application.
*/
@@ -37,3 +31,4 @@ public class Application {
}
}
+// CHECKSTYLE:ON
http://git-wip-us.apache.org/repos/asf/camel/blob/8e412cd0/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/CamelGeocoderRoute.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/CamelGeocoderRoute.java b/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/CamelGeocoderRoute.java
new file mode 100644
index 0000000..4ea6e93
--- /dev/null
+++ b/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/CamelGeocoderRoute.java
@@ -0,0 +1,47 @@
+/**
+ * Licensed to the Apache Software Foundation (ASF) under one or more
+ * contributor license agreements. See the NOTICE file distributed with
+ * this work for additional information regarding copyright ownership.
+ * 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
+ *
+ * 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.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ */
+package org.apache.camel.example.springboot.geocoder;
+
+import com.google.code.geocoder.model.GeocodeResponse;
+import org.apache.camel.builder.RouteBuilder;
+import org.apache.camel.model.rest.RestBindingMode;
+import org.springframework.stereotype.Component;
+
+import static org.apache.camel.model.rest.RestParamType.query;
+
+/**
+ * A simple Camel REST DSL route example using the Geocoder component and documented with Swagger
+ */
+@Component
+public class CamelGeocoderRoute extends RouteBuilder {
+
+ @Override
+ public void configure() throws Exception {
+ // rest-dsl is also configured in the application.properties file
+
+ rest("/geocoder").description("Geocoder REST service")
+ .consumes("application/json")
+ .produces("application/json")
+
+ .get().description("Geocoder address lookup").outType(GeocodeResponse.class)
+ .param().name("address").type(query).description("The address to lookup").dataType("string").endParam()
+ .responseMessage().code(200).message("Geocoder successful").endResponseMessage()
+ // call the geocoder to lookup details from the provided address
+ .toD("geocoder:address:${header.address}");
+ }
+
+}
http://git-wip-us.apache.org/repos/asf/camel/blob/8e412cd0/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/CamelRouter.java
----------------------------------------------------------------------
diff --git a/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/CamelRouter.java b/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/CamelRouter.java
deleted file mode 100644
index 3f0183a..0000000
--- a/examples/camel-example-spring-boot-geocoder/src/main/java/org/apache/camel/example/springboot/geocoder/CamelRouter.java
+++ /dev/null
@@ -1,55 +0,0 @@
-/**
- * Licensed to the Apache Software Foundation (ASF) under one or more
- * contributor license agreements. See the NOTICE file distributed with
- * this work for additional information regarding copyright ownership.
- * 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
- *
- * 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.
- * See the License for the specific language governing permissions and
- * limitations under the License.
- */
-package org.apache.camel.example.springboot.geocoder;
-
-import com.google.code.geocoder.model.GeocodeResponse;
-import org.apache.camel.builder.RouteBuilder;
-import org.apache.camel.model.rest.RestBindingMode;
-import org.springframework.stereotype.Component;
-
-import static org.apache.camel.model.rest.RestParamType.query;
-
-/**
- * A simple Camel REST DSL route example using the Geocoder component and documented with Swagger
- *
- */
-@Component
-public class CamelRouter extends RouteBuilder {
-
- @Override
- public void configure() throws Exception {
- restConfiguration()
- .component("servlet")
- .bindingMode(RestBindingMode.json)
- .dataFormatProperty("prettyPrint", "true")
- .apiContextPath("/api-doc")
- .apiProperty("api.title", "Geocoder API").apiProperty("api.version", "1.0.0")
- .apiProperty("cors", "true");
-
-
- rest("/geocoder").description("Geocoder REST service")
- .consumes("application/json")
- .produces("application/json")
-
- .get().description("Geocoder address lookup").outType(GeocodeResponse.class)
- .param().name("address").type(query).description("The address to lookup").dataType("string").endParam()
- .responseMessage().code(200).message("Geocoder successful").endResponseMessage()
- .toD("geocoder:address:${header.address}");
-
- }
-
-}
http://git-wip-us.apache.org/repos/asf/camel/blob/8e412cd0/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
new file mode 100644
index 0000000..221789b
--- /dev/null
+++ b/examples/camel-example-spring-boot-geocoder/src/main/resources/application.properties
@@ -0,0 +1,36 @@
+## ---------------------------------------------------------------------------
+## Licensed to the Apache Software Foundation (ASF) under one or more
+## contributor license agreements. See the NOTICE file distributed with
+## this work for additional information regarding copyright ownership.
+## 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
+##
+## 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.
+## See the License for the specific language governing permissions and
+## limitations under the License.
+
+camel.springboot.name=Geocoder
+
+# use servlet as the component
+# (this can be omitted as camel will lookup on the classpath and discover it automatic)
+camel.rest.component=servlet
+
+# turn on json binding
+camel.rest.binding-mode=json
+
+# output in pretty print mode
+camel.rest.data-format-property.prettyPrint=true
+
+# context path for swagger api docs
+camel.rest.api-context-path=/api-doc
+
+# swagger api properties
+camel.rest.api-property.api.title=Geocoder API
+camel.rest.api-property.api.version=1.0.0
+camel.rest.api-property.cors=true
+