X-Git-Url: https://gerrit.onap.org/r/gitweb?a=blobdiff_plain;f=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fadmin%2FPolicyRestController.java;fp=POLICY-SDK-APP%2Fsrc%2Fmain%2Fjava%2Forg%2Fonap%2Fpolicy%2Fadmin%2FPolicyRestController.java;h=21f15bb8aa902ff4db56a52a807c0dc36aee6a14;hb=a97e1eafd731937aab373213ab04c3296cc97595;hp=8df9d1b89f24d9394f00f95f1d683af5de0ad3b5;hpb=54eaa820dd76f8da6076b6aad3d2c75c68236693;p=policy%2Fengine.git diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java index 8df9d1b89..21f15bb8a 100644 --- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java +++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java @@ -338,10 +338,17 @@ public class PolicyRestController extends RestrictedBaseController{ // get the response content into a String String responseJson = null; // read the inputStream into a buffer (trick found online scans entire input looking for end-of-file) - java.util.Scanner scanner = new java.util.Scanner(connection.getInputStream()); - scanner.useDelimiter("\\A"); - responseJson = scanner.hasNext() ? scanner.next() : ""; - scanner.close(); + try(java.util.Scanner scanner = new java.util.Scanner(connection.getInputStream())) { + scanner.useDelimiter("\\A"); + responseJson = scanner.hasNext() ? scanner.next() : ""; + } catch (Exception e) { + //Reason for rethrowing the exception is if any exception occurs during reading of inputsteam + //then the exception handling is done by the outer block without returning the response immediately + //Also finally block is existing only in outer block and not here so all exception handling is + //done in only one place + policyLogger.error("Exception Occured"+e); + throw e; + } policyLogger.info("JSON response from PAP: " + responseJson); return responseJson; }