diff --git a/extensions/amazon-lambda/common-runtime/pom.xml b/extensions/amazon-lambda/common-runtime/pom.xml index 0bbbafd5157be..a4d201dc27e56 100644 --- a/extensions/amazon-lambda/common-runtime/pom.xml +++ b/extensions/amazon-lambda/common-runtime/pom.xml @@ -46,6 +46,11 @@ com.fasterxml.jackson.datatype jackson-datatype-joda + + org.junit.jupiter + junit-jupiter + test + diff --git a/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaMapperRecorder.java b/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaMapperRecorder.java index 884fb85b3dea6..4cca67d5cb778 100644 --- a/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaMapperRecorder.java +++ b/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaMapperRecorder.java @@ -2,7 +2,6 @@ import org.jboss.logging.Logger; -import com.amazonaws.services.lambda.runtime.ClientContext; import com.amazonaws.services.lambda.runtime.CognitoIdentity; import com.fasterxml.jackson.databind.DeserializationFeature; import com.fasterxml.jackson.databind.MapperFeature; @@ -30,7 +29,7 @@ public void initObjectMapper() { public void initContextReaders() { cognitoIdReader = objectMapper.readerFor(CognitoIdentity.class); - clientCtxReader = objectMapper.readerFor(ClientContext.class); + clientCtxReader = objectMapper.readerFor(ClientContextImpl.class); } diff --git a/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/ClientContextImpl.java b/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/ClientContextImpl.java new file mode 100644 index 0000000000000..bbb3dd42495d3 --- /dev/null +++ b/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/ClientContextImpl.java @@ -0,0 +1,63 @@ +package io.quarkus.amazon.lambda.runtime; + +import java.util.Map; + +import com.amazonaws.services.lambda.runtime.Client; +import com.amazonaws.services.lambda.runtime.ClientContext; +import com.fasterxml.jackson.annotation.JsonGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonSetter; + +public class ClientContextImpl implements ClientContext { + private ClientImpl impl; + private Map cust; + private Map env; + + @JsonGetter("client") + public ClientImpl getImpl() { + return impl; + } + + @JsonSetter("client") + public void setImpl(ClientImpl impl) { + this.impl = impl; + } + + @JsonGetter("custom") + public Map getCust() { + return cust; + } + + @JsonSetter("custom") + public void setCust(Map cust) { + this.cust = cust; + } + + @JsonGetter("env") + public Map getEnv() { + return env; + } + + @JsonSetter("env") + public void setEnv(Map env) { + this.env = env; + } + + @Override + @JsonIgnore + public Client getClient() { + return impl; + } + + @Override + @JsonIgnore + public Map getCustom() { + return cust; + } + + @Override + @JsonIgnore + public Map getEnvironment() { + return env; + } +} diff --git a/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/ClientImpl.java b/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/ClientImpl.java new file mode 100644 index 0000000000000..b68b2831121e7 --- /dev/null +++ b/extensions/amazon-lambda/common-runtime/src/main/java/io/quarkus/amazon/lambda/runtime/ClientImpl.java @@ -0,0 +1,94 @@ +package io.quarkus.amazon.lambda.runtime; + +import com.amazonaws.services.lambda.runtime.Client; +import com.fasterxml.jackson.annotation.JsonGetter; +import com.fasterxml.jackson.annotation.JsonIgnore; +import com.fasterxml.jackson.annotation.JsonSetter; + +public class ClientImpl implements Client { + private String id; + private String title; + private String versionName; + private String versionCode; + private String packageName; + + @JsonGetter("client_id") + public String getId() { + return id; + } + + @JsonSetter("client_id") + public void setId(String id) { + this.id = id; + } + + @JsonGetter("app_title") + public String getTitle() { + return title; + } + + @JsonSetter("app_title") + public void setTitle(String title) { + this.title = title; + } + + @JsonGetter("app_version_name") + public String getVersionName() { + return versionName; + } + + @JsonSetter("app_version_name") + public void setVersionName(String versionName) { + this.versionName = versionName; + } + + @JsonGetter("app_version_code") + public String getVersionCode() { + return versionCode; + } + + @JsonSetter("app_version_code") + public void setVersionCode(String versionCode) { + this.versionCode = versionCode; + } + + @JsonGetter("app_package_name") + public String getPackageName() { + return packageName; + } + + @JsonSetter("app_package_name") + public void setPackageName(String packageName) { + this.packageName = packageName; + } + + @Override + @JsonIgnore + public String getInstallationId() { + return id; + } + + @Override + @JsonIgnore + public String getAppTitle() { + return title; + } + + @Override + @JsonIgnore + public String getAppVersionName() { + return versionName; + } + + @Override + @JsonIgnore + public String getAppVersionCode() { + return versionCode; + } + + @Override + @JsonIgnore + public String getAppPackageName() { + return packageName; + } +} diff --git a/extensions/amazon-lambda/common-runtime/src/test/java/io/quarkus/amazon/lambda/test/ClientContextTest.java b/extensions/amazon-lambda/common-runtime/src/test/java/io/quarkus/amazon/lambda/test/ClientContextTest.java new file mode 100644 index 0000000000000..658a8fcd23b2f --- /dev/null +++ b/extensions/amazon-lambda/common-runtime/src/test/java/io/quarkus/amazon/lambda/test/ClientContextTest.java @@ -0,0 +1,64 @@ +package io.quarkus.amazon.lambda.test; + +import org.junit.jupiter.api.Assertions; +import org.junit.jupiter.api.Test; + +import com.amazonaws.services.lambda.runtime.ClientContext; +import com.fasterxml.jackson.databind.DeserializationFeature; +import com.fasterxml.jackson.databind.MapperFeature; +import com.fasterxml.jackson.databind.ObjectMapper; +import com.fasterxml.jackson.databind.ObjectReader; + +import io.quarkus.amazon.lambda.runtime.ClientContextImpl; + +public class ClientContextTest { + + static final String ctx = "{\n" + + " \"client\": {\n" + + " \"client_id\":\"\",\n" + + " \"app_title\":\"\",\n" + + " \"app_version_name\":\"\",\n" + + " \"app_version_code\":\"\",\n" + + " \"app_package_name\":\"\"\n" + + " },\n" + + " \n" + + " \"custom\": { \"hello\": \"world\"},\n" + + " \n" + + " \"env\":{\n" + + " \"platform\":\"\",\n" + + " \"model\":\"\",\n" + + " \"make\":\"\",\n" + + " \"platform_version\":\"\",\n" + + " \"locale\":\"\"\n" + + " },\n" + + "\n" + + " \"services\": { \n" + + " \"mobile_analytics\": {\n" + + " \"app_id\":\"\"\n" + + " }\n" + + " }\n" + + " }"; + + @Test + public void testContextMarshalling() throws Exception { + ObjectMapper mapper = new ObjectMapper().configure(DeserializationFeature.FAIL_ON_UNKNOWN_PROPERTIES, false) + .configure(MapperFeature.ACCEPT_CASE_INSENSITIVE_PROPERTIES, true); + + ObjectReader reader = mapper.readerFor(ClientContextImpl.class); + + ClientContext clientContext = reader.readValue(ctx); + Assertions.assertNotNull(clientContext.getClient()); + Assertions.assertNotNull(clientContext.getCustom()); + Assertions.assertNotNull(clientContext.getEnvironment()); + + Assertions.assertEquals("", clientContext.getClient().getInstallationId()); + Assertions.assertEquals("", clientContext.getClient().getAppTitle()); + Assertions.assertEquals("", clientContext.getClient().getAppVersionName()); + Assertions.assertEquals("", clientContext.getClient().getAppVersionCode()); + Assertions.assertEquals("", clientContext.getClient().getAppPackageName()); + + Assertions.assertEquals("world", clientContext.getCustom().get("hello")); + Assertions.assertEquals("", clientContext.getEnvironment().get("platform")); + + } +} diff --git a/extensions/amazon-lambda/runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaRecorder.java b/extensions/amazon-lambda/runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaRecorder.java index 04ad30f364b12..5374bf6c47943 100644 --- a/extensions/amazon-lambda/runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaRecorder.java +++ b/extensions/amazon-lambda/runtime/src/main/java/io/quarkus/amazon/lambda/runtime/AmazonLambdaRecorder.java @@ -140,7 +140,7 @@ public void chooseHandlerClass(List>> uname @SuppressWarnings("rawtypes") public void startPollLoop(ShutdownContext context) { AbstractLambdaPollLoop loop = new AbstractLambdaPollLoop(AmazonLambdaMapperRecorder.objectMapper, - AmazonLambdaMapperRecorder.cognitoIdReader, AmazonLambdaMapperRecorder.cognitoIdReader) { + AmazonLambdaMapperRecorder.cognitoIdReader, AmazonLambdaMapperRecorder.clientCtxReader) { @Override protected Object processRequest(Object input, AmazonLambdaContext context) throws Exception { diff --git a/extensions/funqy/funqy-amazon-lambda/runtime/src/main/java/io/quarkus/funqy/lambda/FunqyLambdaBindingRecorder.java b/extensions/funqy/funqy-amazon-lambda/runtime/src/main/java/io/quarkus/funqy/lambda/FunqyLambdaBindingRecorder.java index f3cbf56a8b07f..10c257ecea9fc 100644 --- a/extensions/funqy/funqy-amazon-lambda/runtime/src/main/java/io/quarkus/funqy/lambda/FunqyLambdaBindingRecorder.java +++ b/extensions/funqy/funqy-amazon-lambda/runtime/src/main/java/io/quarkus/funqy/lambda/FunqyLambdaBindingRecorder.java @@ -104,7 +104,7 @@ public static void handle(InputStream inputStream, OutputStream outputStream, Co @SuppressWarnings("rawtypes") public void startPollLoop(ShutdownContext context) { AbstractLambdaPollLoop loop = new AbstractLambdaPollLoop(AmazonLambdaMapperRecorder.objectMapper, - AmazonLambdaMapperRecorder.cognitoIdReader, AmazonLambdaMapperRecorder.cognitoIdReader) { + AmazonLambdaMapperRecorder.cognitoIdReader, AmazonLambdaMapperRecorder.clientCtxReader) { @Override protected Object processRequest(Object input, AmazonLambdaContext context) throws Exception {