Skip to content

Commit 787c353

Browse files
eranationsapessi
andauthored
Fix for issue #317 (#323)
* fix issue 317 - use charset from request * update dependencies * update build dependencies, remove spring boot 2.0.x * restoring ci config Co-authored-by: Stefano Buliani <[email protected]>
1 parent ac36745 commit 787c353

File tree

12 files changed

+50
-15
lines changed

12 files changed

+50
-15
lines changed

.github/workflows/continuous-integration-workflow.yml

Lines changed: 3 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -63,11 +63,11 @@ jobs:
6363
- name: Build latest
6464
run: ./gha_build.sh springboot2 true true
6565
- name: Build Spring Boot 2.0
66-
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
66+
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
6767
- name: Build Spring Boot 2.1
68-
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
68+
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
6969
- name: Build Spring Boot 2.2
70-
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
70+
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
7171

7272
build_struts2:
7373
name: Build and test Struts 2

aws-serverless-java-container-core/src/main/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletResponse.java

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -419,7 +419,13 @@ public void flushBuffer() throws IOException {
419419
if (null != writer) {
420420
writer.flush();
421421
}
422-
responseBody = new String(bodyOutputStream.toByteArray(), LambdaContainerHandler.getContainerConfig().getDefaultContentCharset());
422+
String charset = characterEncoding;
423+
424+
if(charset == null) {
425+
charset = LambdaContainerHandler.getContainerConfig().getDefaultContentCharset();
426+
}
427+
428+
responseBody = new String(bodyOutputStream.toByteArray(), charset);
423429
log.debug("Response buffer flushed with {} bytes, latch={}", responseBody.length(), writersCountDownLatch.getCount());
424430
isCommitted = true;
425431
writersCountDownLatch.countDown();

aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringAwsProxyTest.java

Lines changed: 16 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -45,6 +45,7 @@ public class SpringAwsProxyTest {
4545
private static final String CUSTOM_HEADER_KEY = "x-custom-header";
4646
private static final String CUSTOM_HEADER_VALUE = "my-custom-value";
4747
private static final String AUTHORIZER_PRINCIPAL_ID = "test-principal-" + UUID.randomUUID().toString();
48+
private static final String UNICODE_VALUE = "שלום לכולם";
4849

4950
@Autowired
5051
private ObjectMapper objectMapper;
@@ -249,6 +250,21 @@ public void responseBody_responseWriter_validBody() throws JsonProcessingExcepti
249250
validateSingleValueModel(output, CUSTOM_HEADER_VALUE);
250251
}
251252

253+
@Test
254+
public void responseBody_responseWriter_validBody_UTF() throws JsonProcessingException {
255+
SingleValueModel singleValueModel = new SingleValueModel();
256+
singleValueModel.setValue(UNICODE_VALUE);
257+
AwsProxyRequest request = new AwsProxyRequestBuilder("/echo/json-body", "POST")
258+
.header("Content-Type", "application/json; charset=UTF-8")
259+
.body(objectMapper.writeValueAsString(singleValueModel))
260+
.build();
261+
262+
AwsProxyResponse output = handler.proxy(request, lambdaContext);
263+
assertEquals(200, output.getStatusCode());
264+
assertNotNull(output.getBody());
265+
validateSingleValueModel(output, UNICODE_VALUE);
266+
}
267+
252268
@Test
253269
public void statusCode_responseStatusCode_customStatusCode() {
254270
AwsProxyRequest request = new AwsProxyRequestBuilder("/echo/status-code", "GET")

aws-serverless-java-container-spring/src/test/java/com/amazonaws/serverless/proxy/spring/SpringBootAppTest.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,6 +160,19 @@ public void utf8_returnUtf8String_expectCorrectHeaderMediaAndCharset() {
160160
assertTrue(output.getMultiValueHeaders().getFirst(HttpHeaders.CONTENT_TYPE).contains("charset=UTF-8"));
161161
}
162162

163+
@Test
164+
public void utf8_returnUtf8String_expectCorrectHeaderMediaAndCharsetNoDefault() {
165+
166+
AwsProxyRequest request = new AwsProxyRequestBuilder("/test/utf8", "GET")
167+
.header("Content-Type", "application/json; charset=UTF-8")
168+
.build();
169+
AwsProxyResponse output = handler.handleRequest(request, context);
170+
validateSingleValueModel(output, TestController.UTF8_TEST_STRING);
171+
assertTrue(output.getMultiValueHeaders().containsKey(HttpHeaders.CONTENT_TYPE));
172+
assertTrue(output.getMultiValueHeaders().getFirst(HttpHeaders.CONTENT_TYPE).contains(";"));
173+
assertTrue(output.getMultiValueHeaders().getFirst(HttpHeaders.CONTENT_TYPE).contains("charset=UTF-8"));
174+
}
175+
163176

164177
private void validateSingleValueModel(AwsProxyResponse output, String value) {
165178
try {

aws-serverless-spring-archetype/src/main/resources/archetype-resources/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ repositories {
77

88
dependencies {
99
compile (
10-
'org.springframework:spring-webmvc:5.1.9.RELEASE',
11-
'org.springframework:spring-context:5.1.9.RELEASE',
10+
'org.springframework:spring-webmvc:5.1.13.RELEASE',
11+
'org.springframework:spring-context:5.1.13.RELEASE',
1212
'com.amazonaws.serverless:aws-serverless-java-container-spring:[1.0,)',
1313
'org.apache.logging.log4j:log4j-core:2.8.2',
1414
'org.apache.logging.log4j:log4j-api:2.8.2',

aws-serverless-spring-archetype/src/main/resources/archetype-resources/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<properties>
1717
<maven.compiler.source>1.8</maven.compiler.source>
1818
<maven.compiler.target>1.8</maven.compiler.target>
19-
<spring.version>5.1.9.RELEASE</spring.version>
19+
<spring.version>5.1.13.RELEASE</spring.version>
2020
<junit.version>4.12</junit.version>
2121
<log4j.version>2.8.2</log4j.version>
2222
</properties>

aws-serverless-springboot2-archetype/src/main/resources/archetype-resources/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -11,7 +11,7 @@ repositories {
1111

1212
dependencies {
1313
compile (
14-
'org.springframework.boot:spring-boot-starter-web:2.1.8.RELEASE',
14+
'org.springframework.boot:spring-boot-starter-web:2.1.12.RELEASE',
1515
'com.amazonaws.serverless:aws-serverless-java-container-springboot2:[1.0,)',
1616
'io.symphonia:lambda-logging:1.0.1'
1717
)

aws-serverless-springboot2-archetype/src/main/resources/archetype-resources/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -16,7 +16,7 @@
1616
<parent>
1717
<groupId>org.springframework.boot</groupId>
1818
<artifactId>spring-boot-starter-parent</artifactId>
19-
<version>2.1.8.RELEASE</version>
19+
<version>2.1.12.RELEASE</version>
2020
</parent>
2121

2222
<properties>

samples/micronaut/pet-store/build.gradle

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,7 @@ plugins {
33
id "com.github.johnrengelman.shadow" version "5.0.0"
44
id "application"
55
id "net.ltgt.apt-eclipse" version "0.21"
6-
id "org.springframework.boot" version "2.1.8.RELEASE"
6+
id "org.springframework.boot" version "2.1.12.RELEASE"
77
id "io.spring.dependency-management" version "1.0.6.RELEASE"
88
}
99

samples/spring/pet-store/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -7,8 +7,8 @@ repositories {
77

88
dependencies {
99
compile (
10-
'org.springframework:spring-webmvc:5.1.9.RELEASE',
11-
'org.springframework:spring-context:5.1.9.RELEASE',
10+
'org.springframework:spring-webmvc:5.1.13.RELEASE',
11+
'org.springframework:spring-context:5.1.13.RELEASE',
1212
'com.amazonaws.serverless:aws-serverless-java-container-spring:[1.0,)',
1313
'org.apache.logging.log4j:log4j-core:2.8.2',
1414
'org.apache.logging.log4j:log4j-api:2.8.2',

samples/springboot2/pet-store/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
plugins {
2-
id 'org.springframework.boot' version '2.1.8.RELEASE'
2+
id 'org.springframework.boot' version '2.1.12.RELEASE'
33
}
44
apply plugin: 'java'
55

@@ -11,7 +11,7 @@ repositories {
1111

1212
dependencies {
1313
compile (
14-
implementation('org.springframework.boot:spring-boot-starter-web:2.1.8.RELEASE') {
14+
implementation('org.springframework.boot:spring-boot-starter-web:2.1.12.RELEASE') {
1515
exclude group: 'org.springframework.boot', module: 'spring-boot-starter-tomcat'
1616
},
1717
'com.amazonaws.serverless:aws-serverless-java-container-springboot2:[1.0,)',

samples/springboot2/pet-store/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -10,7 +10,7 @@
1010
<parent>
1111
<groupId>org.springframework.boot</groupId>
1212
<artifactId>spring-boot-starter-parent</artifactId>
13-
<version>2.1.8.RELEASE</version>
13+
<version>2.1.12.RELEASE</version>
1414
</parent>
1515

1616
<properties>

0 commit comments

Comments
 (0)