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 2021/03/30 11:32:33 UTC
[camel] 03/04: Camel-AWS2-Lambda: Producer operations refactoring -
updateFunction
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 88adade06e71d3c6d341883c51d5036295843de8
Author: Andrea Cosentino <an...@gmail.com>
AuthorDate: Tue Mar 30 13:29:00 2021 +0200
Camel-AWS2-Lambda: Producer operations refactoring - updateFunction
---
.../component/aws2/lambda/Lambda2Producer.java | 31 +++++++---------------
1 file changed, 10 insertions(+), 21 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 23cbbbb..3f3ed7c 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
@@ -370,26 +370,13 @@ public class Lambda2Producer extends DefaultProducer {
}
private void updateFunction(LambdaClient lambdaClient, Exchange exchange) throws Exception {
+ UpdateFunctionCodeRequest request = null;
+ UpdateFunctionCodeResponse result;
if (getConfiguration().isPojoRequest()) {
- Object payload = exchange.getIn().getMandatoryBody();
- if (payload instanceof UpdateFunctionCodeRequest) {
- UpdateFunctionCodeResponse result;
- try {
- result = lambdaClient.updateFunctionCode((UpdateFunctionCodeRequest) payload);
- } catch (AwsServiceException ase) {
- LOG.trace("updateFunction command returned the error code {}", ase.awsErrorDetails().errorCode());
- throw ase;
- }
-
- Message message = getMessageForResponse(exchange);
- message.setBody(result);
- }
+ request = exchange.getIn().getMandatoryBody(UpdateFunctionCodeRequest.class);
} else {
- UpdateFunctionCodeResponse result;
-
- try {
- UpdateFunctionCodeRequest.Builder request
- = UpdateFunctionCodeRequest.builder().functionName(getEndpoint().getFunction());
+ UpdateFunctionCodeRequest.Builder builder = UpdateFunctionCodeRequest.builder();
+ builder.functionName(getEndpoint().getFunction());
if (ObjectHelper.isEmpty(exchange.getIn().getBody())
&& (ObjectHelper.isEmpty(exchange.getIn().getHeader(Lambda2Constants.S3_BUCKET))
@@ -399,10 +386,13 @@ public class Lambda2Producer extends DefaultProducer {
if (ObjectHelper.isNotEmpty(exchange.getIn().getHeader(Lambda2Constants.PUBLISH))) {
Boolean publish = exchange.getIn().getHeader(Lambda2Constants.PUBLISH, Boolean.class);
- request.publish(publish);
+ builder.publish(publish);
}
- result = lambdaClient.updateFunctionCode(request.build());
+ request = builder.build();
+ }
+ try {
+ result = lambdaClient.updateFunctionCode(request);
} catch (AwsServiceException ase) {
LOG.trace("updateFunction command returned the error code {}", ase.awsErrorDetails().errorCode());
@@ -411,7 +401,6 @@ public class Lambda2Producer extends DefaultProducer {
Message message = getMessageForResponse(exchange);
message.setBody(result);
- }
}
private void createEventSourceMapping(LambdaClient lambdaClient, Exchange exchange) throws InvalidPayloadException {