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 {
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;
}
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);
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();
}
}
- 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);
}
}
}
- invocationBuilder.header("X-ECOMP-RequestID", org.slf4j.MDC.get("X-ECOMP-RequestID"));
-
Response response;
try {