This is an automated email from the ASF dual-hosted git repository. rombert pushed a commit to annotated tag org.apache.sling.testing.sling-mock-1.5.0 in repository https://gitbox.apache.org/repos/asf/sling-org-apache-sling-testing-sling-mock.git
commit 489ae34f525acf3a0aa61ca7e9cc03c44fd0bee2 Author: Stefan Seifert <[email protected]> AuthorDate: Thu Sep 3 22:39:08 2015 +0000 SLING-4998 ResponseBodySupport - use default charset if no response charset is set git-svn-id: https://svn.apache.org/repos/asf/sling/trunk/testing/mocks/sling-mock@1701143 13f79535-47bb-0310-9956-ffa450edef68 --- .../testing/mock/sling/servlet/ResponseBodySupport.java | 15 +++++++++++---- 1 file changed, 11 insertions(+), 4 deletions(-) diff --git a/src/main/java/org/apache/sling/testing/mock/sling/servlet/ResponseBodySupport.java b/src/main/java/org/apache/sling/testing/mock/sling/servlet/ResponseBodySupport.java index 128299b..10db2cc 100644 --- a/src/main/java/org/apache/sling/testing/mock/sling/servlet/ResponseBodySupport.java +++ b/src/main/java/org/apache/sling/testing/mock/sling/servlet/ResponseBodySupport.java @@ -26,6 +26,9 @@ import java.io.UnsupportedEncodingException; import javax.servlet.ServletOutputStream; +import org.apache.commons.lang3.CharEncoding; +import org.apache.commons.lang3.StringUtils; + /** * Manage response body content. */ @@ -60,9 +63,9 @@ class ResponseBodySupport { public PrintWriter getWriter(String charset) { if (printWriter == null) { try { - printWriter = new PrintWriter(new OutputStreamWriter(getOutputStream(), charset)); + printWriter = new PrintWriter(new OutputStreamWriter(getOutputStream(), defaultCharset(charset))); } catch (UnsupportedEncodingException ex) { - throw new RuntimeException("Unsupported encoding: " + charset, ex); + throw new RuntimeException("Unsupported encoding: " + defaultCharset(charset), ex); } } return printWriter; @@ -84,10 +87,14 @@ class ResponseBodySupport { printWriter.flush(); } try { - return new String(getOutput(), charset); + return new String(getOutput(), defaultCharset(charset)); } catch (UnsupportedEncodingException ex) { - throw new RuntimeException("Unsupported encoding: " + charset, ex); + throw new RuntimeException("Unsupported encoding: " + defaultCharset(charset), ex); } } + + private String defaultCharset(String charset) { + return StringUtils.defaultString(charset, CharEncoding.UTF_8); + } } -- To stop receiving notification emails like this one, please contact "[email protected]" <[email protected]>.
