You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@camel.apache.org by ac...@apache.org on 2017/11/20 13:25:10 UTC
[camel] branch master updated: CAMEL-12012 - Camel-AWS: Add
component verifiers like S3 for all the AWS components - SES component
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
The following commit(s) were added to refs/heads/master by this push:
new 318b4fe CAMEL-12012 - Camel-AWS: Add component verifiers like S3 for all the AWS components - SES component
318b4fe is described below
commit 318b4fe10b8652d4872b37eac2ceaada6c862294
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Mon Nov 20 14:14:08 2017 +0100
CAMEL-12012 - Camel-AWS: Add component verifiers like S3 for all the AWS components - SES component
---
.../camel/component/aws/ses/SesComponent.java | 10 ++-
.../aws/ses/SesComponentVerifierExtension.java | 86 ++++++++++++++++++++++
.../aws/sdb/SdbComponentVerifierExtensionTest.java | 2 -
.../SesComponentVerifierExtensionTest.java} | 14 ++--
4 files changed, 98 insertions(+), 14 deletions(-)
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java
index d330533..9cf4be9 100644
--- a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponent.java
@@ -20,16 +20,18 @@ import java.util.Map;
import org.apache.camel.CamelContext;
import org.apache.camel.Endpoint;
-import org.apache.camel.impl.UriEndpointComponent;
+import org.apache.camel.impl.DefaultComponent;
-public class SesComponent extends UriEndpointComponent {
+public class SesComponent extends DefaultComponent {
public SesComponent() {
- super(SesEndpoint.class);
+ this(null);
}
public SesComponent(CamelContext context) {
- super(context, SesEndpoint.class);
+ super(context);
+
+ registerExtension(new SesComponentVerifierExtension());
}
protected Endpoint createEndpoint(String uri, String remaining, Map<String, Object> parameters) throws Exception {
diff --git a/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponentVerifierExtension.java b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponentVerifierExtension.java
new file mode 100644
index 0000000..c028a2c
--- /dev/null
+++ b/components/camel-aws/src/main/java/org/apache/camel/component/aws/ses/SesComponentVerifierExtension.java
@@ -0,0 +1,86 @@
+/**
+ * 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.aws.ses;
+
+import java.util.Map;
+
+import com.amazonaws.SdkClientException;
+import com.amazonaws.auth.AWSCredentials;
+import com.amazonaws.auth.AWSCredentialsProvider;
+import com.amazonaws.auth.AWSStaticCredentialsProvider;
+import com.amazonaws.auth.BasicAWSCredentials;
+import com.amazonaws.services.simpleemail.AmazonSimpleEmailService;
+import com.amazonaws.services.simpleemail.AmazonSimpleEmailServiceClientBuilder;
+
+import org.apache.camel.component.extension.verifier.DefaultComponentVerifierExtension;
+import org.apache.camel.component.extension.verifier.ResultBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorBuilder;
+import org.apache.camel.component.extension.verifier.ResultErrorHelper;
+
+public class SesComponentVerifierExtension extends DefaultComponentVerifierExtension {
+
+ public SesComponentVerifierExtension() {
+ this("aws-ses");
+ }
+
+ public SesComponentVerifierExtension(String scheme) {
+ super(scheme);
+ }
+
+ // *********************************
+ // Parameters validation
+ // *********************************
+
+ @Override
+ protected Result verifyParameters(Map<String, Object> parameters) {
+
+ ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.PARAMETERS).error(ResultErrorHelper.requiresOption("accessKey", parameters))
+ .error(ResultErrorHelper.requiresOption("secretKey", parameters)).error(ResultErrorHelper.requiresOption("region", parameters));
+
+ // Validate using the catalog
+
+ super.verifyParametersAgainstCatalog(builder, parameters);
+
+ return builder.build();
+ }
+
+ // *********************************
+ // Connectivity validation
+ // *********************************
+
+ @Override
+ protected Result verifyConnectivity(Map<String, Object> parameters) {
+ ResultBuilder builder = ResultBuilder.withStatusAndScope(Result.Status.OK, Scope.CONNECTIVITY);
+
+ try {
+ SesConfiguration configuration = setProperties(new SesConfiguration(), parameters);
+ AWSCredentials credentials = new BasicAWSCredentials(configuration.getAccessKey(), configuration.getSecretKey());
+ AWSCredentialsProvider credentialsProvider = new AWSStaticCredentialsProvider(credentials);
+ AmazonSimpleEmailService client = AmazonSimpleEmailServiceClientBuilder.standard().withCredentials(credentialsProvider).withRegion(configuration.getRegion()).build();
+ client.getSendStatistics();
+ } catch (SdkClientException e) {
+ ResultErrorBuilder errorBuilder = ResultErrorBuilder.withCodeAndDescription(VerificationError.StandardCode.AUTHENTICATION, e.getMessage())
+ .detail("aws_ses_exception_message", e.getMessage()).detail(VerificationError.ExceptionAttribute.EXCEPTION_CLASS, e.getClass().getName())
+ .detail(VerificationError.ExceptionAttribute.EXCEPTION_INSTANCE, e);
+
+ builder.error(errorBuilder.build());
+ } catch (Exception e) {
+ builder.error(ResultErrorBuilder.withException(e).build());
+ }
+ return builder.build();
+ }
+}
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentVerifierExtensionTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentVerifierExtensionTest.java
index 1799fa0..e3e2512 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentVerifierExtensionTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentVerifierExtensionTest.java
@@ -19,8 +19,6 @@ package org.apache.camel.component.aws.sdb;
import java.util.HashMap;
import java.util.Map;
-import com.amazonaws.regions.Regions;
-
import org.apache.camel.Component;
import org.apache.camel.component.extension.ComponentVerifierExtension;
import org.apache.camel.test.junit4.CamelTestSupport;
diff --git a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentVerifierExtensionTest.java b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentVerifierExtensionTest.java
similarity index 87%
copy from components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentVerifierExtensionTest.java
copy to components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentVerifierExtensionTest.java
index 1799fa0..a08d3f8 100644
--- a/components/camel-aws/src/test/java/org/apache/camel/component/aws/sdb/SdbComponentVerifierExtensionTest.java
+++ b/components/camel-aws/src/test/java/org/apache/camel/component/aws/ses/SesComponentVerifierExtensionTest.java
@@ -14,20 +14,18 @@
* See the License for the specific language governing permissions and
* limitations under the License.
*/
-package org.apache.camel.component.aws.sdb;
+package org.apache.camel.component.aws.ses;
import java.util.HashMap;
import java.util.Map;
-import com.amazonaws.regions.Regions;
-
import org.apache.camel.Component;
import org.apache.camel.component.extension.ComponentVerifierExtension;
import org.apache.camel.test.junit4.CamelTestSupport;
import org.junit.Assert;
import org.junit.Test;
-public class SdbComponentVerifierExtensionTest extends CamelTestSupport {
+public class SesComponentVerifierExtensionTest extends CamelTestSupport {
// *************************************************
// Tests (parameters)
@@ -39,7 +37,7 @@ public class SdbComponentVerifierExtensionTest extends CamelTestSupport {
@Test
public void testParameters() throws Exception {
- Component component = context().getComponent("aws-sdb");
+ Component component = context().getComponent("aws-ses");
ComponentVerifierExtension verifier = component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new);
@@ -47,7 +45,7 @@ public class SdbComponentVerifierExtensionTest extends CamelTestSupport {
parameters.put("secretKey", "l");
parameters.put("accessKey", "k");
parameters.put("region", "l");
- parameters.put("domainName", "domain1");
+ parameters.put("from", "test@test.com");
ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.PARAMETERS, parameters);
@@ -56,14 +54,14 @@ public class SdbComponentVerifierExtensionTest extends CamelTestSupport {
@Test
public void testConnectivity() throws Exception {
- Component component = context().getComponent("aws-sdb");
+ Component component = context().getComponent("aws-ses");
ComponentVerifierExtension verifier = component.getExtension(ComponentVerifierExtension.class).orElseThrow(IllegalStateException::new);
Map<String, Object> parameters = new HashMap<>();
parameters.put("secretKey", "l");
parameters.put("accessKey", "k");
parameters.put("region", "us-east-1");
- parameters.put("domainName", "domain1");
+ parameters.put("from", "test@test.com");
ComponentVerifierExtension.Result result = verifier.verify(ComponentVerifierExtension.Scope.CONNECTIVITY, parameters);
--
To stop receiving notification emails like this one, please contact
['"commits@camel.apache.org" <co...@camel.apache.org>'].