This is an automated email from the ASF dual-hosted git repository.
jeb pushed a commit to branch master
in repository
https://gitbox.apache.org/repos/asf/sling-org-apache-sling-servlets-get.git
The following commit(s) were added to refs/heads/master by this push:
new 25ded7e SLING-8011 removed closure of json generator
25ded7e is described below
commit 25ded7e2bed2abf92d96e03b0b0713004880d87b
Author: Jason E Bailey <[email protected]>
AuthorDate: Sun Oct 14 20:46:04 2018 -0400
SLING-8011 removed closure of json generator
when closing the json generator it is closing the output stream that it
uses to record json. In the case of this servlet that output stream is
the ServletResponse output stream which should not be closed by a
servlet directly.
---
.../sling/servlets/get/impl/SlingInfoServlet.java | 48 +++++++++-------------
1 file changed, 19 insertions(+), 29 deletions(-)
diff --git
a/src/main/java/org/apache/sling/servlets/get/impl/SlingInfoServlet.java
b/src/main/java/org/apache/sling/servlets/get/impl/SlingInfoServlet.java
index b9166db..0df76fd 100644
--- a/src/main/java/org/apache/sling/servlets/get/impl/SlingInfoServlet.java
+++ b/src/main/java/org/apache/sling/servlets/get/impl/SlingInfoServlet.java
@@ -41,18 +41,13 @@ import org.osgi.service.component.annotations.Component;
* The <code>SlingInfoServlet</code>
*/
@SuppressWarnings("serial")
-@Component(service = Servlet.class,
- property = {
- "service.description=Sling Info Servlet",
- "service.vendor=The Apache Software Foundation",
- "sling.servlet.paths=/system/sling/info"
- })
+@Component(service = Servlet.class, property = { "service.description=Sling
Info Servlet",
+ "service.vendor=The Apache Software Foundation",
"sling.servlet.paths=/system/sling/info" })
public class SlingInfoServlet extends SlingSafeMethodsServlet {
private static final String CACHE_CONTROL_HEADER = "Cache-Control";
- private static final String CACHE_CONTROL_HEADER_VALUE =
- "private, no-store, no-cache, max-age=0, must-revalidate";
+ private static final String CACHE_CONTROL_HEADER_VALUE = "private,
no-store, no-cache, max-age=0, must-revalidate";
static final String PROVIDER_LABEL = "sessionInfo";
@@ -71,22 +66,21 @@ public class SlingInfoServlet extends
SlingSafeMethodsServlet {
}
@Override
- protected void doGet(final SlingHttpServletRequest request,
- final SlingHttpServletResponse response) throws IOException {
+ protected void doGet(final SlingHttpServletRequest request, final
SlingHttpServletResponse response)
+ throws IOException {
Map<String, String> data = null;
if (request.getRequestPathInfo().getSelectors().length > 0) {
final String label =
request.getRequestPathInfo().getSelectors()[0];
- if ( PROVIDER_LABEL.equals(label) ) {
+ if (PROVIDER_LABEL.equals(label)) {
data = this.getInfo(request);
}
}
if (data == null) {
- response.sendError(HttpServletResponse.SC_NOT_FOUND,
- "Unknown Info Request");
+ response.sendError(HttpServletResponse.SC_NOT_FOUND, "Unknown Info
Request");
} else {
response.setHeader(CACHE_CONTROL_HEADER,
CACHE_CONTROL_HEADER_VALUE);
@@ -103,28 +97,24 @@ public class SlingInfoServlet extends
SlingSafeMethodsServlet {
}
}
- private void renderJson(final SlingHttpServletResponse response,
- final Map<String, String> data) throws IOException {
+ private void renderJson(final SlingHttpServletResponse response, final
Map<String, String> data)
+ throws IOException {
// render data in JSON format
response.setContentType("application/json");
response.setCharacterEncoding("UTF-8");
final Writer out = response.getWriter();
- try (JsonGenerator w = Json.createGenerator(out)){
- w.writeStartObject();
- for (final Map.Entry<String, String> e : data.entrySet()) {
- w.write(e.getKey(), e.getValue());
- }
- w.writeEnd();
- } catch (JsonException jse) {
- out.write(jse.toString());
- } finally {
- out.flush();
+ //deliberately not closing, as that closes the response out.
+ final JsonGenerator w = Json.createGenerator(out);
+ w.writeStartObject();
+ for (final Map.Entry<String, String> e : data.entrySet()) {
+ w.write(e.getKey(), e.getValue());
}
+ w.writeEnd();
}
- private void renderHtml(final SlingHttpServletResponse response,
- final Map<String, String> data) throws IOException {
+ private void renderHtml(final SlingHttpServletResponse response, final
Map<String, String> data)
+ throws IOException {
// render data in JSON format
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
@@ -149,8 +139,8 @@ public class SlingInfoServlet extends
SlingSafeMethodsServlet {
out.flush();
}
- private void renderPlainText(final SlingHttpServletResponse response,
- final Map<String, String> data) throws IOException {
+ private void renderPlainText(final SlingHttpServletResponse response,
final Map<String, String> data)
+ throws IOException {
// render data in JSON format
response.setContentType("text/plain");