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 604e176215..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; @@ -128,6 +134,7 @@ public void close() { if (this.body != null) { try { this.body.close(); + this.body = null; } catch (IOException e) { // ignored } @@ -227,13 +234,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 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.",