You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by lb...@apache.org on 2019/08/09 06:54:49 UTC

[camel-quarkus] branch master updated: chore: replace custom properties binding implementation with PropertyBindingSupport from camel support

This is an automated email from the ASF dual-hosted git repository.

lburgazzoli pushed a commit to branch master
in repository https://gitbox.apache.org/repos/asf/camel-quarkus.git


The following commit(s) were added to refs/heads/master by this push:
     new a76c752  chore: replace custom properties binding implementation with PropertyBindingSupport from camel support
a76c752 is described below

commit a76c7526960ecabb1a1ebafc18c211a361bcf998
Author: lburgazzoli <lb...@gmail.com>
AuthorDate: Thu Aug 8 19:24:43 2019 +0200

    chore: replace custom properties binding implementation with PropertyBindingSupport from camel support
---
 .../core/runtime/support/FastCamelContext.java     | 35 ++++++------
 .../core/runtime/support/FastCamelRuntime.java     | 32 +++++------
 .../core/runtime/support/RuntimeSupport.java       | 62 ----------------------
 .../aws/src/main/resources/application.properties  |  2 -
 .../bean/src/main/resources/application.properties | 18 +++----
 .../src/main/resources/application.properties      |  2 -
 .../core/src/main/resources/application.properties |  5 +-
 .../jdbc/src/main/resources/application.properties |  2 -
 .../src/main/resources/application.properties      |  2 -
 .../src/main/resources/application.properties      |  2 -
 .../src/main/resources/application.properties      |  2 -
 .../src/main/resources/application.properties      |  2 -
 12 files changed, 42 insertions(+), 124 deletions(-)

diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/FastCamelContext.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/FastCamelContext.java
index 2dfabfc..6ccbdad 100644
--- a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/FastCamelContext.java
+++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/FastCamelContext.java
@@ -17,12 +17,12 @@
 package org.apache.camel.quarkus.core.runtime.support;
 
 import java.util.Collection;
+import java.util.HashMap;
 import java.util.Map;
 import java.util.Properties;
 import java.util.concurrent.ExecutorService;
 import java.util.regex.Matcher;
 
-import org.apache.camel.AggregationStrategy;
 import org.apache.camel.AsyncProcessor;
 import org.apache.camel.CamelContext;
 import org.apache.camel.CamelContextAware;
@@ -91,7 +91,6 @@ import org.apache.camel.spi.ModelJAXBContextFactory;
 import org.apache.camel.spi.NodeIdFactory;
 import org.apache.camel.spi.PackageScanClassResolver;
 import org.apache.camel.spi.ProcessorFactory;
-import org.apache.camel.spi.PropertiesComponent;
 import org.apache.camel.spi.ReactiveExecutor;
 import org.apache.camel.spi.Registry;
 import org.apache.camel.spi.RestRegistryFactory;
@@ -105,6 +104,7 @@ import org.apache.camel.spi.UuidGenerator;
 import org.apache.camel.spi.ValidatorRegistry;
 import org.apache.camel.util.FilePathResolver;
 import org.apache.camel.util.StringHelper;
+import org.apache.camel.support.PropertyBindingSupport;
 
 public class FastCamelContext extends AbstractCamelContext {
 
@@ -353,26 +353,27 @@ public class FastCamelContext extends AbstractCamelContext {
         return new ReactiveExecutorResolver().resolve(this);
     }
 
-    public AsyncProcessor createMulticast(Collection<Processor> processors, ExecutorService executor,
-            boolean shutdownExecutorService) {
-        return new MulticastProcessor(this, processors, (AggregationStrategy) null, true, executor, shutdownExecutorService,
-                false, false, 0L, (Processor) null, false, false);
+    @Override
+    public AsyncProcessor createMulticast(Collection<Processor> processors, ExecutorService executor, boolean shutdownExecutorService) {
+        return new MulticastProcessor(this, processors, null, true, executor, shutdownExecutorService,
+                false, false, 0L, null, false, false);
     }
 
+    @SuppressWarnings("unchecked")
     protected <T> T resolve(Class<T> clazz, String type, String name, CamelContext context) {
         T result = context.getRegistry().lookupByNameAndType(name, clazz);
-        if (result instanceof CamelContextAware) {
-            ((CamelContextAware) result).setCamelContext(context);
-        }
-        PropertiesComponent comp = getPropertiesComponent();
-        if (comp instanceof org.apache.camel.component.properties.PropertiesComponent) {
-            Properties props = ((org.apache.camel.component.properties.PropertiesComponent) comp).getInitialProperties();
-            if (props != null) {
-                String pfx = CamelRuntime.PFX_CAMEL + type + "." + name;
-                log.debug("Binding {} {} with prefix {}", type, name, pfx);
-                RuntimeSupport.bindProperties(this, props, result, pfx);
-            }
+
+        CamelContextAware.trySetCamelContext(result, context);
+
+        Properties props = getPropertiesComponent().loadProperties();
+        if (props != null && !props.isEmpty()) {
+            PropertyBindingSupport.bindProperties(
+                this,
+                result,
+                new HashMap<>((Map) props),
+                CamelRuntime.PFX_CAMEL + type + "." + name);
         }
+
         return result;
     }
 
diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/FastCamelRuntime.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/FastCamelRuntime.java
index de39a2b..ea20c8b 100644
--- a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/FastCamelRuntime.java
+++ b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/FastCamelRuntime.java
@@ -18,7 +18,9 @@ package org.apache.camel.quarkus.core.runtime.support;
 
 import java.io.InputStream;
 import java.util.ArrayList;
+import java.util.HashMap;
 import java.util.List;
+import java.util.Map;
 import java.util.Properties;
 import java.util.stream.Collectors;
 
@@ -29,7 +31,6 @@ import org.apache.camel.ExtendedCamelContext;
 import org.apache.camel.Route;
 import org.apache.camel.RoutesBuilder;
 import org.apache.camel.RuntimeCamelException;
-import org.apache.camel.ShutdownableService;
 import org.apache.camel.component.properties.PropertiesComponent;
 import org.apache.camel.model.Model;
 import org.apache.camel.model.RouteDefinition;
@@ -43,6 +44,7 @@ import org.apache.camel.quarkus.core.runtime.StartingEvent;
 import org.apache.camel.quarkus.core.runtime.StoppedEvent;
 import org.apache.camel.quarkus.core.runtime.StoppingEvent;
 import org.apache.camel.spi.Registry;
+import org.apache.camel.support.PropertyBindingSupport;
 import org.apache.camel.support.ResourceHelper;
 import org.apache.camel.util.ObjectHelper;
 import org.graalvm.nativeimage.ImageInfo;
@@ -77,21 +79,17 @@ public class FastCamelRuntime implements CamelRuntime {
         doStop();
     }
 
+    @SuppressWarnings("unchecked")
     public void doInit() {
         try {
             this.context = createContext();
 
-            // Configure the camel context using properties in the form:
-            //
-            //     camel.context.${name} = ${value}
-            //
-            RuntimeSupport.bindProperties(properties, context, PFX_CAMEL_CONTEXT);
+            if (properties != null) {
+                PropertyBindingSupport.bindProperties(context, context, new HashMap<>((Map)properties), PFX_CAMEL_CONTEXT);
+            }
 
             context.setLoadTypeConverters(false);
-
-            PropertiesComponent pc = createPropertiesComponent(properties);
-            RuntimeSupport.bindProperties(pc.getInitialProperties(), pc, PFX_CAMEL_PROPERTIES);
-            context.addComponent("properties", pc);
+            context.addComponent("properties", createPropertiesComponent(properties));
 
             this.context.getTypeConverterRegistry().setInjector(this.context.getInjector());
             fireEvent(InitializingEvent.class, new InitializingEvent());
@@ -141,10 +139,9 @@ public class FastCamelRuntime implements CamelRuntime {
     protected void doStop() throws Exception {
         fireEvent(StoppingEvent.class, new StoppingEvent());
         context.stop();
+
         fireEvent(StoppedEvent.class, new StoppedEvent());
-        if (context instanceof ShutdownableService) {
-            ((ShutdownableService) context).shutdown();
-        }
+        context.shutdown();
     }
 
     protected void loadRoutes(CamelContext context) throws Exception {
@@ -230,11 +227,14 @@ public class FastCamelRuntime implements CamelRuntime {
         return runtimeConfig;
     }
 
-    protected PropertiesComponent createPropertiesComponent(Properties initialPoperties) {
+    @SuppressWarnings("unchecked")
+    protected PropertiesComponent createPropertiesComponent(Properties initialProperties) {
         PropertiesComponent pc = new PropertiesComponent();
-        pc.setInitialProperties(initialPoperties);
+        pc.setInitialProperties(initialProperties);
 
-        RuntimeSupport.bindProperties(properties, pc, PFX_CAMEL_PROPERTIES);
+        if (initialProperties != null) {
+            PropertyBindingSupport.bindProperties(context, pc, new HashMap<>((Map)initialProperties), PFX_CAMEL_PROPERTIES);
+        }
 
         return pc;
     }
diff --git a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/RuntimeSupport.java b/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/RuntimeSupport.java
deleted file mode 100644
index 25ecdda..0000000
--- a/extensions/core/runtime/src/main/java/org/apache/camel/quarkus/core/runtime/support/RuntimeSupport.java
+++ /dev/null
@@ -1,62 +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.quarkus.core.runtime.support;
-
-import java.util.Properties;
-
-import org.apache.camel.CamelContext;
-import org.apache.camel.support.IntrospectionSupport;
-import org.slf4j.Logger;
-import org.slf4j.LoggerFactory;
-
-public final class RuntimeSupport {
-    private static final Logger LOGGER = LoggerFactory.getLogger(RuntimeSupport.class);
-
-    private RuntimeSupport() {
-    }
-
-    public static void bindProperties(CamelContext context, Properties properties, Object target, String prefix) {
-        if (!prefix.endsWith(".")) {
-            prefix += ".";
-        }
-
-        final String p = prefix;
-
-        properties.entrySet().stream()
-                .filter(entry -> entry.getKey() instanceof String)
-                .filter(entry -> entry.getValue() != null)
-                .filter(entry -> ((String) entry.getKey()).startsWith(p))
-                .forEach(entry -> {
-                    String key = ((String) entry.getKey()).substring(p.length());
-                    Object val = entry.getValue();
-
-                    try {
-                        if (context != null && val instanceof String) {
-                            val = context.resolvePropertyPlaceholders((String) val);
-                        }
-                        IntrospectionSupport.setProperty(context, target, key, val);
-                    } catch (Exception ex) {
-                        throw new RuntimeException(ex);
-                    }
-                });
-    }
-
-    public static void bindProperties(Properties properties, Object target, String prefix) {
-        bindProperties(null, properties, target, prefix);
-    }
-
-}
diff --git a/integration-tests/aws/src/main/resources/application.properties b/integration-tests/aws/src/main/resources/application.properties
index 754f649..b40bf30 100644
--- a/integration-tests/aws/src/main/resources/application.properties
+++ b/integration-tests/aws/src/main/resources/application.properties
@@ -32,8 +32,6 @@ quarkus.camel.defer-init-phase=true
 # Camel
 #
 camel.context.name = quarkus-camel-example
-camel.component.properties.prefixToken={{
-camel.component.properties.suffixToken=}}
 
 #
 # Camel :: AWS S3
diff --git a/integration-tests/bean/src/main/resources/application.properties b/integration-tests/bean/src/main/resources/application.properties
index 9549fb6..b87f452 100644
--- a/integration-tests/bean/src/main/resources/application.properties
+++ b/integration-tests/bean/src/main/resources/application.properties
@@ -17,24 +17,18 @@
 #
 # Quarkus
 #
+quarkus.ssl.native=true
 quarkus.log.file.enable = false
 
 #
-# Camel
+# Quarkus :: Camel
 #
 quarkus.camel.disable-xml=true
 quarkus.camel.disable-jaxb=true
-
-camel.context.name=quarkus-camel-example
-
-camel.routes.dump=true
-camel.routes.defer=true
-camel.routes.locations=
-
-camel.component.properties.prefixToken={{
-camel.component.properties.suffixToken=}}
+quarkus.camel.dump-routes=true
+quarkus.camel.defer-init-phase=true
 
 #
-# Integration
+# Camel
 #
-integration.folder={{sys:folder:./target/orders}}
+camel.context.name = quarkus-camel-example
\ No newline at end of file
diff --git a/integration-tests/core-cdi/src/main/resources/application.properties b/integration-tests/core-cdi/src/main/resources/application.properties
index 9f95372..925ec45 100644
--- a/integration-tests/core-cdi/src/main/resources/application.properties
+++ b/integration-tests/core-cdi/src/main/resources/application.properties
@@ -31,8 +31,6 @@ quarkus.camel.defer-init-phase=true
 # Camel
 #
 camel.context.name = quarkus-camel-example
-camel.component.properties.prefixToken={{
-camel.component.properties.suffixToken=}}
 
 #
 # Integration
diff --git a/integration-tests/core/src/main/resources/application.properties b/integration-tests/core/src/main/resources/application.properties
index f43bb86..df1e64a 100644
--- a/integration-tests/core/src/main/resources/application.properties
+++ b/integration-tests/core/src/main/resources/application.properties
@@ -26,12 +26,11 @@ quarkus.camel.disable-xml=true
 quarkus.camel.disable-jaxb=true
 quarkus.camel.dump-routes=true
 quarkus.camel.defer-init-phase=true
+
 #
 # Camel
 #
-camel.context.name = quarkus-camel-example
-camel.component.properties.prefixToken={{
-camel.component.properties.suffixToken=}}
+camel.context.name=quarkus-camel-example
 
 #
 # Integration
diff --git a/integration-tests/jdbc/src/main/resources/application.properties b/integration-tests/jdbc/src/main/resources/application.properties
index 649ec19..f1e4300 100644
--- a/integration-tests/jdbc/src/main/resources/application.properties
+++ b/integration-tests/jdbc/src/main/resources/application.properties
@@ -38,5 +38,3 @@ quarkus.datasource.camel-ds.min-size=2
 # Camel
 #
 camel.context.name = quarkus-camel-example
-camel.component.properties.prefixToken={{
-camel.component.properties.suffixToken=}}
diff --git a/integration-tests/netty4-http/src/main/resources/application.properties b/integration-tests/netty4-http/src/main/resources/application.properties
index 9c608d1..623b297 100644
--- a/integration-tests/netty4-http/src/main/resources/application.properties
+++ b/integration-tests/netty4-http/src/main/resources/application.properties
@@ -32,8 +32,6 @@ quarkus.camel.defer-init-phase=false
 # Camel
 #
 camel.context.name = quarkus-camel-example
-camel.component.properties.prefixToken={{
-camel.component.properties.suffixToken=}}
 
 #
 # Camel :: AWS
diff --git a/integration-tests/salesforce/src/main/resources/application.properties b/integration-tests/salesforce/src/main/resources/application.properties
index 3065c01..675d16e 100644
--- a/integration-tests/salesforce/src/main/resources/application.properties
+++ b/integration-tests/salesforce/src/main/resources/application.properties
@@ -28,8 +28,6 @@ quarkus.camel.defer-init-phase=true
 # Camel
 #
 camel.context.name = quarkus-camel-example
-camel.component.properties.prefixToken={{
-camel.component.properties.suffixToken=}}
 
 #
 # Camel :: Salesforce
diff --git a/integration-tests/servlet/src/main/resources/application.properties b/integration-tests/servlet/src/main/resources/application.properties
index 071e429..01b95d1 100644
--- a/integration-tests/servlet/src/main/resources/application.properties
+++ b/integration-tests/servlet/src/main/resources/application.properties
@@ -41,5 +41,3 @@ quarkus.camel.servlet.ignored-key.url-patterns=/my-favorite-folder/*
 # Camel
 #
 camel.context.name = quarkus-camel-example
-camel.component.properties.prefixToken={{
-camel.component.properties.suffixToken=}}
diff --git a/integration-tests/twitter/src/main/resources/application.properties b/integration-tests/twitter/src/main/resources/application.properties
index 3818c7e..e013446 100644
--- a/integration-tests/twitter/src/main/resources/application.properties
+++ b/integration-tests/twitter/src/main/resources/application.properties
@@ -32,8 +32,6 @@ quarkus.camel.defer-init-phase=true
 # Camel
 #
 camel.context.name = quarkus-camel-example
-camel.component.properties.prefixToken={{
-camel.component.properties.suffixToken=}}
 
 #
 # Twitter :: User Name