Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Fix encoding in pretty mode #3373

Merged
merged 1 commit into from
Aug 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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
Loading