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 93a01a0b7d4ca94e6696a51734e85d5297dc0a5d Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Wed Apr 22 12:08:59 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 e548eb5..ad1eab8 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 @@ -409,7 +409,21 @@ public class IAM2Producer extends DefaultProducer { } } - private void createGroup(IamClient iamClient, Exchange exchange) { + private void createGroup(IamClient iamClient, Exchange exchange) throws InvalidPayloadException { + if (getConfiguration().isPojoRequest()) { + Object payload = exchange.getIn().getMandatoryBody(); + if (payload instanceof CreateGroupRequest) { + CreateGroupResponse result; + try { + result = iamClient.createGroup((CreateGroupRequest) payload); + } catch (AwsServiceException ase) { + LOG.trace("Create Group command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } else { CreateGroupRequest.Builder builder = CreateGroupRequest.builder(); if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(IAM2Constants.GROUP_NAME))) { String groupName = exchange.getIn().getHeader(IAM2Constants.GROUP_NAME, String.class); @@ -430,9 +444,24 @@ public class IAM2Producer extends DefaultProducer { } Message message = getMessageForResponse(exchange); message.setBody(result); + } } - private void deleteGroup(IamClient iamClient, Exchange exchange) { + private void deleteGroup(IamClient iamClient, Exchange exchange) throws InvalidPayloadException { + if (getConfiguration().isPojoRequest()) { + Object payload = exchange.getIn().getMandatoryBody(); + if (payload instanceof CreateGroupRequest) { + DeleteGroupResponse result; + try { + result = iamClient.deleteGroup((DeleteGroupRequest) payload); + } catch (AwsServiceException ase) { + LOG.trace("Delete Group command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } else { DeleteGroupRequest.Builder builder = DeleteGroupRequest.builder(); if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(IAM2Constants.GROUP_NAME))) { String groupName = exchange.getIn().getHeader(IAM2Constants.GROUP_NAME, String.class); @@ -449,6 +478,7 @@ public class IAM2Producer extends DefaultProducer { } Message message = getMessageForResponse(exchange); message.setBody(result); + } } private void listGroups(IamClient iamClient, Exchange exchange) {