aboutsummaryrefslogtreecommitdiffstats
path: root/POLICY-SDK-APP
diff options
context:
space:
mode:
authorKrishnajinka <kris.jinka@samsung.com>2018-07-13 17:54:49 +0900
committerKrishnajinka <kris.jinka@samsung.com>2018-07-13 18:11:36 +0900
commita97e1eafd731937aab373213ab04c3296cc97595 (patch)
treef17368b79fb5f30185ce7a8b782ead09ba43f923 /POLICY-SDK-APP
parent54eaa820dd76f8da6076b6aad3d2c75c68236693 (diff)
fix try block
Issue-ID: POLICY-961 Change-Id: Ia1f388368007a4a82a57520dc6ddd99cc484a393 Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
Diffstat (limited to 'POLICY-SDK-APP')
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/admin/PolicyRestController.java15
-rw-r--r--POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java11
2 files changed, 18 insertions, 8 deletions
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;
}
diff --git a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java
index a8831eaaf..b14a8815e 100644
--- a/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java
+++ b/POLICY-SDK-APP/src/main/java/org/onap/policy/admin/RESTfulPAPEngine.java
@@ -455,10 +455,13 @@ public class RESTfulPAPEngine extends StdPDPItemSetChangeNotifier implements PAP
// get the response content into a String
String json = 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");
- json = scanner.hasNext() ? scanner.next() : "";
- scanner.close();
+ try(java.util.Scanner scanner = new java.util.Scanner(connection.getInputStream())) {
+ scanner.useDelimiter("\\A");
+ json = scanner.hasNext() ? scanner.next() : "";
+ }catch(Exception e) {
+ LOGGER.error(XACMLErrorConstants.ERROR_PROCESS_FLOW + "Failed to read inputStream from connection: " + e, e);
+ throw e;
+ }
LOGGER.info("JSON response from PAP: " + json);
// convert Object sent as JSON into local object