aboutsummaryrefslogtreecommitdiffstats
path: root/vid-app-common/src/main/java/org/onap/vid/logging
diff options
context:
space:
mode:
authorEylon Malin <eylon.malin@intl.att.com>2019-10-10 15:22:07 +0300
committerEylon Malin <eylon.malin@intl.att.com>2019-10-23 08:11:51 +0300
commite8d29ab5e3775472f59a4997fa3a5df9319de306 (patch)
tree5f53a1548e7d191385d77f2fd5df0d96c04d4af1 /vid-app-common/src/main/java/org/onap/vid/logging
parentf09e8d114804e4237e79f27ed492835ecb1b17b0 (diff)
use logging interceptor in SDC client
Issue-ID: VID-253 Change-Id: I67947886fd8945a224ee81d5eb0a8fedf1f7317c Signed-off-by: Eylon Malin <eylon.malin@intl.att.com>
Diffstat (limited to 'vid-app-common/src/main/java/org/onap/vid/logging')
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricRequestInterceptor.java33
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricResponseInterceptor.java33
-rw-r--r--vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java16
3 files changed, 80 insertions, 2 deletions
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricRequestInterceptor.java b/vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricRequestInterceptor.java
new file mode 100644
index 000000000..0cc5a2aaa
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricRequestInterceptor.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.vid.logging;
+
+import org.apache.http.HttpRequest;
+import org.apache.http.HttpRequestInterceptor;
+import org.apache.http.protocol.HttpContext;
+
+public class ApacheClientMetricRequestInterceptor extends ApacheClientMetricInterceptor implements HttpRequestInterceptor {
+
+ @Override
+ public void process(HttpRequest request, HttpContext context) {
+ this.pre(request, request);
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricResponseInterceptor.java b/vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricResponseInterceptor.java
new file mode 100644
index 000000000..72b54e7a5
--- /dev/null
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/ApacheClientMetricResponseInterceptor.java
@@ -0,0 +1,33 @@
+/*-
+ * ============LICENSE_START=======================================================
+ * VID
+ * ================================================================================
+ * Copyright (C) 2017 - 2019 AT&T Intellectual Property. All rights reserved.
+ * ================================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END=========================================================
+ */
+
+package org.onap.vid.logging;
+
+import org.apache.http.HttpResponse;
+import org.apache.http.HttpResponseInterceptor;
+import org.apache.http.protocol.HttpContext;
+
+public class ApacheClientMetricResponseInterceptor extends ApacheClientMetricInterceptor implements HttpResponseInterceptor {
+
+ @Override
+ public void process(HttpResponse response, HttpContext context) {
+ this.post(null, response);
+ }
+}
diff --git a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java
index 309ead40c..f87297c37 100644
--- a/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java
+++ b/vid-app-common/src/main/java/org/onap/vid/logging/VidLoggerAspect.java
@@ -32,6 +32,7 @@ import org.aspectj.lang.ProceedingJoinPoint;
import org.aspectj.lang.annotation.Around;
import org.aspectj.lang.annotation.Aspect;
import org.aspectj.lang.annotation.Pointcut;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
import org.onap.portalsdk.core.logging.aspect.EELFLoggerAdvice;
import org.onap.portalsdk.core.logging.logic.EELFLoggerDelegate;
import org.onap.portalsdk.core.service.AppService;
@@ -39,6 +40,7 @@ import org.onap.portalsdk.core.util.SystemProperties;
import org.onap.portalsdk.core.web.support.UserUtils;
import org.onap.vid.controller.ControllersUtils;
import org.onap.vid.utils.SystemPropertiesWrapper;
+import org.slf4j.MDC;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.context.request.RequestContextHolder;
import org.springframework.web.context.request.ServletRequestAttributes;
@@ -87,9 +89,10 @@ public class VidLoggerAspect {
Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(),joinPoint.getSignature().getName()};
Object[] returnArgs = advice.before(securityEventType, fabricateArgsWithNull(), passOnArgs);
- fixSetRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequestOrNull(joinPoint),
+ HttpServletRequest httpServletRequest = httpServletRequestOrNull(joinPoint);
+ fixSetRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequest,
joinPoint.getSignature().getDeclaringType().getName());
-
+ addRequestIdToMdcForMetricFilter(httpServletRequest);
fixServerFqdnInMDC();
//Execute the actual method
@@ -108,6 +111,14 @@ public class VidLoggerAspect {
return result;
}
+ //prepare MDC for org.onap.logging.filter.base.AbstractMetricLogFilter
+ private void addRequestIdToMdcForMetricFilter(HttpServletRequest httpServletRequest) {
+ if (httpServletRequest!=null) {
+ String requestId = UserUtils.getRequestId(httpServletRequest);
+ MDC.put(ONAPLogConstants.MDCs.REQUEST_ID, requestId);
+ }
+ }
+
// Set the status code into MDC *before* the metrics log is written by advice.after()
private void fixStatusCodeInMDC(String restStatus) {
EELFLoggerDelegate.mdcPut(SystemProperties.STATUS_CODE, restStatus);
@@ -155,6 +166,7 @@ public class VidLoggerAspect {
String loginId = controllersUtils.extractUserId(httpServletRequest);
logger.setRequestBasedDefaultsIntoGlobalLoggingContext(httpServletRequest, appName, requestId, loginId);
+
}
}