Added Null check 57/78657/5
authorJegadeesh Babu <jegabab1@in.ibm.com>
Mon, 18 Feb 2019 13:26:48 +0000 (18:56 +0530)
committerTakamune Cho <takamune.cho@att.com>
Wed, 27 Feb 2019 01:13:11 +0000 (01:13 +0000)
Code to avoid null pointer Exception

Issue-ID: APPC-1451
Change-Id: I5e2324a2ddffbc50251ee93a1278cfb68e62a551
Signed-off-by: Jegadeesh Babu <jegabab1@in.ibm.com>
appc-adapters/appc-ansible-adapter/appc-ansible-adapter-bundle/src/main/java/org/onap/appc/adapter/ansible/impl/AnsibleAdapterImpl.java

index fafe3de..ace39ee 100644 (file)
@@ -6,6 +6,8 @@
  * ================================================================================
  * Copyright (C) 2017 Amdocs
  * =============================================================================
+ * Modifications Copyright (C) 2019 IBM
+ * =============================================================================
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
@@ -476,12 +478,14 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
     private AnsibleResult postExecRequest(String agentUrl, String payload, String user, String password,
             SvcLogicContext ctx) {
 
-        AnsibleResult testResult;
+        AnsibleResult testResult = null;
         ConnectionBuilder httpClient = getHttpConn(defaultSocketTimeout, "");
         if (!testMode) {
+          if(httpClient!=null) {
             httpClient.setHttpContext(user, password);
             testResult = httpClient.post(agentUrl, payload);
             httpClient.close();
+          }
         } else {
             testResult = testServer.Post(agentUrl, payload);
         }
@@ -509,9 +513,11 @@ public class AnsibleAdapterImpl implements AnsibleAdapter {
             logger.info("Querying ansible GetResult URL = " + agentUrl);
 
             if (!testMode) {
+              if(httpClient!=null) {
                 httpClient.setHttpContext(user, password);
                 testResult = httpClient.get(agentUrl);
                 httpClient.close();
+              }
             } else {
                 testResult = testServer.Get(agentUrl);
             }