Skip to content

Commit 5d04795

Browse files
committed
hint for LambdaEventSerializers
Signed-off-by: muhamadto <muhamadto@gmail.com>
1 parent d8e58ff commit 5d04795

File tree

7 files changed

+105
-76
lines changed

7 files changed

+105
-76
lines changed

pom.xml

Lines changed: 18 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -55,17 +55,24 @@
5555
<sonar.host.url>https://sonarcloud.io</sonar.host.url>
5656

5757
<sonar.issue.ignore.multicriteria>e1,e2</sonar.issue.ignore.multicriteria>
58-
<sonar.issue.ignore.multicriteria.e1.ruleKey>java:S107</sonar.issue.ignore.multicriteria.e1.ruleKey>
59-
<sonar.issue.ignore.multicriteria.e1.resourceKey>**/cdk/*.java</sonar.issue.ignore.multicriteria.e1.resourceKey>
58+
<sonar.issue.ignore.multicriteria.e1.ruleKey>java:S107
59+
</sonar.issue.ignore.multicriteria.e1.ruleKey>
60+
<sonar.issue.ignore.multicriteria.e1.resourceKey>**/cdk/*.java
61+
</sonar.issue.ignore.multicriteria.e1.resourceKey>
6062

6163
<!-- This class has 6 parents which is greater than 5 authorized,
6264
suspended as we are using CDK and the original code has 5 levels of inheritance already-->
63-
<sonar.issue.ignore.multicriteria.e2.ruleKey>java:S110</sonar.issue.ignore.multicriteria.e2.ruleKey>
64-
<sonar.issue.ignore.multicriteria.e2.resourceKey>**/cdk/*.java</sonar.issue.ignore.multicriteria.e2.resourceKey>
65+
<sonar.issue.ignore.multicriteria.e2.ruleKey>java:S110
66+
</sonar.issue.ignore.multicriteria.e2.ruleKey>
67+
<sonar.issue.ignore.multicriteria.e2.resourceKey>**/cdk/*.java
68+
</sonar.issue.ignore.multicriteria.e2.resourceKey>
6569

66-
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml, ${project.basedir}/target/site/jacoco-it/jacoco.xml</sonar.coverage.jacoco.xmlReportPaths>
70+
<sonar.coverage.jacoco.xmlReportPaths>${project.basedir}/target/site/jacoco/jacoco.xml,
71+
${project.basedir}/target/site/jacoco-it/jacoco.xml
72+
</sonar.coverage.jacoco.xmlReportPaths>
6773

68-
<sonar.coverage.exclusions>**/model/*.java, **/Application.java,**/*Hints.java</sonar.coverage.exclusions>
74+
<sonar.coverage.exclusions>**/model/*.java, **/Application.java, **/*Hints.java
75+
</sonar.coverage.exclusions>
6976
<lombok.version>1.18.28</lombok.version>
7077
</properties>
7178

@@ -106,13 +113,16 @@
106113
<groupId>com.amazonaws</groupId>
107114
<artifactId>aws-lambda-java-core</artifactId>
108115
<version>1.2.2</version>
109-
<scope>provided</scope>
110116
</dependency>
111117
<dependency>
112118
<groupId>com.amazonaws</groupId>
113119
<artifactId>aws-lambda-java-serialization</artifactId>
114120
<version>1.1.2</version>
115-
<scope>provided</scope>
121+
</dependency>
122+
<dependency>
123+
<groupId>com.amazonaws</groupId>
124+
<artifactId>aws-lambda-java-log4j2</artifactId>
125+
<version>1.5.1</version>
116126
</dependency>
117127
<dependency>
118128
<groupId>software.amazon.lambda</groupId>

spring-native-aws-lambda-function/pom.xml

Lines changed: 5 additions & 37 deletions
Original file line numberDiff line numberDiff line change
@@ -42,8 +42,7 @@
4242
</developers>
4343

4444
<properties>
45-
<spring-cloud.version>2022.0.1</spring-cloud.version>
46-
<aspectj.version>1.9.20</aspectj.version>
45+
<spring-cloud.version>2022.0.3</spring-cloud.version>
4746

4847
<repackage.classifier/>
4948
<native.build.args>
@@ -80,8 +79,10 @@
8079
<groupId>com.amazonaws</groupId>
8180
<artifactId>aws-lambda-java-serialization</artifactId>
8281
</dependency>
83-
84-
82+
<dependency>
83+
<groupId>com.amazonaws</groupId>
84+
<artifactId>aws-lambda-java-log4j2</artifactId>
85+
</dependency>
8586
<!-- AWS LAMBDA ENDS -->
8687

8788
<!-- SPRING CLOUD -->
@@ -112,36 +113,6 @@
112113
<groupId>org.projectlombok</groupId>
113114
<artifactId>lombok</artifactId>
114115
</dependency>
115-
116-
<dependency>
117-
<groupId>ch.qos.logback</groupId>
118-
<artifactId>logback-core</artifactId>
119-
<version>1.4.8</version>
120-
</dependency>
121-
122-
<dependency>
123-
<groupId>ch.qos.logback</groupId>
124-
<artifactId>logback-classic</artifactId>
125-
<version>1.4.8</version>
126-
</dependency>
127-
128-
<dependency>
129-
<groupId>org.slf4j</groupId>
130-
<artifactId>slf4j-api</artifactId>
131-
<version>2.0.7</version>
132-
</dependency>
133-
134-
<dependency>
135-
<groupId>ch.qos.logback.contrib</groupId>
136-
<artifactId>logback-json-classic</artifactId>
137-
<version>0.1.5</version>
138-
</dependency>
139-
140-
<dependency>
141-
<groupId>ch.qos.logback.contrib</groupId>
142-
<artifactId>logback-jackson</artifactId>
143-
<version>0.1.5</version>
144-
</dependency>
145116
<!-- UTILITIES ENDS -->
146117

147118
<!-- TEST -->
@@ -167,9 +138,6 @@
167138

168139
<build>
169140
<finalName>${project.artifactId}</finalName>
170-
<directory>${project.basedir}/target</directory>
171-
<plugins>
172-
</plugins>
173141
</build>
174142

175143
<profiles>

spring-native-aws-lambda-function/src/main/java/com/coffeebeans/springnativeawslambda/Application.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,11 @@
2323
import org.springframework.context.annotation.ImportRuntimeHints;
2424

2525
@SpringBootApplication
26-
@ImportRuntimeHints(AppRuntimeHints.class)
26+
@ImportRuntimeHints({
27+
ReflectionRuntimeHints.class,
28+
ResourcesRuntimeHints.class,
29+
SerializationRuntimeHints.class
30+
})
2731
public class Application {
2832

2933
public static void main(String[] args) {
Lines changed: 39 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,39 @@
1+
/*
2+
* Licensed to Muhammad Hamadto
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* See the NOTICE file distributed with this work for additional information regarding copyright ownership.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package com.coffeebeans.springnativeawslambda;
20+
21+
import java.util.List;
22+
import org.joda.time.DateTime;
23+
import org.springframework.aot.hint.MemberCategory;
24+
import org.springframework.aot.hint.RuntimeHints;
25+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
26+
import org.springframework.aot.hint.TypeReference;
27+
28+
public class ReflectionRuntimeHints implements RuntimeHintsRegistrar {
29+
30+
@Override
31+
public void registerHints(final RuntimeHints hints, final ClassLoader classLoader) {
32+
final List<TypeReference> typeReferences = List.of(
33+
TypeReference.of(DateTime.class)
34+
);
35+
36+
hints.reflection().registerTypes(typeReferences,
37+
builder -> builder.withMembers(MemberCategory.values()));
38+
}
39+
}
Lines changed: 30 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,30 @@
1+
/*
2+
* Licensed to Muhammad Hamadto
3+
*
4+
* Licensed under the Apache License, Version 2.0 (the "License");
5+
* you may not use this file except in compliance with the License.
6+
* You may obtain a copy of the License at
7+
* http://www.apache.org/licenses/LICENSE-2.0
8+
*
9+
* See the NOTICE file distributed with this work for additional information regarding copyright ownership.
10+
*
11+
* Unless required by applicable law or agreed to in writing, software
12+
* distributed under the License is distributed on an "AS IS" BASIS,
13+
* WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
14+
* See the License for the specific language governing permissions and
15+
* limitations under the License.
16+
*
17+
*/
18+
19+
package com.coffeebeans.springnativeawslambda;
20+
21+
import org.springframework.aot.hint.RuntimeHints;
22+
import org.springframework.aot.hint.RuntimeHintsRegistrar;
23+
24+
public class ResourcesRuntimeHints implements RuntimeHintsRegistrar {
25+
26+
@Override
27+
public void registerHints(final RuntimeHints hints, final ClassLoader classLoader) {
28+
hints.resources().registerPattern("com/amazonaws/lambda/thirdparty/org/joda/time/tz/*");
29+
}
30+
}
Lines changed: 8 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -18,29 +18,24 @@
1818

1919
package com.coffeebeans.springnativeawslambda;
2020

21+
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyRequestEvent;
22+
import com.amazonaws.services.lambda.runtime.events.APIGatewayProxyResponseEvent;
2123
import com.coffeebeans.springnativeawslambda.model.Request;
2224
import com.coffeebeans.springnativeawslambda.model.Response;
23-
import java.util.List;
24-
import org.springframework.aot.hint.MemberCategory;
2525
import org.springframework.aot.hint.RuntimeHints;
2626
import org.springframework.aot.hint.RuntimeHintsRegistrar;
27-
import org.springframework.aot.hint.TypeReference;
2827

29-
public class AppRuntimeHints implements RuntimeHintsRegistrar {
28+
public class SerializationRuntimeHints implements RuntimeHintsRegistrar {
3029

3130
@Override
3231
public void registerHints(final RuntimeHints hints, final ClassLoader classLoader) {
33-
hints.serialization().registerType(Request.class);
3432
hints.serialization().registerType(Response.class);
35-
hints.resources().registerPattern("org/joda/time/tz/*");
33+
hints.serialization().registerType(Request.class);
3634

37-
final List<TypeReference> typeReferences = List.of(
38-
TypeReference.of("org.apache.logging.log4j.message.DefaultFlowMessageFactory"),
39-
TypeReference.of("org.apache.logging.log4j.message.ParameterizedMessageFactory"),
40-
TypeReference.of("java.util.ServiceLoader")
41-
);
35+
hints.serialization().registerType(APIGatewayProxyResponseEvent.class);
4236

43-
hints.reflection().registerTypes(typeReferences,
44-
builder -> builder.withMembers(MemberCategory.values()));
37+
hints.serialization().registerType(APIGatewayProxyRequestEvent.class);
38+
hints.serialization().registerType(APIGatewayProxyRequestEvent.ProxyRequestContext.class);
39+
hints.serialization().registerType(APIGatewayProxyRequestEvent.RequestIdentity.class);
4540
}
4641
}

spring-native-aws-lambda-function/src/main/resources/logback.xml

Lines changed: 0 additions & 17 deletions
This file was deleted.

0 commit comments

Comments
 (0)