From db67364ec8fb51b80270bdcb165b83f0a44660f2 Mon Sep 17 00:00:00 2001
From: Mirco Hacker <mirco.hacker@codecentric.de>
Date: Tue, 23 Apr 2024 12:30:56 +0200
Subject: [PATCH 1/2] Add template rendering to samples

---
 samples/springboot3/alt-pet-store/build.gradle   |  5 ++++-
 .../springboot3/controller/IndexController.java  | 16 ++++++++++++++++
 .../src/main/resources/application.yaml          |  3 +++
 .../src/main/resources/templates/index.ftlh      |  5 +++++
 samples/springboot3/alt-pet-store/template.yml   |  2 +-
 samples/springboot3/pet-store/build.gradle       |  2 ++
 .../springboot3/controller/IndexController.java  | 16 ++++++++++++++++
 .../src/main/resources/application.yaml          |  3 +++
 .../src/main/resources/templates/index.ftlh      |  5 +++++
 samples/springboot3/pet-store/template.yml       |  2 +-
 10 files changed, 56 insertions(+), 3 deletions(-)
 create mode 100644 samples/springboot3/alt-pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/controller/IndexController.java
 create mode 100644 samples/springboot3/alt-pet-store/src/main/resources/application.yaml
 create mode 100644 samples/springboot3/alt-pet-store/src/main/resources/templates/index.ftlh
 create mode 100644 samples/springboot3/pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/controller/IndexController.java
 create mode 100644 samples/springboot3/pet-store/src/main/resources/application.yaml
 create mode 100644 samples/springboot3/pet-store/src/main/resources/templates/index.ftlh

diff --git a/samples/springboot3/alt-pet-store/build.gradle b/samples/springboot3/alt-pet-store/build.gradle
index 0ddec053b..69d30f0fb 100644
--- a/samples/springboot3/alt-pet-store/build.gradle
+++ b/samples/springboot3/alt-pet-store/build.gradle
@@ -5,6 +5,7 @@ repositories {
   mavenCentral()
   maven {url "https://repo.spring.io/milestone"}
   maven {url "https://repo.spring.io/snapshot"}
+  maven {url "https://repo.spring.io/libs-snapshot-local"}
 }
 
 dependencies {
@@ -12,8 +13,10 @@ dependencies {
           implementation('org.springframework.boot:spring-boot-starter-web:3.2.5') {
             exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
           },
-          'com.amazonaws.serverless:aws-serverless-java-container-springboot3:[2.0-SNAPSHOT,)',
+          'com.amazonaws.serverless:aws-serverless-java-container-springboot3:2.1.0-SNAPSHOT',
   )
+
+  implementation("org.springframework.boot:spring-boot-starter-freemarker:3.2.5")
 }
 
 task buildZip(type: Zip) {
diff --git a/samples/springboot3/alt-pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/controller/IndexController.java b/samples/springboot3/alt-pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/controller/IndexController.java
new file mode 100644
index 000000000..f833ebd51
--- /dev/null
+++ b/samples/springboot3/alt-pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/controller/IndexController.java
@@ -0,0 +1,16 @@
+package com.amazonaws.serverless.sample.springboot3.controller;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+
+@Controller
+public class IndexController {
+
+    public IndexController() {
+    }
+
+    @GetMapping("/index")
+    public String something2() {
+        return "index";
+    }
+}
diff --git a/samples/springboot3/alt-pet-store/src/main/resources/application.yaml b/samples/springboot3/alt-pet-store/src/main/resources/application.yaml
new file mode 100644
index 000000000..4b4d02dc5
--- /dev/null
+++ b/samples/springboot3/alt-pet-store/src/main/resources/application.yaml
@@ -0,0 +1,3 @@
+logging:
+  level:
+    root: debug
\ No newline at end of file
diff --git a/samples/springboot3/alt-pet-store/src/main/resources/templates/index.ftlh b/samples/springboot3/alt-pet-store/src/main/resources/templates/index.ftlh
new file mode 100644
index 000000000..795094095
--- /dev/null
+++ b/samples/springboot3/alt-pet-store/src/main/resources/templates/index.ftlh
@@ -0,0 +1,5 @@
+<h1> hello from freemarker </h1>
+
+<#list 1..10 as x>
+    ${x}
+</#list>
diff --git a/samples/springboot3/alt-pet-store/template.yml b/samples/springboot3/alt-pet-store/template.yml
index c883f0850..ea06277ed 100644
--- a/samples/springboot3/alt-pet-store/template.yml
+++ b/samples/springboot3/alt-pet-store/template.yml
@@ -34,7 +34,7 @@ Resources:
 Outputs:
   SpringPetStoreApi:
     Description: URL for application
-    Value: !Sub 'https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/pets'
+    Value: !Sub 'https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/index'
     Export:
       Name: SpringPetStoreApi
       
diff --git a/samples/springboot3/pet-store/build.gradle b/samples/springboot3/pet-store/build.gradle
index 0ddec053b..de80385f2 100644
--- a/samples/springboot3/pet-store/build.gradle
+++ b/samples/springboot3/pet-store/build.gradle
@@ -14,6 +14,8 @@ dependencies {
           },
           'com.amazonaws.serverless:aws-serverless-java-container-springboot3:[2.0-SNAPSHOT,)',
   )
+
+  implementation("org.springframework.boot:spring-boot-starter-freemarker:3.2.5")
 }
 
 task buildZip(type: Zip) {
diff --git a/samples/springboot3/pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/controller/IndexController.java b/samples/springboot3/pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/controller/IndexController.java
new file mode 100644
index 000000000..f833ebd51
--- /dev/null
+++ b/samples/springboot3/pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/controller/IndexController.java
@@ -0,0 +1,16 @@
+package com.amazonaws.serverless.sample.springboot3.controller;
+
+import org.springframework.stereotype.Controller;
+import org.springframework.web.bind.annotation.GetMapping;
+
+@Controller
+public class IndexController {
+
+    public IndexController() {
+    }
+
+    @GetMapping("/index")
+    public String something2() {
+        return "index";
+    }
+}
diff --git a/samples/springboot3/pet-store/src/main/resources/application.yaml b/samples/springboot3/pet-store/src/main/resources/application.yaml
new file mode 100644
index 000000000..4b4d02dc5
--- /dev/null
+++ b/samples/springboot3/pet-store/src/main/resources/application.yaml
@@ -0,0 +1,3 @@
+logging:
+  level:
+    root: debug
\ No newline at end of file
diff --git a/samples/springboot3/pet-store/src/main/resources/templates/index.ftlh b/samples/springboot3/pet-store/src/main/resources/templates/index.ftlh
new file mode 100644
index 000000000..795094095
--- /dev/null
+++ b/samples/springboot3/pet-store/src/main/resources/templates/index.ftlh
@@ -0,0 +1,5 @@
+<h1> hello from freemarker </h1>
+
+<#list 1..10 as x>
+    ${x}
+</#list>
diff --git a/samples/springboot3/pet-store/template.yml b/samples/springboot3/pet-store/template.yml
index a8474349b..aa59c9bd5 100644
--- a/samples/springboot3/pet-store/template.yml
+++ b/samples/springboot3/pet-store/template.yml
@@ -27,6 +27,6 @@ Resources:
 Outputs:
   SpringBootPetStoreApi:
     Description: URL for application
-    Value: !Sub 'https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/pets'
+    Value: !Sub 'https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/index'
     Export:
       Name: SpringBootPetStoreApi

From 0d74ab00eec7bb9d70a312826c63098d3c09aefd Mon Sep 17 00:00:00 2001
From: Mirco Hacker <mirco.hacker@codecentric.de>
Date: Fri, 26 Apr 2024 17:03:40 +0200
Subject: [PATCH 2/2] Add a function URL to be used with
 SpringDelegatingLambdaContainerHandler

---
 .../alt-pet-store/src/main/resources/application.yaml    | 4 +++-
 samples/springboot3/alt-pet-store/template.yml           | 9 ++++++---
 samples/springboot3/pet-store/build.gradle               | 2 +-
 .../sample/springboot3/StreamLambdaHandler.java          | 6 ++++--
 .../pet-store/src/main/resources/application.yaml        | 4 +++-
 samples/springboot3/pet-store/template.yml               | 9 ++++++---
 6 files changed, 23 insertions(+), 11 deletions(-)

diff --git a/samples/springboot3/alt-pet-store/src/main/resources/application.yaml b/samples/springboot3/alt-pet-store/src/main/resources/application.yaml
index 4b4d02dc5..c08f5c56d 100644
--- a/samples/springboot3/alt-pet-store/src/main/resources/application.yaml
+++ b/samples/springboot3/alt-pet-store/src/main/resources/application.yaml
@@ -1,3 +1,5 @@
 logging:
   level:
-    root: debug
\ No newline at end of file
+    root: debug
+    org:
+      springframework: info
\ No newline at end of file
diff --git a/samples/springboot3/alt-pet-store/template.yml b/samples/springboot3/alt-pet-store/template.yml
index ea06277ed..39c7586e5 100644
--- a/samples/springboot3/alt-pet-store/template.yml
+++ b/samples/springboot3/alt-pet-store/template.yml
@@ -30,12 +30,15 @@ Resources:
           Properties:
             TimeoutInMillis: 20000
             PayloadFormatVersion: '1.0'
-
+      FunctionUrlConfig:
+        AuthType: NONE
 Outputs:
+  MyFunctionUrlEndpoint:
+    Description: "Function URL for application"
+    Value:
+      Fn::GetAtt: PetStoreFunctionUrl.FunctionUrl
   SpringPetStoreApi:
     Description: URL for application
     Value: !Sub 'https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/index'
-    Export:
-      Name: SpringPetStoreApi
       
 
diff --git a/samples/springboot3/pet-store/build.gradle b/samples/springboot3/pet-store/build.gradle
index de80385f2..276defbe2 100644
--- a/samples/springboot3/pet-store/build.gradle
+++ b/samples/springboot3/pet-store/build.gradle
@@ -12,7 +12,7 @@ dependencies {
           implementation('org.springframework.boot:spring-boot-starter-web:3.2.5') {
             exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
           },
-          'com.amazonaws.serverless:aws-serverless-java-container-springboot3:[2.0-SNAPSHOT,)',
+          'com.amazonaws.serverless:aws-serverless-java-container-springboot3:2.1.0-SNAPSHOT',
   )
 
   implementation("org.springframework.boot:spring-boot-starter-freemarker:3.2.5")
diff --git a/samples/springboot3/pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/StreamLambdaHandler.java b/samples/springboot3/pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/StreamLambdaHandler.java
index a65c6f1ec..0df9bce57 100644
--- a/samples/springboot3/pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/StreamLambdaHandler.java
+++ b/samples/springboot3/pet-store/src/main/java/com/amazonaws/serverless/sample/springboot3/StreamLambdaHandler.java
@@ -2,9 +2,11 @@
 
 
 import com.amazonaws.serverless.exceptions.ContainerInitializationException;
+import com.amazonaws.serverless.proxy.internal.servlet.AwsHttpApiV2ProxyHttpServletRequest;
 import com.amazonaws.serverless.proxy.internal.testutils.Timer;
 import com.amazonaws.serverless.proxy.model.AwsProxyRequest;
 import com.amazonaws.serverless.proxy.model.AwsProxyResponse;
+import com.amazonaws.serverless.proxy.model.HttpApiV2ProxyRequest;
 import com.amazonaws.serverless.proxy.spring.SpringBootLambdaContainerHandler;
 import com.amazonaws.serverless.sample.springboot3.filter.CognitoIdentityFilter;
 import com.amazonaws.services.lambda.runtime.Context;
@@ -20,10 +22,10 @@
 
 
 public class StreamLambdaHandler implements RequestStreamHandler {
-    private static SpringBootLambdaContainerHandler<AwsProxyRequest, AwsProxyResponse> handler;
+    private static SpringBootLambdaContainerHandler<HttpApiV2ProxyRequest, AwsProxyResponse> handler;
     static {
         try {
-            handler = SpringBootLambdaContainerHandler.getAwsProxyHandler(Application.class);
+            handler = SpringBootLambdaContainerHandler.getHttpApiV2ProxyHandler(Application.class);
 
             // we use the onStartup method of the handler to register our custom filter
             handler.onStartup(servletContext -> {
diff --git a/samples/springboot3/pet-store/src/main/resources/application.yaml b/samples/springboot3/pet-store/src/main/resources/application.yaml
index 4b4d02dc5..c08f5c56d 100644
--- a/samples/springboot3/pet-store/src/main/resources/application.yaml
+++ b/samples/springboot3/pet-store/src/main/resources/application.yaml
@@ -1,3 +1,5 @@
 logging:
   level:
-    root: debug
\ No newline at end of file
+    root: debug
+    org:
+      springframework: info
\ No newline at end of file
diff --git a/samples/springboot3/pet-store/template.yml b/samples/springboot3/pet-store/template.yml
index aa59c9bd5..c77bb927f 100644
--- a/samples/springboot3/pet-store/template.yml
+++ b/samples/springboot3/pet-store/template.yml
@@ -23,10 +23,13 @@ Resources:
           Properties:
             TimeoutInMillis: 20000
             PayloadFormatVersion: '1.0'
-
+      FunctionUrlConfig:
+        AuthType: NONE
 Outputs:
+  MyFunctionUrlEndpoint:
+    Description: "Function URL for application"
+    Value:
+      Fn::GetAtt: PetStoreFunctionUrl.FunctionUrl
   SpringBootPetStoreApi:
     Description: URL for application
     Value: !Sub 'https://${ServerlessHttpApi}.execute-api.${AWS::Region}.amazonaws.com/index'
-    Export:
-      Name: SpringBootPetStoreApi
