Rework the deploy/undeploy method
[clamp.git] / src / main / java / org / onap / clamp / clds / util / LoggingUtils.java
index 300d606..47b4f9a 100644 (file)
@@ -38,6 +38,7 @@ import java.util.Date;
 import java.util.TimeZone;\r
 import java.util.UUID;\r
 \r
+import javax.net.ssl.HttpsURLConnection;\r
 import javax.servlet.http.HttpServletRequest;\r
 import javax.validation.constraints.NotNull;\r
 \r
@@ -259,6 +260,36 @@ public class LoggingUtils {
         this.mLogger.info(ONAPLogConstants.Markers.INVOKE_SYNC + "{"+ invocationID +"}");\r
         return con;\r
     }\r
+\r
+    /**\r
+     * Report pending invocation with <tt>INVOKE</tt> marker,\r
+     * setting standard ONAP logging headers automatically.\r
+     *\r
+     * @param builder request builder, for setting headers.\r
+     * @param sync whether synchronous, nullable.\r
+     * @return invocation ID to be passed with invocation.\r
+     */\r
+    public HttpsURLConnection invokeHttps(final HttpsURLConnection con, String targetEntity, String targetServiceName) {\r
+        final String invocationID = UUID.randomUUID().toString();\r
+\r
+        // Set standard HTTP headers on (southbound request) builder.\r
+        con.setRequestProperty(ONAPLogConstants.Headers.REQUEST_ID,\r
+            defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.REQUEST_ID)));\r
+        con.setRequestProperty(ONAPLogConstants.Headers.INVOCATION_ID,\r
+            invocationID);\r
+        con.setRequestProperty(ONAPLogConstants.Headers.PARTNER_NAME,\r
+            defaultToEmpty(MDC.get(ONAPLogConstants.MDCs.PARTNER_NAME)));\r
+\r
+        invokeContext(targetEntity, targetServiceName, invocationID);\r
+\r
+        // Log INVOKE*, with the invocationID as the message body.\r
+        // (We didn't really want this kind of behavior in the standard,\r
+        // but is it worse than new, single-message MDC?)\r
+        this.mLogger.info(ONAPLogConstants.Markers.INVOKE);\r
+        this.mLogger.info(ONAPLogConstants.Markers.INVOKE_SYNC + "{"+ invocationID +"}");\r
+        return con;\r
+    }\r
+\r
     public void invokeReturn() {\r
         // Add the Invoke-return marker and clear the needed MDC\r
         this.mLogger.info(ONAPLogConstants.Markers.INVOKE_RETURN);\r