Skip to content

Commit

Permalink
LPD-31239 Add log
Browse files Browse the repository at this point in the history
  • Loading branch information
brianchandotcom committed Aug 12, 2024
1 parent 7b71122 commit 6ba40fd
Show file tree
Hide file tree
Showing 2 changed files with 41 additions and 0 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -4,6 +4,7 @@ dependencies {
api group: "org.springframework.boot", name: "spring-boot-starter-webflux", version: "2.7.18"

implementation group: "com.liferay", name: "com.liferay.petra.string", version: "latest.release"
implementation group: "org.json", name: "json", version: "20231013"

testImplementation group: "com.liferay", name: "com.liferay.petra.function", version: "latest.release"
testImplementation group: "com.liferay.portal", name: "com.liferay.portal.impl", version: "latest.release"
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -5,14 +5,20 @@

package com.liferay.client.extension.util.spring.boot;

import java.util.Map;
import java.util.Objects;
import java.util.function.Function;

import org.apache.commons.logging.Log;

import org.json.JSONObject;

import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.HttpHeaders;
import org.springframework.http.HttpMethod;
import org.springframework.http.HttpStatus;
import org.springframework.http.MediaType;
import org.springframework.security.oauth2.jwt.Jwt;
import org.springframework.web.reactive.function.client.ClientResponse;
import org.springframework.web.reactive.function.client.WebClient;
import org.springframework.web.reactive.function.client.WebClientResponseException;
Expand Down Expand Up @@ -147,6 +153,40 @@ protected String getWebClientBaseURL() {
return _lxcDXPServerProtocol + "://" + _lxcDXPMainDomain;
}

protected void log(Jwt jwt, Log log) {
if (log.isInfoEnabled()) {
log.info("JWT Claims: " + jwt.getClaims());
log.info("JWT ID: " + jwt.getId());
log.info("JWT Subject: " + jwt.getSubject());
}
}

protected void log(Jwt jwt, Log log, Map<String, String> parameters) {
if (log.isInfoEnabled()) {
log.info("JWT Claims: " + jwt.getClaims());
log.info("JWT ID: " + jwt.getId());
log.info("JWT Subject: " + jwt.getSubject());
log.info("Parameters: " + parameters);
}
}

protected void log(Jwt jwt, Log log, String json) {
if (log.isInfoEnabled()) {
try {
JSONObject jsonObject = new JSONObject(json);

log.info("JSON: " + jsonObject.toString(4));
}
catch (Exception exception) {
log.error("JSON: " + json, exception);
}

log.info("JWT Claims: " + jwt.getClaims());
log.info("JWT ID: " + jwt.getId());
log.info("JWT Subject: " + jwt.getSubject());
}
}

protected String patch(String authorization, String body, String path) {
return _getWebClient(
).patch(
Expand Down

0 comments on commit 6ba40fd

Please sign in to comment.