You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@logging.apache.org by rg...@apache.org on 2018/02/11 03:57:25 UTC
logging-log4j-audit-sample git commit: Add save and restore to
RequestContext
Repository: logging-log4j-audit-sample
Updated Branches:
refs/heads/master ea807f926 -> 0ae6e9c12
Add save and restore to RequestContext
Project: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit-sample/repo
Commit: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit-sample/commit/0ae6e9c1
Tree: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit-sample/tree/0ae6e9c1
Diff: http://git-wip-us.apache.org/repos/asf/logging-log4j-audit-sample/diff/0ae6e9c1
Branch: refs/heads/master
Commit: 0ae6e9c12dea06002f2638f223fdd6dad419f470
Parents: ea807f9
Author: Ralph Goers <rg...@apache.org>
Authored: Sat Feb 10 20:57:20 2018 -0700
Committer: Ralph Goers <rg...@apache.org>
Committed: Sat Feb 10 20:57:20 2018 -0700
----------------------------------------------------------------------
.../log4j/audit/service/RequestContext.java | 39 ++++++++++++++++++++
1 file changed, 39 insertions(+)
----------------------------------------------------------------------
http://git-wip-us.apache.org/repos/asf/logging-log4j-audit-sample/blob/0ae6e9c1/audit-service-war/src/main/java/org/apache/logging/log4j/audit/service/RequestContext.java
----------------------------------------------------------------------
diff --git a/audit-service-war/src/main/java/org/apache/logging/log4j/audit/service/RequestContext.java b/audit-service-war/src/main/java/org/apache/logging/log4j/audit/service/RequestContext.java
index b883483..2e46b63 100644
--- a/audit-service-war/src/main/java/org/apache/logging/log4j/audit/service/RequestContext.java
+++ b/audit-service-war/src/main/java/org/apache/logging/log4j/audit/service/RequestContext.java
@@ -35,20 +35,28 @@ import org.apache.logging.log4j.core.util.UuidUtil;
public final class RequestContext {
@ClientServer
public static final String REQUEST_ID = "requestId";
+ private String requestId;
@ClientServer
public static final String SESSION_ID = "sessionId";
+ private String sessionId;
@ClientServer
public static final String ACCOUNT_NUMBER = "accountNumber";
+ private Long accountNumber;
@ClientServer
public static final String IP_ADDRESS = "ipAddress";
+ private String ipAddress;
@ClientServer
public static final String USER_ID = "userId";
+ private String userId;
@ClientServer
public static final String LOGIN_ID = "loginId";
+ private String loginId;
@Local
public static final String CALLING_HOST = "callingHost";
+ private String callingHost;
public static final String HOST_NAME = "hostName";
+ private String hostName;
private static final String LOCAL_HOST_NAME = NetUtils.getLocalHostname();
/**
@@ -147,4 +155,35 @@ public final class RequestContext {
public static void setCallingHost(String hostName) {
ThreadContext.put(CALLING_HOST, hostName);
}
+
+ /**
+ * Save the RequestContext data.
+ * @return A copy of the RequestContext data.
+ */
+ public static RequestContext save() {
+ RequestContext context = new RequestContext();
+ context.accountNumber = getAccountNumber();
+ context.callingHost = getCallingHost();
+ context.hostName = getHostName();
+ context.ipAddress = getIpAddress();
+ context.loginId = getLoginId();
+ context.requestId = getRequestId();
+ context.sessionId = getSessionId();
+ context.userId = getUserId();
+ return context;
+ }
+
+ /**
+ * Populate the ThreadContext from a RequestContext object.
+ */
+ public void restore() {
+ setAccountNumber(this.accountNumber);
+ setCallingHost(this.callingHost);
+ setHostName(this.hostName);
+ setIpAddress(this.ipAddress);
+ setLoginId(this.loginId);
+ ThreadContext.put(REQUEST_ID, this.requestId);
+ setSessionId(this.sessionId);
+ setUserId(this.userId);
+ }
}