From f04a9c54ef73b8e5e0aadba1c0f99ef7ba5343f9 Mon Sep 17 00:00:00 2001 From: Eran Medan Date: Fri, 14 Feb 2020 20:30:52 -0500 Subject: [PATCH 1/4] fix issue 317 - use charset from request --- .../internal/servlet/AwsHttpServletResponse.java | 8 +++++++- .../proxy/spring/SpringAwsProxyTest.java | 16 ++++++++++++++++ .../proxy/spring/SpringBootAppTest.java | 13 +++++++++++++ 3 files changed, 36 insertions(+), 1 deletion(-) diff --git a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletResponse.java b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletResponse.java index da695c509..153cdb91e 100644 --- a/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletResponse.java +++ b/aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletResponse.java @@ -419,7 +419,13 @@ public void flushBuffer() throws IOException { if (null != writer) { writer.flush(); } - responseBody = new String(bodyOutputStream.toByteArray(), LambdaContainerHandler.getContainerConfig().getDefaultContentCharset()); + String charset = characterEncoding; + + if(charset == null) { + charset = LambdaContainerHandler.getContainerConfig().getDefaultContentCharset(); + } + + responseBody = new String(bodyOutputStream.toByteArray(), charset); log.debug("Response buffer flushed with {} bytes, latch={}", responseBody.length(), writersCountDownLatch.getCount()); isCommitted = true; writersCountDownLatch.countDown(); diff --git a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringAwsProxyTest.java b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringAwsProxyTest.java index b9cb728d6..ebd0f2fd3 100644 --- a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringAwsProxyTest.java +++ b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringAwsProxyTest.java @@ -45,6 +45,7 @@ public class SpringAwsProxyTest { private static final String CUSTOM_HEADER_KEY = "x-custom-header"; private static final String CUSTOM_HEADER_VALUE = "my-custom-value"; private static final String AUTHORIZER_PRINCIPAL_ID = "test-principal-" + UUID.randomUUID().toString(); + private static final String UNICODE_VALUE = "שלום לכולם"; @Autowired private ObjectMapper objectMapper; @@ -249,6 +250,21 @@ public void responseBody_responseWriter_validBody() throws JsonProcessingExcepti validateSingleValueModel(output, CUSTOM_HEADER_VALUE); } + @Test + public void responseBody_responseWriter_validBody_UTF() throws JsonProcessingException { + SingleValueModel singleValueModel = new SingleValueModel(); + singleValueModel.setValue(UNICODE_VALUE); + AwsProxyRequest request = new AwsProxyRequestBuilder("/echo/json-body", "POST") + .header("Content-Type", "application/json; charset=UTF-8") + .body(objectMapper.writeValueAsString(singleValueModel)) + .build(); + + AwsProxyResponse output = handler.proxy(request, lambdaContext); + assertEquals(200, output.getStatusCode()); + assertNotNull(output.getBody()); + validateSingleValueModel(output, UNICODE_VALUE); + } + @Test public void statusCode_responseStatusCode_customStatusCode() { AwsProxyRequest request = new AwsProxyRequestBuilder("/echo/status-code", "GET") diff --git a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringBootAppTest.java b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringBootAppTest.java index 91a559caa..9925a3614 100644 --- a/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringBootAppTest.java +++ b/aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringBootAppTest.java @@ -149,6 +149,19 @@ public void utf8_returnUtf8String_expectCorrectHeaderMediaAndCharset() { assertTrue(output.getMultiValueHeaders().getFirst(HttpHeaders.CONTENT_TYPE).contains("charset=UTF-8")); } + @Test + public void utf8_returnUtf8String_expectCorrectHeaderMediaAndCharsetNoDefault() { + + AwsProxyRequest request = new AwsProxyRequestBuilder("/test/utf8", "GET") + .header("Content-Type", "application/json; charset=UTF-8") + .build(); + AwsProxyResponse output = handler.handleRequest(request, context); + validateSingleValueModel(output, TestController.UTF8_TEST_STRING); + assertTrue(output.getMultiValueHeaders().containsKey(HttpHeaders.CONTENT_TYPE)); + assertTrue(output.getMultiValueHeaders().getFirst(HttpHeaders.CONTENT_TYPE).contains(";")); + assertTrue(output.getMultiValueHeaders().getFirst(HttpHeaders.CONTENT_TYPE).contains("charset=UTF-8")); + } + private void validateSingleValueModel(AwsProxyResponse output, String value) { try { From 52f8e37d72511cce3e6e84b9f7a1fd4729c5ef73 Mon Sep 17 00:00:00 2001 From: Eran Medan Date: Fri, 14 Feb 2020 21:48:29 -0500 Subject: [PATCH 2/4] update dependencies --- aws-serverless-java-container-spring/pom.xml | 2 +- aws-serverless-java-container-springboot2/pom.xml | 6 +++--- .../src/main/resources/archetype-resources/build.gradle | 4 ++-- .../src/main/resources/archetype-resources/pom.xml | 2 +- .../src/main/resources/archetype-resources/build.gradle | 2 +- .../src/main/resources/archetype-resources/pom.xml | 2 +- samples/micronaut/pet-store/build.gradle | 2 +- samples/spring/pet-store/build.gradle | 4 ++-- samples/spring/pet-store/pom.xml | 2 +- samples/springboot2/pet-store/build.gradle | 4 ++-- samples/springboot2/pet-store/pom.xml | 2 +- 11 files changed, 16 insertions(+), 16 deletions(-) diff --git a/aws-serverless-java-container-spring/pom.xml b/aws-serverless-java-container-spring/pom.xml index 01bab3056..18aad6b26 100644 --- a/aws-serverless-java-container-spring/pom.xml +++ b/aws-serverless-java-container-spring/pom.xml @@ -16,7 +16,7 @@ - 5.1.9.RELEASE + 5.1.13.RELEASE 1.5.22.RELEASE 5.1.5.RELEASE diff --git a/aws-serverless-java-container-springboot2/pom.xml b/aws-serverless-java-container-springboot2/pom.xml index 90c98f009..f18d8ebbc 100644 --- a/aws-serverless-java-container-springboot2/pom.xml +++ b/aws-serverless-java-container-springboot2/pom.xml @@ -15,9 +15,9 @@ 1.5-SNAPSHOT - 5.1.9.RELEASE - 5.1.6.RELEASE - 2.1.8.RELEASE + 5.1.13.RELEASE + 5.1.8.RELEASE + 2.1.12.RELEASE 1.8 1.8 diff --git a/aws-serverless-spring-archetype/src/main/resources/archetype-resources/build.gradle b/aws-serverless-spring-archetype/src/main/resources/archetype-resources/build.gradle index e67eb52e4..6447fe4e8 100644 --- a/aws-serverless-spring-archetype/src/main/resources/archetype-resources/build.gradle +++ b/aws-serverless-spring-archetype/src/main/resources/archetype-resources/build.gradle @@ -7,8 +7,8 @@ repositories { dependencies { compile ( - 'org.springframework:spring-webmvc:5.1.9.RELEASE', - 'org.springframework:spring-context:5.1.9.RELEASE', + 'org.springframework:spring-webmvc:5.1.13.RELEASE', + 'org.springframework:spring-context:5.1.13.RELEASE', 'com.amazonaws.serverless:aws-serverless-java-container-spring:[1.0,)', 'org.apache.logging.log4j:log4j-core:2.8.2', 'org.apache.logging.log4j:log4j-api:2.8.2', diff --git a/aws-serverless-spring-archetype/src/main/resources/archetype-resources/pom.xml b/aws-serverless-spring-archetype/src/main/resources/archetype-resources/pom.xml index a6a574c8b..2f6d386d7 100644 --- a/aws-serverless-spring-archetype/src/main/resources/archetype-resources/pom.xml +++ b/aws-serverless-spring-archetype/src/main/resources/archetype-resources/pom.xml @@ -16,7 +16,7 @@ 1.8 1.8 - 5.1.9.RELEASE + 5.1.13.RELEASE 4.12 2.8.2 diff --git a/aws-serverless-springboot2-archetype/src/main/resources/archetype-resources/build.gradle b/aws-serverless-springboot2-archetype/src/main/resources/archetype-resources/build.gradle index e85ac40d8..9d9d17af1 100644 --- a/aws-serverless-springboot2-archetype/src/main/resources/archetype-resources/build.gradle +++ b/aws-serverless-springboot2-archetype/src/main/resources/archetype-resources/build.gradle @@ -11,7 +11,7 @@ repositories { dependencies { compile ( - 'org.springframework.boot:spring-boot-starter-web:2.1.8.RELEASE', + 'org.springframework.boot:spring-boot-starter-web:2.1.12.RELEASE', 'com.amazonaws.serverless:aws-serverless-java-container-springboot2:[1.0,)', 'io.symphonia:lambda-logging:1.0.1' ) diff --git a/aws-serverless-springboot2-archetype/src/main/resources/archetype-resources/pom.xml b/aws-serverless-springboot2-archetype/src/main/resources/archetype-resources/pom.xml index 3dfaa1235..8d1fc100c 100644 --- a/aws-serverless-springboot2-archetype/src/main/resources/archetype-resources/pom.xml +++ b/aws-serverless-springboot2-archetype/src/main/resources/archetype-resources/pom.xml @@ -16,7 +16,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.8.RELEASE + 2.1.12.RELEASE diff --git a/samples/micronaut/pet-store/build.gradle b/samples/micronaut/pet-store/build.gradle index 94f3d1b5f..8ed45b3d7 100644 --- a/samples/micronaut/pet-store/build.gradle +++ b/samples/micronaut/pet-store/build.gradle @@ -3,7 +3,7 @@ plugins { id "com.github.johnrengelman.shadow" version "5.0.0" id "application" id "net.ltgt.apt-eclipse" version "0.21" - id "org.springframework.boot" version "2.1.8.RELEASE" + id "org.springframework.boot" version "2.1.12.RELEASE" id "io.spring.dependency-management" version "1.0.6.RELEASE" } diff --git a/samples/spring/pet-store/build.gradle b/samples/spring/pet-store/build.gradle index 7d7a74c44..a8e815fbb 100644 --- a/samples/spring/pet-store/build.gradle +++ b/samples/spring/pet-store/build.gradle @@ -7,8 +7,8 @@ repositories { dependencies { compile ( - 'org.springframework:spring-webmvc:5.1.9.RELEASE', - 'org.springframework:spring-context:5.1.9.RELEASE', + 'org.springframework:spring-webmvc:5.1.13.RELEASE', + 'org.springframework:spring-context:5.1.13.RELEASE', 'com.amazonaws.serverless:aws-serverless-java-container-spring:[1.0,)', 'org.apache.logging.log4j:log4j-core:2.8.2', 'org.apache.logging.log4j:log4j-api:2.8.2', diff --git a/samples/spring/pet-store/pom.xml b/samples/spring/pet-store/pom.xml index d25d1dc02..c365d9b1c 100644 --- a/samples/spring/pet-store/pom.xml +++ b/samples/spring/pet-store/pom.xml @@ -26,7 +26,7 @@ 1.8 1.8 - 5.1.9.RELEASE + 5.1.13.RELEASE 4.12 2.8.2 diff --git a/samples/springboot2/pet-store/build.gradle b/samples/springboot2/pet-store/build.gradle index 65826e900..fd4e81817 100644 --- a/samples/springboot2/pet-store/build.gradle +++ b/samples/springboot2/pet-store/build.gradle @@ -1,5 +1,5 @@ plugins { - id 'org.springframework.boot' version '2.1.8.RELEASE' + id 'org.springframework.boot' version '2.1.12.RELEASE' } apply plugin: 'java' @@ -11,7 +11,7 @@ repositories { dependencies { compile ( - implementation('org.springframework.boot:spring-boot-starter-web:2.1.8.RELEASE') { + implementation('org.springframework.boot:spring-boot-starter-web:2.1.12.RELEASE') { exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat' }, 'com.amazonaws.serverless:aws-serverless-java-container-springboot2:[1.0,)', diff --git a/samples/springboot2/pet-store/pom.xml b/samples/springboot2/pet-store/pom.xml index 547a7ead1..15bf3e671 100644 --- a/samples/springboot2/pet-store/pom.xml +++ b/samples/springboot2/pet-store/pom.xml @@ -10,7 +10,7 @@ org.springframework.boot spring-boot-starter-parent - 2.1.8.RELEASE + 2.1.12.RELEASE From c3677eeaca962cce78814effce44f4562bb17a47 Mon Sep 17 00:00:00 2001 From: Eran Medan Date: Fri, 14 Feb 2020 22:42:01 -0500 Subject: [PATCH 3/4] update build dependencies, remove spring boot 2.0.x --- .github/workflows/continuous-integration-workflow.yml | 11 ++++++----- 1 file changed, 6 insertions(+), 5 deletions(-) diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index c1b10ca79..3ed3c3c7a 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -49,7 +49,7 @@ jobs: - name: Build Spring 4.3 run: ./gha_build.sh spring false false -Dspring.version=4.3.25.RELEASE -Dspring-security.version=4.2.13.RELEASE - name: Build Spring 5.0 - run: ./gha_build.sh spring false false -Dspring.version=5.0.15.RELEASE -Dspring-security.version=5.0.13.RELEASE + run: ./gha_build.sh spring false false -Dspring.version=5.0.16.RELEASE -Dspring-security.version=5.0.14.RELEASE build_springboot2: name: Build and test SpringBoot 2 @@ -58,12 +58,13 @@ jobs: - uses: actions/checkout@v2 - name: Build latest run: ./gha_build.sh springboot2 true true - - name: Build Spring Boot 2.0 - run: ./gha_build.sh springboot2 false false -Dspringboot.version=2.0.9.RELEASE -Dspring.version=5.0.13.RELEASE -Dspringsecurity.version=5.0.12.RELEASE +# removed since 2.0.9.RELEASE uses Spring 5.0.13 which fails the dependency check (see https://pivotal.io/security/cve-2020-5398) +# - name: Build Spring Boot 2.0 +# run: ./gha_build.sh springboot2 false false -Dspringboot.version=2.0.9.RELEASE -Dspring.version=5.0.16.RELEASE -Dspringsecurity.version=5.0.14.RELEASE - name: Build Spring Boot 2.1 - run: ./gha_build.sh springboot2 false false -Dspringboot.version=2.1.10.RELEASE -Dspring.version=5.1.11.RELEASE -Dspringsecurity.version=5.1.7.RELEASE + run: ./gha_build.sh springboot2 false false -Dspringboot.version=2.1.12.RELEASE -Dspring.version=5.1.13.RELEASE -Dspringsecurity.version=5.1.8.RELEASE - name: Build Spring Boot 2.2 - run: ./gha_build.sh springboot2 false false -Dspringboot.version=2.2.1.RELEASE -Dspring.version=5.2.1.RELEASE -Dspringsecurity.version=5.2.1.RELEASE + run: ./gha_build.sh springboot2 false false -Dspringboot.version=2.2.3.RELEASE -Dspring.version=5.2.3.RELEASE -Dspringsecurity.version=5.2.2.RELEASE build_struts2: name: Build and test Struts 2 From 8edb013f533af784adbb28d16062c2b5bb89dca8 Mon Sep 17 00:00:00 2001 From: Eran Medan Date: Fri, 14 Feb 2020 23:19:38 -0500 Subject: [PATCH 4/4] restoring ci config --- .github/workflows/continuous-integration-workflow.yml | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/.github/workflows/continuous-integration-workflow.yml b/.github/workflows/continuous-integration-workflow.yml index 3ed3c3c7a..d35974860 100644 --- a/.github/workflows/continuous-integration-workflow.yml +++ b/.github/workflows/continuous-integration-workflow.yml @@ -58,9 +58,8 @@ jobs: - uses: actions/checkout@v2 - name: Build latest run: ./gha_build.sh springboot2 true true -# removed since 2.0.9.RELEASE uses Spring 5.0.13 which fails the dependency check (see https://pivotal.io/security/cve-2020-5398) -# - name: Build Spring Boot 2.0 -# run: ./gha_build.sh springboot2 false false -Dspringboot.version=2.0.9.RELEASE -Dspring.version=5.0.16.RELEASE -Dspringsecurity.version=5.0.14.RELEASE + - name: Build Spring Boot 2.0 + run: ./gha_build.sh springboot2 false false -Dspringboot.version=2.0.9.RELEASE -Dspring.version=5.0.16.RELEASE -Dspringsecurity.version=5.0.14.RELEASE - name: Build Spring Boot 2.1 run: ./gha_build.sh springboot2 false false -Dspringboot.version=2.1.12.RELEASE -Dspring.version=5.1.13.RELEASE -Dspringsecurity.version=5.1.8.RELEASE - name: Build Spring Boot 2.2