diff options
author | Xue Gao <xg353y@intl.att.com> | 2019-06-18 12:10:14 +0000 |
---|---|---|
committer | Gerrit Code Review <gerrit@onap.org> | 2019-06-18 12:10:14 +0000 |
commit | eb216ac66f47c2b9d2b69a6e080d3969f75d78af (patch) | |
tree | 080b7839e8f755e6542d719bcdb7f6568bfa6a49 /src/main | |
parent | 60b5b25fa4687f8d64f1c5c48515db735a0e5141 (diff) | |
parent | 456cf4f6af9c22449dd4a39b1d13900fc38481c1 (diff) |
Merge "New unit tests and sonar fixes"
Diffstat (limited to 'src/main')
-rw-r--r-- | src/main/java/org/onap/clamp/clds/util/LoggingUtils.java | 66 |
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 cbe7eba96..163ab6913 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; + } } |