summaryrefslogtreecommitdiffstats
path: root/nokia
diff options
context:
space:
mode:
authorajay priyadarshi <ajay.priyadarshi@ril.com>2018-03-14 12:56:15 +0530
committerajay priyadarshi <ajay.priyadarshi@ril.com>2018-03-14 12:56:15 +0530
commit5c76dfc8933c0c1b51c4c72865b4b05628130178 (patch)
tree7ec871a2b8537b0ead44f688e7d562eed58a482e /nokia
parent096c0fee2751a8bac1e67b21867e5b23f6a93b63 (diff)
sonar fix:R&E handling in MultipartUtility
cbam/impl/MultipartUtility.java file name: MultipartUtility.java Change-Id: Ie54ef11b5bae5d56cc9b045325af7c0ddbace825 Issue-ID: VFC-814 Signed-off-by: ajay priyadarshi <ajay.priyadarshi@ril.com>
Diffstat (limited to 'nokia')
-rw-r--r--nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java40
1 files changed, 22 insertions, 18 deletions
diff --git a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java
index f8f0c400..834c2a7b 100644
--- a/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java
+++ b/nokia/vnfmdriver/vfcadaptorservice/vfcadaptor/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/cbam/impl/MultipartUtility.java
@@ -32,6 +32,8 @@ import java.security.cert.CertificateException;
import java.security.cert.X509Certificate;
import java.util.ArrayList;
import java.util.List;
+import java.security.NoSuchAlgorithmException;
+import java.security.KeyManagementException;
import javax.net.ssl.HostnameVerifier;
import javax.net.ssl.HttpsURLConnection;
@@ -74,7 +76,7 @@ public class MultipartUtility {
* @throws IOException
*/
public MultipartUtility(String requestURL, String charset)
- throws Exception {
+ throws CertificateException, IOException, NoSuchAlgorithmException, KeyManagementException{
this.charset = charset;
// creates a unique boundary based on time stamp
@@ -165,10 +167,10 @@ public class MultipartUtility {
KEY_STORE_TYPE = sslConf.getKeyStoreType();
}
// load jks file
- FileInputStream f_certStore = new FileInputStream(CommonUtil.getAppRoot() + CERT_STORE);
- KeyStore ks = KeyStore.getInstance(KEY_STORE_TYPE);
- ks.load(f_certStore, CERT_STORE_PASSWORD.toCharArray());
- f_certStore.close();
+ try(FileInputStream f_certStore = new FileInputStream(CommonUtil.getAppRoot() + CERT_STORE)){
+ KeyStore ks = KeyStore.getInstance(KEY_STORE_TYPE);
+ ks.load(f_certStore, CERT_STORE_PASSWORD.toCharArray());
+
// init and create
String alg = KeyManagerFactory.getDefaultAlgorithm();
@@ -176,6 +178,7 @@ public class MultipartUtility {
kmFact.init(ks, CERT_STORE_PASSWORD.toCharArray());
kms = kmFact.getKeyManagers();
+ }
} catch(Exception e) {
logger.error("create KeyManager fail!", e);
}
@@ -196,15 +199,16 @@ public class MultipartUtility {
}
String jksFilePath1 =CommonUtil.getAppRoot() + TRUST_STORE;
logger.info("jks path is " + jksFilePath1);
- FileInputStream f_trustStore = new FileInputStream(jksFilePath1);
- KeyStore ks = KeyStore.getInstance(TRUST_STORE_TYPE);
- ks.load(f_trustStore, TRUST_STORE_PASSWORD.toCharArray());
- f_trustStore.close();
+ try(FileInputStream f_trustStore = new FileInputStream(jksFilePath1)){
+ KeyStore ks = KeyStore.getInstance(TRUST_STORE_TYPE);
+ ks.load(f_trustStore, TRUST_STORE_PASSWORD.toCharArray());
+
String alg = TrustManagerFactory.getDefaultAlgorithm();
TrustManagerFactory tmFact = TrustManagerFactory.getInstance(alg);
tmFact.init(ks);
tms = tmFact.getTrustManagers();
+ }
} catch(Exception e) {
logger.error("create TrustManager fail!", e);
@@ -235,14 +239,14 @@ public class MultipartUtility {
writer.append(LINE_FEED);
writer.flush();
- FileInputStream inputStream = new FileInputStream(uploadFile);
- byte[] buffer = new byte[4096];
- int bytesRead = -1;
- while ((bytesRead = inputStream.read(buffer)) != -1) {
- outputStream.write(buffer, 0, bytesRead);
- }
- outputStream.flush();
- inputStream.close();
+ try(FileInputStream inputStream = new FileInputStream(uploadFile)){
+ byte[] buffer = new byte[4096];
+ int bytesRead = -1;
+ while ((bytesRead = inputStream.read(buffer)) != -1) {
+ outputStream.write(buffer, 0, bytesRead);
+ }
+ outputStream.flush();
+ }
writer.append(LINE_FEED);
writer.flush();
@@ -289,4 +293,4 @@ public class MultipartUtility {
return response;
}
-} \ No newline at end of file
+}