This is an automated email from the ASF dual-hosted git repository. davsclaus pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit ae2068f859e546bb89b7405a2f8c559f4beb01b1 Author: Claus Ibsen <claus.ib...@gmail.com> AuthorDate: Wed Jun 12 11:31:22 2019 +0200 CAMEL-13634: Camel main - Allow to configure rest dsl configuration --- .../java/org/apache/camel/main/MainSupport.java | 1 - .../camel/main/RestConfigurationProperties.java | 68 ++++++++++++++++++++++ .../camel/support/PropertyBindingSupport.java | 13 +++-- .../src/main/resources/application.properties | 5 ++ 4 files changed, 80 insertions(+), 7 deletions(-) diff --git a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java index 459a95a..71d427c 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/MainSupport.java @@ -41,7 +41,6 @@ import org.apache.camel.model.HystrixConfigurationDefinition; import org.apache.camel.model.Model; import org.apache.camel.model.ModelCamelContext; import org.apache.camel.model.RouteDefinition; -import org.apache.camel.model.rest.RestConfigurationDefinition; import org.apache.camel.spi.CamelBeanPostProcessor; import org.apache.camel.spi.DataFormat; import org.apache.camel.spi.EventNotifier; diff --git a/core/camel-main/src/main/java/org/apache/camel/main/RestConfigurationProperties.java b/core/camel-main/src/main/java/org/apache/camel/main/RestConfigurationProperties.java index 9150315d..27a0899 100644 --- a/core/camel-main/src/main/java/org/apache/camel/main/RestConfigurationProperties.java +++ b/core/camel-main/src/main/java/org/apache/camel/main/RestConfigurationProperties.java @@ -16,6 +16,8 @@ */ package org.apache.camel.main; +import java.util.HashMap; + import org.apache.camel.spi.RestConfiguration; import org.apache.camel.support.PatternHelper; @@ -271,4 +273,70 @@ public class RestConfigurationProperties extends RestConfiguration { return this; } + /** + * Adds a component property + */ + public RestConfigurationProperties withComponentProperty(String key, Object value) { + if (getComponentProperties() == null) { + setComponentProperties(new HashMap<>()); + } + getComponentProperties().put(key, value); + return this; + } + + /** + * Adds a endpoint property + */ + public RestConfigurationProperties withEndpointProperty(String key, Object value) { + if (getEndpointProperties() == null) { + setEndpointProperties(new HashMap<>()); + } + getEndpointProperties().put(key, value); + return this; + } + + /** + * Adds a consumer property + */ + public RestConfigurationProperties withConsumerProperty(String key, Object value) { + if (getConsumerProperties() == null) { + setConsumerProperties(new HashMap<>()); + } + getConsumerProperties().put(key, value); + return this; + } + + /** + * Adds a data format property + */ + public RestConfigurationProperties withDataFormatProperty(String key, Object value) { + if (getDataFormatProperties() == null) { + setDataFormatProperties(new HashMap<>()); + } + getDataFormatProperties().put(key, value); + return this; + } + + /** + * Adds a api property + */ + public RestConfigurationProperties withApiProperty(String key, Object value) { + if (getApiProperties() == null) { + setApiProperties(new HashMap<>()); + } + getApiProperties().put(key, value); + return this; + } + + /** + * Adds a CORS header property + */ + public RestConfigurationProperties withCorsHeader(String key, String value) { + if (getCorsHeaders() == null) { + setCorsHeaders(new HashMap<>()); + } + getCorsHeaders().put(key, value); + return this; + } + } diff --git a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java index be3ee8f..081312f 100644 --- a/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java +++ b/core/camel-support/src/main/java/org/apache/camel/support/PropertyBindingSupport.java @@ -442,13 +442,14 @@ public final class PropertyBindingSupport { Method method = findBestSetterMethod(newClass, part, fluentBuilder); if (method != null) { Class<?> parameterType = method.getParameterTypes()[0]; + Object instance = null; if (parameterType != null && org.apache.camel.util.ObjectHelper.hasDefaultPublicNoArgConstructor(parameterType)) { - Object instance = context.getInjector().newInstance(parameterType); - if (instance != null) { - org.apache.camel.support.ObjectHelper.invokeMethod(method, newTarget, instance); - newTarget = instance; - newClass = newTarget.getClass(); - } + instance = context.getInjector().newInstance(parameterType); + } + if (instance != null) { + org.apache.camel.support.ObjectHelper.invokeMethod(method, newTarget, instance); + newTarget = instance; + newClass = newTarget.getClass(); } } } else { diff --git a/examples/camel-example-main/src/main/resources/application.properties b/examples/camel-example-main/src/main/resources/application.properties index 0c96fed..71ab7ab 100644 --- a/examples/camel-example-main/src/main/resources/application.properties +++ b/examples/camel-example-main/src/main/resources/application.properties @@ -34,6 +34,11 @@ camel.component.quartz2.start-delayed-seconds = 3 ### camel.hystrix.group-key=myGroup ### camel.hystrix.execution-timeout-in-milliseconds=5000 +# to configure Rest DSL (global and you need to add camel-undertow to the classpath) +### camel.rest.component=undertow +### camel.rest.port=8080 +### camel.rest.component-properties[host-options.buffer-size]=8192 + # you can configure whether OS environment should override (=2 which is default) or as fallback (=1) ### camel.component.properties.environment-variable-mode=1