This is an automated email from the ASF dual-hosted git repository. acosentino pushed a commit to branch master in repository https://gitbox.apache.org/repos/asf/camel.git
commit 9900b76747d80a78c16d8b87506633f7aefaac81 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Fri Jul 24 15:23:52 2020 +0200 CAMEL-15310 - AWS* - Support for more than 1 client in the registry - Camel-AWS2-SES --- .../aws2/ses/Ses2ComponentConfigurer.java | 5 ++++ .../component/aws2/ses/Ses2EndpointConfigurer.java | 5 ++++ .../apache/camel/component/aws2/ses/aws2-ses.json | 2 ++ .../src/main/docs/aws2-ses-component.adoc | 6 +++-- .../camel/component/aws2/ses/Ses2Component.java | 4 ++- .../component/aws2/ses/Ses2Configuration.java | 15 +++++++++++ .../aws2/ses/SESComponentClientRegistryTest.java | 24 ++++++++++++++++++ .../dsl/Aws2SesComponentBuilderFactory.java | 16 ++++++++++++ .../builder/endpoint/StaticEndpointBuilders.java | 8 +++--- .../endpoint/dsl/Ses2EndpointBuilderFactory.java | 29 ++++++++++++++++++++++ 10 files changed, 107 insertions(+), 7 deletions(-) diff --git a/components/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2ComponentConfigurer.java b/components/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2ComponentConfigurer.java index b19847a..acf192b 100644 --- a/components/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2ComponentConfigurer.java +++ b/components/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2ComponentConfigurer.java @@ -30,6 +30,8 @@ public class Ses2ComponentConfigurer extends PropertyConfigurerSupport implement case "accessKey": getOrCreateConfiguration(target).setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazonsesclient": case "amazonSESClient": getOrCreateConfiguration(target).setAmazonSESClient(property(camelContext, software.amazon.awssdk.services.ses.SesClient.class, value)); return true; + case "autodiscoverclient": + case "autoDiscoverClient": getOrCreateConfiguration(target).setAutoDiscoverClient(property(camelContext, boolean.class, value)); return true; case "basicpropertybinding": case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true; case "configuration": target.setConfiguration(property(camelContext, org.apache.camel.component.aws2.ses.Ses2Configuration.class, value)); return true; @@ -61,6 +63,7 @@ public class Ses2ComponentConfigurer extends PropertyConfigurerSupport implement Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonSESClient", software.amazon.awssdk.services.ses.SesClient.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("configuration", org.apache.camel.component.aws2.ses.Ses2Configuration.class); answer.put("lazyStartProducer", boolean.class); @@ -85,6 +88,8 @@ public class Ses2ComponentConfigurer extends PropertyConfigurerSupport implement case "accessKey": return getOrCreateConfiguration(target).getAccessKey(); case "amazonsesclient": case "amazonSESClient": return getOrCreateConfiguration(target).getAmazonSESClient(); + case "autodiscoverclient": + case "autoDiscoverClient": return getOrCreateConfiguration(target).isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "configuration": return target.getConfiguration(); diff --git a/components/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2EndpointConfigurer.java b/components/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2EndpointConfigurer.java index 8f6d8b0..d59b519 100644 --- a/components/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2EndpointConfigurer.java +++ b/components/camel-aws2-ses/src/generated/java/org/apache/camel/component/aws2/ses/Ses2EndpointConfigurer.java @@ -23,6 +23,8 @@ public class Ses2EndpointConfigurer extends PropertyConfigurerSupport implements case "accessKey": target.getConfiguration().setAccessKey(property(camelContext, java.lang.String.class, value)); return true; case "amazonsesclient": case "amazonSESClient": target.getConfiguration().setAmazonSESClient(property(camelContext, software.amazon.awssdk.services.ses.SesClient.class, value)); return true; + case "autodiscoverclient": + case "autoDiscoverClient": target.getConfiguration().setAutoDiscoverClient(property(camelContext, boolean.class, value)); return true; case "basicpropertybinding": case "basicPropertyBinding": target.setBasicPropertyBinding(property(camelContext, boolean.class, value)); return true; case "lazystartproducer": @@ -54,6 +56,7 @@ public class Ses2EndpointConfigurer extends PropertyConfigurerSupport implements Map<String, Object> answer = new CaseInsensitiveMap(); answer.put("accessKey", java.lang.String.class); answer.put("amazonSESClient", software.amazon.awssdk.services.ses.SesClient.class); + answer.put("autoDiscoverClient", boolean.class); answer.put("basicPropertyBinding", boolean.class); answer.put("lazyStartProducer", boolean.class); answer.put("proxyHost", java.lang.String.class); @@ -78,6 +81,8 @@ public class Ses2EndpointConfigurer extends PropertyConfigurerSupport implements case "accessKey": return target.getConfiguration().getAccessKey(); case "amazonsesclient": case "amazonSESClient": return target.getConfiguration().getAmazonSESClient(); + case "autodiscoverclient": + case "autoDiscoverClient": return target.getConfiguration().isAutoDiscoverClient(); case "basicpropertybinding": case "basicPropertyBinding": return target.isBasicPropertyBinding(); case "lazystartproducer": diff --git a/components/camel-aws2-ses/src/generated/resources/org/apache/camel/component/aws2/ses/aws2-ses.json b/components/camel-aws2-ses/src/generated/resources/org/apache/camel/component/aws2/ses/aws2-ses.json index e0aa89c..45e536c 100644 --- a/components/camel-aws2-ses/src/generated/resources/org/apache/camel/component/aws2/ses/aws2-ses.json +++ b/components/camel-aws2-ses/src/generated/resources/org/apache/camel/component/aws2/ses/aws2-ses.json @@ -22,6 +22,7 @@ }, "componentProperties": { "amazonSESClient": { "kind": "property", "displayName": "Amazon SESClient", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.ses.SesClient", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ses.Ses2Configuration", "configurationField": "configuration", "description": "To use the AmazonSimpleEmailService as the client" }, + "autoDiscoverClient": { "kind": "property", "displayName": "Auto Discover Client", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "true", "configurationClass": "org.apache.camel.component.aws2.ses.Ses2Configuration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the regist [...] "configuration": { "kind": "property", "displayName": "Configuration", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "org.apache.camel.component.aws2.ses.Ses2Configuration", "deprecated": false, "secret": false, "description": "component configuration" }, "lazyStartProducer": { "kind": "property", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the r [...] "proxyHost": { "kind": "property", "displayName": "Proxy Host", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ses.Ses2Configuration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the SES client" }, @@ -40,6 +41,7 @@ "properties": { "from": { "kind": "path", "displayName": "From", "group": "producer", "label": "", "required": true, "type": "string", "javaType": "java.lang.String", "deprecated": false, "deprecationNote": "", "secret": false, "configurationClass": "org.apache.camel.component.aws2.ses.Ses2Configuration", "configurationField": "configuration", "description": "The sender's email address." }, "amazonSESClient": { "kind": "parameter", "displayName": "Amazon SESClient", "group": "producer", "label": "", "required": false, "type": "object", "javaType": "software.amazon.awssdk.services.ses.SesClient", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ses.Ses2Configuration", "configurationField": "configuration", "description": "To use the AmazonSimpleEmailService as the client" }, + "autoDiscoverClient": { "kind": "parameter", "displayName": "Auto Discover Client", "group": "common", "label": "common", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": "true", "configurationClass": "org.apache.camel.component.aws2.ses.Ses2Configuration", "configurationField": "configuration", "description": "Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the regis [...] "lazyStartProducer": { "kind": "parameter", "displayName": "Lazy Start Producer", "group": "producer", "label": "producer", "required": false, "type": "boolean", "javaType": "boolean", "deprecated": false, "secret": false, "defaultValue": false, "description": "Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the [...] "proxyHost": { "kind": "parameter", "displayName": "Proxy Host", "group": "producer", "label": "", "required": false, "type": "string", "javaType": "java.lang.String", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ses.Ses2Configuration", "configurationField": "configuration", "description": "To define a proxy host when instantiating the SES client" }, "proxyPort": { "kind": "parameter", "displayName": "Proxy Port", "group": "producer", "label": "", "required": false, "type": "integer", "javaType": "java.lang.Integer", "deprecated": false, "secret": false, "configurationClass": "org.apache.camel.component.aws2.ses.Ses2Configuration", "configurationField": "configuration", "description": "To define a proxy port when instantiating the SES client" }, diff --git a/components/camel-aws2-ses/src/main/docs/aws2-ses-component.adoc b/components/camel-aws2-ses/src/main/docs/aws2-ses-component.adoc index bbbc155..3e60258 100644 --- a/components/camel-aws2-ses/src/main/docs/aws2-ses-component.adoc +++ b/components/camel-aws2-ses/src/main/docs/aws2-ses-component.adoc @@ -36,7 +36,7 @@ You can append query options to the URI in the following format, // component options: START -The AWS 2 Simple Email Service (SES) component supports 15 options, which are listed below. +The AWS 2 Simple Email Service (SES) component supports 16 options, which are listed below. @@ -44,6 +44,7 @@ The AWS 2 Simple Email Service (SES) component supports 15 options, which are li |=== | Name | Description | Default | Type | *amazonSESClient* (producer) | To use the AmazonSimpleEmailService as the client | | SesClient +| *autoDiscoverClient* (common) | Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry automatically otherwise it will skip that checking. | true | boolean | *configuration* (producer) | component configuration | | Ses2Configuration | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] | *proxyHost* (producer) | To define a proxy host when instantiating the SES client | | String @@ -83,13 +84,14 @@ with the following path and query parameters: |=== -=== Query Parameters (15 parameters): +=== Query Parameters (16 parameters): [width="100%",cols="2,5,^1,2",options="header"] |=== | Name | Description | Default | Type | *amazonSESClient* (producer) | To use the AmazonSimpleEmailService as the client | | SesClient +| *autoDiscoverClient* (common) | Setting the autoDiscoverClient mechanism, if true, the component will look for a client instance in the registry automatically otherwise it will skip that checking. | true | boolean | *lazyStartProducer* (producer) | Whether the producer should be started lazy (on the first message). By starting lazy you can use this to allow CamelContext and routes to startup in situations where a producer may otherwise fail during starting and cause the route to fail being started. By deferring this startup to be lazy then the startup failure can be handled during routing messages via Camel's routing error handlers. Beware that when the first message is processed then creating and [...] | *proxyHost* (producer) | To define a proxy host when instantiating the SES client | | String | *proxyPort* (producer) | To define a proxy port when instantiating the SES client | | Integer diff --git a/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.java b/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.java index 0ebcb70..7590bc2 100644 --- a/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.java +++ b/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Component.java @@ -60,7 +60,9 @@ public class Ses2Component extends DefaultComponent { configuration.setFrom(remaining); Ses2Endpoint endpoint = new Ses2Endpoint(uri, this, configuration); setProperties(endpoint, parameters); - checkAndSetRegistryClient(configuration, endpoint); + if (endpoint.getConfiguration().isAutoDiscoverClient()) { + checkAndSetRegistryClient(configuration, endpoint); + } if (configuration.getAmazonSESClient() == null && (configuration.getAccessKey() == null || configuration.getSecretKey() == null)) { throw new IllegalArgumentException("AmazonSESClient or accessKey and secretKey must be specified"); } diff --git a/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Configuration.java b/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Configuration.java index fc7b8ab..780e4e2 100644 --- a/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Configuration.java +++ b/components/camel-aws2-ses/src/main/java/org/apache/camel/component/aws2/ses/Ses2Configuration.java @@ -57,6 +57,8 @@ public class Ses2Configuration implements Cloneable { private String region; @UriParam(defaultValue = "false") private boolean trustAllCertificates; + @UriParam(label = "common", defaultValue = "true") + private boolean autoDiscoverClient = true; public String getAccessKey() { return accessKey; @@ -219,6 +221,19 @@ public class Ses2Configuration implements Cloneable { public void setTrustAllCertificates(boolean trustAllCertificates) { this.trustAllCertificates = trustAllCertificates; } + + public boolean isAutoDiscoverClient() { + return autoDiscoverClient; + } + + /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + */ + public void setAutoDiscoverClient(boolean autoDiscoverClient) { + this.autoDiscoverClient = autoDiscoverClient; + } // ************************************************* // diff --git a/components/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/SESComponentClientRegistryTest.java b/components/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/SESComponentClientRegistryTest.java index caabaf9..2c3e391 100644 --- a/components/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/SESComponentClientRegistryTest.java +++ b/components/camel-aws2-ses/src/test/java/org/apache/camel/component/aws2/ses/SESComponentClientRegistryTest.java @@ -20,6 +20,8 @@ import org.apache.camel.test.junit5.CamelTestSupport; import org.junit.jupiter.api.Test; import static org.junit.jupiter.api.Assertions.assertNotNull; +import static org.junit.jupiter.api.Assertions.assertNotSame; +import static org.junit.jupiter.api.Assertions.assertSame; import static org.junit.jupiter.api.Assertions.assertThrows; public class SESComponentClientRegistryTest extends CamelTestSupport { @@ -45,4 +47,26 @@ public class SESComponentClientRegistryTest extends CamelTestSupport { }); component.close(); } + + @Test + public void createEndpointWithAutoDiscoverClientFalse() throws Exception { + + AmazonSESClientMock awsSESClient = new AmazonSESClientMock(); + context.getRegistry().bind("awsSesClient", awsSESClient); + Ses2Component component = context.getComponent("aws2-ses", Ses2Component.class); + Ses2Endpoint endpoint = (Ses2Endpoint) component.createEndpoint("aws2-ses://f...@example.com?accessKey=xxx&secretKey=yyy&autoDiscoverClient=false"); + + assertNotSame(awsSESClient, endpoint.getConfiguration().getAmazonSESClient()); + } + + @Test + public void createEndpointWithAutoDiscoverClientTrue() throws Exception { + + AmazonSESClientMock awsSESClient = new AmazonSESClientMock(); + context.getRegistry().bind("awsSesClient", awsSESClient); + Ses2Component component = context.getComponent("aws2-ses", Ses2Component.class); + Ses2Endpoint endpoint = (Ses2Endpoint) component.createEndpoint("aws2-ses://f...@example.com?accessKey=xxx&secretKey=yyy"); + + assertSame(awsSESClient, endpoint.getConfiguration().getAmazonSESClient()); + } } diff --git a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2SesComponentBuilderFactory.java b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2SesComponentBuilderFactory.java index 73d6170..b43c9d2 100644 --- a/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2SesComponentBuilderFactory.java +++ b/core/camel-componentdsl/src/generated/java/org/apache/camel/builder/component/dsl/Aws2SesComponentBuilderFactory.java @@ -60,6 +60,21 @@ public interface Aws2SesComponentBuilderFactory { return this; } /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default Aws2SesComponentBuilder autoDiscoverClient( + boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * component configuration. * * The option is a: @@ -268,6 +283,7 @@ public interface Aws2SesComponentBuilderFactory { Object value) { switch (name) { case "amazonSESClient": getOrCreateConfiguration((Ses2Component) component).setAmazonSESClient((software.amazon.awssdk.services.ses.SesClient) value); return true; + case "autoDiscoverClient": getOrCreateConfiguration((Ses2Component) component).setAutoDiscoverClient((boolean) value); return true; case "configuration": ((Ses2Component) component).setConfiguration((org.apache.camel.component.aws2.ses.Ses2Configuration) value); return true; case "lazyStartProducer": ((Ses2Component) component).setLazyStartProducer((boolean) value); return true; case "proxyHost": getOrCreateConfiguration((Ses2Component) component).setProxyHost((java.lang.String) value); return true; diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java index ec4c1e7..42f252a 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/StaticEndpointBuilders.java @@ -1459,7 +1459,7 @@ public class StaticEndpointBuilders { * * @param path from */ - public static org.apache.camel.builder.endpoint.dsl.Ses2EndpointBuilderFactory.Ses2EndpointBuilder aws2Ses( + static org.apache.camel.builder.endpoint.dsl.Ses2EndpointBuilderFactory.Ses2EndpointBuilder aws2Ses( String path) { return org.apache.camel.builder.endpoint.dsl.Ses2EndpointBuilderFactory.endpointBuilder("aws2-ses", path); } @@ -1480,7 +1480,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path from */ - public static org.apache.camel.builder.endpoint.dsl.Ses2EndpointBuilderFactory.Ses2EndpointBuilder aws2Ses( + static org.apache.camel.builder.endpoint.dsl.Ses2EndpointBuilderFactory.Ses2EndpointBuilder aws2Ses( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.Ses2EndpointBuilderFactory.endpointBuilder(componentName, path); @@ -2242,7 +2242,7 @@ public class StaticEndpointBuilders { * * @param path from */ - static org.apache.camel.builder.endpoint.dsl.SesEndpointBuilderFactory.SesEndpointBuilder awsSes( + public static org.apache.camel.builder.endpoint.dsl.SesEndpointBuilderFactory.SesEndpointBuilder awsSes( String path) { return org.apache.camel.builder.endpoint.dsl.SesEndpointBuilderFactory.endpointBuilder("aws-ses", path); } @@ -2263,7 +2263,7 @@ public class StaticEndpointBuilders { * instead of the default name * @param path from */ - static org.apache.camel.builder.endpoint.dsl.SesEndpointBuilderFactory.SesEndpointBuilder awsSes( + public static org.apache.camel.builder.endpoint.dsl.SesEndpointBuilderFactory.SesEndpointBuilder awsSes( String componentName, String path) { return org.apache.camel.builder.endpoint.dsl.SesEndpointBuilderFactory.endpointBuilder(componentName, path); diff --git a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Ses2EndpointBuilderFactory.java b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Ses2EndpointBuilderFactory.java index 6356b37..6165cc8 100644 --- a/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Ses2EndpointBuilderFactory.java +++ b/core/camel-endpointdsl/src/generated/java/org/apache/camel/builder/endpoint/dsl/Ses2EndpointBuilderFactory.java @@ -63,6 +63,35 @@ public interface Ses2EndpointBuilderFactory { return this; } /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option is a: <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default Ses2EndpointBuilder autoDiscoverClient( + boolean autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** + * Setting the autoDiscoverClient mechanism, if true, the component will + * look for a client instance in the registry automatically otherwise it + * will skip that checking. + * + * The option will be converted to a <code>boolean</code> type. + * + * Default: true + * Group: common + */ + default Ses2EndpointBuilder autoDiscoverClient(String autoDiscoverClient) { + doSetProperty("autoDiscoverClient", autoDiscoverClient); + return this; + } + /** * Whether the producer should be started lazy (on the first message). * By starting lazy you can use this to allow CamelContext and routes to * startup in situations where a producer may otherwise fail during