Skip to content

Commit

Permalink
Merge pull request #526 from swisspost/feature/issue525_LoggingHandle…
Browse files Browse the repository at this point in the history
…r_JsonArray

#525 Try to parse request/response payload as JsonArray
  • Loading branch information
mcweba authored Sep 27, 2023
2 parents e5bf76d + 465689f commit ebc868b
Show file tree
Hide file tree
Showing 2 changed files with 18 additions and 8 deletions.
5 changes: 1 addition & 4 deletions .github/workflows/maven.yml
Original file line number Diff line number Diff line change
Expand Up @@ -32,10 +32,7 @@ jobs:
redis-version: 4

- name: Install chromedriver
uses: nanasess/[email protected]
with:
# Optional: do not specify to match Chrome's version
chromedriver-version: '114.0.5735.90'
uses: nanasess/setup-chromedriver@v2

- name: Install, unit test
run: mvn install -Dmaven.javadoc.skip=true -PpublicRepos -B -V
Expand Down
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 ebc868b

Please sign in to comment.