summaryrefslogtreecommitdiffstats
path: root/huawei/vnfmadapter/VnfmadapterService
diff options
context:
space:
mode:
authorKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2018-02-16 14:04:36 +0530
committerKanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>2018-02-16 14:25:51 +0530
commitbb1d702a7675354817c28c0888264d06202dbee6 (patch)
tree10aed890e0349a2c8489dcd15fc94f003f125a98 /huawei/vnfmadapter/VnfmadapterService
parentd4982f7b1777e9cdae9a4cc7d0d104263889ac69 (diff)
Make sure the streams are closed properly - common
Issue-ID: VFC-764 Change-Id: Id05b4415a1a0cd05ca9b5386385051ffcabea6d3 Signed-off-by: Kanagaraj Manickam k00365106 <kanagaraj.manickam@huawei.com>
Diffstat (limited to 'huawei/vnfmadapter/VnfmadapterService')
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java54
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ExceptionArgs.java15
-rw-r--r--huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ServiceException.java32
3 files changed, 56 insertions, 45 deletions
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java
index 24d6ed11..2cbd1ab8 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/DownloadCsarManager.java
@@ -57,7 +57,7 @@ public class DownloadCsarManager {
/**
* Download from given URL.
- *
+ *
* @param url String
* @return
*/
@@ -67,49 +67,53 @@ public class DownloadCsarManager {
/**
* Download from given URL to given file location.
- *
+ *
* @param url String
* @param filepath String
* @return
*/
public static String download(String url, String filepath) {
String status = "";
- try {
- CloseableHttpClient client = HttpClients.createDefault();
+ try (CloseableHttpClient client = HttpClients.createDefault()){
HttpGet httpget = new HttpGet(url);
CloseableHttpResponse response = client.execute(httpget);
HttpEntity entity = response.getEntity();
- InputStream is = entity.getContent();
- if(filepath == null) {
- filepath = getFilePath(response); // NOSONAR
- }
+ try(InputStream is = entity.getContent()) {
+ if(filepath == null) {
+ filepath = getFilePath(response); // NOSONAR
+ }
- File file = new File(filepath);
- file.getParentFile().mkdirs();
- FileOutputStream fileout = new FileOutputStream(file);
+ File file = new File(filepath);
+ file.getParentFile().mkdirs();
+ try(FileOutputStream fileout = new FileOutputStream(file)){
- byte[] buffer = new byte[CACHE];
- int ch;
- while((ch = is.read(buffer)) != -1) {
- fileout.write(buffer, 0, ch);
+ byte[] buffer = new byte[CACHE];
+ int ch;
+ while((ch = is.read(buffer)) != -1) {
+ fileout.write(buffer, 0, ch);
+ }
+ fileout.flush();
+ status = Constant.DOWNLOADCSAR_SUCCESS;
+ } catch(Exception e) {
+ status = Constant.DOWNLOADCSAR_FAIL;
+ LOG.error("Download csar file failed! " + e.getMessage(), e);
+ }
+ } catch(Exception e) {
+ status = Constant.DOWNLOADCSAR_FAIL;
+ LOG.error("Download csar file failed! " + e.getMessage(), e);
}
- is.close();
- fileout.flush();
- fileout.close();
- client.close();
- status = Constant.DOWNLOADCSAR_SUCCESS;
-
} catch(Exception e) {
status = Constant.DOWNLOADCSAR_FAIL;
LOG.error("Download csar file failed! " + e.getMessage(), e);
}
+
return status;
}
/**
* Retrieve file path from given response.
- *
+ *
* @param response HttpResponse
* @return
*/
@@ -127,7 +131,7 @@ public class DownloadCsarManager {
/**
* Retrieve file name from given response.
- *
+ *
* @param response HttpResponse
* @return
*/
@@ -152,7 +156,7 @@ public class DownloadCsarManager {
/**
* Provides random file name.
- *
+ *
* @return
*/
public static String getRandomFileName() {
@@ -161,7 +165,7 @@ public class DownloadCsarManager {
/**
* unzip CSAR packge
- *
+ *
* @param fileName filePath
* @return
* @throws IOException
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ExceptionArgs.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ExceptionArgs.java
index 49e9500f..73c6548b 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ExceptionArgs.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ExceptionArgs.java
@@ -16,16 +16,23 @@
package org.onap.vfc.nfvo.vnfm.svnfm.vnfmadapter.common.restclient;
+import java.io.Serializable;
+
/**
* ROA exception handling parameters.
* <br/>
* <p>
* </p>
- *
+ *
* @author
* @version 28-May-2016
*/
-public class ExceptionArgs {
+public class ExceptionArgs implements Serializable {
+
+ /**
+ *
+ */
+ private static final long serialVersionUID = 7411730460834659138L;
/**
* Exception descriptions.
@@ -51,7 +58,7 @@ public class ExceptionArgs {
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
*/
public ExceptionArgs() {
@@ -62,7 +69,7 @@ public class ExceptionArgs {
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param descArgs: descriptions.
* @param reasonArgs: reasons.
diff --git a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ServiceException.java b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ServiceException.java
index af8086b7..136df51c 100644
--- a/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ServiceException.java
+++ b/huawei/vnfmadapter/VnfmadapterService/service/src/main/java/org/onap/vfc/nfvo/vnfm/svnfm/vnfmadapter/common/restclient/ServiceException.java
@@ -22,7 +22,7 @@ import java.text.MessageFormat;
* The base class for all common exception.<br/>
* <p>
* </p>
- *
+ *
* @author
* @version 28-May-2016
*/
@@ -43,7 +43,7 @@ public class ServiceException extends Exception {
*/
private String id = DEFAULT_ID;
- private Object[] args = null;
+ private Object[] args = null; // NOSONAR
private int httpCode = 500;
@@ -54,7 +54,7 @@ public class ServiceException extends Exception {
* <p>
* This method is only used as deserialized, in other cases, use parameterized constructor.
* </p>
- *
+ *
* @since
*/
public ServiceException() {
@@ -65,7 +65,7 @@ public class ServiceException extends Exception {
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param id: details.
* @param cause: reason.
@@ -79,7 +79,7 @@ public class ServiceException extends Exception {
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param message: details.
*/
@@ -91,7 +91,7 @@ public class ServiceException extends Exception {
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param message: details.
@@ -105,7 +105,7 @@ public class ServiceException extends Exception {
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param httpCode: http status code.
@@ -121,7 +121,7 @@ public class ServiceException extends Exception {
* <p>
* the exception include the httpcode and message.
* </p>
- *
+ *
* @since
* @param httpCode http code.
* @param message details.
@@ -135,7 +135,7 @@ public class ServiceException extends Exception {
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param httpCode: http code.
@@ -153,7 +153,7 @@ public class ServiceException extends Exception {
* <p>
* Have a placeholder exception, use args formatted message.
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param message: details.
@@ -170,7 +170,7 @@ public class ServiceException extends Exception {
* <p>
* Have a placeholder exception, use args formatted message
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param message: details.
@@ -187,7 +187,7 @@ public class ServiceException extends Exception {
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param id: exception id.
* @param message: details.
@@ -202,7 +202,7 @@ public class ServiceException extends Exception {
* Constructor<br/>
* <p>
* </p>
- *
+ *
* @since
* @param cause: reason.
*/
@@ -212,7 +212,7 @@ public class ServiceException extends Exception {
/**
* Get exceptoin id.<br/>
- *
+ *
* @return
* @since
*/
@@ -237,7 +237,7 @@ public class ServiceException extends Exception {
/**
* Obtain the ROA exception handling framework parameters<br/>
- *
+ *
* @return exception args.
* @since
*/
@@ -251,7 +251,7 @@ public class ServiceException extends Exception {
/**
* Gets the parameter information<br/>
- *
+ *
* @return parameter list.
* @since
*/