camel-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From lburgazz...@apache.org
Subject [1/2] camel git commit: CAMEL-11729: camel-connector-maven-plugin : generated spring boot starters should support customizers
Date Tue, 05 Sep 2017 15:00:23 GMT
Repository: camel
Updated Branches:
  refs/heads/master 30baf10b7 -> bc09a41da


CAMEL-11729: camel-connector-maven-plugin : generated spring boot starters should support
customizers


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

Branch: refs/heads/master
Commit: 3a3c05bd8d8cc6b0bb9634b2e3c9adc5a6e14fa4
Parents: 30baf10
Author: lburgazzoli <lburgazzoli@gmail.com>
Authored: Fri Sep 1 12:54:45 2017 +0200
Committer: lburgazzoli <lburgazzoli@gmail.com>
Committed: Tue Sep 5 16:48:52 2017 +0200

----------------------------------------------------------------------
 .../SpringBootAutoConfigurationMojo.java        | 91 +++++++++++++++++---
 .../component/connector/ConnectorComponent.java | 13 ++-
 .../connector/ConnectorCustomizer.java          | 27 ++++++
 .../connector/DefaultConnectorComponent.java    | 37 +++++---
 ...witterMentionConnectorAutoConfiguration.java | 90 +++++++++++++++----
 ...tterMentionConnectorConfigurationCommon.java |  4 +-
 .../main/resources/camel-connector-schema.json  |  2 +-
 .../src/main/resources/camel-connector.json     |  2 +-
 ...TwitterSearchConnectorAutoConfiguration.java | 90 +++++++++++++++----
 ...itterSearchConnectorConfigurationCommon.java |  4 +-
 .../main/resources/camel-connector-schema.json  |  2 +-
 .../src/main/resources/camel-connector.json     |  2 +-
 .../java/org/foo/TwitterSearchCustomizer.java   | 38 ++++++++
 .../foo/TwitterSearchCustomizerProperties.java  | 37 ++++++++
 .../src/main/resources/application.properties   |  3 +-
 15 files changed, 366 insertions(+), 76 deletions(-)
----------------------------------------------------------------------


http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/SpringBootAutoConfigurationMojo.java
----------------------------------------------------------------------
diff --git a/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/SpringBootAutoConfigurationMojo.java
b/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/SpringBootAutoConfigurationMojo.java
index 23a2396..179d788 100644
--- a/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/SpringBootAutoConfigurationMojo.java
+++ b/connectors/camel-connector-maven-plugin/src/main/java/org/apache/camel/maven/connector/SpringBootAutoConfigurationMojo.java
@@ -58,6 +58,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean
 import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.boot.context.properties.DeprecatedConfigurationProperty;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Lazy;
@@ -270,6 +271,11 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
         final String configNameCommon = javaType.substring(pos + 1).replace("Component",
"ConnectorConfigurationCommon");
         final String configName = javaType.substring(pos + 1).replace("Component", "ConnectorConfiguration");
 
+        // add method for auto configure
+        final String shortJavaType = getShortJavaType(javaType);
+        // must be named -component because camel-spring-boot uses that to lookup components
+        final String beanName = connectorScheme + "-component";
+
         javaClass.setPackage(packageName).setName(name);
 
         String doc = "Generated by camel-connector-maven-plugin - do not edit this file!";
@@ -285,16 +291,36 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             AnnotationSource<JavaClassSource> ann = javaClass.addAnnotation(EnableConfigurationProperties.class);
             ann.setLiteralValue("value", configurationName + ".class");
 
-            javaClass.addImport("java.util.HashMap");
-            javaClass.addImport("java.util.Map");
+            javaClass.addImport(HashMap.class);
+            javaClass.addImport(Map.class);
             javaClass.addImport("org.apache.camel.util.IntrospectionSupport");
         }
 
         javaClass.addImport(javaType);
+        javaClass.addImport(ApplicationContext.class);
         javaClass.addImport(BeanCreationException.class);
+        javaClass.addImport(List.class);
+        javaClass.addImport("org.slf4j.Logger");
+        javaClass.addImport("org.slf4j.LoggerFactory");
         javaClass.addImport("org.apache.camel.CamelContext");
+        javaClass.addImport("org.apache.camel.component.connector.ConnectorCustomizer");
+        javaClass.addImport("org.apache.camel.spi.HasId");
+        javaClass.addImport("org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator");
+        javaClass.addImport("org.apache.camel.util.ObjectHelper");
 
         javaClass.addField()
+            .setPrivate()
+            .setStatic(true)
+            .setFinal(true)
+            .setName("LOGGER")
+            .setType("Logger")
+            .setLiteralInitializer("LoggerFactory.getLogger(" + name + ".class)");
+        javaClass.addField()
+            .setPrivate()
+            .setName("applicationContext")
+            .setType("ApplicationContext")
+            .addAnnotation(Autowired.class);
+        javaClass.addField()
             .setName("camelContext")
             .setType("org.apache.camel.CamelContext")
             .setPrivate()
@@ -304,16 +330,17 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             .setType(configName)
             .setPrivate()
             .addAnnotation(Autowired.class);
-
-        // add method for auto configure
-        String shortJavaType = getShortJavaType(javaType);
-        // must be named -component because camel-spring-boot uses that to lookup components
-        String beanName = connectorScheme + "-component";
+        javaClass.addField()
+            .setPrivate()
+            .setName("customizers")
+            .setType("List<ConnectorCustomizer<" + shortJavaType + ">>")
+            .addAnnotation(Autowired.class)
+            .setLiteralValue("required", "false");
 
         MethodSource<JavaClassSource> configureMethod = javaClass.addMethod()
             .setName("configure" + shortJavaType)
             .setPublic()
-            .setBody(createComponentBody(shortJavaType, hasOptions))
+            .setBody(createComponentBody(shortJavaType, hasOptions, connectorScheme.toLowerCase(Locale.US)))
             .setReturnType(shortJavaType)
             .addThrows(Exception.class);
 
@@ -325,7 +352,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
         MethodSource<JavaClassSource> postProcessMethod = javaClass.addMethod()
             .setName("postConstruct" + shortJavaType)
             .setPublic()
-            .setBody(createPostConstructBody(shortJavaType, configNameCommon));
+            .setBody(createPostConstructBody(shortJavaType, configNameCommon, connectorScheme.toLowerCase(Locale.US)));
 
 
         postProcessMethod.addAnnotation(PostConstruct.class);
@@ -368,7 +395,7 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
         }
     }
 
-    private static String createComponentBody(String shortJavaType, boolean hasOptions) {
+    private static String createComponentBody(String shortJavaType, boolean hasOptions, String
name) {
         StringBuilder sb = new StringBuilder();
         sb.append(shortJavaType).append(" connector = new ").append(shortJavaType).append("();").append("\n");
         sb.append("connector.setCamelContext(camelContext);\n");
@@ -379,14 +406,33 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
             sb.append("IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(),
connector, parameters);\n");
             sb.append("connector.setComponentOptions(parameters);\n");
         }
+        sb.append("if (ObjectHelper.isNotEmpty(customizers)) {\n");
+        sb.append("    for (ConnectorCustomizer<").append(shortJavaType).append(">
customizer : customizers) {\n");
+        sb.append("\n");
+        sb.append("        boolean useCustomizer = (customizer instanceof HasId)");
+        sb.append("            ? HierarchicalPropertiesEvaluator.evaluate(\n");
+        sb.append("                applicationContext.getEnvironment(),\n");
+        sb.append("               \"camel.connector.customizer\",\n");
+        sb.append("               \"camel.connector.").append(name).append(".customizer\",\n");
+        sb.append("               ((HasId)customizer).getId())\n");
+        sb.append("            : HierarchicalPropertiesEvaluator.evaluate(\n");
+        sb.append("                applicationContext.getEnvironment(),\n");
+        sb.append("               \"camel.connector.customizer\",\n");
+        sb.append("               \"camel.connector.").append(name).append(".customizer\");\n");
+        sb.append("\n");
+        sb.append("        if (useCustomizer) {\n");
+        sb.append("            LOGGER.debug(\"Configure connector {}, with customizer {}\",
connector, customizer);\n");
+        sb.append("            customizer.customize(connector);\n");
+        sb.append("        }\n");
+        sb.append("    }\n");
+        sb.append("}\n");
         sb.append("\n");
         sb.append("return connector;");
         return sb.toString();
     }
 
-    private static String createPostConstructBody(String shortJavaType, String commonConfigurationName)
{
+    private static String createPostConstructBody(String shortJavaType, String commonConfigurationName,
String name) {
         StringBuilder sb = new StringBuilder();
-        sb.append("if (camelContext != null) {\n");
         sb.append("Map<String, Object> parameters = new HashMap<>();\n");
         sb.append("\n");
         sb.append("for (Map.Entry<String, " + commonConfigurationName + "> entry :
configuration.getConfigurations().entrySet()) {\n");
@@ -399,13 +445,32 @@ public class SpringBootAutoConfigurationMojo extends AbstractMojo {
         sb.append("IntrospectionSupport.getProperties(entry.getValue(), parameters, null,
false);\n");
         sb.append("IntrospectionSupport.setProperties(camelContext, camelContext.getTypeConverter(),
connector, parameters);\n");
         sb.append("connector.setComponentOptions(parameters);\n");
+        sb.append("if (ObjectHelper.isNotEmpty(customizers)) {\n");
+        sb.append("    for (ConnectorCustomizer<").append(shortJavaType).append(">
customizer : customizers) {\n");
+        sb.append("\n");
+        sb.append("        boolean useCustomizer = (customizer instanceof HasId)");
+        sb.append("            ? HierarchicalPropertiesEvaluator.evaluate(\n");
+        sb.append("                applicationContext.getEnvironment(),\n");
+        sb.append("               \"camel.connector.customizer\",\n");
+        sb.append("               \"camel.connector.").append(name).append(".\" + entry.getKey()
+ \".customizer\",\n");
+        sb.append("               ((HasId)customizer).getId())\n");
+        sb.append("            : HierarchicalPropertiesEvaluator.evaluate(\n");
+        sb.append("                applicationContext.getEnvironment(),\n");
+        sb.append("               \"camel.connector.customizer\",\n");
+        sb.append("               \"camel.connector.").append(name).append(".\" + entry.getKey()
+ \".customizer\");\n");
+        sb.append("\n");
+        sb.append("        if (useCustomizer) {\n");
+        sb.append("            LOGGER.debug(\"Configure connector {}, with customizer {}\",
connector, customizer);\n");
+        sb.append("            customizer.customize(connector);\n");
+        sb.append("        }\n");
+        sb.append("    }\n");
+        sb.append("}\n");
         sb.append("\n");
         sb.append("camelContext.addComponent(entry.getKey(), connector);\n");
         sb.append("} catch (Exception e) {\n");
         sb.append("throw new BeanCreationException(entry.getKey(), e.getMessage(), e);\n");
         sb.append("}\n");
         sb.append("}\n");
-        sb.append("}\n");
         return sb.toString();
     }
 

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/ConnectorComponent.java
----------------------------------------------------------------------
diff --git a/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/ConnectorComponent.java
b/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/ConnectorComponent.java
index b25ff70..48134bb 100644
--- a/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/ConnectorComponent.java
+++ b/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/ConnectorComponent.java
@@ -27,15 +27,20 @@ import org.apache.camel.catalog.CamelCatalog;
  * A component which is based from a Camel Connector.
  */
 public interface ConnectorComponent extends Component {
-
     /**
-     * Adds a new option to the existing map of options
+     * Adds a new option to the connector's options.
      *
-     * @param options  the existing options
      * @param name     the name of the option
      * @param value    the value of the option
      */
-    void addConnectorOption(Map<String, String> options, String name, String value);
+    void addOption(String name, Object value);
+
+    /**
+     * Adds options to the connector's options.
+     *
+     * @param options  the options
+     */
+    void addOptions(Map<String, Object> options);
 
     /**
      * Creates the endpoint uri based on the options from the connector.

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/ConnectorCustomizer.java
----------------------------------------------------------------------
diff --git a/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/ConnectorCustomizer.java
b/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/ConnectorCustomizer.java
new file mode 100644
index 0000000..ddf2057
--- /dev/null
+++ b/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/ConnectorCustomizer.java
@@ -0,0 +1,27 @@
+/**
+ * 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.component.connector;
+
+@FunctionalInterface
+public interface ConnectorCustomizer<T extends ConnectorComponent> {
+    /**
+     * Customize the specified {@link ConnectorComponent}.
+     *
+     * @param connector the connector to customize
+     */
+    void customize(T connector);
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/DefaultConnectorComponent.java
----------------------------------------------------------------------
diff --git a/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/DefaultConnectorComponent.java
b/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/DefaultConnectorComponent.java
index d9f24eb..1d0c675 100644
--- a/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/DefaultConnectorComponent.java
+++ b/connectors/camel-connector/src/main/java/org/apache/camel/component/connector/DefaultConnectorComponent.java
@@ -20,7 +20,6 @@ import java.lang.reflect.Constructor;
 import java.lang.reflect.Modifier;
 import java.net.URI;
 import java.net.URISyntaxException;
-import java.util.Collections;
 import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedHashMap;
@@ -60,7 +59,7 @@ public abstract class DefaultConnectorComponent extends DefaultComponent
impleme
     private final String componentName;
     private final String componentScheme;
     private final ConnectorModel model;
-    private Map<String, Object> options;
+    private final Map<String, Object> options;
     private Processor beforeProducer;
     private Processor afterProducer;
     private Processor beforeConsumer;
@@ -71,6 +70,7 @@ public abstract class DefaultConnectorComponent extends DefaultComponent
impleme
         this.baseScheme = this.model.getBaseScheme();
         this.componentName = componentName;
         this.componentScheme = componentName + "-component";
+        this.options = new HashMap<>();
 
         // add to catalog
         this.catalog.addComponent(componentName, className);
@@ -89,6 +89,14 @@ public abstract class DefaultConnectorComponent extends DefaultComponent
impleme
         registerExtension(this::getComponentVerifierExtension);
     }
 
+    protected <T> void addConnectorOption(Map<String, T> options, String name,
T value) {
+        log.trace("Adding option: {}={}", name, value);
+        T val = options.put(name, value);
+        if (val != null) {
+            log.debug("Options {} overridden, old value was {}", name, val);
+        }
+    }
+
     @Override
     protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object>
parameters) throws Exception {
         // if we extracted any scheduler query parameters we would need to rebuild the uri
without them
@@ -136,15 +144,6 @@ public abstract class DefaultConnectorComponent extends DefaultComponent
impleme
     }
 
     @Override
-    public void addConnectorOption(Map<String, String> options, String name, String
value) {
-        log.trace("Adding option: {}={}", name, value);
-        Object val = options.put(name, value);
-        if (val != null) {
-            log.debug("Options {} overridden, old value was {}", name, val);
-        }
-    }
-
-    @Override
     public CamelCatalog getCamelCatalog() {
         return catalog;
     }
@@ -171,9 +170,19 @@ public abstract class DefaultConnectorComponent extends DefaultComponent
impleme
 
     @Override
     public void setOptions(Map<String, Object> baseComponentOptions) {
-        // Copy the map so if the given map is externally modified the connector
-        // is not impacted.
-        this.options = Collections.unmodifiableMap(new HashMap<>(baseComponentOptions));
+        this.options.clear();
+        this.options.putAll(baseComponentOptions);
+    }
+
+    @Override
+    public void addOption(String name, Object value) {
+        addConnectorOption(this.options, name, value);
+    }
+
+    @Override
+    public void addOptions(Map<String, Object> options) {
+        options.forEach((name, value)->  addConnectorOption(this.options, name, value));
+
     }
 
     @Override

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/examples/twitter-mention-connector/src/main/java/org/foo/mention/springboot/TwitterMentionConnectorAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/connectors/examples/twitter-mention-connector/src/main/java/org/foo/mention/springboot/TwitterMentionConnectorAutoConfiguration.java
b/connectors/examples/twitter-mention-connector/src/main/java/org/foo/mention/springboot/TwitterMentionConnectorAutoConfiguration.java
index c09ad0a..e7f3c02 100644
--- a/connectors/examples/twitter-mention-connector/src/main/java/org/foo/mention/springboot/TwitterMentionConnectorAutoConfiguration.java
+++ b/connectors/examples/twitter-mention-connector/src/main/java/org/foo/mention/springboot/TwitterMentionConnectorAutoConfiguration.java
@@ -17,12 +17,19 @@
 package org.foo.mention.springboot;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import javax.annotation.Generated;
 import javax.annotation.PostConstruct;
 import org.apache.camel.CamelContext;
+import org.apache.camel.component.connector.ConnectorCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
 import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
 import org.foo.mention.TwitterMentionComponent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.BeanCreationException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -30,6 +37,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Lazy;
@@ -44,10 +52,16 @@ import org.springframework.context.annotation.Lazy;
 @EnableConfigurationProperties(TwitterMentionConnectorConfiguration.class)
 public class TwitterMentionConnectorAutoConfiguration {
 
+    private static final Logger LOGGER = LoggerFactory
+            .getLogger(TwitterMentionConnectorAutoConfiguration.class);
+    @Autowired
+    private ApplicationContext applicationContext;
     @Autowired
     private CamelContext camelContext;
     @Autowired
     private TwitterMentionConnectorConfiguration configuration;
+    @Autowired(required = false)
+    private List<ConnectorCustomizer<TwitterMentionComponent>> customizers;
 
     @Lazy
     @Bean(name = "twitter-mention-component")
@@ -63,30 +77,70 @@ public class TwitterMentionConnectorAutoConfiguration {
         IntrospectionSupport.setProperties(camelContext,
                 camelContext.getTypeConverter(), connector, parameters);
         connector.setComponentOptions(parameters);
+        if (ObjectHelper.isNotEmpty(customizers)) {
+            for (ConnectorCustomizer<TwitterMentionComponent> customizer : customizers)
{
+                boolean useCustomizer = (customizer instanceof HasId)
+                        ? HierarchicalPropertiesEvaluator.evaluate(
+                                applicationContext.getEnvironment(),
+                                "camel.connector.customizer",
+                                "camel.connector.twitter-mention.customizer",
+                                ((HasId) customizer).getId())
+                        : HierarchicalPropertiesEvaluator.evaluate(
+                                applicationContext.getEnvironment(),
+                                "camel.connector.customizer",
+                                "camel.connector.twitter-mention.customizer");
+                if (useCustomizer) {
+                    LOGGER.debug("Configure connector {}, with customizer {}",
+                            connector, customizer);
+                    customizer.customize(connector);
+                }
+            }
+        }
         return connector;
     }
 
     @PostConstruct
     public void postConstructTwitterMentionComponent() {
-        if (camelContext != null) {
-            Map<String, Object> parameters = new HashMap<>();
-            for (Map.Entry<String, TwitterMentionConnectorConfigurationCommon> entry
: configuration
-                    .getConfigurations().entrySet()) {
-                parameters.clear();
-                TwitterMentionComponent connector = new TwitterMentionComponent();
-                connector.setCamelContext(camelContext);
-                try {
-                    IntrospectionSupport.getProperties(entry.getValue(),
-                            parameters, null, false);
-                    IntrospectionSupport.setProperties(camelContext,
-                            camelContext.getTypeConverter(), connector,
-                            parameters);
-                    connector.setComponentOptions(parameters);
-                    camelContext.addComponent(entry.getKey(), connector);
-                } catch (Exception e) {
-                    throw new BeanCreationException(entry.getKey(),
-                            e.getMessage(), e);
+        Map<String, Object> parameters = new HashMap<>();
+        for (Map.Entry<String, TwitterMentionConnectorConfigurationCommon> entry :
configuration
+                .getConfigurations().entrySet()) {
+            parameters.clear();
+            TwitterMentionComponent connector = new TwitterMentionComponent();
+            connector.setCamelContext(camelContext);
+            try {
+                IntrospectionSupport.getProperties(entry.getValue(),
+                        parameters, null, false);
+                IntrospectionSupport.setProperties(camelContext,
+                        camelContext.getTypeConverter(), connector, parameters);
+                connector.setComponentOptions(parameters);
+                if (ObjectHelper.isNotEmpty(customizers)) {
+                    for (ConnectorCustomizer<TwitterMentionComponent> customizer :
customizers) {
+                        boolean useCustomizer = (customizer instanceof HasId)
+                                ? HierarchicalPropertiesEvaluator.evaluate(
+                                        applicationContext.getEnvironment(),
+                                        "camel.connector.customizer",
+                                        "camel.connector.twitter-mention."
+                                                + entry.getKey()
+                                                + ".customizer",
+                                        ((HasId) customizer).getId())
+                                : HierarchicalPropertiesEvaluator.evaluate(
+                                        applicationContext.getEnvironment(),
+                                        "camel.connector.customizer",
+                                        "camel.connector.twitter-mention."
+                                                + entry.getKey()
+                                                + ".customizer");
+                        if (useCustomizer) {
+                            LOGGER.debug(
+                                    "Configure connector {}, with customizer {}",
+                                    connector, customizer);
+                            customizer.customize(connector);
+                        }
+                    }
                 }
+                camelContext.addComponent(entry.getKey(), connector);
+            } catch (Exception e) {
+                throw new BeanCreationException(entry.getKey(), e.getMessage(),
+                        e);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/examples/twitter-mention-connector/src/main/java/org/foo/mention/springboot/TwitterMentionConnectorConfigurationCommon.java
----------------------------------------------------------------------
diff --git a/connectors/examples/twitter-mention-connector/src/main/java/org/foo/mention/springboot/TwitterMentionConnectorConfigurationCommon.java
b/connectors/examples/twitter-mention-connector/src/main/java/org/foo/mention/springboot/TwitterMentionConnectorConfigurationCommon.java
index c59c980..10c70b1 100644
--- a/connectors/examples/twitter-mention-connector/src/main/java/org/foo/mention/springboot/TwitterMentionConnectorConfigurationCommon.java
+++ b/connectors/examples/twitter-mention-connector/src/main/java/org/foo/mention/springboot/TwitterMentionConnectorConfigurationCommon.java
@@ -19,8 +19,8 @@ package org.foo.mention.springboot;
 import javax.annotation.Generated;
 
 /**
- * This connector integrates with Twitter to send tweets or search for tweets
- * and more.
+ * Use twitter-directmessage twitter-search twitter-streaming and
+ * twitter-timeline instead of this connector.
  * 
  * Generated by camel-package-maven-plugin - do not edit this file!
  */

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector-schema.json
----------------------------------------------------------------------
diff --git a/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector-schema.json
b/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector-schema.json
index 1e8c895..666b3b6 100644
--- a/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector-schema.json
+++ b/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector-schema.json
@@ -7,7 +7,7 @@
     "title": "TwitterMention",
     "description": "Connection from twitter when anyone mention you",
     "label": "twitter",
-    "deprecated": false,
+    "deprecated": true,
     "async": false,
     "consumerOnly": true,
     "lenientProperties": false,

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector.json
----------------------------------------------------------------------
diff --git a/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector.json
b/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector.json
index 2ab77c2..d97831a 100644
--- a/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector.json
+++ b/connectors/examples/twitter-mention-connector/src/main/resources/camel-connector.json
@@ -2,7 +2,7 @@
   "baseScheme" : "twitter",
   "baseGroupId" : "org.apache.camel",
   "baseArtifactId" : "camel-twitter",
-  "baseVersion" : "2.20.0-SNAPSHOT",
+  "baseVersion" : "2.20.0-20170831.153623-177",
   "baseJavaType" : "org.apache.camel.component.twitter.TwitterComponent",
   "name" : "TwitterMention",
   "scheme" : "twitter-mention",

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/examples/twitter-search-connector/src/main/java/org/foo/search/springboot/TwitterSearchConnectorAutoConfiguration.java
----------------------------------------------------------------------
diff --git a/connectors/examples/twitter-search-connector/src/main/java/org/foo/search/springboot/TwitterSearchConnectorAutoConfiguration.java
b/connectors/examples/twitter-search-connector/src/main/java/org/foo/search/springboot/TwitterSearchConnectorAutoConfiguration.java
index 0a458ac..fb76779 100644
--- a/connectors/examples/twitter-search-connector/src/main/java/org/foo/search/springboot/TwitterSearchConnectorAutoConfiguration.java
+++ b/connectors/examples/twitter-search-connector/src/main/java/org/foo/search/springboot/TwitterSearchConnectorAutoConfiguration.java
@@ -17,12 +17,19 @@
 package org.foo.search.springboot;
 
 import java.util.HashMap;
+import java.util.List;
 import java.util.Map;
 import javax.annotation.Generated;
 import javax.annotation.PostConstruct;
 import org.apache.camel.CamelContext;
+import org.apache.camel.component.connector.ConnectorCustomizer;
+import org.apache.camel.spi.HasId;
+import org.apache.camel.spring.boot.util.HierarchicalPropertiesEvaluator;
 import org.apache.camel.util.IntrospectionSupport;
+import org.apache.camel.util.ObjectHelper;
 import org.foo.search.TwitterSearchComponent;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
 import org.springframework.beans.factory.BeanCreationException;
 import org.springframework.beans.factory.annotation.Autowired;
 import org.springframework.boot.autoconfigure.AutoConfigureAfter;
@@ -30,6 +37,7 @@ import org.springframework.boot.autoconfigure.condition.ConditionalOnBean;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnClass;
 import org.springframework.boot.autoconfigure.condition.ConditionalOnMissingBean;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.ApplicationContext;
 import org.springframework.context.annotation.Bean;
 import org.springframework.context.annotation.Configuration;
 import org.springframework.context.annotation.Lazy;
@@ -44,10 +52,16 @@ import org.springframework.context.annotation.Lazy;
 @EnableConfigurationProperties(TwitterSearchConnectorConfiguration.class)
 public class TwitterSearchConnectorAutoConfiguration {
 
+    private static final Logger LOGGER = LoggerFactory
+            .getLogger(TwitterSearchConnectorAutoConfiguration.class);
+    @Autowired
+    private ApplicationContext applicationContext;
     @Autowired
     private CamelContext camelContext;
     @Autowired
     private TwitterSearchConnectorConfiguration configuration;
+    @Autowired(required = false)
+    private List<ConnectorCustomizer<TwitterSearchComponent>> customizers;
 
     @Lazy
     @Bean(name = "twitter-search-component")
@@ -63,30 +77,70 @@ public class TwitterSearchConnectorAutoConfiguration {
         IntrospectionSupport.setProperties(camelContext,
                 camelContext.getTypeConverter(), connector, parameters);
         connector.setComponentOptions(parameters);
+        if (ObjectHelper.isNotEmpty(customizers)) {
+            for (ConnectorCustomizer<TwitterSearchComponent> customizer : customizers)
{
+                boolean useCustomizer = (customizer instanceof HasId)
+                        ? HierarchicalPropertiesEvaluator.evaluate(
+                                applicationContext.getEnvironment(),
+                                "camel.connector.customizer",
+                                "camel.connector.twitter-search.customizer",
+                                ((HasId) customizer).getId())
+                        : HierarchicalPropertiesEvaluator.evaluate(
+                                applicationContext.getEnvironment(),
+                                "camel.connector.customizer",
+                                "camel.connector.twitter-search.customizer");
+                if (useCustomizer) {
+                    LOGGER.debug("Configure connector {}, with customizer {}",
+                            connector, customizer);
+                    customizer.customize(connector);
+                }
+            }
+        }
         return connector;
     }
 
     @PostConstruct
     public void postConstructTwitterSearchComponent() {
-        if (camelContext != null) {
-            Map<String, Object> parameters = new HashMap<>();
-            for (Map.Entry<String, TwitterSearchConnectorConfigurationCommon> entry
: configuration
-                    .getConfigurations().entrySet()) {
-                parameters.clear();
-                TwitterSearchComponent connector = new TwitterSearchComponent();
-                connector.setCamelContext(camelContext);
-                try {
-                    IntrospectionSupport.getProperties(entry.getValue(),
-                            parameters, null, false);
-                    IntrospectionSupport.setProperties(camelContext,
-                            camelContext.getTypeConverter(), connector,
-                            parameters);
-                    connector.setComponentOptions(parameters);
-                    camelContext.addComponent(entry.getKey(), connector);
-                } catch (Exception e) {
-                    throw new BeanCreationException(entry.getKey(),
-                            e.getMessage(), e);
+        Map<String, Object> parameters = new HashMap<>();
+        for (Map.Entry<String, TwitterSearchConnectorConfigurationCommon> entry : configuration
+                .getConfigurations().entrySet()) {
+            parameters.clear();
+            TwitterSearchComponent connector = new TwitterSearchComponent();
+            connector.setCamelContext(camelContext);
+            try {
+                IntrospectionSupport.getProperties(entry.getValue(),
+                        parameters, null, false);
+                IntrospectionSupport.setProperties(camelContext,
+                        camelContext.getTypeConverter(), connector, parameters);
+                connector.setComponentOptions(parameters);
+                if (ObjectHelper.isNotEmpty(customizers)) {
+                    for (ConnectorCustomizer<TwitterSearchComponent> customizer : customizers)
{
+                        boolean useCustomizer = (customizer instanceof HasId)
+                                ? HierarchicalPropertiesEvaluator.evaluate(
+                                        applicationContext.getEnvironment(),
+                                        "camel.connector.customizer",
+                                        "camel.connector.twitter-search."
+                                                + entry.getKey()
+                                                + ".customizer",
+                                        ((HasId) customizer).getId())
+                                : HierarchicalPropertiesEvaluator.evaluate(
+                                        applicationContext.getEnvironment(),
+                                        "camel.connector.customizer",
+                                        "camel.connector.twitter-search."
+                                                + entry.getKey()
+                                                + ".customizer");
+                        if (useCustomizer) {
+                            LOGGER.debug(
+                                    "Configure connector {}, with customizer {}",
+                                    connector, customizer);
+                            customizer.customize(connector);
+                        }
+                    }
                 }
+                camelContext.addComponent(entry.getKey(), connector);
+            } catch (Exception e) {
+                throw new BeanCreationException(entry.getKey(), e.getMessage(),
+                        e);
             }
         }
     }

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/examples/twitter-search-connector/src/main/java/org/foo/search/springboot/TwitterSearchConnectorConfigurationCommon.java
----------------------------------------------------------------------
diff --git a/connectors/examples/twitter-search-connector/src/main/java/org/foo/search/springboot/TwitterSearchConnectorConfigurationCommon.java
b/connectors/examples/twitter-search-connector/src/main/java/org/foo/search/springboot/TwitterSearchConnectorConfigurationCommon.java
index fb506f6..2adcb3f 100644
--- a/connectors/examples/twitter-search-connector/src/main/java/org/foo/search/springboot/TwitterSearchConnectorConfigurationCommon.java
+++ b/connectors/examples/twitter-search-connector/src/main/java/org/foo/search/springboot/TwitterSearchConnectorConfigurationCommon.java
@@ -19,8 +19,8 @@ package org.foo.search.springboot;
 import javax.annotation.Generated;
 
 /**
- * This connector integrates with Twitter to send tweets or search for tweets
- * and more.
+ * Use twitter-directmessage twitter-search twitter-streaming and
+ * twitter-timeline instead of this connector.
  * 
  * Generated by camel-package-maven-plugin - do not edit this file!
  */

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/examples/twitter-search-connector/src/main/resources/camel-connector-schema.json
----------------------------------------------------------------------
diff --git a/connectors/examples/twitter-search-connector/src/main/resources/camel-connector-schema.json
b/connectors/examples/twitter-search-connector/src/main/resources/camel-connector-schema.json
index c870f82..60ffe74 100644
--- a/connectors/examples/twitter-search-connector/src/main/resources/camel-connector-schema.json
+++ b/connectors/examples/twitter-search-connector/src/main/resources/camel-connector-schema.json
@@ -7,7 +7,7 @@
     "title": "TwitterSearch",
     "description": "Search for twitter",
     "label": "twitter",
-    "deprecated": false,
+    "deprecated": true,
     "async": false,
     "consumerOnly": true,
     "lenientProperties": false,

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/examples/twitter-search-connector/src/main/resources/camel-connector.json
----------------------------------------------------------------------
diff --git a/connectors/examples/twitter-search-connector/src/main/resources/camel-connector.json
b/connectors/examples/twitter-search-connector/src/main/resources/camel-connector.json
index e33257c..9fcaef8 100644
--- a/connectors/examples/twitter-search-connector/src/main/resources/camel-connector.json
+++ b/connectors/examples/twitter-search-connector/src/main/resources/camel-connector.json
@@ -2,7 +2,7 @@
   "baseScheme" : "twitter",
   "baseGroupId" : "org.apache.camel",
   "baseArtifactId" : "camel-twitter",
-  "baseVersion" : "2.20.0-SNAPSHOT",
+  "baseVersion" : "2.20.0-20170831.153623-177",
   "baseJavaType" : "org.apache.camel.component.twitter.TwitterComponent",
   "name" : "TwitterSearch",
   "scheme" : "twitter-search",

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/examples/twitter-search-example/src/main/java/org/foo/TwitterSearchCustomizer.java
----------------------------------------------------------------------
diff --git a/connectors/examples/twitter-search-example/src/main/java/org/foo/TwitterSearchCustomizer.java
b/connectors/examples/twitter-search-example/src/main/java/org/foo/TwitterSearchCustomizer.java
new file mode 100644
index 0000000..2190949
--- /dev/null
+++ b/connectors/examples/twitter-search-example/src/main/java/org/foo/TwitterSearchCustomizer.java
@@ -0,0 +1,38 @@
+/**
+ * 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.foo;
+
+import org.apache.camel.component.connector.ConnectorCustomizer;
+import org.apache.camel.util.ObjectHelper;
+import org.foo.search.TwitterSearchComponent;
+import org.springframework.beans.factory.annotation.Autowired;
+import org.springframework.boot.context.properties.EnableConfigurationProperties;
+import org.springframework.context.annotation.Configuration;
+
+@Configuration
+@EnableConfigurationProperties(TwitterSearchCustomizerProperties.class)
+public class TwitterSearchCustomizer implements ConnectorCustomizer<TwitterSearchComponent>
{
+    @Autowired
+    private TwitterSearchCustomizerProperties configuration;
+
+    @Override
+    public void customize(TwitterSearchComponent component) {
+        if (ObjectHelper.isNotEmpty(configuration.getKeywords())) {
+            component.addOption("keywords", configuration.getKeywords());
+        }
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/examples/twitter-search-example/src/main/java/org/foo/TwitterSearchCustomizerProperties.java
----------------------------------------------------------------------
diff --git a/connectors/examples/twitter-search-example/src/main/java/org/foo/TwitterSearchCustomizerProperties.java
b/connectors/examples/twitter-search-example/src/main/java/org/foo/TwitterSearchCustomizerProperties.java
new file mode 100644
index 0000000..e90df62
--- /dev/null
+++ b/connectors/examples/twitter-search-example/src/main/java/org/foo/TwitterSearchCustomizerProperties.java
@@ -0,0 +1,37 @@
+/**
+ * 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.foo;
+
+import org.springframework.boot.context.properties.ConfigurationProperties;
+
+@ConfigurationProperties(prefix = "camel.connector.twitter-search.customizer")
+public class TwitterSearchCustomizerProperties {
+    /**
+     * Can be used for search and streaming/filter. Multiple values can be
+     * separated with comma.
+     */
+    private String keywords;
+
+
+    public String getKeywords() {
+        return keywords;
+    }
+
+    public void setKeywords(String keywords) {
+        this.keywords = keywords;
+    }
+}

http://git-wip-us.apache.org/repos/asf/camel/blob/3a3c05bd/connectors/examples/twitter-search-example/src/main/resources/application.properties
----------------------------------------------------------------------
diff --git a/connectors/examples/twitter-search-example/src/main/resources/application.properties
b/connectors/examples/twitter-search-example/src/main/resources/application.properties
index d8e08ea..30319b1 100644
--- a/connectors/examples/twitter-search-example/src/main/resources/application.properties
+++ b/connectors/examples/twitter-search-example/src/main/resources/application.properties
@@ -25,5 +25,6 @@ camel.connector.twitter-search.configurations.tw-search.consumer-key = NMqaca1bz
 camel.connector.twitter-search.configurations.tw-search.consumer-secret = VxNQiRLwwKVD0K9mmfxlTTbVdgRpriORypnUbHhxeQw
 camel.connector.twitter-search.configurations.tw-search.access-token = 26693234-W0YjxL9cMJrC0VZZ4xdgFMymxIQ10LeL1K8YlbBY
 camel.connector.twitter-search.configurations.tw-search.access-token-secret = BZD51BgzbOdFstWZYsqB5p5dbuuDV12vrOdatzhY4E
-camel.connector.twitter-search.configurations.tw-search.keywords = cameltest
+camel.connector.twitter-search.configurations.tw-search.keywords = camel-test
 
+camel.connector.twitter-search.customizer.keywords = cameltest
\ No newline at end of file


Mime
View raw message