Skip to content

Commit 89155f2

Browse files

File tree

6 files changed

+54
-292
lines changed

6 files changed

+54
-292
lines changed

BREAKING-CHANGES.md

+4
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,9 @@
11
# Known breaking changes
22

3+
## Version 3.24
4+
5+
- Removing JsonP support.
6+
37
## Version 3.13
48

59
- If throwErrorOnExtraParameters is set to true and the JSON contains extra attributes,

core/src/main/java/org/mapfish/print/servlet/MapPrinterServlet.java

+15-76
Original file line numberDiff line numberDiff line change
@@ -121,7 +121,7 @@ public class MapPrinterServlet extends BaseMapServlet {
121121
/**
122122
* If the job is done (value is true) or not (value is false).
123123
*
124-
* Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest,
124+
* Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest,
125125
* javax.servlet.http.HttpServletResponse)} response.
126126
*/
127127
public static final String JSON_DONE = "done";
@@ -134,22 +134,22 @@ public class MapPrinterServlet extends BaseMapServlet {
134134
* <li>cancelled</li>
135135
* <li>error</li>
136136
* </ul>
137-
* Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest,
137+
* Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest,
138138
* javax.servlet.http.HttpServletResponse)} response
139139
*/
140140
public static final String JSON_STATUS = "status";
141141
/**
142142
* The elapsed time in ms from the point the job started. If the job is finished, this is the duration it
143143
* took to process the job.
144144
*
145-
* Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest,
145+
* Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest,
146146
* javax.servlet.http.HttpServletResponse)} response.
147147
*/
148148
public static final String JSON_ELAPSED_TIME = "elapsedTime";
149149
/**
150150
* A rough estimate for the time in ms the job still has to wait in the queue until it starts processing.
151151
*
152-
* Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest,
152+
* Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest,
153153
* javax.servlet.http.HttpServletResponse)} response.
154154
*/
155155
public static final String JSON_WAITING_TIME = "waitingTime";
@@ -271,7 +271,8 @@ private static PJsonObject parseJson(
271271
private static String maybeAddRequestId(final String ref, final HttpServletRequest request) {
272272
final Optional<String> headerName =
273273
REQUEST_ID_HEADERS.stream().filter(h -> request.getHeader(h) != null).findFirst();
274-
return headerName.map(s -> ref + "@" + request.getHeader(s).replaceAll("[^a-zA-Z0-9._:-]", "_")
274+
return headerName.map(
275+
s -> ref + "@" + request.getHeader(s).replaceAll("[^a-zA-Z0-9._:-]", "_")
275276
).orElse(ref);
276277
}
277278

@@ -284,18 +285,16 @@ private static String maybeAddRequestId(final String ref, final HttpServletReque
284285
*
285286
* @param appId the app ID
286287
* @param referenceId the job reference
287-
* @param jsonpCallback if given the result is returned with a function call wrapped around it
288288
* @param statusRequest the request object
289289
* @param statusResponse the response object
290290
*/
291291
@RequestMapping(value = "/{appId}" + STATUS_URL + "/{referenceId:\\S+}.json", method = RequestMethod.GET)
292292
public final void getStatusSpecificAppId(
293293
@SuppressWarnings("unused") @PathVariable final String appId,
294294
@PathVariable final String referenceId,
295-
@RequestParam(value = "jsonp", defaultValue = "") final String jsonpCallback,
296295
final HttpServletRequest statusRequest,
297296
final HttpServletResponse statusResponse) {
298-
getStatus(referenceId, jsonpCallback, statusRequest, statusResponse);
297+
getStatus(referenceId, statusRequest, statusResponse);
299298
}
300299

301300
/**
@@ -306,25 +305,21 @@ public final void getStatusSpecificAppId(
306305
* </code></pre>
307306
*
308307
* @param referenceId the job reference
309-
* @param jsonpCallback if given the result is returned with a function call wrapped around it
310308
* @param statusRequest the request object
311309
* @param statusResponse the response object
312310
*/
313311
@RequestMapping(value = STATUS_URL + "/{referenceId:\\S+}.json", method = RequestMethod.GET)
314312
public final void getStatus(
315313
@PathVariable final String referenceId,
316-
@RequestParam(value = "jsonp", defaultValue = "") final String jsonpCallback,
317314
final HttpServletRequest statusRequest,
318315
final HttpServletResponse statusResponse) {
319316
MDC.put(Processor.MDC_JOB_ID_KEY, referenceId);
320317
setNoCache(statusResponse);
321318
try {
322319
PrintJobStatus status = this.jobManager.getStatus(referenceId);
323320

324-
setContentType(statusResponse, jsonpCallback);
321+
setContentType(statusResponse);
325322
try (PrintWriter writer = statusResponse.getWriter()) {
326-
327-
appendJsonpCallback(jsonpCallback, writer);
328323
JSONWriter json = new JSONWriter(writer);
329324
json.object();
330325
{
@@ -339,7 +334,6 @@ public final void getStatus(
339334
addDownloadLinkToJson(statusRequest, referenceId, json);
340335
}
341336
json.endObject();
342-
appendJsonpCallbackEnd(jsonpCallback, writer);
343337
}
344338
} catch (JSONException | IOException e) {
345339
throw ExceptionUtils.getRuntimeException(e);
@@ -638,22 +632,18 @@ public final void createReportAndGetNoAppId(
638632
/**
639633
* To get (in JSON) the information about the available formats and CO.
640634
*
641-
* @param jsonpCallback if given the result is returned with a function call wrapped around it
642635
* @param listAppsResponse the response object
643636
*/
644637
@RequestMapping(value = LIST_APPS_URL, method = RequestMethod.GET)
645638
public final void listAppIds(
646-
@RequestParam(value = "jsonp", defaultValue = "") final String jsonpCallback,
647639
final HttpServletResponse listAppsResponse) throws ServletException,
648640
IOException {
649641
MDC.remove(Processor.MDC_JOB_ID_KEY);
650642
setCache(listAppsResponse);
651643
Set<String> appIds = this.printerFactory.getAppIds();
652644

653-
setContentType(listAppsResponse, jsonpCallback);
645+
setContentType(listAppsResponse);
654646
try (PrintWriter writer = listAppsResponse.getWriter()) {
655-
appendJsonpCallback(jsonpCallback, writer);
656-
657647
JSONWriter json = new JSONWriter(writer);
658648
try {
659649
json.array();
@@ -664,27 +654,23 @@ public final void listAppIds(
664654
} catch (JSONException e) {
665655
throw new ServletException(e);
666656
}
667-
668-
appendJsonpCallbackEnd(jsonpCallback, writer);
669657
}
670658
}
671659

672660
/**
673661
* To get (in JSON) the information about the available formats and CO.
674662
*
675663
* @param pretty if true then pretty print the capabilities
676-
* @param jsonpCallback if given the result is returned with a function call wrapped around it
677664
* @param request the request
678665
* @param capabilitiesResponse the response object
679666
*/
680667
@RequestMapping(value = CAPABILITIES_URL, method = RequestMethod.GET)
681668
public final void getCapabilities(
682669
@RequestParam(value = "pretty", defaultValue = "false") final boolean pretty,
683-
@RequestParam(value = "jsonp", defaultValue = "") final String jsonpCallback,
684670
final HttpServletRequest request,
685671
final HttpServletResponse capabilitiesResponse) throws ServletException,
686672
IOException {
687-
getCapabilities(DEFAULT_CONFIGURATION_FILE_KEY, pretty, jsonpCallback, request, capabilitiesResponse);
673+
getCapabilities(DEFAULT_CONFIGURATION_FILE_KEY, pretty, request, capabilitiesResponse);
688674
}
689675

690676
/**
@@ -693,15 +679,13 @@ public final void getCapabilities(
693679
* @param appId the name of the "app" or in other words, a mapping to the configuration file for
694680
* this request.
695681
* @param pretty if true then pretty print the capabilities
696-
* @param jsonpCallback if given the result is returned with a function call wrapped around it
697682
* @param request the request
698683
* @param capabilitiesResponse the response object
699684
*/
700685
@RequestMapping(value = "/{appId}" + CAPABILITIES_URL, method = RequestMethod.GET)
701686
public final void getCapabilities(
702687
@PathVariable final String appId,
703688
@RequestParam(value = "pretty", defaultValue = "false") final boolean pretty,
704-
@RequestParam(value = "jsonp", defaultValue = "") final String jsonpCallback,
705689
final HttpServletRequest request,
706690
final HttpServletResponse capabilitiesResponse) throws ServletException,
707691
IOException {
@@ -719,16 +703,12 @@ public final void getCapabilities(
719703
return;
720704
}
721705

722-
setContentType(capabilitiesResponse, jsonpCallback);
706+
setContentType(capabilitiesResponse);
723707

724708
final ByteArrayOutputStream prettyPrintBuffer = new ByteArrayOutputStream();
725709

726710
try (Writer writer = pretty ? new OutputStreamWriter(prettyPrintBuffer, Constants.DEFAULT_CHARSET) :
727711
capabilitiesResponse.getWriter()) {
728-
if (!pretty && !StringUtils.isEmpty(jsonpCallback)) {
729-
writer.append(jsonpCallback).append("(");
730-
}
731-
732712
JSONWriter json = new JSONWriter(writer);
733713
try {
734714
json.object();
@@ -749,53 +729,38 @@ public final void getCapabilities(
749729
} catch (JSONException e) {
750730
throw new ServletException(e);
751731
}
752-
753-
if (!pretty && !StringUtils.isEmpty(jsonpCallback)) {
754-
writer.append(");");
755-
}
756732
}
757733

758734
if (pretty) {
759735
final JSONObject jsonObject =
760736
new JSONObject(new String(prettyPrintBuffer.toByteArray(), Constants.DEFAULT_CHARSET));
761-
762-
if (!StringUtils.isEmpty(jsonpCallback)) {
763-
capabilitiesResponse.getOutputStream().print(jsonpCallback + "(");
764-
}
765737
capabilitiesResponse.getOutputStream().print(jsonObject.toString(JSON_INDENT_FACTOR));
766-
if (!StringUtils.isEmpty(jsonpCallback)) {
767-
capabilitiesResponse.getOutputStream().print(");");
768-
}
769738
}
770739
}
771740

772741
/**
773742
* Get a sample request for the app. An empty response may be returned if there is not example request.
774743
*
775-
* @param jsonpCallback if given the result is returned with a function call wrapped around it
776744
* @param request the request object
777745
* @param getExampleResponse the response object
778746
*/
779747
@RequestMapping(value = EXAMPLE_REQUEST_URL, method = RequestMethod.GET)
780748
public final void getExampleRequest(
781-
@RequestParam(value = "jsonp", defaultValue = "") final String jsonpCallback,
782749
final HttpServletRequest request,
783750
final HttpServletResponse getExampleResponse) throws IOException {
784-
getExampleRequest(DEFAULT_CONFIGURATION_FILE_KEY, jsonpCallback, request, getExampleResponse);
751+
getExampleRequest(DEFAULT_CONFIGURATION_FILE_KEY, request, getExampleResponse);
785752
}
786753

787754
/**
788755
* Get a sample request for the app. An empty response may be returned if there is not example request.
789756
*
790757
* @param appId the id of the app to get the request for.
791-
* @param jsonpCallback if given the result is returned with a function call wrapped around it
792758
* @param request the request object
793759
* @param getExampleResponse the response object
794760
*/
795761
@RequestMapping(value = "{appId}" + EXAMPLE_REQUEST_URL, method = RequestMethod.GET)
796762
public final void getExampleRequest(
797763
@PathVariable final String appId,
798-
@RequestParam(value = "jsonp", defaultValue = "") final String jsonpCallback,
799764
final HttpServletRequest request,
800765
final HttpServletResponse getExampleResponse) throws
801766
IOException {
@@ -827,7 +792,7 @@ public final void getExampleRequest(
827792
jsonObject.remove(JSON_APP);
828793
requestData = jsonObject.toString(JSON_INDENT_FACTOR);
829794

830-
setContentType(getExampleResponse, jsonpCallback);
795+
setContentType(getExampleResponse);
831796
} catch (JSONException e) {
832797
// ignore, return raw text
833798
}
@@ -864,9 +829,7 @@ public final void getExampleRequest(
864829
}
865830

866831
try (PrintWriter writer = getExampleResponse.getWriter()) {
867-
appendJsonpCallback(jsonpCallback, writer);
868832
writer.append(result);
869-
appendJsonpCallbackEnd(jsonpCallback, writer);
870833
}
871834
} catch (NoSuchAppException e) {
872835
error(getExampleResponse, "No print app identified by: " + appId, HttpStatus.NOT_FOUND);
@@ -1076,31 +1039,7 @@ private <R> R loadReport(
10761039

10771040
}
10781041

1079-
private void setContentType(
1080-
final HttpServletResponse statusResponse,
1081-
final String jsonpCallback) {
1082-
if (StringUtils.isEmpty(jsonpCallback)) {
1083-
statusResponse.setContentType("application/json; charset=utf-8");
1084-
} else {
1085-
statusResponse.setContentType("application/javascript; charset=utf-8");
1086-
}
1087-
}
1088-
1089-
private void appendJsonpCallback(
1090-
final String jsonpCallback,
1091-
final PrintWriter writer) {
1092-
if (!StringUtils.isEmpty(jsonpCallback)) {
1093-
writer.append(jsonpCallback);
1094-
writer.append("(");
1095-
}
1042+
private void setContentType(final HttpServletResponse statusResponse) {
1043+
statusResponse.setContentType("application/json; charset=utf-8");
10961044
}
1097-
1098-
private void appendJsonpCallbackEnd(
1099-
final String jsonpCallback,
1100-
final PrintWriter writer) {
1101-
if (!StringUtils.isEmpty(jsonpCallback)) {
1102-
writer.append(");");
1103-
}
1104-
}
1105-
11061045
}

core/src/test/java/org/mapfish/print/servlet/MapPrinterServletSecurityTest.java

+1-1
Original file line numberDiff line numberDiff line change
@@ -110,7 +110,7 @@ public void testCreateReportAndGet_RequestAllowed_OtherGetDenied() throws Except
110110
while (!done) {
111111
MockHttpServletRequest servletStatusRequest = new MockHttpServletRequest("GET", statusURL);
112112
MockHttpServletResponse servletStatusResponse = new MockHttpServletResponse();
113-
servlet.getStatus(ref, null, servletStatusRequest, servletStatusResponse);
113+
servlet.getStatus(ref, servletStatusRequest, servletStatusResponse);
114114

115115
String contentAsString = servletStatusResponse.getContentAsString();
116116

0 commit comments

Comments
 (0)