Skip to content

Commit 3cd1ec3

Browse files
committed
Merge pull request #189 and renamed struts archetype to struts2
2 parents 8c25373 + 87b83a1 commit 3cd1ec3

File tree

17 files changed

+61
-7
lines changed

17 files changed

+61
-7
lines changed

aws-serverless-java-container-core/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<groupId>com.amazonaws.serverless</groupId>
1313
<artifactId>aws-serverless-java-container</artifactId>
1414
<version>1.2-SNAPSHOT</version>
15+
<relativePath>..</relativePath>
1516
</parent>
1617

1718
<properties>

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

Lines changed: 11 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -265,14 +265,17 @@ public Collection<String> getHeaderNames() {
265265

266266
@Override
267267
public String getCharacterEncoding() {
268-
return headers.getFirst(HttpHeaders.CONTENT_ENCODING);
268+
final String contentType = Optional.ofNullable(getContentType()).orElse("");
269+
if (contentType.contains(";")) {
270+
return contentType.split(";")[1].split("=")[1].trim().toLowerCase(Locale.getDefault());
271+
} else {
272+
return "";
273+
}
269274
}
270275

271276

272277
@Override
273-
public String getContentType() {
274-
return headers.getFirst(HttpHeaders.CONTENT_TYPE);
275-
}
278+
public String getContentType() { return getHeader(HttpHeaders.CONTENT_TYPE); }
276279

277280

278281
@Override
@@ -334,7 +337,10 @@ public PrintWriter getWriter() throws IOException {
334337

335338
@Override
336339
public void setCharacterEncoding(String s) {
337-
setHeader(HttpHeaders.CONTENT_ENCODING, s, true);
340+
final String characterEncoding = Optional.ofNullable(s).orElse("").toLowerCase(Locale.getDefault());
341+
final String oldValue = Optional.ofNullable(getHeader(HttpHeaders.CONTENT_TYPE)).orElse("");
342+
String contentType = oldValue.contains(";") ? oldValue.split(";")[0].trim(): oldValue;
343+
setHeader(HttpHeaders.CONTENT_TYPE, String.format("%s; charset=%s", contentType, characterEncoding), true);
338344
}
339345

340346

aws-serverless-java-container-core/src/test/java/com/amazonaws/serverless/proxy/internal/servlet/AwsHttpServletResponseTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -265,6 +265,49 @@ public void headers_addIntHeader_expectMultipleHeaderValues() {
265265
assertEquals("15", resp.getHeader("Test"));
266266
}
267267

268+
@Test
269+
public void characterEncoding_setCharacterEncoding() {
270+
AwsHttpServletResponse resp = new AwsHttpServletResponse(null, null);
271+
resp.setContentType("application/json");
272+
resp.setCharacterEncoding("UTF-8");
273+
assertNotEquals("UTF-8", resp.getHeader("Content-Encoding"));
274+
assertEquals("application/json; charset=utf-8", resp.getContentType());
275+
assertEquals("application/json; charset=utf-8", resp.getHeader("Content-Type"));
276+
}
277+
278+
@Test
279+
public void characterEncoding_setContentType() {
280+
AwsHttpServletResponse resp = new AwsHttpServletResponse(null, null);
281+
resp.setContentType("application/json; charset=utf-8");
282+
resp.setCharacterEncoding("UTF-8");
283+
284+
assertEquals("application/json; charset=utf-8", resp.getContentType());
285+
assertEquals("application/json; charset=utf-8", resp.getHeader("Content-Type"));
286+
assertEquals("utf-8", resp.getCharacterEncoding());
287+
}
288+
289+
@Test
290+
public void characterEncoding_setContentTypeAndsetCharacterEncoding() {
291+
AwsHttpServletResponse resp = new AwsHttpServletResponse(null, null);
292+
resp.setContentType("application/json");
293+
resp.setCharacterEncoding("UTF-8");
294+
295+
assertEquals("application/json; charset=utf-8", resp.getContentType());
296+
assertEquals("application/json; charset=utf-8", resp.getHeader("Content-Type"));
297+
assertEquals("utf-8", resp.getCharacterEncoding());
298+
}
299+
300+
@Test
301+
public void characterEncoding_setCharacterEncodingAndsetContentType() {
302+
AwsHttpServletResponse resp = new AwsHttpServletResponse(null, null);
303+
resp.setCharacterEncoding("UTF-8");
304+
resp.setContentType("application/json");
305+
306+
assertEquals("application/json", resp.getContentType());
307+
assertEquals("application/json", resp.getHeader("Content-Type"));
308+
assertEquals("", resp.getCharacterEncoding());
309+
}
310+
268311
private int getMaxAge(String header) {
269312
Matcher ageMatcher = MAX_AGE_PATTERN.matcher(header);
270313
assertTrue(ageMatcher.find());

aws-serverless-java-container-jersey/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<groupId>com.amazonaws.serverless</groupId>
1313
<artifactId>aws-serverless-java-container</artifactId>
1414
<version>1.2-SNAPSHOT</version>
15+
<relativePath>..</relativePath>
1516
</parent>
1617

1718
<properties>

aws-serverless-java-container-spark/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<groupId>com.amazonaws.serverless</groupId>
1313
<artifactId>aws-serverless-java-container</artifactId>
1414
<version>1.2-SNAPSHOT</version>
15+
<relativePath>..</relativePath>
1516
</parent>
1617

1718
<properties>

aws-serverless-java-container-spring/pom.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,7 @@
1212
<groupId>com.amazonaws.serverless</groupId>
1313
<artifactId>aws-serverless-java-container</artifactId>
1414
<version>1.2-SNAPSHOT</version>
15+
<relativePath>..</relativePath>
1516
</parent>
1617

1718
<properties>

aws-serverless-struts-archetype/pom.xml renamed to aws-serverless-struts2-archetype/pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -9,7 +9,7 @@
99
</parent>
1010

1111
<groupId>com.amazonaws.serverless.archetypes</groupId>
12-
<artifactId>aws-serverless-struts-archetype</artifactId>
12+
<artifactId>aws-serverless-struts2-archetype</artifactId>
1313
<version>1.2-SNAPSHOT</version>
1414
<packaging>maven-archetype</packaging>
1515

0 commit comments

Comments
 (0)