From 8f21819de7f63856f087ad40ac0f36c644781e54 Mon Sep 17 00:00:00 2001 From: Kanagaraj Manickam k00365106 Date: Wed, 21 Mar 2018 14:34:21 +0530 Subject: Add support for DELETE with request body Issue-ID: CLI-103 Change-Id: If2bca74d8963549aa8696fa896f7b1a69ff5ee05 Signed-off-by: Kanagaraj Manickam k00365106 --- .../cli/fw/http/connect/OnapHttpConnection.java | 28 ++++++++++++++++++---- 1 file changed, 24 insertions(+), 4 deletions(-) (limited to 'profiles/http/src') 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(); + } + } } -- cgit 1.2.3-korg