aboutsummaryrefslogtreecommitdiffstats
path: root/controlloop/common/model-impl/rest/src/main
diff options
context:
space:
mode:
authorMike Babinski <mb1915@att.com>2017-08-22 04:40:23 +0000
committerMike Babinski <mb1915@att.com>2017-08-23 22:19:40 +0000
commit945627aef4645a9a696aeb2150669e43aae9f98a (patch)
treec2c7aa3bc2124def4a41e3f1710946922d2d325d /controlloop/common/model-impl/rest/src/main
parent1b93494ed7c4808aaf979472a9349177ff99d8d8 (diff)
Fix Sonar Blockers for Drools-Applications
Add null checks to protect against potential null exceptions. Issue-ID: POLICY-111 Change-Id: Ib079d1b48a6858332ea3eaa0e75a991f518a0f9a Signed-off-by: Mike Babinski <mb1915@att.com>
Diffstat (limited to 'controlloop/common/model-impl/rest/src/main')
-rw-r--r--controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java17
1 files changed, 10 insertions, 7 deletions
diff --git a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java
index 8c79d2ad3..c38c1076c 100644
--- a/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java
+++ b/controlloop/common/model-impl/rest/src/main/java/org/onap/policy/rest/RESTManager.java
@@ -67,8 +67,10 @@ public final class RESTManager {
try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentials).build()) {
HttpPost post = new HttpPost(url);
- for (String key : headers.keySet()) {
- post.addHeader(key, headers.get(key));
+ if (headers != null) {
+ for (String key : headers.keySet()) {
+ post.addHeader(key, headers.get(key));
+ }
}
post.addHeader("Content-Type", contentType);
@@ -100,16 +102,17 @@ public final class RESTManager {
try (CloseableHttpClient client = HttpClientBuilder.create().setDefaultCredentialsProvider(credentials).build()) {
HttpGet get = new HttpGet(url);
- for (String key : headers.keySet()) {
- get.addHeader(key, headers.get(key));
+ if (headers != null) {
+ for (String key : headers.keySet()) {
+ get.addHeader(key, headers.get(key));
+ }
}
HttpResponse response = client.execute(get);
String returnBody = EntityUtils.toString(response.getEntity(), "UTF-8");
- System.out.println("HTTP GET Response Status Code: " + response.getStatusLine().getStatusCode());
- System.out.println("HTTP GET Response Body:");
- System.out.println(returnBody);
+ logger.debug("HTTP GET Response Status Code: " + response.getStatusLine().getStatusCode());
+ logger.debug("HTTP GET Response Body: " + returnBody);
return new Pair<Integer, String>(response.getStatusLine().getStatusCode(), returnBody);
} catch (IOException e) {