RestApiCallNode HTTP method patch not working
[ccsdk/sli/plugins.git] / restapi-call-node / provider / src / main / java / org / onap / ccsdk / sli / plugins / restapicall / RestapiCallNode.java
index 83b12c7..521c66c 100644 (file)
@@ -58,6 +58,7 @@ import javax.ws.rs.core.Response;
 import javax.ws.rs.core.UriBuilder;
 import org.apache.commons.lang3.StringUtils;
 import org.glassfish.jersey.client.ClientProperties;
+import org.glassfish.jersey.client.HttpUrlConnectorProvider;
 import org.glassfish.jersey.client.authentication.HttpAuthenticationFeature;
 import org.glassfish.jersey.client.oauth1.ConsumerCredentials;
 import org.glassfish.jersey.client.oauth1.OAuth1ClientSupport;
@@ -165,6 +166,8 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
             false, null));
         p.returnRequestPayload = valueOf(parseParam(
             paramMap, "returnRequestPayload", false, null));
+        p.accept = parseParam(paramMap, "accept",
+                false, null);
         return p;
     }
 
@@ -620,6 +623,8 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
                 .build();
         }
         client.property(ClientProperties.CONNECT_TIMEOUT, 5000);
+        // Needed to support additional HTTP methods such as PATCH
+        client.property(HttpUrlConnectorProvider.SET_METHOD_WORKAROUND, true);
 
         WebTarget webTarget = addAuthType(client, p).target(p.restapiUrl);
 
@@ -631,14 +636,16 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
         r.code = 200;
 
         if (!p.skipSending) {
-            String tt = p.format == Format.XML ? "application/xml" : "application/json";
-            String tt1 = tt + ";charset=UTF-8";
-            if (p.contentType != null) {
-                tt = p.contentType;
-                tt1 = p.contentType;
+            String accept = p.accept;
+            if(accept == null) {
+                accept = p.format == Format.XML ? "application/xml" : "application/json";
+            }
+            String contentType = p.contentType;
+            if(contentType == null) {
+                contentType = accept + ";charset=UTF-8";
             }
 
-            Invocation.Builder invocationBuilder = webTarget.request(tt1).accept(tt);
+            Invocation.Builder invocationBuilder = webTarget.request(contentType).accept(accept);
 
             if (p.format == Format.NONE) {
                 invocationBuilder.header("", "");
@@ -658,7 +665,7 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
             Response response;
 
             try {
-                response = invocationBuilder.method(p.httpMethod.toString(), entity(request, tt1));
+                response = invocationBuilder.method(p.httpMethod.toString(), entity(request, contentType));
             } catch (ProcessingException | IllegalStateException e) {
                 throw new SvcLogicException(requestPostingException +
                     e.getLocalizedMessage(), e);
@@ -1012,4 +1019,4 @@ public class RestapiCallNode implements SvcLogicJavaPlugin {
         public String responsePrefix;
         public boolean skipSending;
     }
-}
\ No newline at end of file
+}