diff options
author | Denes Nemeth <denes.nemeth@nokia.com> | 2018-03-05 11:34:34 +0100 |
---|---|---|
committer | Denes Nemeth <denes.nemeth@nokia.com> | 2018-03-05 11:46:33 +0100 |
commit | be56383397388d35f41089723e912856c03f4673 (patch) | |
tree | 70fa2ec82e5de369fb7397e8b261bfcf8748282b /nokiav2/driver/src/main/java/org/onap/vfc | |
parent | 729c12f0145d4ac71e92545e7408379b48c8f389 (diff) |
Fix release artifacts
Change-Id: Ic61a50d8c7b9c2121b7ebbac5324b1c2b99e1f3a
Signed-off-by: Denes Nemeth <denes.nemeth@nokia.com>
Issue-ID: VFC-728
Diffstat (limited to 'nokiav2/driver/src/main/java/org/onap/vfc')
5 files changed, 63 insertions, 37 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 2013a7bf..4a737480 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 @@ -28,9 +28,16 @@ import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; import javax.servlet.http.Part; +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.SystemFunctions.systemFunctions; import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL; import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.HttpHeaders.CONTENT_DISPOSITION; +import static org.springframework.http.HttpHeaders.CONTENT_LENGTH; +import static org.springframework.http.HttpHeaders.CONTENT_TYPE; +import static org.springframework.http.HttpStatus.OK; import static org.springframework.http.MediaType.TEXT_HTML_VALUE; import static org.springframework.web.bind.annotation.RequestMethod.GET; import static org.springframework.web.bind.annotation.RequestMethod.POST; @@ -56,10 +63,10 @@ public class ConverterApi { logger.info("REST: convert package"); Part part = request.getParts().iterator().next(); byte[] bytes = vnfPackageConverter.covert(part.getInputStream()); - httpResponse.addHeader(HttpHeaders.CONTENT_TYPE, ContentType.APPLICATION_OCTET_STREAM.getMimeType()); - httpResponse.setStatus(HttpStatus.OK.value()); - httpResponse.addHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length)); - httpResponse.addHeader(HttpHeaders.CONTENT_DISPOSITION, "attachment; filename=\"" + "core.csar" + "\""); + httpResponse.addHeader(CONTENT_TYPE, APPLICATION_OCTET_STREAM.getMimeType()); + httpResponse.setStatus(OK.value()); + httpResponse.addHeader(CONTENT_LENGTH, Integer.toString(bytes.length)); + httpResponse.addHeader(CONTENT_DISPOSITION, "attachment; filename=\"" + "core.csar" + "\""); httpResponse.getOutputStream().write(bytes); httpResponse.getOutputStream().flush(); } @@ -72,10 +79,10 @@ public class ConverterApi { */ @RequestMapping(value = "/convert", method = GET, produces = TEXT_HTML_VALUE) @ResponseBody - public void getUploadPageForConvertingVnfd(HttpServletResponse httpResponse) throws Exception { + public void getUploadPageForConvertingVnfd(HttpServletResponse httpResponse) throws IOException { logger.info("REST: get converter main page"); byte[] bytes = systemFunctions().loadFile("upload.html"); - httpResponse.addHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length)); + httpResponse.addHeader(CONTENT_LENGTH, Integer.toString(bytes.length)); httpResponse.getOutputStream().write(bytes); } } diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SwaggerApi.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SwaggerApi.java index 6d4d19e6..659e82fd 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SwaggerApi.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/restapi/SwaggerApi.java @@ -26,8 +26,13 @@ import org.springframework.web.bind.annotation.ResponseBody; import javax.servlet.http.HttpServletResponse; +import java.io.IOException; + import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.vnfm.DriverProperties.BASE_URL; import static org.slf4j.LoggerFactory.getLogger; +import static org.springframework.http.HttpHeaders.CONTENT_LENGTH; +import static org.springframework.http.HttpHeaders.CONTENT_TYPE; +import static org.springframework.http.MediaType.APPLICATION_JSON_VALUE; import static org.springframework.web.bind.annotation.RequestMethod.GET; /** @@ -52,11 +57,11 @@ public class SwaggerApi { */ @RequestMapping(value = "/swagger.json", method = GET) @ResponseBody - public void getSwaggerApiDefinition(HttpServletResponse httpResponse) throws Exception { + public void getSwaggerApiDefinition(HttpServletResponse httpResponse) throws IOException { logger.info("REST: get swagger definition"); - httpResponse.addHeader(HttpHeaders.CONTENT_TYPE, MediaType.APPLICATION_JSON_VALUE); + httpResponse.addHeader(CONTENT_TYPE, APPLICATION_JSON_VALUE); byte[] bytes = selfRegistrationManager.getSwaggerApiDefinition(); - httpResponse.addHeader(HttpHeaders.CONTENT_LENGTH, Integer.toString(bytes.length)); + httpResponse.addHeader(CONTENT_LENGTH, Integer.toString(bytes.length)); httpResponse.getOutputStream().write(bytes); } } diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/CbamUtils.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/CbamUtils.java index 7377abfc..ebd4234a 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/CbamUtils.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/CbamUtils.java @@ -20,8 +20,20 @@ import com.google.gson.JsonElement; import com.google.gson.JsonObject; import org.slf4j.Logger; +/** + * Collection of utility functions + */ public class CbamUtils { + private static class OperationMustBeAborted extends RuntimeException{ + OperationMustBeAborted(String msg){ + super(msg); + } + OperationMustBeAborted(Exception e, String msg){ + super(msg, e); + } + } + private CbamUtils() { //use static way } @@ -43,7 +55,7 @@ public class CbamUtils { public static JsonElement childElement(JsonObject parent, String name) { JsonElement child = parent.get(name); if (child == null) { - throw new RuntimeException("Missing child " + name); + throw new OperationMustBeAborted("Missing child " + name); } return child; } @@ -58,7 +70,7 @@ public class CbamUtils { */ public static RuntimeException fatalFailure(Logger logger, String msg, Exception e) { logger.error(msg, e); - throw new RuntimeException(msg, e); + throw new OperationMustBeAborted(e, msg); } /** @@ -70,6 +82,6 @@ public class CbamUtils { */ public static RuntimeException fatalFailure(Logger logger, String msg) { logger.error(msg); - throw new RuntimeException(msg); + throw new OperationMustBeAborted(msg); } } diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/StoreLoader.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/StoreLoader.java index faa436e3..249925ea 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/StoreLoader.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/StoreLoader.java @@ -18,6 +18,7 @@ package org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util; import org.apache.commons.codec.binary.Base64; +import javax.swing.text.html.Option; import java.io.ByteArrayInputStream; import java.io.InputStream; import java.security.KeyFactory; @@ -34,6 +35,9 @@ import java.util.HashSet; import java.util.Optional; import java.util.Set; +import static java.util.Optional.empty; +import static java.util.Optional.of; +import static org.onap.vfc.nfvo.driver.vnfm.svnfm.nokia.util.CbamUtils.fatalFailure; import static org.slf4j.LoggerFactory.getLogger; /** @@ -41,7 +45,7 @@ import static org.slf4j.LoggerFactory.getLogger; */ public final class StoreLoader { - public static final String PASSWORD = "password"; + public static final String PASS_ALIAS = "password"; private static final String RSA = "RSA"; private static final String X_509 = "X.509"; private static final String SUN = "SUN"; @@ -59,8 +63,7 @@ public final class StoreLoader { if (rindex == -1 || lindex == -1) { return ""; } - String substring = content.substring(rindex, lindex) + end(scope); - return substring; + return content.substring(rindex, lindex) + end(scope); } /** @@ -105,17 +108,17 @@ public final class StoreLoader { */ public static KeyStore loadStore(String pem, String storePassword, String keyPassword) { Optional<PrivateKey> privateKey = generatePrivateKey(pem); - Certificate[] certs = createCertificates(pem); + Optional<Certificate[]> certs = createCertificates(pem); try { KeyStore ks = KeyStore.getInstance(JKS, SUN); ks.load(null, storePassword.toCharArray()); if (privateKey.isPresent()) { - ks.setKeyEntry(PASSWORD, privateKey.get(), keyPassword.toCharArray(), certs); - } else if (certs != null) { + ks.setKeyEntry(PASS_ALIAS, privateKey.get(), keyPassword.toCharArray(), certs.orElse(null)); + } else if (certs.isPresent()) { int index = 0; - for (Certificate cert : certs) { + for (Certificate cert : certs.get()) { TrustedCertificateEntry ts = new TrustedCertificateEntry(cert); - ks.setEntry(PASSWORD + index, ts, null); + ks.setEntry(PASS_ALIAS + index, ts, null); index++; } } @@ -125,7 +128,7 @@ public final class StoreLoader { } } - private static Certificate[] createCertificates(String pem) { + private static Optional<Certificate[]> createCertificates(String pem) { Set<Certificate> certificates = new HashSet<>(); try { for (String certificate : getCertifacates(pem)) { @@ -136,14 +139,13 @@ public final class StoreLoader { certificates.addAll(c); } } catch (Exception e) { - logger.error(e.getMessage(), e); - throw new RuntimeException("Unable to load certificates", e); + throw fatalFailure(logger, "Unable to load certificates", e); } if (certificates.size() > 0) { - return certificates.toArray(new Certificate[certificates.size()]); + return of(certificates.toArray(new Certificate[certificates.size()])); } else { - return null; + return empty(); } } @@ -153,12 +155,11 @@ public final class StoreLoader { if (!key.isEmpty()) { KeyFactory keyFactory = KeyFactory.getInstance(RSA); PKCS8EncodedKeySpec keySpec = new PKCS8EncodedKeySpec(toDer(key, RSA_PRIVATE_KEY)); - return Optional.of(keyFactory.generatePrivate(keySpec)); + return of(keyFactory.generatePrivate(keySpec)); } - return Optional.empty(); + return empty(); } catch (NoSuchAlgorithmException | InvalidKeySpecException e) { - logger.error("Unable to load key", e); - throw new RuntimeException("Unable to load key", e); + throw fatalFailure(logger, "Unable to load key", e); } } diff --git a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java index e2a2e660..805be641 100644 --- a/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java +++ b/nokiav2/driver/src/main/java/org/onap/vfc/nfvo/driver/vnfm/svnfm/nokia/util/SystemFunctions.java @@ -28,19 +28,19 @@ import java.io.PrintStream; * the classes that uses static calls. */ public class SystemFunctions { - private static SystemFunctions INSTANCE; + private static SystemFunctions singletonInstance; /** * @return singleton instance */ public static SystemFunctions systemFunctions() { - if (INSTANCE != null) { - return INSTANCE; + if (singletonInstance != null) { + return singletonInstance; } else { synchronized (SystemFunctions.class) { - INSTANCE = new SystemFunctions(); + singletonInstance = new SystemFunctions(); } - return INSTANCE; + return singletonInstance; } } @@ -56,6 +56,7 @@ public class SystemFunctions { try { Thread.sleep(millis); } catch (InterruptedException e) { + Thread.currentThread().interrupt(); throw new RuntimeException(e); } } @@ -108,7 +109,7 @@ public class SystemFunctions { * destination that is typically not continuously monitored. */ public PrintStream err() { - return System.err; + return System.err; //NO SONAR (intentional wrapping of system err } /** @@ -137,7 +138,7 @@ public class SystemFunctions { * @see java.io.PrintStream#println(java.lang.String) */ public PrintStream out() { - return System.out; + return System.out; //NO SONAR (intentional wrapping of system out) } /** @@ -147,7 +148,7 @@ public class SystemFunctions { * the host environment or user. */ public InputStream in() { - return System.in; + return System.in; //NO SONAR (intentional wrapping of system in) } /** |