From 3002b0b9ee280001f0adeb6afc8eca5726b76d93 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Fri, 9 Feb 2024 15:49:15 +0100 Subject: [PATCH 1/3] Be clear that's not an HTTP error --- .../main/java/org/mapfish/print/http/HttpRequestFetcher.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java b/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java index 604e176215..caf2e9ae6e 100644 --- a/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java +++ b/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java @@ -227,13 +227,13 @@ public InputStream getBody() { @Override public int getRawStatusCode() { - return 500; + return 999; } @Override @Nonnull public String getStatusText() { - return e.getMessage(); + return String.format("IOException: %s", e.getMessage()); } @Override From 2097d40b8fddf4bd096fc55df635e9735e4cae5c Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Tue, 13 Feb 2024 15:35:57 +0100 Subject: [PATCH 2/3] Remove pointer to closed input stream --- .../print/http/ConfigFileResolvingHttpRequestFactory.java | 3 ++- .../main/java/org/mapfish/print/http/HttpRequestFetcher.java | 1 + .../org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java | 1 + 3 files changed, 4 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactory.java b/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactory.java index 57d8a70719..cee9a8da71 100644 --- a/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactory.java +++ b/core/src/main/java/org/mapfish/print/http/ConfigFileResolvingHttpRequestFactory.java @@ -231,7 +231,8 @@ private ClientHttpResponse doHttpRequestWithRetry(final HttpHeaders headers) thr throw e; } } - } while (true); } + } while (true); + } private ClientHttpResponse executeCallbacksAndRequest(final ClientHttpRequest requestToExecute) throws IOException { diff --git a/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java b/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java index caf2e9ae6e..adc8c6d365 100644 --- a/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java +++ b/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java @@ -128,6 +128,7 @@ public void close() { if (this.body != null) { try { this.body.close(); + this.body = null; } catch (IOException e) { // ignored } diff --git a/core/src/main/java/org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java b/core/src/main/java/org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java index 4936e6d9b0..91adce4991 100644 --- a/core/src/main/java/org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java +++ b/core/src/main/java/org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java @@ -241,6 +241,7 @@ public void close() { getBody(); if (inputStream != null) { inputStream.close(); + inputStream = null; } } catch (IOException e) { LOGGER.error("Error occurred while trying to retrieve Http Response {} in order to close it.", From e2e3701b137fa9e9d46de0184873cd20f49296d2 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Tue, 13 Feb 2024 15:38:21 +0100 Subject: [PATCH 3/3] Add some logs for debugging --- .../java/org/mapfish/print/http/HttpRequestFetcher.java | 8 +++++++- 1 file changed, 7 insertions(+), 1 deletion(-) diff --git a/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java b/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java index adc8c6d365..8d23a25b8b 100644 --- a/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java +++ b/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java @@ -92,8 +92,13 @@ private CachedClientHttpResponse(final ClientHttpResponse originalResponse) thro this.statusText = originalResponse.getStatusText(); this.cachedFile = File.createTempFile("cacheduri", null, HttpRequestFetcher.this.temporaryDirectory); + LOGGER.debug("Caching URI resource to {}", this.cachedFile); try (OutputStream os = Files.newOutputStream(this.cachedFile.toPath())) { - IOUtils.copy(originalResponse.getBody(), os); + InputStream body = originalResponse.getBody(); + LOGGER.debug("Get from input stream {}, for response {}", + body.getClass(), originalResponse.getClass()); + LOGGER.debug("Body available: {}", body.available()); + IOUtils.copy(body, os); } } @@ -101,6 +106,7 @@ private CachedClientHttpResponse(final ClientHttpResponse originalResponse) thro @Nonnull public InputStream getBody() throws IOException { if (this.body == null) { + LOGGER.debug("Loading cached URI resource from {}", this.cachedFile); this.body = new FileInputStream(this.cachedFile); } return this.body;