diff options
author | Denes Nemeth <denes.nemeth@nokia.com> | 2018-03-07 12:54:19 +0100 |
---|---|---|
committer | Denes Nemeth <denes.nemeth@nokia.com> | 2018-03-07 21:56:38 +0100 |
commit | 817338bc7da3127ff01e6736d284a081461f484b (patch) | |
tree | 071d310a8b2a50ab81e3ea07a33dfc2b760cb04a /nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java | |
parent | 45f12914d2ba01cd0b7df7069e2879d4d7d275c6 (diff) |
Fix sonar issues
Change-Id: If699a0d8ba39238ff8e559567c8c5d44fb1e1d7c
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java')
-rw-r--r-- | nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java | 24 |
1 files changed, 19 insertions, 5 deletions
diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java index 6af13c58..8eb2007b 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/ConverterApi.java @@ -15,6 +15,7 @@ */ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.restapi; +import com.google.common.io.ByteStreams; import org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.packagetransformer.OnapVnfPackageBuilder; import org.slf4j.Logger; import org.springframework.stereotype.Controller; @@ -24,9 +25,11 @@ import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.Part; +import java.io.ByteArrayInputStream; import java.io.IOException; import static org.apache.http.entity.ContentType.APPLICATION_OCTET_STREAM; +import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.buildFatalFailure; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.SystemFunctions.systemFunctions; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL; import static org.slf4j.LoggerFactory.getLogger; @@ -53,15 +56,26 @@ public class ConverterApi { */ @RequestMapping(value = "/convert", method = POST) @ResponseBody - public void convert(HttpServletResponse httpResponse, HttpServletRequest request) throws Exception { + public void convert(HttpServletResponse httpResponse, HttpServletRequest request) throws IOException { logger.info("REST: convert package"); - Part part = request.getParts().iterator().next(); - byte[] bytes = vnfPackageConverter.covert(part.getInputStream()); + byte[] content; + try { + Part part = request.getParts().iterator().next(); + content = ByteStreams.toByteArray(part.getInputStream()); + } catch (Exception e) { + throw buildFatalFailure(logger, "Unable to extract package from REST parameters", e); + } + byte[] convertedPackage; + try { + convertedPackage = vnfPackageConverter.covert(new ByteArrayInputStream(content)); + } catch (IOException e) { + throw buildFatalFailure(logger, "Unable to convert VNF package", e); + } httpResponse.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM.getMimeType()); httpResponse.setStatus(OK.value()); - httpResponse.addHeader(CONTENT_LENGTH, Integer.toString(bytes.length)); + httpResponse.addHeader(CONTENT_LENGTH, Integer.toString(convertedPackage.length)); httpResponse.addHeader(CONTENT_DISPOSITION, "attachment; filename=\"" + "core.csar" + "\""); - httpResponse.getOutputStream().write(bytes); + httpResponse.getOutputStream().write(convertedPackage); httpResponse.getOutputStream().flush(); } |