summaryrefslogtreecommitdiffstats
path: root/ONAP-PAP-REST/src/main
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 /ONAP-PAP-REST/src/main
parent54eaa820dd76f8da6076b6aad3d2c75c68236693 (diff)
fix try block
Issue-ID: POLICY-961 Change-Id: Ia1f388368007a4a82a57520dc6ddd99cc484a393 Signed-off-by: Krishnajinka <kris.jinka@samsung.com>
Diffstat (limited to 'ONAP-PAP-REST/src/main')
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/PAPRestConfig.java13
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ConfigPolicy.java15
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java13
-rw-r--r--ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java9
4 files changed, 10 insertions, 40 deletions
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/PAPRestConfig.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/PAPRestConfig.java
index 1b9afe547..7e514ef24 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/PAPRestConfig.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/PAPRestConfig.java
@@ -57,9 +57,8 @@ public class PAPRestConfig extends WebMvcConfigurerAdapter {
@PostConstruct
public void init(){
Properties prop = new Properties();
- InputStream input = null;
- try {
- input = new FileInputStream("xacml.pap.properties");
+
+ try(InputStream input = new FileInputStream("xacml.pap.properties")) {
// load a properties file
prop.load(input);
setDbDriver(prop.getProperty("javax.persistence.jdbc.driver"));
@@ -68,14 +67,6 @@ public class PAPRestConfig extends WebMvcConfigurerAdapter {
setDbPassword( CryptoUtils.decryptTxtNoExStr(prop.getProperty("javax.persistence.jdbc.password", "")));
}catch(Exception e){
LOGGER.error("Exception Occured while loading properties file"+e);
- }finally{
- if(input != null){
- try {
- input.close();
- } catch (IOException e) {
- LOGGER.error("Exception Occured while clsoing the stream"+e);
- }
- }
}
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ConfigPolicy.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ConfigPolicy.java
index 48eb784a7..b808e5882 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ConfigPolicy.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/ConfigPolicy.java
@@ -80,24 +80,15 @@ public class ConfigPolicy extends Policy {
// Saving the Configurations file at server location for config policy.
protected void saveConfigurations(String policyName) {
- BufferedWriter bw = null;
- try {
- String fileName = getConfigFile(policyName);
- bw = new BufferedWriter(new FileWriter(CONFIG_HOME + File.separator + fileName));
+
+ String fileName = getConfigFile(policyName);
+ try(BufferedWriter bw = new BufferedWriter(new FileWriter(CONFIG_HOME + File.separator + fileName))) {
bw.write(configBodyData);
if (LOGGER.isDebugEnabled()) {
LOGGER.debug("Configuration is succesfully saved");
}
} catch (IOException e) {
LOGGER.error("Exception Occured while writing Configuration Data"+e);
- } finally {
- if(bw != null){
- try {
- bw.close();
- } catch (Exception e) {
- LOGGER.error("Exception Occured while closing the BufferedWriter"+e);
- }
- }
}
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java
index 7757c2f19..0679e79d8 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/CreateNewMicroServiceModel.java
@@ -185,9 +185,8 @@ public class CreateNewMicroServiceModel {
int BUFFER = 2048;
File file = new File(zipFile);
- ZipFile zip = null;
- try {
- zip = new ZipFile("ExtractDir" + File.separator +file);
+
+ try(ZipFile zip = new ZipFile("ExtractDir" + File.separator +file)) {
String newPath = zipFile.substring(0, zipFile.length() - 4);
new File(newPath).mkdir();
Enumeration zipFileEntries = zip.entries();
@@ -225,14 +224,6 @@ public class CreateNewMicroServiceModel {
}
} catch (IOException e) {
logger.error("Failed to unzip model file " + zipFile + e);
- }finally{
- if(zip != null){
- try {
- zip.close();
- } catch (Exception e) {
- logger.error("Exception Occured while closing the zip file"+e);
- }
- }
}
}
diff --git a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
index a8449e307..60b35fb09 100644
--- a/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
+++ b/ONAP-PAP-REST/src/main/java/org/onap/policy/pap/xacml/rest/components/PolicyDBDao.java
@@ -1923,18 +1923,15 @@ public class PolicyDBDao {
private String readConfigFile(String configPath){
String configDataString = null;
- InputStream configContentStream = null;
- try {
- configContentStream = new FileInputStream(configPath);
+
+ try(InputStream configContentStream = new FileInputStream(configPath)) {
configDataString = IOUtils.toString(configContentStream);
} catch (FileNotFoundException e) {
logger.error("Caught FileNotFoundException on new FileInputStream("+configPath+")",e);
throw new IllegalArgumentException("The config file path does not exist");
} catch(IOException e2){
- logger.error("Caught IOException on newIOUtils.toString("+configContentStream+")",e2);
+ logger.error("Caught IOException on newIOUtils.toString(configContentStream)",e2);
throw new IllegalArgumentException("The config file path cannot be read");
- } finally {
- IOUtils.closeQuietly(configContentStream);
}
if(configDataString == null){
throw new IllegalArgumentException("The config file path cannot be read");