Skip to content

Commit

Permalink
#525 Try to parse request/response payload as JsonArray
Browse files Browse the repository at this point in the history
  • Loading branch information
mcweba committed Sep 26, 2023
1 parent 150acfa commit b036d7a
Showing 1 changed file with 17 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,7 @@
import io.vertx.core.http.HttpMethod;
import io.vertx.core.http.HttpServerRequest;
import io.vertx.core.json.DecodeException;
import io.vertx.core.json.JsonArray;
import io.vertx.core.json.JsonObject;
import org.apache.logging.log4j.LogManager;
import org.apache.logging.log4j.core.Appender;
Expand Down Expand Up @@ -294,17 +295,29 @@ public void log(String uri, HttpMethod method, int statusCode, String statusMess
requestLog.put(HEADERS, headersAsJson(requestHeaders));
responseLog.put(HEADERS, headersAsJson(responseHeaders));
if (requestPayload != null) {
String requestPayloadString = requestPayload.toString("UTF-8");

Check warning on line 298 in gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java#L298

Added line #L298 was not covered by tests
try {
requestLog.put(BODY, new JsonObject(requestPayload.toString("UTF-8")));
requestLog.put(BODY, new JsonObject(requestPayloadString));

Check warning on line 300 in gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java#L300

Added line #L300 was not covered by tests
} catch (DecodeException e) {
// ignore, bogus JSON
// maybe payload was a JsonArray
try {
requestLog.put(BODY, new JsonArray(requestPayloadString));
} catch (DecodeException ex) {
log.info("request payload could not be parsed and will not be logged");
}

Check warning on line 307 in gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java#L304-L307

Added lines #L304 - L307 were not covered by tests
}
}
if (responsePayload != null) {
String responsePayloadString = responsePayload.toString("UTF-8");

Check warning on line 311 in gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java#L311

Added line #L311 was not covered by tests
try {
responseLog.put(BODY, new JsonObject(responsePayload.toString("UTF-8")));
responseLog.put(BODY, new JsonObject(responsePayloadString));

Check warning on line 313 in gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java#L313

Added line #L313 was not covered by tests
} catch (DecodeException e) {
// ignore, bogus JSON
// maybe payload was a JsonArray
try {
responseLog.put(BODY, new JsonArray(responsePayloadString));
} catch (DecodeException ex) {
log.info("response payload could not be parsed and will not be logged");
}

Check warning on line 320 in gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java

View check run for this annotation

Codecov / codecov/patch

gateleen-logging/src/main/java/org/swisspush/gateleen/logging/LoggingHandler.java#L317-L320

Added lines #L317 - L320 were not covered by tests
}
}

Expand Down

0 comments on commit b036d7a

Please sign in to comment.