@@ -121,7 +121,7 @@ public class MapPrinterServlet extends BaseMapServlet {
121
121
/**
122
122
* If the job is done (value is true) or not (value is false).
123
123
*
124
- * Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest,
124
+ * Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest,
125
125
* javax.servlet.http.HttpServletResponse)} response.
126
126
*/
127
127
public static final String JSON_DONE = "done" ;
@@ -134,22 +134,22 @@ public class MapPrinterServlet extends BaseMapServlet {
134
134
* <li>cancelled</li>
135
135
* <li>error</li>
136
136
* </ul>
137
- * Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest,
137
+ * Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest,
138
138
* javax.servlet.http.HttpServletResponse)} response
139
139
*/
140
140
public static final String JSON_STATUS = "status" ;
141
141
/**
142
142
* The elapsed time in ms from the point the job started. If the job is finished, this is the duration it
143
143
* took to process the job.
144
144
*
145
- * Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest,
145
+ * Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest,
146
146
* javax.servlet.http.HttpServletResponse)} response.
147
147
*/
148
148
public static final String JSON_ELAPSED_TIME = "elapsedTime" ;
149
149
/**
150
150
* A rough estimate for the time in ms the job still has to wait in the queue until it starts processing.
151
151
*
152
- * Part of the {@link #getStatus(String, String, javax.servlet.http.HttpServletRequest,
152
+ * Part of the {@link #getStatus(String, javax.servlet.http.HttpServletRequest,
153
153
* javax.servlet.http.HttpServletResponse)} response.
154
154
*/
155
155
public static final String JSON_WAITING_TIME = "waitingTime" ;
@@ -271,7 +271,8 @@ private static PJsonObject parseJson(
271
271
private static String maybeAddRequestId (final String ref , final HttpServletRequest request ) {
272
272
final Optional <String > headerName =
273
273
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._:-]" , "_" )
275
276
).orElse (ref );
276
277
}
277
278
@@ -284,18 +285,16 @@ private static String maybeAddRequestId(final String ref, final HttpServletReque
284
285
*
285
286
* @param appId the app ID
286
287
* @param referenceId the job reference
287
- * @param jsonpCallback if given the result is returned with a function call wrapped around it
288
288
* @param statusRequest the request object
289
289
* @param statusResponse the response object
290
290
*/
291
291
@ RequestMapping (value = "/{appId}" + STATUS_URL + "/{referenceId:\\ S+}.json" , method = RequestMethod .GET )
292
292
public final void getStatusSpecificAppId (
293
293
@ SuppressWarnings ("unused" ) @ PathVariable final String appId ,
294
294
@ PathVariable final String referenceId ,
295
- @ RequestParam (value = "jsonp" , defaultValue = "" ) final String jsonpCallback ,
296
295
final HttpServletRequest statusRequest ,
297
296
final HttpServletResponse statusResponse ) {
298
- getStatus (referenceId , jsonpCallback , statusRequest , statusResponse );
297
+ getStatus (referenceId , statusRequest , statusResponse );
299
298
}
300
299
301
300
/**
@@ -306,25 +305,21 @@ public final void getStatusSpecificAppId(
306
305
* </code></pre>
307
306
*
308
307
* @param referenceId the job reference
309
- * @param jsonpCallback if given the result is returned with a function call wrapped around it
310
308
* @param statusRequest the request object
311
309
* @param statusResponse the response object
312
310
*/
313
311
@ RequestMapping (value = STATUS_URL + "/{referenceId:\\ S+}.json" , method = RequestMethod .GET )
314
312
public final void getStatus (
315
313
@ PathVariable final String referenceId ,
316
- @ RequestParam (value = "jsonp" , defaultValue = "" ) final String jsonpCallback ,
317
314
final HttpServletRequest statusRequest ,
318
315
final HttpServletResponse statusResponse ) {
319
316
MDC .put (Processor .MDC_JOB_ID_KEY , referenceId );
320
317
setNoCache (statusResponse );
321
318
try {
322
319
PrintJobStatus status = this .jobManager .getStatus (referenceId );
323
320
324
- setContentType (statusResponse , jsonpCallback );
321
+ setContentType (statusResponse );
325
322
try (PrintWriter writer = statusResponse .getWriter ()) {
326
-
327
- appendJsonpCallback (jsonpCallback , writer );
328
323
JSONWriter json = new JSONWriter (writer );
329
324
json .object ();
330
325
{
@@ -339,7 +334,6 @@ public final void getStatus(
339
334
addDownloadLinkToJson (statusRequest , referenceId , json );
340
335
}
341
336
json .endObject ();
342
- appendJsonpCallbackEnd (jsonpCallback , writer );
343
337
}
344
338
} catch (JSONException | IOException e ) {
345
339
throw ExceptionUtils .getRuntimeException (e );
@@ -638,22 +632,18 @@ public final void createReportAndGetNoAppId(
638
632
/**
639
633
* To get (in JSON) the information about the available formats and CO.
640
634
*
641
- * @param jsonpCallback if given the result is returned with a function call wrapped around it
642
635
* @param listAppsResponse the response object
643
636
*/
644
637
@ RequestMapping (value = LIST_APPS_URL , method = RequestMethod .GET )
645
638
public final void listAppIds (
646
- @ RequestParam (value = "jsonp" , defaultValue = "" ) final String jsonpCallback ,
647
639
final HttpServletResponse listAppsResponse ) throws ServletException ,
648
640
IOException {
649
641
MDC .remove (Processor .MDC_JOB_ID_KEY );
650
642
setCache (listAppsResponse );
651
643
Set <String > appIds = this .printerFactory .getAppIds ();
652
644
653
- setContentType (listAppsResponse , jsonpCallback );
645
+ setContentType (listAppsResponse );
654
646
try (PrintWriter writer = listAppsResponse .getWriter ()) {
655
- appendJsonpCallback (jsonpCallback , writer );
656
-
657
647
JSONWriter json = new JSONWriter (writer );
658
648
try {
659
649
json .array ();
@@ -664,27 +654,23 @@ public final void listAppIds(
664
654
} catch (JSONException e ) {
665
655
throw new ServletException (e );
666
656
}
667
-
668
- appendJsonpCallbackEnd (jsonpCallback , writer );
669
657
}
670
658
}
671
659
672
660
/**
673
661
* To get (in JSON) the information about the available formats and CO.
674
662
*
675
663
* @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
677
664
* @param request the request
678
665
* @param capabilitiesResponse the response object
679
666
*/
680
667
@ RequestMapping (value = CAPABILITIES_URL , method = RequestMethod .GET )
681
668
public final void getCapabilities (
682
669
@ RequestParam (value = "pretty" , defaultValue = "false" ) final boolean pretty ,
683
- @ RequestParam (value = "jsonp" , defaultValue = "" ) final String jsonpCallback ,
684
670
final HttpServletRequest request ,
685
671
final HttpServletResponse capabilitiesResponse ) throws ServletException ,
686
672
IOException {
687
- getCapabilities (DEFAULT_CONFIGURATION_FILE_KEY , pretty , jsonpCallback , request , capabilitiesResponse );
673
+ getCapabilities (DEFAULT_CONFIGURATION_FILE_KEY , pretty , request , capabilitiesResponse );
688
674
}
689
675
690
676
/**
@@ -693,15 +679,13 @@ public final void getCapabilities(
693
679
* @param appId the name of the "app" or in other words, a mapping to the configuration file for
694
680
* this request.
695
681
* @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
697
682
* @param request the request
698
683
* @param capabilitiesResponse the response object
699
684
*/
700
685
@ RequestMapping (value = "/{appId}" + CAPABILITIES_URL , method = RequestMethod .GET )
701
686
public final void getCapabilities (
702
687
@ PathVariable final String appId ,
703
688
@ RequestParam (value = "pretty" , defaultValue = "false" ) final boolean pretty ,
704
- @ RequestParam (value = "jsonp" , defaultValue = "" ) final String jsonpCallback ,
705
689
final HttpServletRequest request ,
706
690
final HttpServletResponse capabilitiesResponse ) throws ServletException ,
707
691
IOException {
@@ -719,16 +703,12 @@ public final void getCapabilities(
719
703
return ;
720
704
}
721
705
722
- setContentType (capabilitiesResponse , jsonpCallback );
706
+ setContentType (capabilitiesResponse );
723
707
724
708
final ByteArrayOutputStream prettyPrintBuffer = new ByteArrayOutputStream ();
725
709
726
710
try (Writer writer = pretty ? new OutputStreamWriter (prettyPrintBuffer , Constants .DEFAULT_CHARSET ) :
727
711
capabilitiesResponse .getWriter ()) {
728
- if (!pretty && !StringUtils .isEmpty (jsonpCallback )) {
729
- writer .append (jsonpCallback ).append ("(" );
730
- }
731
-
732
712
JSONWriter json = new JSONWriter (writer );
733
713
try {
734
714
json .object ();
@@ -749,53 +729,38 @@ public final void getCapabilities(
749
729
} catch (JSONException e ) {
750
730
throw new ServletException (e );
751
731
}
752
-
753
- if (!pretty && !StringUtils .isEmpty (jsonpCallback )) {
754
- writer .append (");" );
755
- }
756
732
}
757
733
758
734
if (pretty ) {
759
735
final JSONObject jsonObject =
760
736
new JSONObject (new String (prettyPrintBuffer .toByteArray (), Constants .DEFAULT_CHARSET ));
761
-
762
- if (!StringUtils .isEmpty (jsonpCallback )) {
763
- capabilitiesResponse .getOutputStream ().print (jsonpCallback + "(" );
764
- }
765
737
capabilitiesResponse .getOutputStream ().print (jsonObject .toString (JSON_INDENT_FACTOR ));
766
- if (!StringUtils .isEmpty (jsonpCallback )) {
767
- capabilitiesResponse .getOutputStream ().print (");" );
768
- }
769
738
}
770
739
}
771
740
772
741
/**
773
742
* Get a sample request for the app. An empty response may be returned if there is not example request.
774
743
*
775
- * @param jsonpCallback if given the result is returned with a function call wrapped around it
776
744
* @param request the request object
777
745
* @param getExampleResponse the response object
778
746
*/
779
747
@ RequestMapping (value = EXAMPLE_REQUEST_URL , method = RequestMethod .GET )
780
748
public final void getExampleRequest (
781
- @ RequestParam (value = "jsonp" , defaultValue = "" ) final String jsonpCallback ,
782
749
final HttpServletRequest request ,
783
750
final HttpServletResponse getExampleResponse ) throws IOException {
784
- getExampleRequest (DEFAULT_CONFIGURATION_FILE_KEY , jsonpCallback , request , getExampleResponse );
751
+ getExampleRequest (DEFAULT_CONFIGURATION_FILE_KEY , request , getExampleResponse );
785
752
}
786
753
787
754
/**
788
755
* Get a sample request for the app. An empty response may be returned if there is not example request.
789
756
*
790
757
* @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
792
758
* @param request the request object
793
759
* @param getExampleResponse the response object
794
760
*/
795
761
@ RequestMapping (value = "{appId}" + EXAMPLE_REQUEST_URL , method = RequestMethod .GET )
796
762
public final void getExampleRequest (
797
763
@ PathVariable final String appId ,
798
- @ RequestParam (value = "jsonp" , defaultValue = "" ) final String jsonpCallback ,
799
764
final HttpServletRequest request ,
800
765
final HttpServletResponse getExampleResponse ) throws
801
766
IOException {
@@ -827,7 +792,7 @@ public final void getExampleRequest(
827
792
jsonObject .remove (JSON_APP );
828
793
requestData = jsonObject .toString (JSON_INDENT_FACTOR );
829
794
830
- setContentType (getExampleResponse , jsonpCallback );
795
+ setContentType (getExampleResponse );
831
796
} catch (JSONException e ) {
832
797
// ignore, return raw text
833
798
}
@@ -864,9 +829,7 @@ public final void getExampleRequest(
864
829
}
865
830
866
831
try (PrintWriter writer = getExampleResponse .getWriter ()) {
867
- appendJsonpCallback (jsonpCallback , writer );
868
832
writer .append (result );
869
- appendJsonpCallbackEnd (jsonpCallback , writer );
870
833
}
871
834
} catch (NoSuchAppException e ) {
872
835
error (getExampleResponse , "No print app identified by: " + appId , HttpStatus .NOT_FOUND );
@@ -1076,31 +1039,7 @@ private <R> R loadReport(
1076
1039
1077
1040
}
1078
1041
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" );
1096
1044
}
1097
-
1098
- private void appendJsonpCallbackEnd (
1099
- final String jsonpCallback ,
1100
- final PrintWriter writer ) {
1101
- if (!StringUtils .isEmpty (jsonpCallback )) {
1102
- writer .append (");" );
1103
- }
1104
- }
1105
-
1106
1045
}
0 commit comments