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 7b2cf4468ec1439ffffd2f0b29a843891614a0d2 Author: Andrea Cosentino <anco...@gmail.com> AuthorDate: Mon Apr 20 12:13: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-lambda get function --- .../component/aws2/lambda/Lambda2Configuration.java | 13 +++++++++++++ .../camel/component/aws2/lambda/Lambda2Producer.java | 18 +++++++++++++++++- 2 files changed, 30 insertions(+), 1 deletion(-) diff --git a/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Configuration.java b/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Configuration.java index e42b1dd..b08350b 100644 --- a/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Configuration.java +++ b/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Configuration.java @@ -41,6 +41,8 @@ public class Lambda2Configuration implements Cloneable { private Integer proxyPort; @UriParam(label = "advanced") private LambdaClient awsLambdaClient; + @UriParam(defaultValue = "false") + private boolean pojoRequest; public LambdaClient getAwsLambdaClient() { return awsLambdaClient; @@ -133,6 +135,17 @@ public class Lambda2Configuration implements Cloneable { public void setProxyPort(Integer proxyPort) { this.proxyPort = proxyPort; } + + public boolean isPojoRequest() { + return pojoRequest; + } + + /** + * If we want to use a POJO request as body or not + */ + public void setPojoRequest(boolean pojoRequest) { + this.pojoRequest = pojoRequest; + } // ************************************************* // diff --git a/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java b/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java index 451e22b..eea5375 100644 --- a/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java +++ b/components/camel-aws2-lambda/src/main/java/org/apache/camel/component/aws2/lambda/Lambda2Producer.java @@ -25,6 +25,7 @@ import java.util.Map; 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.CastUtils; @@ -149,7 +150,21 @@ public class Lambda2Producer extends DefaultProducer { } } - private void getFunction(LambdaClient lambdaClient, Exchange exchange) { + private void getFunction(LambdaClient lambdaClient, Exchange exchange) throws InvalidPayloadException { + if (getConfiguration().isPojoRequest()) { + Object payload = exchange.getIn().getMandatoryBody(); + if (payload instanceof GetFunctionRequest) { + GetFunctionResponse result; + try { + result = lambdaClient.getFunction((GetFunctionRequest) payload); + } catch (AwsServiceException ase) { + LOG.trace("getFunction command returned the error code {}", ase.awsErrorDetails().errorCode()); + throw ase; + } + Message message = getMessageForResponse(exchange); + message.setBody(result); + } + } else { GetFunctionResponse result; try { result = lambdaClient.getFunction(GetFunctionRequest.builder().functionName(getEndpoint().getFunction()).build()); @@ -159,6 +174,7 @@ public class Lambda2Producer extends DefaultProducer { } Message message = getMessageForResponse(exchange); message.setBody(result); + } } private void deleteFunction(LambdaClient lambdaClient, Exchange exchange) {