rest api call node target entity
[ccsdk/sli/plugins.git] / restapi-call-node / provider / src / main / java / org / onap / ccsdk / sli / plugins / restapicall / RestapiCallNode.java
index 8038b94..165eefd 100755 (executable)
@@ -72,8 +72,11 @@ import org.glassfish.jersey.media.multipart.file.FileDataBodyPart;
 import org.onap.ccsdk.sli.core.sli.SvcLogicContext;
 import org.onap.ccsdk.sli.core.sli.SvcLogicException;
 import org.onap.ccsdk.sli.core.sli.SvcLogicJavaPlugin;
+import org.onap.logging.filter.base.MetricLogClientFilter;
+import org.onap.logging.ref.slf4j.ONAPLogConstants;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
+import org.slf4j.MDC;
 
 public class RestapiCallNode implements SvcLogicJavaPlugin {
 
@@ -222,6 +225,7 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
         p.accept = parseParam(paramMap, "accept", false, null);
         p.multipartFormData = valueOf(parseParam(paramMap, "multipartFormData", false, "false"));
         p.multipartFile = parseParam(paramMap, "multipartFile", false, null);
+        p.targetEntity = parseParam(paramMap, "targetEntity", false, null);
         return p;
     }
 
@@ -462,10 +466,13 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
     protected void sendRequest(Map<String, String> paramMap, SvcLogicContext ctx, RetryPolicy retryPolicy)
         throws SvcLogicException {
 
-        HttpResponse r = new HttpResponse();
+       HttpResponse r = new HttpResponse();
         try {
             handlePartner(paramMap);
             Parameters p = getParameters(paramMap, new Parameters());
+            if(p.targetEntity != null && !p.targetEntity.isEmpty()) {
+                MDC.put(ONAPLogConstants.MDCs.TARGET_ENTITY, p.targetEntity);
+            }
             if (p.restapiUrl.contains(",") && retryPolicy == null) {
                 String[] urls = p.restapiUrl.split(",");
                 retryPolicy = new RetryPolicy(urls, urls.length * 2);
@@ -785,11 +792,9 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
         setClientTimeouts(client);
         // Needed to support additional HTTP methods such as PATCH
         client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
-
+        client.register(new MetricLogClientFilter());
         WebTarget webTarget = addAuthType(client, p).target(p.restapiUrl);
 
-        log.info("Sending request below to url " + p.restapiUrl);
-        log.info(request);
         long t1 = System.currentTimeMillis();
 
         HttpResponse r = new HttpResponse();
@@ -821,14 +826,20 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
                 }
             }
 
-            invocationBuilder.header("X-ECOMP-RequestID", org.slf4j.MDC.get("X-ECOMP-RequestID"));
-
             invocationBuilder.property(ClientProperties.SUPPRESS_HTTP_COMPLIANCE_VALIDATION, true);
 
             Response response;
 
             try {
-                response = invocationBuilder.method(p.httpMethod.toString(), entity(request, contentType));
+                // When the HTTP operation has no body do not set the content-type
+                //setting content-type has caused errors with some servers when no body is present
+                if (request == null) {
+                    response = invocationBuilder.method(p.httpMethod.toString());
+                } else {
+                    log.info("Sending request below to url " + p.restapiUrl);
+                    log.info(request);
+                    response = invocationBuilder.method(p.httpMethod.toString(), entity(request, contentType));
+                }
             } catch (ProcessingException | IllegalStateException e) {
                 throw new SvcLogicException(requestPostingException + e.getLocalizedMessage(), e);
             }
@@ -869,8 +880,6 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
                 }
             }
 
-            invocationBuilder.header("X-ECOMP-RequestID", org.slf4j.MDC.get("X-ECOMP-RequestID"));
-
             Response response;
 
             try {