summaryrefslogtreecommitdiffstats
path: root/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main
diff options
context:
space:
mode:
authorvempo <vitaliy.emporopulo@amdocs.com>2018-08-06 16:21:01 +0300
committerAvi Gaffa <avi.gaffa@amdocs.com>2018-08-06 16:09:04 +0000
commit44651d903d83f9256c324ec2a3c8886e91e1e433 (patch)
tree0e1961ce6c69dcb8eb18cf8b4e8af1e5eed6e3b4 /openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main
parent1ecdbf74427467327de0b1e11cd0a839d6dc05bd (diff)
Minor improvements to logging for servlets
Fixed import order, more resilient statuses for Spring, cleaner code and tests, more convenient APIs. Change-Id: I6493c81d9c3c1c543c354562e074876268794438 Issue-ID: SDC-1580 Signed-off-by: vempo <vitaliy.emporopulo@amdocs.com>
Diffstat (limited to 'openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main')
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/CombinedTracker.java33
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java2
-rw-r--r--openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilter.java10
3 files changed, 24 insertions, 21 deletions
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/CombinedTracker.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/CombinedTracker.java
index 2dd2c12143..5d940aa821 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/CombinedTracker.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/CombinedTracker.java
@@ -17,39 +17,38 @@
package org.openecomp.sdc.logging.servlet;
import javax.servlet.http.HttpServletRequest;
-import org.openecomp.sdc.logging.api.Logger;
/**
- * Tracker for all the elements of ONAP logging and tracing at an entry point to an application - context and audit.
- * The order of invocations is important, assuming the context must be kept as long as audit hasn't been finished.
+ * Tracker for all the elements of ONAP logging and tracing at an entry point to an application.
+ * The order of invocations is important, and on {@link #preRequest(HttpServletRequest)} it respects the order of
+ * trackers passed to the constructor. On {@link #postRequest(RequestProcessingResult)}, the invocation will be in the
+ * <b>reverse</b> order.
*
* @author evitaliy
* @since 01 Aug 2018
*/
public class CombinedTracker implements Tracker {
- private final ContextTracker context;
- private final AuditTracker audit;
+ private final Tracker[] trackers;
- public CombinedTracker(Logger logger, HttpHeader partnerNameHeader, HttpHeader requestIdHeader) {
- this.context = new ContextTracker(partnerNameHeader, requestIdHeader);
- this.audit = new AuditTracker(logger);
- }
-
- public CombinedTracker(Class<?> resourceType, HttpHeader partnerNameHeader, HttpHeader requestIdHeader) {
- this.context = new ContextTracker(partnerNameHeader, requestIdHeader);
- this.audit = new AuditTracker(resourceType);
+ public CombinedTracker(Tracker... trackers) {
+ this.trackers = new Tracker[trackers.length];
+ System.arraycopy(trackers, 0, this.trackers, 0, trackers.length);
}
@Override
public void preRequest(HttpServletRequest request) {
- this.context.preRequest(request);
- this.audit.preRequest(request);
+
+ for (Tracker t : trackers) {
+ t.preRequest(request);
+ }
}
@Override
public void postRequest(RequestProcessingResult result) {
- this.audit.postRequest(result);
- this.context.postRequest(result);
+
+ for (int i = trackers.length - 1; i > -1; i--) {
+ trackers[i].postRequest(result);
+ }
}
}
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java
index db10c2e4f3..dd5af859d4 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/HttpHeader.java
@@ -43,7 +43,7 @@ public class HttpHeader {
*
* @param headerNames cannot be null or empty
*/
- public HttpHeader(String[] headerNames) {
+ public HttpHeader(String... headerNames) {
if (Objects.requireNonNull(headerNames, NAMES_CANNOT_BE_NULL).length < 1) {
throw new IllegalArgumentException(AT_LEAST_ONE_NAME_REQUIRED);
diff --git a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilter.java b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilter.java
index f846359b82..fb651495ac 100644
--- a/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilter.java
+++ b/openecomp-be/lib/openecomp-sdc-logging-lib/openecomp-sdc-logging-api/src/main/java/org/openecomp/sdc/logging/servlet/jaxrs/LoggingRequestFilter.java
@@ -27,7 +27,9 @@ import javax.ws.rs.core.Context;
import javax.ws.rs.ext.Provider;
import org.openecomp.sdc.logging.api.Logger;
import org.openecomp.sdc.logging.api.LoggerFactory;
+import org.openecomp.sdc.logging.servlet.AuditTracker;
import org.openecomp.sdc.logging.servlet.CombinedTracker;
+import org.openecomp.sdc.logging.servlet.ContextTracker;
import org.openecomp.sdc.logging.servlet.HttpHeader;
import org.openecomp.sdc.logging.servlet.Tracker;
@@ -63,8 +65,8 @@ public class LoggingRequestFilter implements ContainerRequestFilter {
private HttpServletRequest httpRequest;
- private HttpHeader requestIdHeader = new HttpHeader(new String[] {DEFAULT_REQUEST_ID_HEADER});
- private HttpHeader partnerNameHeader = new HttpHeader(new String[] {DEFAULT_PARTNER_NAME_HEADER});
+ private HttpHeader requestIdHeader = new HttpHeader(DEFAULT_REQUEST_ID_HEADER);
+ private HttpHeader partnerNameHeader = new HttpHeader(DEFAULT_PARTNER_NAME_HEADER);
private ResourceInfo resource;
@@ -107,7 +109,9 @@ public class LoggingRequestFilter implements ContainerRequestFilter {
@Override
public void filter(ContainerRequestContext requestContext) {
Class<?> resourceClass = resource.getResourceMethod().getDeclaringClass();
- Tracker tracker = new CombinedTracker(resourceClass, partnerNameHeader, requestIdHeader);
+ Tracker tracker = new CombinedTracker(
+ new ContextTracker(partnerNameHeader, requestIdHeader),
+ new AuditTracker(resourceClass));
requestContext.setProperty(LOGGING_TRACKER_KEY, tracker);
tracker.preRequest(httpRequest);
}