Skip to content

Commit

Permalink
Fix encoding in pretty mode
Browse files Browse the repository at this point in the history
  • Loading branch information
sbrunner committed Aug 9, 2024
1 parent e059789 commit fcc1a4b
Show file tree
Hide file tree
Showing 3 changed files with 43 additions and 1 deletion.
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}

Expand Down
40 changes: 40 additions & 0 deletions examples/src/test/java/org/mapfish/print/PrintApiTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -89,6 +89,46 @@ public void testGetCapabilitiesPretty_NoApp() throws Exception {
}
}

private void capabilitiesTest(final JSONObject json) {
boolean found = false;
JSONArray layouts = json.getJSONArray("layouts");
JSONObject firstLayout = layouts.getJSONObject(0);
JSONArray attributes = firstLayout.getJSONArray("attributes");
for (int i = 0; i < attributes.length(); i++) {
Object v = attributes.get(i);
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() throws Exception {
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 =
Expand Down
2 changes: 2 additions & 0 deletions examples/src/test/resources/examples/simple/config.yaml
Original file line number Diff line number Diff line change
Expand Up @@ -8,6 +8,8 @@ templates:
attributes:
title: !string
default: 'Countries'
copyright: !string
default: '© me'
map: !map
maxDpi: 400
width: 780
Expand Down

0 comments on commit fcc1a4b

Please sign in to comment.