aboutsummaryrefslogtreecommitdiffstats
path: root/profiles/http/src/main
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2018-03-21 14:34:21 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2018-03-21 14:34:21 +0530
commit8f21819de7f63856f087ad40ac0f36c644781e54 (patch)
treeb3bfde440878654c1c897fabcb2fb33423facfcd /profiles/http/src/main
parent10414799b301d26fee6195ab0128fd3dde140b0a (diff)
Add support for DELETE with request body
Issue-ID: CLI-103 Change-Id: If2bca74d8963549aa8696fa896f7b1a69ff5ee05 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'profiles/http/src/main')
-rw-r--r--profiles/http/src/main/java/org/onap/cli/fw/http/connect/OnapHttpConnection.java28
1 files changed, 24 insertions, 4 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();
+ }
+ }
}