diff --git a/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java b/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java index e2a6d31844..d49e91457e 100644 --- a/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java +++ b/core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java @@ -789,7 +789,7 @@ public final void getCapabilities( if (pretty) { final JSONObject jsonObject = new JSONObject(prettyPrintBuffer.toString(Constants.DEFAULT_CHARSET)); - capabilitiesResponse.getOutputStream().print(jsonObject.toString(JSON_INDENT_FACTOR)); + capabilitiesResponse.getWriter().print(jsonObject.toString(JSON_INDENT_FACTOR)); } } diff --git a/examples/src/test/java/org/mapfish/print/PrintApiTest.java b/examples/src/test/java/org/mapfish/print/PrintApiTest.java index f297aa3d4b..025c838bd4 100644 --- a/examples/src/test/java/org/mapfish/print/PrintApiTest.java +++ b/examples/src/test/java/org/mapfish/print/PrintApiTest.java @@ -89,6 +89,46 @@ public void testGetCapabilitiesPretty_NoApp() throws Exception { } } + private void capabilitiesTest(final JSONObject json) { + boolean found = false; + json.getJSONArray("layouts") + .getJSONObject(0) + .getJSONArray("attributes") + .forEach( + v -> { + assertTrue(v instanceof JSONObject); + JSONObject o = (JSONObject) v; + if ("copyright".equals(o.getString("name"))) { + found = true; + assertEquals("© me", o.getString("default")); + } + }); + assertTrue(found); + } + + @Test + public void testGetCapabilitiesEncoding() { + ClientHttpRequest request = + getPrintRequest("simple/" + MapPrinterServlet.CAPABILITIES_URL, HttpMethod.GET); + try (ClientHttpResponse response = request.execute()) { + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertTrue(getBodyAsText(response).contains("\n")); + capabilitiesTest(new JSONObject(getBodyAsText(response))); + } + } + + @Test + public void testGetCapabilitiesEncodingPretty() throws Exception { + ClientHttpRequest request = + getPrintRequest( + "simple/" + MapPrinterServlet.CAPABILITIES_URL + "?pretty=true", HttpMethod.GET); + try (ClientHttpResponse response = request.execute()) { + assertEquals(HttpStatus.OK, response.getStatusCode()); + assertTrue(getBodyAsText(response).contains("\n")); + capabilitiesTest(new JSONObject(getBodyAsText(response))); + } + } + @Test public void testExampleRequest_NoApp() throws Exception { ClientHttpRequest request = diff --git a/examples/src/test/resources/examples/simple/config.yaml b/examples/src/test/resources/examples/simple/config.yaml index 50d215da31..2549ea810b 100644 --- a/examples/src/test/resources/examples/simple/config.yaml +++ b/examples/src/test/resources/examples/simple/config.yaml @@ -8,6 +8,8 @@ templates: attributes: title: !string default: 'Countries' + copyright: !string + default: '© me' map: !map maxDpi: 400 width: 780