summaryrefslogtreecommitdiffstats
path: root/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect
diff options
context:
space:
mode:
authorChristopher Lott (cl778h) <clott@research.att.com>2017-09-07 08:52:41 -0400
committerChristopher Lott (cl778h) <clott@research.att.com>2017-09-07 08:54:52 -0400
commit8cd208ebaa33627daf05d8ffff7b28e53a7067d0 (patch)
tree0b07ec3c6305c46f34eae69d8fb6fa824aaae256 /ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect
parentb52d4cebc430a083ec1e6881c4f01dfe709ac726 (diff)
Adjust code for Sonar issues
Made non-functional updates to address static code analysis issues. Update license header with simple double-quote characters. Issue: PORTAL-72, PORTAL-90 Change-Id: Ic2c330daea07d721f0e6b350ebf03da97073f7ce Signed-off-by: Christopher Lott (cl778h) <clott@research.att.com>
Diffstat (limited to 'ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect')
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/AuditLog.java9
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java22
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspect.java49
-rw-r--r--ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/MetricsLog.java9
4 files changed, 43 insertions, 46 deletions
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/AuditLog.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/AuditLog.java
index 93075937..6a5ce910 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/AuditLog.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/AuditLog.java
@@ -6,7 +6,7 @@
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the “License”);
+ * under the Apache License, Version 2.0 (the "License");
* you may not use this software except in compliance with the License.
* You may obtain a copy of the License at
*
@@ -19,7 +19,7 @@
* limitations under the License.
*
* Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
* you may not use this documentation except in compliance with the License.
* You may obtain a copy of the License at
*
@@ -42,9 +42,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-
-@Target({ElementType.METHOD, ElementType.TYPE})
+@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface AuditLog {
- String value() default "";
+ String value() default "";
} \ No newline at end of file
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
index 269d4b9c..779a24fc 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAdvice.java
@@ -6,7 +6,7 @@
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the “License”);
+ * under the Apache License, Version 2.0 (the "License");
* you may not use this software except in compliance with the License.
* You may obtain a copy of the License at
*
@@ -19,7 +19,7 @@
* limitations under the License.
*
* Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
* you may not use this documentation except in compliance with the License.
* You may obtain a copy of the License at
*
@@ -105,16 +105,14 @@ public class EELFLoggerAdvice {
MDC.put(SystemProperties.TARGET_SERVICE_NAME, methodName);
if (securityEventType != null) {
MDC.put(className + methodName + SystemProperties.AUDITLOG_BEGIN_TIMESTAMP, getCurrentDateTimeUTC());
- HttpServletRequest req = null;
if (args[0] != null && args[0] instanceof HttpServletRequest) {
- req = (HttpServletRequest) args[0];
+ HttpServletRequest req = (HttpServletRequest) args[0];
logger.setRequestBasedDefaultsIntoGlobalLoggingContext(req, appName);
}
}
- logger.debug(EELFLoggerDelegate.debugLogger, (methodName + " was invoked."));
+ logger.debug(EELFLoggerDelegate.debugLogger, "{} was invoked.", methodName);
} catch (Exception e) {
- adviceLogger.error(EELFLoggerDelegate.errorLogger,
- "Exception occurred in EELFLoggerAdvice.before() method. Details: " + e.getMessage());
+ adviceLogger.error(EELFLoggerDelegate.errorLogger, "before failed", e);
}
return new Object[] { "" };
@@ -197,8 +195,7 @@ public class EELFLoggerAdvice {
MDC.remove(SystemProperties.TARGET_ENTITY);
MDC.remove(SystemProperties.TARGET_SERVICE_NAME);
} catch (Exception e) {
- adviceLogger.error(EELFLoggerDelegate.errorLogger,
- "Exception occurred in EELFLoggerAdvice.after() method. Details: " + e.getMessage());
+ adviceLogger.error(EELFLoggerDelegate.errorLogger, "after failed", e);
}
}
@@ -212,7 +209,6 @@ public class EELFLoggerAdvice {
private void logSecurityMessage(EELFLoggerDelegate logger, SecurityEventTypeEnum securityEventType, String result,
String restMethod) {
StringBuilder additionalInfoAppender = new StringBuilder();
- String auditMessage = "";
additionalInfoAppender.append(String.format("%s request was received.", restMethod));
@@ -224,7 +220,7 @@ public class EELFLoggerAdvice {
additionalInfoAppender.append(" Request-URL:" + MDC.get(SystemProperties.FULL_URL));
}
- auditMessage = AuditLogFormatter.getInstance().createMessage(MDC.get(SystemProperties.PROTOCOL),
+ String auditMessage = AuditLogFormatter.getInstance().createMessage(MDC.get(SystemProperties.PROTOCOL),
securityEventType.name(), MDC.get(SystemProperties.MDC_LOGIN_ID), additionalInfoAppender.toString());
logger.info(EELFLoggerDelegate.auditLogger, auditMessage);
@@ -243,9 +239,7 @@ public class EELFLoggerAdvice {
String timeDifference = String.format("%d ms", endDate.getTime() - beginDate.getTime());
MDC.put(SystemProperties.MDC_TIMER, timeDifference);
} catch (Exception e) {
- adviceLogger.error(EELFLoggerDelegate.errorLogger,
- "Exception occurred in EELFLoggerAdvice.calculateDateTimeDifference() method. Details: "
- + e.getMessage());
+ adviceLogger.error(EELFLoggerDelegate.errorLogger, "calculateDateTimeDifference failed", e);
}
}
}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspect.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspect.java
index 8c958924..3ffd0894 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspect.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/EELFLoggerAspect.java
@@ -6,7 +6,7 @@
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the “License”);
+ * under the Apache License, Version 2.0 (the "License");
* you may not use this software except in compliance with the License.
* You may obtain a copy of the License at
*
@@ -19,7 +19,7 @@
* limitations under the License.
*
* Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
* you may not use this documentation except in compliance with the License.
* You may obtain a copy of the License at
*
@@ -44,20 +44,21 @@ import org.aspectj.lang.annotation.Pointcut;
import org.onap.portalsdk.core.util.SystemProperties.SecurityEventTypeEnum;
import org.springframework.beans.factory.annotation.Autowired;
-
@Aspect
@org.springframework.context.annotation.Configuration
public class EELFLoggerAspect {
-
+
@Autowired
- EELFLoggerAdvice advice;
-
+ private EELFLoggerAdvice advice;
+
/*
* Point-cut expression to handle all INCOMING_REST_MESSAGES
*/
@Pointcut("execution(public * org.onap.portalsdk.core.controller.*.*(..))")
- public void incomingAuditMessages() {}
-
+ public void incomingAuditMessages() {
+ // Nothing is logged on incoming message
+ }
+
@Around("incomingAuditMessages() && @annotation(auditLog)")
public Object logAuditMethodAround(ProceedingJoinPoint joinPoint, AuditLog auditLog) throws Throwable {
return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
@@ -67,40 +68,44 @@ public class EELFLoggerAspect {
public Object logAuditMethodClassAround(ProceedingJoinPoint joinPoint, AuditLog auditLog) throws Throwable {
return this.logAroundMethod(joinPoint, SecurityEventTypeEnum.INCOMING_REST_MESSAGE);
}
-
+
/*
* Point cut expression to capture metrics logging
*/
@Pointcut("execution(public * *(..))")
- public void publicMethod() {}
-
+ public void publicMethod() {
+ // By default do nothing
+ }
+
@Around("publicMethod() && @within(metricsLog)")
public Object logMetricsClassAround(ProceedingJoinPoint joinPoint, MetricsLog metricsLog) throws Throwable {
return this.logAroundMethod(joinPoint, null);
}
-
+
@Around("publicMethod() && @annotation(metricsLog)")
public Object logMetricsMethodAround(ProceedingJoinPoint joinPoint, MetricsLog metricsLog) throws Throwable {
return this.logAroundMethod(joinPoint, null);
}
-
- private Object logAroundMethod(ProceedingJoinPoint joinPoint, SecurityEventTypeEnum securityEventType) throws Throwable {
- //Before
- Object[] passOnArgs = new Object[] {joinPoint.getSignature().getDeclaringType().getName(),joinPoint.getSignature().getName()};
+
+ private Object logAroundMethod(ProceedingJoinPoint joinPoint, SecurityEventTypeEnum securityEventType)
+ throws Throwable {
+ // Before
+ Object[] passOnArgs = new Object[] { joinPoint.getSignature().getDeclaringType().getName(),
+ joinPoint.getSignature().getName() };
Object[] returnArgs = advice.before(securityEventType, joinPoint.getArgs(), passOnArgs);
-
- //Execute the actual method
+
+ // Execute the actual method
Object result = null;
String restStatus = "COMPLETE";
try {
result = joinPoint.proceed();
- } catch(Exception e) {
+ } catch (Exception e) {
restStatus = "ERROR";
}
-
- //After
+
+ // After
advice.after(securityEventType, restStatus, joinPoint.getArgs(), returnArgs, passOnArgs);
-
+
return result;
}
}
diff --git a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/MetricsLog.java b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/MetricsLog.java
index 7d552774..3e089aeb 100644
--- a/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/MetricsLog.java
+++ b/ecomp-sdk/epsdk-core/src/main/java/org/onap/portalsdk/core/logging/aspect/MetricsLog.java
@@ -6,7 +6,7 @@
* ===================================================================
*
* Unless otherwise specified, all software contained herein is licensed
- * under the Apache License, Version 2.0 (the “License”);
+ * under the Apache License, Version 2.0 (the "License");
* you may not use this software except in compliance with the License.
* You may obtain a copy of the License at
*
@@ -19,7 +19,7 @@
* limitations under the License.
*
* Unless otherwise specified, all documentation contained herein is licensed
- * under the Creative Commons License, Attribution 4.0 Intl. (the “License”);
+ * under the Creative Commons License, Attribution 4.0 Intl. (the "License");
* you may not use this documentation except in compliance with the License.
* You may obtain a copy of the License at
*
@@ -42,9 +42,8 @@ import java.lang.annotation.Retention;
import java.lang.annotation.RetentionPolicy;
import java.lang.annotation.Target;
-
-@Target({ElementType.METHOD, ElementType.TYPE})
+@Target({ ElementType.METHOD, ElementType.TYPE })
@Retention(RetentionPolicy.RUNTIME)
public @interface MetricsLog {
- String value() default "";
+ String value() default "";
}