Sonar suggested fixes 21/1621/2
authorSerban Jora <sj2381@att.com>
Mon, 16 Apr 2018 17:05:52 +0000 (13:05 -0400)
committerSerban Jora <sj2381@att.com>
Mon, 16 Apr 2018 18:44:32 +0000 (14:44 -0400)
Change-Id: I1c84c398b7ab6d8a0d3f4694e876fef1c92f1be9
Signed-off-by: Serban Jora <sj2381@att.com>
Issue-ID: ACUMOS-672
Signed-off-by: Serban Jora <sj2381@att.com>
gateway/src/main/java/org/acumos/federation/gateway/Application.java
gateway/src/main/java/org/acumos/federation/gateway/adapter/PeerGateway.java
gateway/src/main/java/org/acumos/federation/gateway/common/API.java
gateway/src/main/java/org/acumos/federation/gateway/common/FederationClient.java
gateway/src/main/java/org/acumos/federation/gateway/config/InterfaceConfiguration.java
gateway/src/main/java/org/acumos/federation/gateway/controller/CatalogController.java
gateway/src/main/java/org/acumos/federation/gateway/controller/PeerSubscriptionController.java
gateway/src/main/java/org/acumos/federation/gateway/service/impl/PeerServiceLocalImpl.java
gateway/src/main/java/org/acumos/federation/gateway/util/Utils.java

index 14edee0..d5b9e94 100644 (file)
@@ -23,8 +23,6 @@ package org.acumos.federation.gateway;
 import java.io.IOException;
 
 import org.acumos.federation.gateway.config.EELFLoggerDelegate;
-import org.acumos.federation.gateway.config.GatewayConfiguration;
-import org.acumos.federation.gateway.config.AdapterConfiguration;
 import org.acumos.federation.gateway.config.LocalConfiguration;
 import org.acumos.federation.gateway.config.FederationConfiguration;
 
@@ -35,9 +33,6 @@ import org.springframework.boot.autoconfigure.jdbc.DataSourceAutoConfiguration;
 import org.springframework.boot.autoconfigure.jdbc.DataSourceTransactionManagerAutoConfiguration;
 import org.springframework.boot.autoconfigure.orm.jpa.HibernateJpaAutoConfiguration;
 import org.springframework.context.ApplicationContext;
-import org.springframework.context.ApplicationContextAware;
-import org.springframework.core.env.ConfigurableEnvironment;
-import org.springframework.scheduling.annotation.EnableScheduling;
 
 import org.springframework.boot.Banner;
 import org.springframework.boot.builder.SpringApplicationBuilder;
@@ -48,8 +43,6 @@ import org.springframework.context.annotation.AnnotationConfigApplicationContext
 import org.springframework.web.context.support.AnnotationConfigWebApplicationContext;
 import org.springframework.boot.context.properties.EnableConfigurationProperties;
 
-import org.springframework.web.context.support.StandardServletEnvironment;
-
 import com.fasterxml.jackson.databind.ObjectMapper;
 
 /**
@@ -79,13 +72,11 @@ public class Application {
                        new SpringApplicationBuilder(Application.class)
                                                                                        .bannerMode(Banner.Mode.OFF)
                                                                                        .web(false);
-               ApplicationContext fedCtx =
-                               gatewayBuilder.child(FederationConfiguration.class)
+               gatewayBuilder.child(FederationConfiguration.class)
                                                                                        .bannerMode(Banner.Mode.OFF)
                                                                                        .web(true)
                                                                                        .run(args);
-               ApplicationContext localCtx =
-                               gatewayBuilder.child(LocalConfiguration.class)
+               gatewayBuilder.child(LocalConfiguration.class)
                                                                                        .bannerMode(Banner.Mode.OFF)
                                                                                        .web(true)
                                                                                        .run(args);
index 13ed28e..2c663ad 100644 (file)
@@ -28,8 +28,6 @@ import java.util.Collections;
 import javax.annotation.PostConstruct;
 import javax.annotation.PreDestroy;
 
-import org.acumos.cds.AccessTypeCode;
-import org.acumos.cds.ValidationStatusCode;
 import org.acumos.cds.client.ICommonDataServiceRestClient;
 import org.acumos.cds.domain.MLPArtifact;
 import org.acumos.cds.domain.MLPPeer;
@@ -43,15 +41,12 @@ import org.acumos.federation.gateway.event.PeerSubscriptionEvent;
 import org.acumos.federation.gateway.common.Clients;
 import org.acumos.federation.gateway.common.FederationClient;
 import org.acumos.federation.gateway.util.Errors;
-import org.acumos.federation.gateway.util.Utils;
 import org.acumos.federation.gateway.cds.SubscriptionScope;
 
 import org.acumos.nexus.client.data.UploadArtifactInfo;
 
 import org.springframework.beans.factory.BeanInitializationException;
 import org.springframework.beans.factory.annotation.Autowired;
-//import org.springframework.scheduling.annotation.Scheduled;
-import org.springframework.boot.context.properties.ConfigurationProperties;
 import org.springframework.context.annotation.Scope;
 import org.springframework.context.annotation.Profile;
 import org.springframework.context.annotation.Conditional;
index b76b186..1815a29 100644 (file)
@@ -72,6 +72,7 @@ public enum API {
                return theParams;
        }
 
+       @Override
        public String toString() {
                return this.path;
        }
@@ -136,7 +137,7 @@ public enum API {
                return uriBuilder(theHttpUrl).buildAndExpand(theParams).encode().toUri();
        }
 
-       public static class Roots {
+       public static interface Roots {
 
                public static final String FEDERATION = "/";
                /**
@@ -145,7 +146,7 @@ public enum API {
                public static final String LOCAL = "/peer/{peerId}";
        }
 
-       public static class Paths {
+       public static interface Paths {
 
                public static final String SOLUTIONS = "/solutions";
                public static final String SOLUTION_DETAILS = "/solutions/{solutionId}";
@@ -166,12 +167,12 @@ public enum API {
                public static final String PEER_UNREGISTER = "/peer/unregister";
        }
 
-       public static class QueryParameters {
+       public static interface QueryParameters {
 
                public static final String SOLUTIONS_SELECTOR = "selector";
        }
 
-       public static class Queries {
+       public static interface Queries {
 
                public static final String[] SOLUTIONS = { QueryParameters.SOLUTIONS_SELECTOR };
        }
index 40d5b00..b0ab29c 100644 (file)
@@ -76,7 +76,7 @@ public class FederationClient extends AbstractClient {
                                        });
                }
                catch (HttpStatusCodeException x) {
-                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed" + ((response == null) ? "" : (" " + response)), x);
+                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed", x);
                        throw x;
                }
                catch (Throwable t) {
@@ -101,7 +101,7 @@ public class FederationClient extends AbstractClient {
                                        });
                }
                catch (HttpStatusCodeException x) {
-                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed" + ((response == null) ? "" : (" " + response)), x);
+                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed", x);
                        throw x;
                }
                catch (Throwable t) {
@@ -146,7 +146,7 @@ public class FederationClient extends AbstractClient {
                                        });
                }
                catch (HttpStatusCodeException x) {
-                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed" + ((response == null) ? "" : (" " + response)), x);
+                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed", x);
                        throw x;
                }
                catch (Throwable t) {
@@ -175,7 +175,7 @@ public class FederationClient extends AbstractClient {
                                        });
                }
                catch (HttpStatusCodeException x) {
-                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed" + ((response == null) ? "" : (" " + response)), x);
+                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed", x);
                        throw x;
                }
                catch (Throwable t) {
@@ -208,7 +208,7 @@ public class FederationClient extends AbstractClient {
                                        });
                }
                catch (HttpStatusCodeException x) {
-                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed" + ((response == null) ? "" : (" " + response)), x);
+                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed", x);
                        throw x;
                }
                catch (Throwable t) {
@@ -241,7 +241,7 @@ public class FederationClient extends AbstractClient {
                                        });
                }
                catch (HttpStatusCodeException x) {
-                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed" + ((response == null) ? "" : (" " + response)), x);
+                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed", x);
                        throw x;
                }
                catch (Throwable t) {
@@ -268,7 +268,7 @@ public class FederationClient extends AbstractClient {
                        response = restTemplate.exchange(uri, HttpMethod.GET, null, Resource.class);
                }
                catch (HttpStatusCodeException x) {
-                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed" + ((response == null) ? "" : (" " + response)), x);
+                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed", x);
                        throw x;
                }
                catch (Throwable t) {
@@ -301,7 +301,7 @@ public class FederationClient extends AbstractClient {
                                        });
                }
                catch (HttpStatusCodeException x) {
-                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed" + ((response == null) ? "" : (" " + response)), x);
+                       log.error(EELFLoggerDelegate.errorLogger, uri + " failed", x);
                        throw x;
                }
                catch (Throwable t) {
index 9f6cca2..de55e83 100644 (file)
@@ -391,7 +391,8 @@ public class InterfaceConfiguration {
 
                if (this.ssl == null) {
                        log.info(EELFLoggerDelegate.debugLogger, "No ssl config was provided");
-               } else {
+               }
+               else {
                        KeyStore keyStore = null;
                        if (this.ssl.hasKeyStoreInfo()) {
                                InputStream keyStoreSource = null;
@@ -418,6 +419,14 @@ public class InterfaceConfiguration {
                                catch (Exception x) {
                                        throw new IllegalStateException("Error loading key material: " + x, x);
                                }
+                               finally {
+                                       try {
+                                               keyStoreSource.close();
+                                       }
+                                       catch (IOException iox) {
+                                               log.debug(EELFLoggerDelegate.debugLogger, "Error closing key store source", iox);
+                                       }
+                               }
                        }
 
                        KeyStore trustStore = null;
@@ -446,6 +455,14 @@ public class InterfaceConfiguration {
                                catch (Exception x) {
                                        throw new IllegalStateException("Error loading trust material: " + x, x);
                                }
+                               finally {
+                                       try {
+                                               trustStoreSource.close();
+                                       }
+                                       catch (IOException iox) {
+                                               log.debug(EELFLoggerDelegate.debugLogger, "Error closing trust store source", iox);
+                                       }
+                               }
                        }
 
                        SSLContextBuilder contextBuilder = SSLContexts.custom();
index 6175a24..8916033 100644 (file)
@@ -90,7 +90,6 @@ public class CatalogController extends AbstractController {
                List<MLPSolution> solutions = null;
                log.debug(EELFLoggerDelegate.debugLogger, API.Paths.SOLUTIONS);
                try {
-                       response = new JsonResponse<List<MLPSolution>>();
                        log.debug(EELFLoggerDelegate.debugLogger, "getSolutionsListFromPeer: selector " + theSelector);
                        Map<String, ?> selector = null;
                        if (theSelector != null)
@@ -255,7 +254,6 @@ public class CatalogController extends AbstractController {
                log.debug(EELFLoggerDelegate.debugLogger,
                                API.Paths.SOLUTION_REVISION_ARTIFACTS + "(" + theSolutionId + "," + theRevisionId + ")");
                try {
-                       response = new JsonResponse<List<MLPArtifact>>();
                        solutionRevisionArtifacts = catalogService.getSolutionRevisionArtifacts(theSolutionId, theRevisionId, context);
                        if (solutionRevisionArtifacts != null &&
                                        !context.getPeer().getPeerInfo().isLocal()) {
index d27e560..1bb6d52 100644 (file)
@@ -83,7 +83,6 @@ public class PeerSubscriptionController extends AbstractController {
                log.debug(EELFLoggerDelegate.debugLogger, API.Roots.LOCAL + "" + API.Paths.SUBSCRIPTION);
                JsonResponse<String> response = null;
                try {
-                       response = new JsonResponse<String>();
                        log.debug(EELFLoggerDelegate.debugLogger, "trigger");
        
                        MLPPeer peer = this.peerService.getPeerById(thePeerId);
index e6aeb57..1c615a4 100644 (file)
@@ -164,7 +164,7 @@ public class PeerServiceLocalImpl extends AbstractServiceLocalImpl implements Pe
                                .orElse(null);
                log.info(EELFLoggerDelegate.debugLogger,
                                "Peer " + thePeerId + " subs:" + (peer == null ? "none" : peer.getSubscriptions()));
-               return peer == Collections.EMPTY_LIST ? null : peer.getSubscriptions();
+               return peer == null ? Collections.EMPTY_LIST : peer.getSubscriptions();
        }
 
        /** */
index ad67b43..dd55f16 100644 (file)
@@ -36,7 +36,7 @@ public class Utils {
 
        private final static EELFLoggerDelegate logger = EELFLoggerDelegate.getLogger(Utils.class);
 
-       public static ObjectMapper objectMapper = new ObjectMapper();
+       private static ObjectMapper objectMapper = new ObjectMapper();
 
        public Utils() {
        }