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 2020/04/14 09:35:47 UTC

[camel] 02/10: CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-kms create key

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 aec81b8a41a50e6df1db15d98612c30d57e5034f
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Apr 14 10:41:31 2020 +0200

    CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-kms create key
---
 .../camel/component/aws2/kms/KMS2Producer.java       | 20 ++++++++++++++++++--
 1 file changed, 18 insertions(+), 2 deletions(-)

diff --git a/components/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Producer.java b/components/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Producer.java
index 46069e0..e107a00 100644
--- a/components/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Producer.java
+++ b/components/camel-aws2-kms/src/main/java/org/apache/camel/component/aws2/kms/KMS2Producer.java
@@ -18,6 +18,7 @@ package org.apache.camel.component.aws2.kms;
 
 import org.apache.camel.Endpoint;
 import org.apache.camel.Exchange;
+import org.apache.camel.InvalidPayloadException;
 import org.apache.camel.Message;
 import org.apache.camel.support.DefaultProducer;
 import org.apache.camel.util.ObjectHelper;
@@ -110,7 +111,7 @@ public class KMS2Producer extends DefaultProducer {
         return (KMS2Endpoint)super.getEndpoint();
     }
 
-    private void listKeys(KmsClient kmsClient, Exchange exchange) {
+    private void listKeys(KmsClient kmsClient, Exchange exchange) throws InvalidPayloadException {
         if (getConfiguration().isPojoRequest()) {
             Object payload = exchange.getIn().getMandatoryBody();
             if (payload instanceof ListKeysRequest) {
@@ -142,7 +143,21 @@ public class KMS2Producer extends DefaultProducer {
         }
     }
 
-    private void createKey(KmsClient kmsClient, Exchange exchange) {
+    private void createKey(KmsClient kmsClient, Exchange exchange) throws InvalidPayloadException {
+        if (getConfiguration().isPojoRequest()) {
+            Object payload = exchange.getIn().getMandatoryBody();
+            if (payload instanceof CreateKeyRequest) {
+                CreateKeyResponse result;
+                try {
+                    result = kmsClient.createKey((CreateKeyRequest) payload);
+                } catch (AwsServiceException ase) {
+                    LOG.trace("Create Key command returned the error code {}", ase.awsErrorDetails().errorCode());
+                    throw ase;
+                }
+                Message message = getMessageForResponse(exchange);
+                message.setBody(result);
+            }
+        } else {
         CreateKeyRequest.Builder builder = CreateKeyRequest.builder();
         if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(KMS2Constants.DESCRIPTION))) {
             String description = exchange.getIn().getHeader(KMS2Constants.DESCRIPTION, String.class);
@@ -157,6 +172,7 @@ public class KMS2Producer extends DefaultProducer {
         }
         Message message = getMessageForResponse(exchange);
         message.setBody(result);
+        }
     }
 
     private void disableKey(KmsClient kmsClient, Exchange exchange) {