From 69d5cbfc766e5ff5ab128fa738fa0794586bd04d Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Fri, 1 Nov 2024 09:34:19 +0100 Subject: [PATCH 1/2] Use getRawStatusCode to don't get an exception on fake status code 999 --- .../http/ErrorResponseClientHttpResponse.java | 7 +++--- .../print/map/geotools/FeaturesParser.java | 2 +- .../map/image/AbstractSingleImageLayer.java | 7 +++--- .../print/map/style/ParserPluginUtils.java | 6 ++--- .../mapfish/print/map/tiled/CoverageTask.java | 23 ++++++++++--------- .../processor/jasper/HttpImageResolver.java | 4 ++-- .../processor/jasper/LegendProcessor.java | 4 ++-- 7 files changed, 28 insertions(+), 25 deletions(-) diff --git a/core/src/main/java/org/mapfish/print/http/ErrorResponseClientHttpResponse.java b/core/src/main/java/org/mapfish/print/http/ErrorResponseClientHttpResponse.java index 61e59196a4..c21874a2b3 100644 --- a/core/src/main/java/org/mapfish/print/http/ErrorResponseClientHttpResponse.java +++ b/core/src/main/java/org/mapfish/print/http/ErrorResponseClientHttpResponse.java @@ -9,8 +9,8 @@ public class ErrorResponseClientHttpResponse extends AbstractClientHttpResponse { private final Exception exception; - /** HTTP code use in response for non HTTP errors. */ - private static final int FAKE_HTTP_ERROR_CODE = 999; + /** HTTP code use in response for non HTTP errors, (Not Acceptable). */ + private static final int FAKE_HTTP_ERROR_CODE = 406; public ErrorResponseClientHttpResponse(final Exception e) { assert e != null; @@ -38,7 +38,8 @@ public int getRawStatusCode() { @Nonnull public String getStatusText() { return String.format( - "%s: %s", this.exception.getClass().getSimpleName(), this.exception.getMessage()); + "Not true HTTP code, %s: %s, see above error", + this.exception.getClass().getSimpleName(), this.exception.getMessage()); } @Override diff --git a/core/src/main/java/org/mapfish/print/map/geotools/FeaturesParser.java b/core/src/main/java/org/mapfish/print/map/geotools/FeaturesParser.java index d4e3e45891..9d84a43b91 100644 --- a/core/src/main/java/org/mapfish/print/map/geotools/FeaturesParser.java +++ b/core/src/main/java/org/mapfish/print/map/geotools/FeaturesParser.java @@ -93,7 +93,7 @@ static final CoordinateReferenceSystem parseCoordinateReferenceSystem( requestFactory.createRequest(new URI(uri), HttpMethod.GET); try (ClientHttpResponse response = request.execute()) { - if (response.getStatusCode() == HttpStatus.OK) { + if (response.getRawStatusCode() == HttpStatus.OK.value()) { final String wkt = IOUtils.toString(response.getBody(), Constants.DEFAULT_ENCODING); try { diff --git a/core/src/main/java/org/mapfish/print/map/image/AbstractSingleImageLayer.java b/core/src/main/java/org/mapfish/print/map/image/AbstractSingleImageLayer.java index 2082c70b15..9ce0821658 100644 --- a/core/src/main/java/org/mapfish/print/map/image/AbstractSingleImageLayer.java +++ b/core/src/main/java/org/mapfish/print/map/image/AbstractSingleImageLayer.java @@ -202,14 +202,15 @@ private boolean isResponseStatusCodeValid( final String stringBody, final String baseMetricName) throws IOException { - if (httpResponse.getStatusCode() != HttpStatus.OK) { + if (httpResponse.getRawStatusCode() != HttpStatus.OK.value()) { String message = String.format( - "Invalid status code for %s (%d!=%d).With request headers:\n%s\n" + "Invalid status code for %s (%d!=%d), status: %s. With request headers:\n%s\n" + "The response was: '%s'\nWith response headers:\n%s", request.getURI(), - httpResponse.getStatusCode().value(), + httpResponse.getRawStatusCode(), HttpStatus.OK.value(), + httpResponse.getStatusText(), String.join("\n", Utils.getPrintableHeadersList(request.getHeaders())), httpResponse.getStatusText(), String.join("\n", Utils.getPrintableHeadersList(httpResponse.getHeaders()))); diff --git a/core/src/main/java/org/mapfish/print/map/style/ParserPluginUtils.java b/core/src/main/java/org/mapfish/print/map/style/ParserPluginUtils.java index 379aba9a80..d965fabb8d 100644 --- a/core/src/main/java/org/mapfish/print/map/style/ParserPluginUtils.java +++ b/core/src/main/java/org/mapfish/print/map/style/ParserPluginUtils.java @@ -34,7 +34,7 @@ public static Optional