aboutsummaryrefslogtreecommitdiffstats
path: root/src/main
diff options
context:
space:
mode:
authork.kedron <k.kedron@partner.samsung.com>2019-04-30 16:37:54 +0200
committerk.kedron <k.kedron@partner.samsung.com>2019-06-04 11:50:03 +0200
commit456cf4f6af9c22449dd4a39b1d13900fc38481c1 (patch)
tree089617e97606dc4ecbc8529f0c1d4ee5546bb1d0 /src/main
parentedae4aaca1bc65fa39d398e5a386c918ab7dde7a (diff)
New unit tests and sonar fixes
Assertion arguments should be passed in the correct order in: - CldsReferencePropertiesItCase - LoggingUtils Remove of duplicate code in LoggingUtils. Typo in README file. Add LoggingUtilsTest unit test. Change-Id: Iddc61877659e9d4308479451a7eb4901b3fc5ea8 Issue-ID: CLAMP-355 Signed-off-by: Krystian Kedron <k.kedron@partner.samsung.com>
Diffstat (limited to 'src/main')
-rw-r--r--src/main/java/org/onap/clamp/clds/util/LoggingUtils.java66
1 files changed, 26 insertions, 40 deletions
diff --git a/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java b/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java
index cbe7eba9..163ab691 100644
--- a/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java
+++ b/src/main/java/org/onap/clamp/clds/util/LoggingUtils.java
@@ -28,6 +28,7 @@ import com.att.eelf.configuration.EELFManager;
import java.net.HttpURLConnection;
import java.net.InetAddress;
+import java.net.URLConnection;
import java.net.UnknownHostException;
import java.text.DateFormat;
import java.text.SimpleDateFormat;
@@ -114,7 +115,7 @@ public class LoggingUtils {
*/
public static void setResponseContext(String code, String description, String className) {
MDC.put("ResponseCode", code);
- MDC.put("StatusCode", code.equals("0") ? "COMPLETE" : "ERROR");
+ MDC.put("StatusCode", "0".equals(code) ? "COMPLETE" : "ERROR");
MDC.put("ResponseDescription", description != null ? description : "");
MDC.put("ClassName", className != null ? className : "");
}
@@ -167,8 +168,6 @@ public class LoggingUtils {
return dateFormat;
}
-
-
/*********************************************************************************************
* Method for ONAP Application Logging Specification v1.2
********************************************************************************************/
@@ -256,7 +255,7 @@ public class LoggingUtils {
public String getProperties(String name) {
return MDC.get(name);
}
-
+
/**
* Report pending invocation with <tt>INVOKE</tt> marker,
* setting standard ONAP logging headers automatically.
@@ -267,24 +266,7 @@ public class LoggingUtils {
* @return The HTTP url connection
*/
public HttpURLConnection invoke(final HttpURLConnection con, String targetEntity, String targetServiceName) {
- final String invocationId = UUID.randomUUID().toString();
-
- // Set standard HTTP headers on (southbound request) builder.
- con.setRequestProperty(ONAPLogConstants.Headers.REQUEST_ID,
- defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)));
- con.setRequestProperty(ONAPLogConstants.Headers.INVOCATION_ID,
- invocationId);
- con.setRequestProperty(ONAPLogConstants.Headers.PARTNER_NAME,
- defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)));
-
- invokeContext(targetEntity, targetServiceName, invocationId);
-
- // Log INVOKE*, with the invocationID as the message body.
- // (We didn't really want this kind of behavior in the standard,
- // but is it worse than new, single-message MDC?)
- this.mlogger.info(ONAPLogConstants.Markers.INVOKE);
- this.mlogger.info(ONAPLogConstants.Markers.INVOKE_SYNC + "{" + invocationId + "}");
- return con;
+ return this.invokeGeneric(con, targetEntity, targetServiceName);
}
/**
@@ -316,24 +298,7 @@ public class LoggingUtils {
* @return The HTTPS url connection
*/
public HttpsURLConnection invokeHttps(final HttpsURLConnection con, String targetEntity, String targetServiceName) {
- final String invocationId = UUID.randomUUID().toString();
-
- // Set standard HTTP headers on (southbound request) builder.
- con.setRequestProperty(ONAPLogConstants.Headers.REQUEST_ID,
- defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)));
- con.setRequestProperty(ONAPLogConstants.Headers.INVOCATION_ID,
- invocationId);
- con.setRequestProperty(ONAPLogConstants.Headers.PARTNER_NAME,
- defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)));
-
- invokeContext(targetEntity, targetServiceName, invocationId);
-
- // Log INVOKE*, with the invocationID as the message body.
- // (We didn't really want this kind of behavior in the standard,
- // but is it worse than new, single-message MDC?)
- this.mlogger.info(ONAPLogConstants.Markers.INVOKE);
- this.mlogger.info(ONAPLogConstants.Markers.INVOKE_SYNC + "{" + invocationId + "}");
- return con;
+ return this.invokeGeneric(con, targetEntity, targetServiceName);
}
/**
@@ -410,4 +375,25 @@ public class LoggingUtils {
MDC.remove(ONAPLogConstants.MDCs.INVOCATIONID_OUT);
MDC.remove(ONAPLogConstants.MDCs.INVOKE_TIMESTAMP);
}
+
+ private <T extends URLConnection> T invokeGeneric(final T con, String targetEntity, String targetServiceName) {
+ final String invocationId = UUID.randomUUID().toString();
+
+ // Set standard HTTP headers on (southbound request) builder.
+ con.setRequestProperty(ONAPLogConstants.Headers.REQUEST_ID,
+ defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)));
+ con.setRequestProperty(ONAPLogConstants.Headers.INVOCATION_ID,
+ invocationId);
+ con.setRequestProperty(ONAPLogConstants.Headers.PARTNER_NAME,
+ defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)));
+
+ invokeContext(targetEntity, targetServiceName, invocationId);
+
+ // Log INVOKE*, with the invocationID as the message body.
+ // (We didn't really want this kind of behavior in the standard,
+ // but is it worse than new, single-message MDC?)
+ this.mlogger.info(ONAPLogConstants.Markers.INVOKE);
+ this.mlogger.info(ONAPLogConstants.Markers.INVOKE_SYNC + "{" + invocationId + "}");
+ return con;
+ }
}