summaryrefslogtreecommitdiffstats
path: root/models-interactions/model-impl/rest/src/main
diff options
context:
space:
mode:
authorJohnKeeney <John.Keeney@est.tech>2019-07-09 12:32:41 +0000
committerJohnKeeney <John.Keeney@est.tech>2019-07-09 12:32:41 +0000
commit396d5e544a29c89d49662a8aa42819b99e8826f0 (patch)
tree3f175187da8ea290fcab97ead777bd8bcb057a2e /models-interactions/model-impl/rest/src/main
parent9d4d28c05d214e906731f4bf536e1428df6925b6 (diff)
Removed all mention of www.example.org from tests
Replaced those tests with test using a local/temp webserver to exercise the RestManager Updated with Jim/Pam's suggestions. Updated following SONAR changed to policy/common Change-Id: Ia2551fbcafd2cd30d74a881237b003216e8caec7 Issue-ID: POLICY-1665 Signed-off-by: JohnKeeney <John.Keeney@est.tech>
Diffstat (limited to 'models-interactions/model-impl/rest/src/main')
-rw-r--r--models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java21
1 files changed, 19 insertions, 2 deletions
diff --git a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java
index f19ed7872..2ee47a9fc 100644
--- a/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java
+++ b/models-interactions/model-impl/rest/src/main/java/org/onap/policy/rest/RestManager.java
@@ -27,6 +27,7 @@ import java.util.Map.Entry;
import javax.xml.bind.DatatypeConverter;
import org.apache.http.HttpHeaders;
import org.apache.http.HttpResponse;
+import org.apache.http.client.methods.HttpDelete;
import org.apache.http.client.methods.HttpGet;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.client.methods.HttpPut;
@@ -124,7 +125,8 @@ public class RestManager {
}
/**
- * Perform REST Delete.
+ * Perform REST Delete. <br/>
+ * <i>Note: Many REST endpoints will return a 400 error for delete requests with a non-empty body</i>
*
* @param url the url
* @param username the user name
@@ -138,8 +140,8 @@ public class RestManager {
String contentType, String body) {
HttpDeleteWithBody delete = new HttpDeleteWithBody(url);
addHeaders(delete, username, password, headers);
- delete.addHeader("Content-Type", contentType);
if (body != null && !body.isEmpty()) {
+ delete.addHeader("Content-Type", contentType);
try {
StringEntity input = new StringEntity(body);
input.setContentType(contentType);
@@ -153,6 +155,21 @@ public class RestManager {
}
/**
+ * Perform REST Delete.
+ *
+ * @param url the url
+ * @param username the user name
+ * @param password the password
+ * @param headers any headers
+ * @return the response status code and the body
+ */
+ public Pair<Integer, String> delete(String url, String username, String password, Map<String, String> headers) {
+ HttpDelete delete = new HttpDelete(url);
+ addHeaders(delete, username, password, headers);
+ return sendRequest(delete);
+ }
+
+ /**
* Send REST request.
*
* @param request http request to send