Fix nullPointerException non-200 guard response. 71/18071/2
authorTemoc Rodriguez <cr056n@att.com>
Tue, 10 Oct 2017 22:26:10 +0000 (15:26 -0700)
committerTemoc Rodriguez <cr056n@att.com>
Wed, 11 Oct 2017 15:05:02 +0000 (08:05 -0700)
Added a check for when the guard response from pdp-x is not
200. When the response is unauthorized or forbidden, it will
have an empty body, try to convert to json, and throw an
exception. Added a null check on the response and returns
indeterminate in the case of an empty body.

Issue-ID: POLICY-280
Change-Id: I9d384472e230495130bd41d377e25b74fe9ea9bd
Signed-off-by: Temoc Rodriguez <cr056n@att.com>
controlloop/common/guard/src/main/java/org/onap/policy/guard/PolicyGuardXacmlHelper.java

index 908a3af..0ecfaa6 100644 (file)
@@ -231,12 +231,13 @@ public class PolicyGuardXacmlHelper {
                } catch (Exception e) {
                        logger.error(
                                        "Exception in 'PolicyGuardXacmlHelper.callRESTfulPDP'", e);
-                       //
-                       // Connection may have failed, return Indeterminate
-                       //
-                       if(response == null || response.isEmpty()){
-                               return Util.INDETERMINATE;
-                       }       
+               }
+               
+               //
+               // Connection may have failed or not been 200 OK, return Indeterminate
+               //
+               if(response == null || response.isEmpty()){
+                       return Util.INDETERMINATE;
                }
                
                rawDecision = new JSONObject(response).getString("decision");