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 e0f95780bd3fd2dbec7015df5a9c11e8a191206c Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Wed Apr 22 12:03:15 2020 +0200 CAMEL-14868 - Camel-AWS2-*: Where possible, give the possiblity to the end user to pass an AWS Request pojo as body, aws2-iam operations --- .../camel/component/aws2/iam/IAM2Producer.java | 34 ++++++++++++++++++++-- 1 file changed, 32 insertions(+), 2 deletions(-) diff --git a/components/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Producer.java b/components/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Producer.java index 3368886..b0ccc13 100644 --- a/components/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Producer.java +++ b/components/camel-aws2-iam/src/main/java/org/apache/camel/component/aws2/iam/IAM2Producer.java @@ -199,7 +199,21 @@ public class IAM2Producer extends DefaultProducer { } } - private void deleteUser(IamClient iamClient, Exchange exchange) { + private void deleteUser(IamClient iamClient, Exchange exchange) throws InvalidPayloadException { + if (getConfiguration().isPojoRequest()) { + Object payload = exchange.getIn().getMandatoryBody(); + if (payload instanceof DeleteUserRequest) { + DeleteUserResponse result; + try { + result = iamClient.deleteUser((DeleteUserRequest) payload); + } catch (AwsServiceException ase) { + LOG.trace("Delete user command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } else { DeleteUserRequest.Builder builder = DeleteUserRequest.builder(); if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(IAM2Constants.USERNAME))) { String userName = exchange.getIn().getHeader(IAM2Constants.USERNAME, String.class); @@ -216,9 +230,24 @@ public class IAM2Producer extends DefaultProducer { } Message message = getMessageForResponse(exchange); message.setBody(result); + } } - private void getUser(IamClient iamClient, Exchange exchange) { + private void getUser(IamClient iamClient, Exchange exchange) throws InvalidPayloadException { + if (getConfiguration().isPojoRequest()) { + Object payload = exchange.getIn().getMandatoryBody(); + if (payload instanceof GetUserRequest) { + GetUserResponse result; + try { + result = iamClient.getUser((GetUserRequest) payload); + } catch (AwsServiceException ase) { + LOG.trace("get user command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } else { GetUserRequest.Builder builder = GetUserRequest.builder(); if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(IAM2Constants.USERNAME))) { String userName = exchange.getIn().getHeader(IAM2Constants.USERNAME, String.class); @@ -235,6 +264,7 @@ public class IAM2Producer extends DefaultProducer { } Message message = getMessageForResponse(exchange); message.setBody(result); + } } private void listUsers(IamClient iamClient, Exchange exchange) {