From 227d6b122da4442b1e7e1ada14a0fde6c7ff424d Mon Sep 17 00:00:00 2001 From: Andreas Fankhauser <23085769+hiddenalpha@users.noreply.github.com> Date: Thu, 4 Jan 2024 15:26:12 +0100 Subject: [PATCH] [SDCISA-13736, SDCISA-10974] Fix bad habits in ExpansionDeltaUtil. --- .../core/util/ExpansionDeltaUtil.java | 37 ++++++++++--------- 1 file changed, 19 insertions(+), 18 deletions(-) diff --git a/gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java b/gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java index 3295e6c43..fc74d5d13 100644 --- a/gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java +++ b/gateleen-core/src/main/java/org/swisspush/gateleen/core/util/ExpansionDeltaUtil.java @@ -5,6 +5,7 @@ import io.vertx.core.MultiMap; import io.vertx.core.buffer.Buffer; import io.vertx.core.http.HttpServerRequest; +import io.vertx.core.http.HttpServerResponse; import io.vertx.core.json.DecodeException; import io.vertx.core.json.JsonArray; import io.vertx.core.json.JsonObject; @@ -159,26 +160,25 @@ public enum SlashHandling { */ public static Handler createRequestExceptionHandler(final HttpServerRequest request, final String uri, final Class caller) { return exception -> { - if (log.isTraceEnabled()) { - log.trace("end response with content"); - } + log.trace("end response with content"); + HttpServerResponse rsp = request.response(); if (exception instanceof TimeoutException) { error("Timeout", request, uri, caller); - request.response().setStatusCode(StatusCode.TIMEOUT.getStatusCode()); - request.response().setStatusMessage(StatusCode.TIMEOUT.getStatusMessage()); + rsp.setStatusCode(StatusCode.TIMEOUT.getStatusCode()); + rsp.setStatusMessage(StatusCode.TIMEOUT.getStatusMessage()); try { - request.response().end(request.response().getStatusMessage()); - } catch (IllegalStateException e) { - // ignore because maybe already closed + rsp.end(rsp.getStatusMessage()); + } catch (IllegalStateException ex) { + log.debug("ignore because maybe already closed", ex); } } else { error(exception.getMessage(), request, uri, caller); - request.response().setStatusCode(StatusCode.SERVICE_UNAVAILABLE.getStatusCode()); - request.response().setStatusMessage(StatusCode.SERVICE_UNAVAILABLE.getStatusMessage()); + rsp.setStatusCode(StatusCode.SERVICE_UNAVAILABLE.getStatusCode()); + rsp.setStatusMessage(StatusCode.SERVICE_UNAVAILABLE.getStatusMessage()); try { - request.response().end(request.response().getStatusMessage()); - } catch (IllegalStateException e) { - // ignore because maybe already closed + rsp.end(rsp.getStatusMessage()); + } catch (IllegalStateException ex) { + log.debug("ignore because maybe already closed", ex); } } }; @@ -195,12 +195,13 @@ public static Handler createRequestExceptionHandler(final HttpServerR public static Handler createResponseExceptionHandler(final HttpServerRequest request, final String uri, final Class caller) { return exception -> { error("Problem with backend: " + exception.getMessage(), request, uri, caller); - request.response().setStatusCode(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode()); - request.response().setStatusMessage(StatusCode.INTERNAL_SERVER_ERROR.getStatusMessage()); + var rsp = request.response(); + rsp.setStatusCode(StatusCode.INTERNAL_SERVER_ERROR.getStatusCode()); + rsp.setStatusMessage(StatusCode.INTERNAL_SERVER_ERROR.getStatusMessage()); try { - request.response().end(request.response().getStatusMessage()); - } catch (IllegalStateException e) { - // ignore because maybe already closed + rsp.end(rsp.getStatusMessage()); + } catch (IllegalStateException ex) { + log.debug("ignore because maybe already closed", ex); } }; }