From 468c740aa7142801b0b4566cbfc3b75b24e4cab8 Mon Sep 17 00:00:00 2001 From: Arindam Mondal Date: Tue, 21 Aug 2018 11:51:20 +0900 Subject: Sonar violation Issue-ID: AAI-1521 Change-Id: I34b801a1ec9525e6b1785914f8d02f938cbf0ee7 Signed-off-by: Arindam Mondal --- .../java/org/onap/aai/util/HttpsAuthExternalClient.java | 8 +++----- .../java/org/onap/aai/util/genxsd/NodesYAMLfromOXM.java | 14 ++++++-------- .../java/org/onap/aai/util/genxsd/PutRelationPathSet.java | 8 ++++++++ 3 files changed, 17 insertions(+), 13 deletions(-) diff --git a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java index 624a394c..4e673b6a 100644 --- a/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java +++ b/aai-core/src/main/java/org/onap/aai/util/HttpsAuthExternalClient.java @@ -53,13 +53,11 @@ public class HttpsAuthExternalClient { config.getClasses().add(org.onap.aai.restcore.CustomJacksonJaxBJsonProvider.class); Client client = null; SSLContext ctx = null; - - try { - String truststore_path = AAIConstants.AAI_HOME_ETC_AUTH + AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_FILENAME); + String truststore_path = AAIConstants.AAI_HOME_ETC_AUTH + AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_FILENAME); + try(FileInputStream tin = new FileInputStream(truststore_path)) { String truststore_password = AAIConfig.get(AAIConstants.AAI_TRUSTSTORE_PASSWD); String keystore_path = AAIConstants.AAI_HOME_ETC_AUTH + keystoreFileName; String keystore_password = keystorePassword; - //System.setProperty("javax.net.ssl.trustStore", truststore_path); //System.setProperty("javax.net.ssl.trustStorePassword", truststore_password); HttpsURLConnection.setDefaultHostnameVerifier( new HostnameVerifier(){ @@ -82,7 +80,7 @@ public class HttpsAuthExternalClient { String alg = TrustManagerFactory.getDefaultAlgorithm(); TrustManagerFactory tmf = TrustManagerFactory.getInstance(alg); - FileInputStream tin = new FileInputStream(truststore_path); + KeyStore ts = KeyStore.getInstance("PKCS12"); char[] tpwd = truststore_password.toCharArray(); ts.load(tin, tpwd); diff --git a/aai-core/src/main/java/org/onap/aai/util/genxsd/NodesYAMLfromOXM.java b/aai-core/src/main/java/org/onap/aai/util/genxsd/NodesYAMLfromOXM.java index 712d82d5..5c4cd8bd 100644 --- a/aai-core/src/main/java/org/onap/aai/util/genxsd/NodesYAMLfromOXM.java +++ b/aai-core/src/main/java/org/onap/aai/util/genxsd/NodesYAMLfromOXM.java @@ -64,7 +64,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor { private static final String normalStartDir = "aai-core"; private static final String yaml_dir = (((System.getProperty("user.dir") != null) && (!System.getProperty("user.dir").contains(normalStartDir))) ? autoGenRoot : root) + "/aai_swagger_yaml"; private StringBuilder inventoryDefSb = null; - private Map operationDefinitions = new HashMap(); + private Map operationDefinitions = new HashMap<>(); private String basePath; @@ -154,7 +154,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor { javaTypeDefinitions.put("inventory", inventoryDefSb.toString()); } StringBuffer sb = new StringBuffer("definitions:\n"); - Map sortedJavaTypeDefinitions = new TreeMap(javaTypeDefinitions); + Map sortedJavaTypeDefinitions = new TreeMap<>(javaTypeDefinitions); for (Map.Entry entry : sortedJavaTypeDefinitions.entrySet()) { if(namespaceFilter != null && (! namespaceFilter.contains(entry.getKey()))) { @@ -383,7 +383,7 @@ public class NodesYAMLfromOXM extends OxmFileProcessor { try { EdgeRuleQuery q = new EdgeRuleQuery.Builder(xmlRootElementName).version(v).fromOnly().build(); Multimap results = ei.getRules(q); - SortedSet ss=new TreeSet(results.keySet()); + SortedSet ss=new TreeSet<>(results.keySet()); sbEdge.append(nodeCaption); nodeCaption=""; for(String key : ss) { @@ -489,11 +489,9 @@ public class NodesYAMLfromOXM extends OxmFileProcessor { logger.error( "Exception creating output file " + outfileName); e.printStackTrace(); } - BufferedWriter bw = null; - try { - Charset charset = Charset.forName("UTF-8"); - Path path = Paths.get(outfileName); - bw = Files.newBufferedWriter(path, charset); + Path path = Paths.get(outfileName); + Charset charset = Charset.forName("UTF-8"); + try(BufferedWriter bw = Files.newBufferedWriter(path, charset);) { bw.write(fileContent); if ( bw != null ) { bw.close(); diff --git a/aai-core/src/main/java/org/onap/aai/util/genxsd/PutRelationPathSet.java b/aai-core/src/main/java/org/onap/aai/util/genxsd/PutRelationPathSet.java index d6eaa5c9..0b0fd946 100644 --- a/aai-core/src/main/java/org/onap/aai/util/genxsd/PutRelationPathSet.java +++ b/aai-core/src/main/java/org/onap/aai/util/genxsd/PutRelationPathSet.java @@ -21,6 +21,7 @@ package org.onap.aai.util.genxsd; import java.io.File; import java.io.FileOutputStream; +import java.io.IOException; import java.util.ArrayList; import java.util.HashMap; import java.util.Map; @@ -137,6 +138,13 @@ public class PutRelationPathSet { e.printStackTrace(); return; } + finally{ + try { + fop.close(); + } catch (IOException e) { + e.printStackTrace(); + } + } try { if(relations.size() > 0) {fop.write("[\n".getBytes());} fop.write(String.join(",\n", relations).getBytes()); -- cgit 1.2.3-korg