Skip to content

Commit

Permalink
Merge pull request #3373 from mapfish/encoding
Browse files Browse the repository at this point in the history
Fix encoding in pretty mode
  • Loading branch information
sbrunner authored Aug 10, 2024
2 parents a8872a4 + 405dea7 commit 5db375c
Show file tree
Hide file tree
Showing 3 changed files with 42 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
39 changes: 39 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,45 @@ public void testGetCapabilitiesPretty_NoApp() throws Exception {
}
}

private void capabilitiesTest(ClientHttpResponse response) throws Exception {
final JSONObject json = new JSONObject(getBodyAsText(response));
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());
capabilitiesTest(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());
capabilitiesTest(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 5db375c

Please sign in to comment.