From 4704cdfc9441679baf1b178c3d9846cba03b4de5 Mon Sep 17 00:00:00 2001 From: Tal Gitelman Date: Sun, 30 Sep 2018 14:50:18 +0300 Subject: exception is thrown on import normative Change-Id: I26cd77466d4c79836665929066d2bff5b6ead92b Issue-ID: SDC-1796 Signed-off-by: Tal Gitelman --- .../be/servlets/AbstractValidationsServlet.java | 22 +++++++++------------- 1 file changed, 9 insertions(+), 13 deletions(-) (limited to 'catalog-be/src/main') diff --git a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java index c4035206f2..14fc77acd5 100644 --- a/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java +++ b/catalog-be/src/main/java/org/openecomp/sdc/be/servlets/AbstractValidationsServlet.java @@ -169,9 +169,8 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { } - protected void validateZip(Wrapper responseWrapper, File file, String payloadName) throws FileNotFoundException { - InputStream fileInputStream = new FileInputStream(file); - Map unzippedFolder = ZipUtil.readZip(new ZipInputStream(fileInputStream)); + protected void validateZip(Wrapper responseWrapper, File file, String payloadName) { + Map unzippedFolder = ZipUtil.readZip(file); if (payloadName == null || payloadName.isEmpty() || !unzippedFolder.containsKey(payloadName)) { log.info("Invalid json was received. payloadName should be yml file name"); Response errorResponse = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)); @@ -179,9 +178,8 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { } } - protected void validateCsar(Wrapper responseWrapper, File file, String payloadName) throws FileNotFoundException { - InputStream fileInputStream = new FileInputStream(file); - Map unzippedFolder = ZipUtil.readZip(new ZipInputStream(fileInputStream)); + protected void validateCsar(Wrapper responseWrapper, File file, String payloadName) { + Map unzippedFolder = ZipUtil.readZip(file); if (payloadName == null || payloadName.isEmpty() || unzippedFolder.isEmpty()) { log.info("Invalid json was received. payloadName should be yml file name"); Response errorResponse = buildErrorResponse(getComponentsUtils().getResponseFormat(ActionStatus.INVALID_CONTENT)); @@ -190,20 +188,18 @@ public abstract class AbstractValidationsServlet extends BeGenericServlet { } - protected void fillZipContents(Wrapper yamlStringWrapper, File file) throws FileNotFoundException { + protected void fillZipContents(Wrapper yamlStringWrapper, File file) { extractZipContents(yamlStringWrapper, file); } - public static void extractZipContents(Wrapper yamlStringWrapper, File file) throws FileNotFoundException { - InputStream fileInputStream = new FileInputStream(file); - Map unzippedFolder = ZipUtil.readZip(new ZipInputStream(fileInputStream)); + public static void extractZipContents(Wrapper yamlStringWrapper, File file) { + Map unzippedFolder = ZipUtil.readZip(file); String ymlName = unzippedFolder.keySet().iterator().next(); fillToscaTemplateFromZip(yamlStringWrapper, ymlName, file); } - private static void fillToscaTemplateFromZip(Wrapper yamlStringWrapper, String payloadName, File file) throws FileNotFoundException { - InputStream fileInputStream = new FileInputStream(file); - Map unzippedFolder = ZipUtil.readZip(new ZipInputStream(fileInputStream)); + private static void fillToscaTemplateFromZip(Wrapper yamlStringWrapper, String payloadName, File file) { + Map unzippedFolder = ZipUtil.readZip(file); byte[] yamlFileInBytes = unzippedFolder.get(payloadName); String yamlAsString = new String(yamlFileInBytes, StandardCharsets.UTF_8); log.debug("received yaml: {}", yamlAsString); -- cgit 1.2.3-korg