summaryrefslogtreecommitdiffstats
path: root/profiles/http/src
diff options
context:
space:
mode:
Diffstat (limited to 'profiles/http/src')
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java28
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java29
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java2
3 files changed, 45 insertions, 14 deletions
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java
index 9291ef51..093f42b5 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java
@@ -35,10 +35,11 @@ import javax.net.ssl.X509TrustManager;
import org.apache.http.Header;
import org.apache.http.HttpEntity;
import org.apache.http.HttpResponse;
-import org.apache.http.ParseException;
+import org.apache.http.annotation.NotThreadSafe;
import org.apache.http.client.CookieStore;
import org.apache.http.client.HttpClient;
import org.apache.http.client.methods.HttpDelete;
+import org.apache.http.client.methods.HttpEntityEnclosingRequestBase;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
@@ -63,6 +64,7 @@ import org.apache.http.impl.cookie.BasicClientCookie;
import org.apache.http.protocol.BasicHttpContext;
import org.apache.http.protocol.HttpContext;
import org.apache.http.util.EntityUtils;
+import org.onap.cli.fw.conf.OnapCommandConstants;
import org.onap.cli.fw.http.conf.OnapCommandHttpConstants;
import org.onap.cli.fw.http.error.OnapCommandHttpFailure;
import org.slf4j.Logger;
@@ -294,7 +296,7 @@ public class OnapHttpConnection {
if (input.isBinaryData()) {
httpPost.setEntity(getMultipartEntity(input));
} else {
- httpPost.setEntity(this.getStringEntity(input));
+ httpPost.setEntity(this.getStringEntity(input));
}
requestBase = httpPost;
} else if ("put".equals(input.getMethod())) {
@@ -304,7 +306,13 @@ public class OnapHttpConnection {
} else if ("get".equals(input.getMethod())) {
requestBase = new HttpGet();
} else if ("delete".equals(input.getMethod())) {
- requestBase = new HttpDelete();
+ if (!input.getBody().isEmpty()) {
+ HttpDeleteWithBody httpDelete = new HttpDeleteWithBody();
+ httpDelete.setEntity(this.getStringEntity(input));
+ requestBase = httpDelete;
+ } else {
+ requestBase = new HttpDelete();
+ }
} else {
throw new IllegalArgumentException("Invalid HTTP method");
}
@@ -332,7 +340,7 @@ public class OnapHttpConnection {
result.setStatus(resp.getStatusLine().getStatusCode());
result.setRespHeaders(this.getHttpHeaders(resp));
this.updateResultFromCookies(result, cookieStore.getCookies());
- } catch (ParseException | IOException e) {
+ } catch (Exception e) { // NOSONAR
throw new OnapCommandHttpFailure(e);
} finally {
String info = input + " " + result;
@@ -360,4 +368,16 @@ public class OnapHttpConnection {
multipartEntity.addPart(fileName, fileBody);
return multipartEntity;
}
+
+ @NotThreadSafe
+ static class HttpDeleteWithBody extends HttpEntityEnclosingRequestBase {
+
+ public String getMethod() {
+ return OnapCommandHttpConstants.DELETE;
+ }
+
+ public HttpDeleteWithBody() {
+ super();
+ }
+ }
}
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
index 973c4ae1..52b7571d 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/schema/OnapCommandSchemaHttpLoader.java
@@ -133,9 +133,18 @@ public class OnapCommandSchemaHttpLoader {
cmd.getInput().setReqQueries(query);
break;
case OnapCommandHttpConstants.CONTEXT:
- Map<String, String> context = (Map<String, String>) map.get(key2);
+ Map<String, Object> context = (Map<String, Object>) map.get(key2);
+
+ for (String key: context.keySet()) {
+ switch (key) {
+ case OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES:
+ Boolean flag = (Boolean) context.get(OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES);
+ cmd.getInput().getContext().put(OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES, flag.toString());
+ break;
+ }
+ }
+
- cmd.getInput().getContext().putAll(context);
break;
case OnapCommandHttpConstants.MULTIPART_ENTITY_NAME:
Object multipartEntityName = map.get(key2);
@@ -376,15 +385,17 @@ public class OnapCommandSchemaHttpLoader {
}
String body = String.valueOf(bodyString);
- JSONObject obj = null;
- try {
- obj = new ObjectMapper().readValue(body, JSONObject.class);
- } catch (IOException e1) { // NOSONAR
- errorList.add(OnapCommandHttpConstants.HTTP_BODY_FAILED_PARSING);
- }
- if (obj == null || "".equals(obj.toString())) {
+
+ if (body == null || "".equals(body)) {
errorList.add(OnapCommandHttpConstants.HTTP_BODY_JSON_EMPTY);
+ } else {
+ try {
+ new ObjectMapper().readValue(body, JSONObject.class);
+ } catch (IOException e1) { // NOSONAR
+ errorList.add(OnapCommandHttpConstants.HTTP_BODY_FAILED_PARSING);
+ }
}
+
OnapCommandUtils.parseParameters(body, bodyParamNames);
return bodyParamNames;
diff --git a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
index 43a80181..ed415335 100644
--- a/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
+++ b/profiles/http/src/main/java/org/onap/cli/fw/http/utils/OnapCommandHttpUtils.java
@@ -89,7 +89,7 @@ public class OnapCommandHttpUtils {
boolean isRemoveEmptyNodes = Boolean.parseBoolean(input.getContext().getOrDefault(OnapCommandHttpConstants.CONTEXT_REMOVE_EMPTY_JSON_NODES, "false"));
if (isRemoveEmptyNodes) {
- input.setBody(OnapCommandHttpUtils.normalizeJson(input.getBody()));
+ inp.setBody(OnapCommandHttpUtils.normalizeJson(inp.getBody()));
}
return inp;