From 2983f4dbeccb4a52635fca61b37fbd72e35bc41b 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/4] Be clear that's not an HTTP error --- .../print/http/ErrorResponseClientHttpResponse.java | 8 ++++++-- 1 file changed, 6 insertions(+), 2 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 9fbf768fc6..61e59196a4 100644 --- a/core/src/main/java/org/mapfish/print/http/ErrorResponseClientHttpResponse.java +++ b/core/src/main/java/org/mapfish/print/http/ErrorResponseClientHttpResponse.java @@ -9,6 +9,9 @@ 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; + public ErrorResponseClientHttpResponse(final Exception e) { assert e != null; this.exception = e; @@ -28,13 +31,14 @@ public InputStream getBody() { @Override public int getRawStatusCode() { - return 500; + return FAKE_HTTP_ERROR_CODE; } @Override @Nonnull public String getStatusText() { - return exception.getMessage(); + return String.format( + "%s: %s", this.exception.getClass().getSimpleName(), this.exception.getMessage()); } @Override From a7825102a3f76c8028a75f87b8b7de082b779312 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/4] Remove pointer to closed input stream --- .../org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java | 2 ++ 1 file changed, 2 insertions(+) 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 d877248c20..dc6767edc4 100644 --- a/core/src/main/java/org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java +++ b/core/src/main/java/org/mapfish/print/http/MfClientHttpRequestFactoryImpl.java @@ -235,12 +235,14 @@ 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.", this.id, e); + inputStream = null; } LOGGER.trace("Closed Http Response object: {}", this.id); } From ca492f4b78306449ba896b0fa0f0d28180330ea6 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/4] Add some logs for debugging --- .../org/mapfish/print/http/HttpRequestFetcher.java | 10 +++++++++- 1 file changed, 9 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 f49b46a144..58ab3d3c0e 100644 --- a/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java +++ b/core/src/main/java/org/mapfish/print/http/HttpRequestFetcher.java @@ -89,8 +89,15 @@ 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 available: {}", + body.getClass(), + originalResponse.getClass(), + body.available()); + IOUtils.copy(body, os); } } @@ -98,6 +105,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; From 8c0535e37cf9244ce047ed5cf6249456e0fe901e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?St=C3=A9phane=20Brunner?= Date: Tue, 30 Apr 2024 11:04:32 +0200 Subject: [PATCH 4/4] Fix pre-commit patch --- .github/workflows/main.yaml | 42 +++++++++++++++++++------------------ 1 file changed, 22 insertions(+), 20 deletions(-) diff --git a/.github/workflows/main.yaml b/.github/workflows/main.yaml index aa425f4bfd..fec05881e7 100644 --- a/.github/workflows/main.yaml +++ b/.github/workflows/main.yaml @@ -30,6 +30,27 @@ jobs: with: fetch-depth: 0 + - run: echo "${HOME}/.local/bin" >> ${GITHUB_PATH} + - run: python3 -m pip install --user --requirement=ci/requirements.txt + + - uses: actions/cache@v4 + with: + path: ~/.cache/pre-commit + key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} + restore-keys: "pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}\npre-commit-" + - run: pre-commit run --all-files + - run: git diff --exit-code --patch > /tmp/pre-commit.patch || true + if: failure() + - uses: actions/upload-artifact@v4 + with: + name: Apply pre-commit fix.patch + path: /tmp/pre-commit.patch + retention-days: 1 + if: failure() + + - name: Print environment information + run: c2cciutils-env + - name: Get tag id: tag2 uses: frabert/replace-string-action@v2.5 @@ -46,6 +67,7 @@ jobs: github-gopass-ci-token: ${{secrets.GOPASS_CI_GITHUB_TOKEN}} patterns: docker if: env.HAS_SECRETS == 'HAS_SECRETS' + - run: gpg --export-secret-keys --armor D121AF2DFA8E140688BD968930C9B913FD42EF13 > CI.asc if: env.HAS_SECRETS == 'HAS_SECRETS' @@ -77,26 +99,6 @@ jobs: if: env.HAS_SECRETS == 'HAS_SECRETS' - run: git diff - - run: echo "${HOME}/.local/bin" >> ${GITHUB_PATH} - - run: python3 -m pip install --user --requirement=ci/requirements.txt - - - uses: actions/cache@v4 - with: - path: ~/.cache/pre-commit - key: pre-commit-${{ hashFiles('.pre-commit-config.yaml') }} - restore-keys: "pre-commit-${{ hashFiles('.pre-commit-config.yaml') }}\npre-commit-" - - run: pre-commit run --all-files - - run: git diff --exit-code --patch > /tmp/pre-commit.patch || true - if: failure() - - uses: actions/upload-artifact@v4 - with: - name: Apply pre-commit fix.patch - path: /tmp/pre-commit.patch - retention-days: 1 - if: failure() - - name: Print environment information - run: c2cciutils-env - - run: make build - run: make checks