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 1f5e7b098f5b0f32e4dd05f7468ccd3e0a96d8ec
Author: Andrea Cosentino <anco...@gmail.com>
AuthorDate: Wed Mar 31 08:52:26 2021 +0200

    Camel-AWS2-Lambda: Producer operations refactoring - tagResource
---
 .../component/aws2/lambda/Lambda2Producer.java     | 29 ++++++++--------------
 1 file changed, 10 insertions(+), 19 deletions(-)

diff --git 
a/components/camel-aws/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java
 
b/components/camel-aws/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java
index 2b404ff..afc6bf9 100644
--- 
a/components/camel-aws/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java
+++ 
b/components/camel-aws/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java
@@ -504,43 +504,34 @@ public class Lambda2Producer extends DefaultProducer {
 
     @SuppressWarnings("unchecked")
     private void tagResource(LambdaClient lambdaClient, Exchange exchange) 
throws InvalidPayloadException {
+       TagResourceRequest request = null;
+       TagResourceResponse result;
         if (getConfiguration().isPojoRequest()) {
-            Object payload = exchange.getIn().getMandatoryBody();
-            if (payload instanceof TagResourceRequest) {
-                TagResourceResponse result;
-                try {
-                    result = lambdaClient.tagResource((TagResourceRequest) 
payload);
-                } catch (AwsServiceException ase) {
-                    LOG.trace("listTags command returned the error code {}", 
ase.awsErrorDetails().errorCode());
-                    throw ase;
-                }
-                Message message = getMessageForResponse(exchange);
-                message.setBody(result);
-            }
+            request = 
exchange.getIn().getMandatoryBody(TagResourceRequest.class);
         } else {
-            TagResourceResponse result;
-            try {
-                TagResourceRequest.Builder request = 
TagResourceRequest.builder();
+                TagResourceRequest.Builder builder = 
TagResourceRequest.builder();
                 if 
(ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.RESOURCE_ARN)))
 {
                     String resource = 
exchange.getIn().getHeader(Lambda2Constants.RESOURCE_ARN, String.class);
-                    request.resource(resource);
+                    builder.resource(resource);
                 } else {
                     throw new IllegalArgumentException("The resource ARN must 
be specified");
                 }
                 if 
(ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.RESOURCE_TAGS)))
 {
                     Map<String, String> tags = 
exchange.getIn().getHeader(Lambda2Constants.RESOURCE_TAGS, Map.class);
-                    request.tags(tags);
+                    builder.tags(tags);
                 } else {
                     throw new IllegalArgumentException("The tags must be 
specified");
                 }
-                result = lambdaClient.tagResource(request.build());
+                request = builder.build();
+        }
+        try {
+                result = lambdaClient.tagResource(request);
             } catch (AwsServiceException ase) {
                 LOG.trace("listTags command returned the error code {}", 
ase.awsErrorDetails().errorCode());
                 throw ase;
             }
             Message message = getMessageForResponse(exchange);
             message.setBody(result);
-        }
     }
 
     @SuppressWarnings("unchecked")

Reply via email to