knox-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From kris...@apache.org
Subject [3/5] knox git commit: KNOX-1664 - Miscellaneous code cleanup
Date Sat, 08 Dec 2018 14:29:56 GMT
http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/deploy/DeploymentFactory.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/deploy/DeploymentFactory.java b/gateway-server/src/main/java/org/apache/knox/gateway/deploy/DeploymentFactory.java
index ca497a3..6358107 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/deploy/DeploymentFactory.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/deploy/DeploymentFactory.java
@@ -213,13 +213,10 @@ public abstract class DeploymentFactory {
       marshaller.marshal( topology, writer );
       writer.close();
       xml = writer.toString();
-    } catch (IOException e) {
-      throw new DeploymentException( "Failed to marshall topology.", e );
-    } catch (JAXBException e) {
+    } catch (IOException | JAXBException e) {
       throw new DeploymentException( "Failed to marshall topology.", e );
     }
-    StringAsset asset = new StringAsset( xml );
-    return asset;
+    return new StringAsset( xml );
   }
 
   private static DeploymentContext createDeploymentContext(
@@ -231,9 +228,8 @@ public abstract class DeploymentFactory {
     WebArchive webArchive = ShrinkWrap.create( WebArchive.class, archivePath );
     WebAppDescriptor webAppDesc = Descriptors.create( WebAppDescriptor.class );
     GatewayDescriptor gateway = GatewayDescriptorFactory.create();
-    DeploymentContext context = new DeploymentContextImpl(
+    return new DeploymentContextImpl(
         config, topology, gateway, webArchive, webAppDesc, providers );
-    return context;
   }
 
   // Scan through the providers in the topology.  Collect any named providers in their roles list.
@@ -445,7 +441,7 @@ public abstract class DeploymentFactory {
 
   private static void injectServices(Object contributor) {
     if (gatewayServices != null) {
-      Statement stmt = null;
+      Statement stmt;
       for(String serviceName : gatewayServices.getServiceNames()) {
 
         try {
@@ -550,7 +546,7 @@ public abstract class DeploymentFactory {
     ServiceDeploymentContributor contributor = null;
     Map<String,Map<Version, ServiceDeploymentContributor>> nameMap = SERVICE_CONTRIBUTOR_MAP.get( role );
     if( nameMap != null && !nameMap.isEmpty()) {
-      Map<Version, ServiceDeploymentContributor> versionMap = null;
+      Map<Version, ServiceDeploymentContributor> versionMap;
       if ( name == null ) {
         versionMap = nameMap.values().iterator().next();
       } else {
@@ -746,25 +742,23 @@ public abstract class DeploymentFactory {
         = new HashMap<>();
 
     ServiceLoader<ProviderDeploymentContributor> loader = ServiceLoader.load( ProviderDeploymentContributor.class );
-    Iterator<ProviderDeploymentContributor> contributors = loader.iterator();
-    while( contributors.hasNext() ) {
-      ProviderDeploymentContributor contributor = contributors.next();
-      if( contributor.getName() == null ) {
-        log.ignoringProviderContributorWithMissingName( contributor.getClass().getName() );
-        continue;
-      }
-      if( contributor.getRole() == null ) {
-        log.ignoringProviderContributorWithMissingRole( contributor.getClass().getName() );
-        continue;
-      }
-      set.add( contributor );
-      Map nameMap = roleMap.get( contributor.getRole() );
-      if( nameMap == null ) {
-        nameMap = new HashMap<>();
-        roleMap.put( contributor.getRole(), nameMap );
-      }
-      nameMap.put( contributor.getName(), contributor );
-    }
+     for (ProviderDeploymentContributor contributor : loader) {
+       if (contributor.getName() == null) {
+         log.ignoringProviderContributorWithMissingName(contributor.getClass().getName());
+         continue;
+       }
+       if (contributor.getRole() == null) {
+         log.ignoringProviderContributorWithMissingRole(contributor.getClass().getName());
+         continue;
+       }
+       set.add(contributor);
+       Map nameMap = roleMap.get(contributor.getRole());
+       if (nameMap == null) {
+         nameMap = new HashMap<>();
+         roleMap.put(contributor.getRole(), nameMap);
+       }
+       nameMap.put(contributor.getName(), contributor);
+     }
     PROVIDER_CONTRIBUTORS = set;
     PROVIDER_CONTRIBUTOR_MAP = roleMap;
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/deploy/impl/ApplicationDeploymentContributor.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/deploy/impl/ApplicationDeploymentContributor.java b/gateway-server/src/main/java/org/apache/knox/gateway/deploy/impl/ApplicationDeploymentContributor.java
index 26a4690..8cbe8bc 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/deploy/impl/ApplicationDeploymentContributor.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/deploy/impl/ApplicationDeploymentContributor.java
@@ -112,9 +112,7 @@ public class ApplicationDeploymentContributor extends ServiceDeploymentContribut
       File rewriteFile = new File( appDir, REWRITE_RULES_FILE_NAME );
       serviceDefinition = loadServiceDefinition( application, serviceFile );
       serviceRules = loadRewriteRules( application, rewriteFile );
-    } catch ( IOException e ) {
-      throw new DeploymentException( "Failed to deploy application: " + application.getName(), e );
-    } catch ( JAXBException e ){
+    } catch ( IOException | JAXBException e ) {
       throw new DeploymentException( "Failed to deploy application: " + application.getName(), e );
     }
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/descriptor/xml/XmlGatewayDescriptorExporter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/descriptor/xml/XmlGatewayDescriptorExporter.java b/gateway-server/src/main/java/org/apache/knox/gateway/descriptor/xml/XmlGatewayDescriptorExporter.java
index 363964f..5523763 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/descriptor/xml/XmlGatewayDescriptorExporter.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/descriptor/xml/XmlGatewayDescriptorExporter.java
@@ -52,9 +52,7 @@ public class XmlGatewayDescriptorExporter implements GatewayDescriptorExporter,
 
       XmlUtils.writeXml( document, writer );
 
-    } catch( ParserConfigurationException e ) {
-      throw new IOException( e );
-    } catch( TransformerException e ) {
+    } catch( ParserConfigurationException | TransformerException e ) {
       throw new IOException( e );
     }
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/descriptor/xml/XmlGatewayDescriptorImporter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/descriptor/xml/XmlGatewayDescriptorImporter.java b/gateway-server/src/main/java/org/apache/knox/gateway/descriptor/xml/XmlGatewayDescriptorImporter.java
index 875fb07..1757526 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/descriptor/xml/XmlGatewayDescriptorImporter.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/descriptor/xml/XmlGatewayDescriptorImporter.java
@@ -43,8 +43,7 @@ public class XmlGatewayDescriptorImporter implements GatewayDescriptorImporter {
     Digester digester = loader.newDigester( new ExtendedBaseRules() );
     digester.setValidating( false );
     try {
-      GatewayDescriptor descriptor = digester.parse( reader );
-      return descriptor;
+      return digester.parse( reader );
     } catch( SAXException e ) {
       throw new IOException( e );
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/dispatch/UrlConnectionDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/dispatch/UrlConnectionDispatch.java b/gateway-server/src/main/java/org/apache/knox/gateway/dispatch/UrlConnectionDispatch.java
index 3aa8f4a..43fb579 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/dispatch/UrlConnectionDispatch.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/dispatch/UrlConnectionDispatch.java
@@ -82,8 +82,7 @@ public class UrlConnectionDispatch extends AbstractGatewayFilter {
       str.append('?');
       str.append(query);
     }
-    URI url = URI.create(str.toString());
-    return url;
+    return URI.create(str.toString());
   }
 
   public void doGet( URI url, HttpServletRequest request, HttpServletResponse response ) throws IOException, URISyntaxException {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/filter/BasicAuthChallengeFilter.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/filter/BasicAuthChallengeFilter.java b/gateway-server/src/main/java/org/apache/knox/gateway/filter/BasicAuthChallengeFilter.java
index 07d5280..1c005d3 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/filter/BasicAuthChallengeFilter.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/filter/BasicAuthChallengeFilter.java
@@ -70,7 +70,7 @@ public class BasicAuthChallengeFilter extends AbstractGatewayFilter {
         if( parts.length == 2 ) {
           String username = parts[0];
           String password = parts[1];
-          if( username.length() > 0 && password.length() > 0 ) {
+          if(!username.isEmpty() && !password.isEmpty()) {
             credentials = new UsernamePasswordCredentials( username, password );
           }
         }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/filter/PortMappingHelperHandler.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/filter/PortMappingHelperHandler.java b/gateway-server/src/main/java/org/apache/knox/gateway/filter/PortMappingHelperHandler.java
index 599f882..a11f52a 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/filter/PortMappingHelperHandler.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/filter/PortMappingHelperHandler.java
@@ -64,7 +64,7 @@ public class PortMappingHelperHandler extends HandlerWrapper {
 
       for(final Map.Entry<String, Integer> entry: config.getGatewayPortMappings().entrySet()) {
 
-        if(entry.getValue().intValue() == config.getGatewayPort()) {
+        if(entry.getValue() == config.getGatewayPort()) {
           defaultTopologyRedirectContext = "/" + config.getGatewayPath() + "/" + entry.getKey();
           break;
         }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/filter/RequestUpdateHandler.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/filter/RequestUpdateHandler.java b/gateway-server/src/main/java/org/apache/knox/gateway/filter/RequestUpdateHandler.java
index 7b90380..7691422 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/filter/RequestUpdateHandler.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/filter/RequestUpdateHandler.java
@@ -46,7 +46,7 @@ public class RequestUpdateHandler extends ScopedHandler {
   private static final GatewayMessages LOG = MessagesFactory
       .get(GatewayMessages.class);
 
-  private String redirectContext = null;
+  private String redirectContext;
 
   public RequestUpdateHandler(final GatewayConfig config,
       final String topologyName, final GatewayServices services) {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsService.java b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsService.java
index 26f08a1..c6bee57 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/metrics/impl/DefaultMetricsService.java
@@ -38,7 +38,6 @@ import org.apache.knox.gateway.services.metrics.MetricsService;
 import java.lang.management.ManagementFactory;
 import java.util.ArrayList;
 import java.util.HashMap;
-import java.util.Iterator;
 import java.util.Map;
 import java.util.ServiceLoader;
 import java.util.concurrent.TimeUnit;
@@ -79,21 +78,18 @@ public class DefaultMetricsService implements MetricsService {
 
   private void loadInstrumentationProviders() {
     ServiceLoader<InstrumentationProviderDescriptor> descriptors = ServiceLoader.load(InstrumentationProviderDescriptor.class);
-    Iterator<InstrumentationProviderDescriptor> descriptorIterator = descriptors.iterator();
-    while ( descriptorIterator.hasNext() ) {
-      instrumentationProviders.putAll(descriptorIterator.next().providesInstrumentation());
+    for (InstrumentationProviderDescriptor descriptor : descriptors) {
+      instrumentationProviders.putAll(descriptor.providesInstrumentation());
     }
   }
 
   private void loadAndInitReporters(GatewayConfig config) {
     ServiceLoader<MetricsReporter> reporters = ServiceLoader.load(MetricsReporter.class);
-    Iterator<MetricsReporter> reportersIterator = reporters.iterator();
-    while ( reportersIterator.hasNext() ) {
-      MetricsReporter metricsReporter = reportersIterator.next();
+    for (MetricsReporter metricsReporter : reporters) {
       try {
         metricsReporter.init(config);
         metricsReporters.add(metricsReporter);
-      } catch ( MetricsReporterException e ) {
+      } catch (MetricsReporterException e) {
         LOG.failedToInitializeReporter(metricsReporter.getName(), e);
       }
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/services/registry/impl/DefaultServiceRegistryService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/registry/impl/DefaultServiceRegistryService.java b/gateway-server/src/main/java/org/apache/knox/gateway/services/registry/impl/DefaultServiceRegistryService.java
index 5777ac7..d15ff45 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/registry/impl/DefaultServiceRegistryService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/registry/impl/DefaultServiceRegistryService.java
@@ -18,10 +18,8 @@
 package org.apache.knox.gateway.services.registry.impl;
 
 import com.fasterxml.jackson.core.JsonFactory;
-import com.fasterxml.jackson.core.JsonParseException;
 import com.fasterxml.jackson.core.JsonProcessingException;
 import com.fasterxml.jackson.core.type.TypeReference;
-import com.fasterxml.jackson.databind.JsonMappingException;
 import com.fasterxml.jackson.databind.ObjectMapper;
 import org.apache.commons.codec.binary.Base64;
 import org.apache.commons.io.FileUtils;
@@ -147,7 +145,7 @@ public class DefaultServiceRegistryService implements ServiceRegistry, Service {
 
   @Override
   public List<String> lookupServiceURLs( String clusterName, String serviceName ) {
-    RegEntry entry = null;
+    RegEntry entry;
     HashMap<String, RegEntry> clusterServices = registry.get(clusterName);
     if (clusterServices != null) {
       entry = clusterServices.get(serviceName);
@@ -166,10 +164,6 @@ public class DefaultServiceRegistryService implements ServiceRegistry, Service {
           = new TypeReference<Registry>() {};
     try {
       map = mapper.readValue(json, typeRef);
-    } catch (JsonParseException e) {
-      LOG.failedToGetMapFromJsonString( json, e );
-    } catch (JsonMappingException e) {
-      LOG.failedToGetMapFromJsonString( json, e );
     } catch (IOException e) {
       LOG.failedToGetMapFromJsonString( json, e );
     }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultAliasService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultAliasService.java b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultAliasService.java
index 9a173f4..2cafd3f 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultAliasService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultAliasService.java
@@ -81,7 +81,7 @@ public class DefaultAliasService implements AliasService {
   @Override
   public char[] getPasswordFromAliasForCluster(String clusterName, String alias, boolean generate)
       throws AliasServiceException {
-    char[] credential = null;
+    char[] credential;
     try {
       credential = keystoreService.getCredentialForCluster(clusterName, alias);
       if (credential == null) {
@@ -164,11 +164,9 @@ public class DefaultAliasService implements AliasService {
     Certificate cert = null;
     try {
       cert = this.keystoreService.getKeystoreForGateway().getCertificate(alias);
-    } catch (KeyStoreException e) {
+    } catch (KeyStoreException | KeystoreServiceException e) {
       LOG.unableToRetrieveCertificateForGateway(e);
       // should we throw an exception?
-    } catch (KeystoreServiceException e) {
-      LOG.unableToRetrieveCertificateForGateway(e);
     }
     return cert;
   }
@@ -180,7 +178,7 @@ public class DefaultAliasService implements AliasService {
     try {
       keyStore = keystoreService.getCredentialStoreForCluster(clusterName);
       if (keyStore != null) {
-        String alias = null;
+        String alias;
         try {
           Enumeration<String> e = keyStore.aliases();
           while (e.hasMoreElements()) {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultCryptoService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultCryptoService.java b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultCryptoService.java
index 7cfc4ee..7010d29 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultCryptoService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultCryptoService.java
@@ -44,7 +44,7 @@ public class DefaultCryptoService implements CryptoService {
   private AliasService as = null;
   private KeystoreService ks = null;
   private HashMap<String,ConfigurableEncryptor> encryptorCache =
-      new HashMap<String,ConfigurableEncryptor>();
+      new HashMap<>();
   private GatewayConfig config = null;
 
   public void setKeystoreService(KeystoreService ks) {
@@ -94,10 +94,6 @@ public class DefaultCryptoService implements CryptoService {
     if (password != null) {
       try {
         return getEncryptor(clusterName,password).encrypt( clear );
-      } catch (NoSuchAlgorithmException e1) {
-        LOG.failedToEncryptPasswordForCluster( clusterName, e1 );
-      } catch (InvalidKeyException e) {
-        LOG.failedToEncryptPasswordForCluster( clusterName, e );
       } catch (Exception e) {
         LOG.failedToEncryptPasswordForCluster( clusterName, e );
       }
@@ -113,8 +109,8 @@ public class DefaultCryptoService implements CryptoService {
   @Override
   public byte[] decryptForCluster(String clusterName, String alias, byte[] cipherText, byte[] iv, byte[] salt) {
     try {
-      char[] password = null;
-      ConfigurableEncryptor encryptor = null;
+      char[] password;
+      ConfigurableEncryptor encryptor;
         password = as.getPasswordFromAliasForCluster(clusterName, alias);
         if (password != null) {
           encryptor = getEncryptor(clusterName,password );
@@ -141,15 +137,7 @@ public class DefaultCryptoService implements CryptoService {
       sig.initVerify(ks.getKeystoreForGateway().getCertificate(alias).getPublicKey());
       sig.update(signed.getBytes(StandardCharsets.UTF_8));
       verified = sig.verify(signature);
-    } catch (SignatureException e) {
-      LOG.failedToVerifySignature( e );
-    } catch (NoSuchAlgorithmException e) {
-      LOG.failedToVerifySignature( e );
-    } catch (InvalidKeyException e) {
-      LOG.failedToVerifySignature( e );
-    } catch (KeyStoreException e) {
-      LOG.failedToVerifySignature( e );
-    } catch (KeystoreServiceException e) {
+    } catch (SignatureException | KeystoreServiceException | KeyStoreException | InvalidKeyException | NoSuchAlgorithmException e) {
       LOG.failedToVerifySignature( e );
     }
     LOG.signatureVerified( verified );
@@ -159,22 +147,14 @@ public class DefaultCryptoService implements CryptoService {
   @Override
   public byte[] sign(String algorithm, String alias, String payloadToSign) {
     try {
-      char[] passphrase = null;
+      char[] passphrase;
       passphrase = as.getGatewayIdentityPassphrase();
       PrivateKey privateKey = (PrivateKey) ks.getKeyForGateway(alias, passphrase);
       Signature signature = Signature.getInstance(algorithm);
       signature.initSign(privateKey);
       signature.update(payloadToSign.getBytes(StandardCharsets.UTF_8));
       return signature.sign();
-    } catch (NoSuchAlgorithmException e) {
-      LOG.failedToSignData( e );
-    } catch (InvalidKeyException e) {
-      LOG.failedToSignData( e );
-    } catch (SignatureException e) {
-      LOG.failedToSignData( e );
-    } catch (KeystoreServiceException e) {
-      LOG.failedToSignData( e );
-    } catch (AliasServiceException e) {
+    } catch (NoSuchAlgorithmException | AliasServiceException | KeystoreServiceException | SignatureException | InvalidKeyException e) {
       LOG.failedToSignData( e );
     }
     return null;

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultKeystoreService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultKeystoreService.java b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultKeystoreService.java
index 11afe75..e72681f 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultKeystoreService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/DefaultKeystoreService.java
@@ -194,7 +194,7 @@ public class DefaultKeystoreService extends BaseKeystoreService implements
         if (hostname == null) {
           hostname = System.getProperty(CERT_GEN_MODE, CERT_GEN_MODE_LOCALHOST);
         }
-        X509Certificate cert = null;
+        X509Certificate cert;
         if(hostname.equals(CERT_GEN_MODE_HOSTNAME)) {
           String dn = buildDistinguishedName(InetAddress.getLocalHost().getHostName());
           cert = X509CertificateUtil.generateCertificate(dn, KPair, 365, "SHA1withRSA");
@@ -242,15 +242,13 @@ public class DefaultKeystoreService extends BaseKeystoreService implements
 
   @Override
   public boolean isCredentialStoreForClusterAvailable(String clusterName) throws KeystoreServiceException {
-    boolean rc = false;
+    boolean rc;
     final File  keyStoreFile = new File( keyStoreDir + clusterName + CREDENTIALS_SUFFIX  );
     readLock.lock();
     try {
       try {
         rc = isKeystoreAvailable(keyStoreFile, "JCEKS");
-      } catch (KeyStoreException e) {
-        throw new KeystoreServiceException(e);
-      } catch (IOException e) {
+      } catch (KeyStoreException | IOException e) {
         throw new KeystoreServiceException(e);
       }
       return rc;
@@ -262,15 +260,13 @@ public class DefaultKeystoreService extends BaseKeystoreService implements
 
   @Override
   public boolean isKeystoreForGatewayAvailable() throws KeystoreServiceException {
-    boolean rc = false;
+    boolean rc;
     final File  keyStoreFile = new File( keyStoreDir + GATEWAY_KEYSTORE  );
     readLock.lock();
     try {
       try {
         rc = isKeystoreAvailable(keyStoreFile, "JKS");
-      } catch (KeyStoreException e) {
-        throw new KeystoreServiceException(e);
-      } catch (IOException e) {
+      } catch (KeyStoreException | IOException e) {
         throw new KeystoreServiceException(e);
       }
       return rc;
@@ -293,11 +289,7 @@ public class DefaultKeystoreService extends BaseKeystoreService implements
       if (ks != null) {
         try {
           key = ks.getKey(alias, passphrase);
-        } catch (UnrecoverableKeyException e) {
-          LOG.failedToGetKeyForGateway( alias, e );
-        } catch (KeyStoreException e) {
-          LOG.failedToGetKeyForGateway( alias, e );
-        } catch (NoSuchAlgorithmException e) {
+        } catch (UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException e) {
           LOG.failedToGetKeyForGateway( alias, e );
         }
       }
@@ -326,11 +318,7 @@ public class DefaultKeystoreService extends BaseKeystoreService implements
       if (ks != null) {
         try {
           key = ks.getKey(alias, passphrase);
-        } catch (UnrecoverableKeyException e) {
-          LOG.failedToGetKeyForGateway( alias, e );
-        } catch (KeyStoreException e) {
-          LOG.failedToGetKeyForGateway( alias, e );
-        } catch (NoSuchAlgorithmException e) {
+        } catch (UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException e) {
           LOG.failedToGetKeyForGateway( alias, e );
         }
       }
@@ -365,13 +353,7 @@ public class DefaultKeystoreService extends BaseKeystoreService implements
       final File  keyStoreFile = new File( keyStoreDir + clusterName + CREDENTIALS_SUFFIX  );
       try {
         writeKeystoreToFile(ks, keyStoreFile);
-      } catch (KeyStoreException e) {
-        LOG.failedToAddCredentialForCluster( clusterName, e );
-      } catch (NoSuchAlgorithmException e) {
-        LOG.failedToAddCredentialForCluster( clusterName, e );
-      } catch (CertificateException e) {
-        LOG.failedToAddCredentialForCluster( clusterName, e );
-      } catch (IOException e) {
+      } catch (KeyStoreException | IOException | CertificateException | NoSuchAlgorithmException e) {
         LOG.failedToAddCredentialForCluster( clusterName, e );
       }
     } finally {
@@ -382,7 +364,7 @@ public class DefaultKeystoreService extends BaseKeystoreService implements
   @Override
   public char[] getCredentialForCluster(String clusterName, String alias)
       throws KeystoreServiceException {
-    char[] credential = null;
+    char[] credential;
     readLock.lock();
     try {
       credential = checkCache(clusterName, alias);
@@ -398,11 +380,7 @@ public class DefaultKeystoreService extends BaseKeystoreService implements
               credential = credentialString.toCharArray();
               addToCache(clusterName, alias, credentialString);
             }
-          } catch (UnrecoverableKeyException e) {
-            LOG.failedToGetCredentialForCluster( clusterName, e );
-          } catch (KeyStoreException e) {
-            LOG.failedToGetCredentialForCluster( clusterName, e );
-          } catch (NoSuchAlgorithmException e) {
+          } catch (UnrecoverableKeyException | NoSuchAlgorithmException | KeyStoreException e) {
             LOG.failedToGetCredentialForCluster( clusterName, e );
           }
 
@@ -425,13 +403,7 @@ public class DefaultKeystoreService extends BaseKeystoreService implements
       removeCredential(alias, ks);
       try {
         writeKeystoreToFile(ks, keyStoreFile);
-      } catch (KeyStoreException e) {
-        LOG.failedToRemoveCredentialForCluster(clusterName, e);
-      } catch (NoSuchAlgorithmException e) {
-        LOG.failedToRemoveCredentialForCluster(clusterName, e);
-      } catch (CertificateException e) {
-        LOG.failedToRemoveCredentialForCluster(clusterName, e);
-      } catch (IOException e) {
+      } catch (KeyStoreException | IOException | CertificateException | NoSuchAlgorithmException e) {
         LOG.failedToRemoveCredentialForCluster(clusterName, e);
       }
     }
@@ -445,7 +417,7 @@ public class DefaultKeystoreService extends BaseKeystoreService implements
    */
   private char[] checkCache(String clusterName, String alias) {
     char[] c = null;
-    String cred = null;
+    String cred;
     Map<String, String> clusterCache = cache.get(clusterName);
     if (clusterCache == null) {
       return null;

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/JettySSLService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/JettySSLService.java b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/JettySSLService.java
index 8041a83..75613c3 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/JettySSLService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/security/impl/JettySSLService.java
@@ -102,7 +102,7 @@ public class JettySSLService implements SSLService {
       if (!ks.isKeystoreForGatewayAvailable()) {
         log.creatingKeyStoreForGateway();
         ks.createKeystoreForGateway();
-        char[] passphrase = null;
+        char[] passphrase;
         try {
           passphrase = as.getGatewayIdentityPassphrase();
         } catch (AliasServiceException e) {
@@ -185,7 +185,7 @@ public class JettySSLService implements SSLService {
     }
     sslContextFactory.setKeyManagerPassword(new String(keypass));
 
-    String truststorePassword = null;
+    String truststorePassword;
     if (clientAuthNeeded || clientAuthWanted) {
       if (truststorePath != null) {
         char[] truststorePwd = null;
@@ -220,13 +220,13 @@ public class JettySSLService implements SSLService {
     }
     sslContextFactory.setTrustAll( trustAllCerts );
     if (sslIncludeCiphers != null && !sslIncludeCiphers.isEmpty()) {
-      sslContextFactory.setIncludeCipherSuites( sslIncludeCiphers.toArray(new String[sslIncludeCiphers.size()]) );
+      sslContextFactory.setIncludeCipherSuites( sslIncludeCiphers.toArray(new String[0]) );
     }
     if (sslExcludeCiphers != null && !sslExcludeCiphers.isEmpty()) {
-      sslContextFactory.setExcludeCipherSuites( sslExcludeCiphers.toArray(new String[sslExcludeCiphers.size()]) );
+      sslContextFactory.setExcludeCipherSuites( sslExcludeCiphers.toArray(new String[0]) );
     }
     if (sslExcludeProtocols != null && !sslExcludeProtocols.isEmpty()) {
-      sslContextFactory.setExcludeProtocols( sslExcludeProtocols.toArray(new String[sslExcludeProtocols.size()]) );
+      sslContextFactory.setExcludeProtocols( sslExcludeProtocols.toArray(new String[0]) );
     }
     return sslContextFactory;
   }
@@ -241,16 +241,9 @@ public class JettySSLService implements SSLService {
 
   private static KeyStore loadKeyStore( String fileName, String storeType, char[] storePass ) throws CertificateException, NoSuchAlgorithmException, IOException, KeyStoreException {
     KeyStore keystore = KeyStore.getInstance(storeType);
-    //Coverity CID 1352655
-    InputStream is = new FileInputStream(fileName);
-    try {
-      keystore.load( is, storePass );
-    } finally {
-      if( is != null ) {
-        is.close();
-      }
+    try (InputStream is = new FileInputStream(fileName)) {
+      keystore.load(is, storePass);
     }
     return keystore;
   }
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
index 2b54c3c..cdc4907 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/services/topology/impl/DefaultTopologyService.java
@@ -128,14 +128,7 @@ public class DefaultTopologyService
       try {
         topology = loadTopologyAttempt(file);
         break;
-      } catch (IOException e) {
-        if (System.currentTimeMillis() - start < TIMEOUT) {
-          log.failedToLoadTopologyRetrying(file.getAbsolutePath(), Long.toString(DELAY), e);
-          Thread.sleep(DELAY);
-        } else {
-          throw e;
-        }
-      } catch (SAXException e) {
+      } catch (IOException | SAXException e) {
         if (System.currentTimeMillis() - start < TIMEOUT) {
           log.failedToLoadTopologyRetrying(file.getAbsolutePath(), Long.toString(DELAY), e);
           Thread.sleep(DELAY);
@@ -281,16 +274,6 @@ public class DefaultTopologyService
                       ActionOutcome.FAILURE);
               log.failedToLoadTopology(file.getAbsolutePath());
             }
-          } catch (IOException e) {
-            // Maybe it makes sense to throw exception
-            auditor.audit(Action.LOAD, file.getAbsolutePath(), ResourceType.TOPOLOGY,
-                    ActionOutcome.FAILURE);
-            log.failedToLoadTopology(file.getAbsolutePath(), e);
-          } catch (SAXException e) {
-            // Maybe it makes sense to throw exception
-            auditor.audit(Action.LOAD, file.getAbsolutePath(), ResourceType.TOPOLOGY,
-                    ActionOutcome.FAILURE);
-            log.failedToLoadTopology(file.getAbsolutePath(), e);
           } catch (Exception e) {
             // Maybe it makes sense to throw exception
             auditor.audit(Action.LOAD, file.getAbsolutePath(), ResourceType.TOPOLOGY,
@@ -337,15 +320,9 @@ public class DefaultTopologyService
       }
 
 
-    } catch (JAXBException e) {
+    } catch (JAXBException | SAXException | IOException e) {
       auditor.audit(Action.DEPLOY, t.getName(), ResourceType.TOPOLOGY, ActionOutcome.FAILURE);
       log.failedToDeployTopology(t.getName(), e);
-    } catch (IOException io) {
-      auditor.audit(Action.DEPLOY, t.getName(), ResourceType.TOPOLOGY, ActionOutcome.FAILURE);
-      log.failedToDeployTopology(t.getName(), io);
-    } catch (SAXException sx){
-      auditor.audit(Action.DEPLOY, t.getName(), ResourceType.TOPOLOGY, ActionOutcome.FAILURE);
-      log.failedToDeployTopology(t.getName(), sx);
     }
     reloadTopologies();
   }
@@ -875,7 +852,7 @@ public class DefaultTopologyService
         String providerConfig =
                       FilenameUtils.normalize(result.get(SimpleDescriptorHandler.RESULT_REFERENCE).getAbsolutePath());
         if (!providerConfigReferences.containsKey(providerConfig)) {
-          providerConfigReferences.put(providerConfig, new ArrayList<String>());
+          providerConfigReferences.put(providerConfig, new ArrayList<>());
         }
         List<String> refs = providerConfigReferences.get(providerConfig);
         String descriptorName = FilenameUtils.normalize(file.getAbsolutePath());
@@ -986,8 +963,8 @@ public class DefaultTopologyService
    */
   private static class TopologyDiscoveryTrigger implements ClusterConfigurationMonitor.ConfigurationChangeListener {
 
-    private TopologyService topologyService = null;
-    private ClusterConfigurationMonitorService ccms = null;
+    private TopologyService topologyService;
+    private ClusterConfigurationMonitorService ccms;
 
     TopologyDiscoveryTrigger(TopologyService topologyService, ClusterConfigurationMonitorService ccms) {
       this.topologyService = topologyService;

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/topology/discovery/DefaultServiceDiscoveryConfig.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/topology/discovery/DefaultServiceDiscoveryConfig.java b/gateway-server/src/main/java/org/apache/knox/gateway/topology/discovery/DefaultServiceDiscoveryConfig.java
index 04e0e8c..d6e3d50 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/topology/discovery/DefaultServiceDiscoveryConfig.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/topology/discovery/DefaultServiceDiscoveryConfig.java
@@ -17,7 +17,7 @@
 package org.apache.knox.gateway.topology.discovery;
 
 public class DefaultServiceDiscoveryConfig implements ServiceDiscoveryConfig {
-    private String address  = null;
+    private String address;
     private String user     = null;
     private String pwdAlias = null;
 

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParser.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParser.java b/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParser.java
index 950bc04..1408ca9 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParser.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/topology/simple/ProviderConfigurationParser.java
@@ -91,7 +91,7 @@ public class ProviderConfigurationParser {
 
 
   static ProviderConfiguration parseXML(InputStream in) throws Exception {
-    XMLProviderConfiguration providerConfig = null;
+    XMLProviderConfiguration providerConfig;
 
     JAXBContext jaxbContext = JAXBContext.newInstance(XMLProviderConfiguration.class);
     Unmarshaller jaxbUnmarshaller = jaxbContext.createUnmarshaller();
@@ -108,8 +108,7 @@ public class ProviderConfigurationParser {
 
   static ProviderConfiguration parseJSON(InputStream in) throws IOException {
     final ObjectMapper mapper = new ObjectMapper();
-    JSONProviderConfiguration providerConfig = mapper.readValue(in, JSONProviderConfiguration.class);
-    return providerConfig;
+    return mapper.readValue(in, JSONProviderConfiguration.class);
   }
 
 
@@ -119,8 +118,7 @@ public class ProviderConfigurationParser {
 
   static ProviderConfiguration parseYAML(InputStream in) throws IOException {
     final ObjectMapper mapper = new ObjectMapper(new YAMLFactory());
-    JSONProviderConfiguration providerConfig = mapper.readValue(in, JSONProviderConfiguration.class);
-    return providerConfig;
+    return mapper.readValue(in, JSONProviderConfiguration.class);
   }
 
 

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/topology/validation/TopologyValidator.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/topology/validation/TopologyValidator.java b/gateway-server/src/main/java/org/apache/knox/gateway/topology/validation/TopologyValidator.java
index 1a7359b..0b678a2 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/topology/validation/TopologyValidator.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/topology/validation/TopologyValidator.java
@@ -117,7 +117,7 @@ public class TopologyValidator {
     StringBuilder out = new StringBuilder();
     out.append("");
     for(String s : getTopologyErrors()){
-      out.append(s + "\n");
+      out.append(s).append("\n");
     }
     return out.toString();
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java b/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java
index 37b0335..2fae90e 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/util/KnoxCLI.java
@@ -497,9 +497,8 @@ public class KnoxCLI extends Configured implements Tool {
     }
 
     protected Service getService(String serviceName) {
-      Service service = null;
 
-      return service;
+      return null;
     }
 
     public abstract void execute() throws Exception;
@@ -507,18 +506,15 @@ public class KnoxCLI extends Configured implements Tool {
     public abstract String getUsage();
 
     protected AliasService getAliasService() {
-      AliasService as = services.getService(GatewayServices.ALIAS_SERVICE);
-      return as;
+      return services.getService(GatewayServices.ALIAS_SERVICE);
     }
 
     protected KeystoreService getKeystoreService() {
-      KeystoreService ks = services.getService(GatewayServices.KEYSTORE_SERVICE);
-      return ks;
+      return services.getService(GatewayServices.KEYSTORE_SERVICE);
     }
 
     protected TopologyService getTopologyService()  {
-      TopologyService ts = services.getService(GatewayServices.TOPOLOGY_SERVICE);
-      return ts;
+      return services.getService(GatewayServices.TOPOLOGY_SERVICE);
     }
 
     protected RemoteConfigurationRegistryClientService getRemoteConfigRegistryClientService() {
@@ -707,7 +703,7 @@ public class KnoxCLI extends Configured implements Tool {
                                        + "the --value option or --generate (will create a random secret\n"
                                        + "for you) or user will be prompt to provide password.";
 
-  private String name = null;
+  private String name;
 
    public AliasCreateCommand(String alias) {
      name = alias;
@@ -774,7 +770,7 @@ public class KnoxCLI extends Configured implements Tool {
                                     "indicated alias from the --cluster specific\n" +
                                     "credential store or the gateway credential store.";
 
-  private String name = null;
+  private String name;
 
    public AliasDeleteCommand(String alias) {
      name = alias;
@@ -1087,7 +1083,8 @@ public class KnoxCLI extends Configured implements Tool {
     }
 
     protected class MissingUsernameException extends Exception {
-      public MissingUsernameException() {};
+      public MissingUsernameException() {}
+
       public MissingUsernameException(String message) { super(message); }
     }
 
@@ -1244,12 +1241,8 @@ public class KnoxCLI extends Configured implements Tool {
 
     protected boolean authenticateUser(String config, UsernamePasswordToken token) throws ConfigurationException {
       Ini ini = new Ini();
-      try {
-        ini.loadFromPath(config);
-        return authenticateUser(ini, token);
-      } catch (ConfigurationException e) {
-        throw e;
-      }
+      ini.loadFromPath(config);
+      return authenticateUser(ini, token);
     }
 
     /**
@@ -1258,7 +1251,7 @@ public class KnoxCLI extends Configured implements Tool {
      * @return - returns the principal found in the userDn after "uid="
      */
     protected String getPrincipal(String userDn){
-      String result = "";
+      String result;
 
 //      Need to determine whether we are using AD or LDAP?
 //      LDAP userDn usually starts with "uid="
@@ -1313,9 +1306,7 @@ public class KnoxCLI extends Configured implements Tool {
         username = getSystemUsername(t);
         password = getSystemPassword(t);
         result = authenticateUser(ini, new UsernamePasswordToken(username, password));
-      } catch (MissingUsernameException | NoSuchProviderException | MissingPasswordException e) {
-        out.println(e.toString());
-      } catch (NullPointerException e) {
+      } catch (MissingUsernameException | NoSuchProviderException | MissingPasswordException | NullPointerException e) {
         out.println(e.toString());
       }
       return result;
@@ -1328,12 +1319,11 @@ public class KnoxCLI extends Configured implements Tool {
      */
     private String getSystemUsername(Topology t) throws MissingUsernameException, NoSuchProviderException {
       final String SYSTEM_USERNAME = "main.ldapRealm.contextFactory.systemUsername";
-      String user = null;
+      String user;
       Provider shiroProvider = t.getProvider("authentication", "ShiroProvider");
       if(shiroProvider != null){
         Map<String, String> params = shiroProvider.getParams();
-        String userDn = params.get(SYSTEM_USERNAME);
-        user = userDn;
+        user = params.get(SYSTEM_USERNAME);
       } else {
         throw new NoSuchProviderException("ShiroProvider", "authentication", t.getName());
       }
@@ -1347,7 +1337,7 @@ public class KnoxCLI extends Configured implements Tool {
      */
     private char[] getSystemPassword(Topology t) throws NoSuchProviderException, MissingPasswordException{
       final String SYSTEM_PASSWORD = "main.ldapRealm.contextFactory.systemPassword";
-      String pass = null;
+      String pass;
       Provider shiro = t.getProvider("authentication", "ShiroProvider");
       if(shiro != null){
         Map<String, String> params = shiro.getParams();
@@ -1650,7 +1640,7 @@ public class KnoxCLI extends Configured implements Tool {
     private int attempts = 0;
 
     @Override
-    public String getUsage() { return USAGE + ":\n\n" + DESC; };
+    public String getUsage() { return USAGE + ":\n\n" + DESC; }
 
     @Override
     public void execute() {
@@ -1899,7 +1889,7 @@ public class KnoxCLI extends Configured implements Tool {
    */
   public abstract class RemoteRegistryUploadCommand extends RemoteRegistryCommand {
     private File sourceFile = null;
-    protected String filename = null;
+    protected String filename;
 
     protected RemoteRegistryUploadCommand(String sourceFileName) {
       this.filename = sourceFileName;
@@ -1998,7 +1988,7 @@ public class KnoxCLI extends Configured implements Tool {
     static final String USAGE = "get-registry-acl entry --registry-client name";
     static final String DESC = "Presents the ACL settings for the specified remote registry entry.\n";
 
-    private String entry = null;
+    private String entry;
 
     RemoteRegistryGetACLCommand(String entry) {
       this.entry = entry;
@@ -2028,7 +2018,7 @@ public class KnoxCLI extends Configured implements Tool {
    * Base class for remote config registry delete commands
    */
   public abstract class RemoteRegistryDeleteCommand extends RemoteRegistryCommand {
-    protected String entryName = null;
+    protected String entryName;
 
     protected RemoteRegistryDeleteCommand(String entryName) {
       this.entryName = entryName;

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/main/java/org/apache/knox/gateway/websockets/GatewayWebsocketHandler.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/main/java/org/apache/knox/gateway/websockets/GatewayWebsocketHandler.java b/gateway-server/src/main/java/org/apache/knox/gateway/websockets/GatewayWebsocketHandler.java
index ffe423e..1e8e8a9 100644
--- a/gateway-server/src/main/java/org/apache/knox/gateway/websockets/GatewayWebsocketHandler.java
+++ b/gateway-server/src/main/java/org/apache/knox/gateway/websockets/GatewayWebsocketHandler.java
@@ -183,7 +183,7 @@ public class GatewayWebsocketHandler extends WebSocketHandler
     String backendURL = urlFromServiceDefinition(serviceDefs,
         serviceRegistryService, entry, path);
 
-    StringBuffer backend = new StringBuffer();
+    StringBuilder backend = new StringBuilder();
     try {
 
       /* if we do not find websocket URL we default to HTTP */
@@ -227,14 +227,12 @@ public class GatewayWebsocketHandler extends WebSocketHandler
 
     final String[] contexts = path.split("/");
 
-    final String serviceURL = serviceRegistry.lookupServiceURL(contexts[2],
-        entry.getName().toUpperCase(Locale.ROOT));
-
     /*
      * we have a match, if ws:// is present it is returned else http:// is
      * returned
      */
-    return serviceURL;
+    return serviceRegistry.lookupServiceURL(contexts[2],
+        entry.getName().toUpperCase(Locale.ROOT));
 
   }
 

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/test/java/org/apache/knox/gateway/AuditLoggingTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/AuditLoggingTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/AuditLoggingTest.java
index 300dffd..e324902 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/AuditLoggingTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/AuditLoggingTest.java
@@ -89,13 +89,13 @@ public class AuditLoggingTest {
     AuditServiceFactory.getAuditService().detachContext();
   }
 
-  @Test
-  /**
+  /*
    * Empty filter chain. Two events with same correlation ID are expected:
    *
    * action=access request_type=uri outcome=unavailable
    * action=access request_type=uri outcome=success message=Response status: 404
    */
+  @Test
   public void testNoFiltersAudit() throws Exception {
     FilterConfig config = EasyMock.createNiceMock( FilterConfig.class );
     EasyMock.replay( config );
@@ -167,12 +167,12 @@ public class AuditLoggingTest {
     assertThat(requestIds.size(), is(numberTotalRequests));
   }
 
-  @Test
-  /**
+  /*
    * One NoOp filter in chain. Single audit event with same with specified request URI is expected:
    *
    * action=access request_type=uri outcome=unavailable
    */
+  @Test
   public void testNoopFilter() throws ServletException, IOException,
       URISyntaxException {
 
@@ -219,19 +219,19 @@ public class AuditLoggingTest {
 
   }
 
-  @Test
-  /**
+  /*
    * Dispatching outbound request. Remote host is unreachable. Two log events is expected:
    *
    * action=dispatch request_type=uri outcome=FAILED
    * action=dispatch request_type=uri outcome=unavailable
    */
+  @Test
   public void testHttpClientOutboundException() throws IOException,
       URISyntaxException {
     String uri = "http://outbound-host:port/path";
 
     HttpServletRequest inboundRequest = EasyMock.createNiceMock( HttpServletRequest.class );
-    EasyMock.expect( inboundRequest.getHeaderNames() ).andReturn( Collections.enumeration( new ArrayList<String>() ) ).anyTimes();
+    EasyMock.expect( inboundRequest.getHeaderNames() ).andReturn( Collections.enumeration(new ArrayList<>() ) ).anyTimes();
     EasyMock.replay( inboundRequest );
 
     HttpServletResponse outboundResponse = EasyMock.createNiceMock( HttpServletResponse.class );

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/test/java/org/apache/knox/gateway/GatewayGlobalConfigTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/GatewayGlobalConfigTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/GatewayGlobalConfigTest.java
index 24b2755..4bc2d73 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/GatewayGlobalConfigTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/GatewayGlobalConfigTest.java
@@ -39,8 +39,7 @@ public class GatewayGlobalConfigTest {
     URL url = ClassLoader.getSystemResource( resource );
     String fileName = url.getFile();
     File file = new File( fileName );
-    String dirName = file.getParentFile().getParent();
-    return dirName;
+    return file.getParentFile().getParent();
   }
 
   @Test

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/test/java/org/apache/knox/gateway/services/security/CryptoServiceTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/services/security/CryptoServiceTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/services/security/CryptoServiceTest.java
index 84a829e..c28dcaa 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/services/security/CryptoServiceTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/services/security/CryptoServiceTest.java
@@ -125,7 +125,7 @@ public class CryptoServiceTest {
     String queryString = "url=http://localhost:50070/api/v1/blahblah";
     ConfigurableEncryptor aes0 = new ConfigurableEncryptor("password");
     aes0.init(config);
-    cs.init(config, new HashMap<String,String>());
+    cs.init(config, new HashMap<>());
     EncryptionResult result0 = cs.encryptForCluster("Test", "encrypt_url", queryString.getBytes(StandardCharsets.UTF_8));
     byte[] decrypted0 = cs.decryptForCluster("Test", "encrypt_url", result0.cipher, result0.iv, result0.salt);
     assertEquals(queryString, new String(decrypted0, StandardCharsets.UTF_8));
@@ -148,7 +148,7 @@ public class CryptoServiceTest {
     String queryString = "url=http://localhost:50070/api/v1/blahblah";
     ConfigurableEncryptor aes0 = new ConfigurableEncryptor("password");
     aes0.init(config);
-    cs.init(config, new HashMap<String,String>());
+    cs.init(config, new HashMap<>());
     EncryptionResult result0 = cs.encryptForCluster("Test", "encrypt_url", queryString.getBytes(StandardCharsets.UTF_8));
     byte[] decrypted0 = cs.decryptForCluster("Test", "encrypt_url", result0.cipher, result0.iv, result0.salt);
     assertEquals(queryString, new String(decrypted0, StandardCharsets.UTF_8));

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/test/java/org/apache/knox/gateway/services/token/impl/DefaultTokenAuthorityServiceTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/services/token/impl/DefaultTokenAuthorityServiceTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/services/token/impl/DefaultTokenAuthorityServiceTest.java
index e778a7d..24f1665 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/services/token/impl/DefaultTokenAuthorityServiceTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/services/token/impl/DefaultTokenAuthorityServiceTest.java
@@ -65,13 +65,13 @@ public class DefaultTokenAuthorityServiceTest extends org.junit.Assert {
     DefaultKeystoreService ks = new DefaultKeystoreService();
     ks.setMasterService(ms);
 
-    ks.init(config, new HashMap<String, String>());
+    ks.init(config, new HashMap<>());
 
     DefaultTokenAuthorityService ta = new DefaultTokenAuthorityService();
     ta.setAliasService(as);
     ta.setKeystoreService(ks);
 
-    ta.init(config, new HashMap<String, String>());
+    ta.init(config, new HashMap<>());
 
     JWT token = ta.issueToken(principal, "RS256");
     assertEquals("KNOXSSO", token.getIssuer());
@@ -107,13 +107,13 @@ public class DefaultTokenAuthorityServiceTest extends org.junit.Assert {
     DefaultKeystoreService ks = new DefaultKeystoreService();
     ks.setMasterService(ms);
 
-    ks.init(config, new HashMap<String, String>());
+    ks.init(config, new HashMap<>());
 
     DefaultTokenAuthorityService ta = new DefaultTokenAuthorityService();
     ta.setAliasService(as);
     ta.setKeystoreService(ks);
 
-    ta.init(config, new HashMap<String, String>());
+    ta.init(config, new HashMap<>());
 
     JWT token = ta.issueToken(principal, "https://login.example.com", "RS256");
     assertEquals("KNOXSSO", token.getIssuer());
@@ -150,13 +150,13 @@ public class DefaultTokenAuthorityServiceTest extends org.junit.Assert {
     DefaultKeystoreService ks = new DefaultKeystoreService();
     ks.setMasterService(ms);
 
-    ks.init(config, new HashMap<String, String>());
+    ks.init(config, new HashMap<>());
 
     DefaultTokenAuthorityService ta = new DefaultTokenAuthorityService();
     ta.setAliasService(as);
     ta.setKeystoreService(ks);
 
-    ta.init(config, new HashMap<String, String>());
+    ta.init(config, new HashMap<>());
 
     JWT token = ta.issueToken(principal, null, "RS256");
     assertEquals("KNOXSSO", token.getIssuer());
@@ -192,13 +192,13 @@ public class DefaultTokenAuthorityServiceTest extends org.junit.Assert {
     DefaultKeystoreService ks = new DefaultKeystoreService();
     ks.setMasterService(ms);
 
-    ks.init(config, new HashMap<String, String>());
+    ks.init(config, new HashMap<>());
 
     DefaultTokenAuthorityService ta = new DefaultTokenAuthorityService();
     ta.setAliasService(as);
     ta.setKeystoreService(ks);
 
-    ta.init(config, new HashMap<String, String>());
+    ta.init(config, new HashMap<>());
 
     JWT token = ta.issueToken(principal, "RS512");
     assertEquals("KNOXSSO", token.getIssuer());
@@ -235,13 +235,13 @@ public class DefaultTokenAuthorityServiceTest extends org.junit.Assert {
     DefaultKeystoreService ks = new DefaultKeystoreService();
     ks.setMasterService(ms);
 
-    ks.init(config, new HashMap<String, String>());
+    ks.init(config, new HashMap<>());
 
     DefaultTokenAuthorityService ta = new DefaultTokenAuthorityService();
     ta.setAliasService(as);
     ta.setKeystoreService(ks);
 
-    ta.init(config, new HashMap<String, String>());
+    ta.init(config, new HashMap<>());
 
     try {
       ta.issueToken(principal, "none");

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
index 30c5ed6..079727c 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/services/topology/DefaultTopologyServiceTest.java
@@ -563,7 +563,7 @@ public class DefaultTopologyServiceTest {
         "ldapGroupRealm.contextFactory.systemAuthenticationMechanism"
     };
 
-    Param param = null;
+    Param param;
     for (String name : names) {
       param = new Param();
       param.setName(name);

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/PropertiesFileServiceDiscoveryTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/PropertiesFileServiceDiscoveryTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/PropertiesFileServiceDiscoveryTest.java
index c44c26a..6a118a1 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/PropertiesFileServiceDiscoveryTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/PropertiesFileServiceDiscoveryTest.java
@@ -105,16 +105,14 @@ public class PropertiesFileServiceDiscoveryTest {
 
     private void printServiceURLs(ServiceDiscovery.Cluster cluster, String...services) {
         for (String name : services) {
-            String value = "";
+            StringBuilder value = new StringBuilder();
             List<String> urls = cluster.getServiceURLs(name);
             if (urls != null && !urls.isEmpty()) {
                 for (String url : urls) {
-                    value += url + " ";
+                    value.append(url).append(" ");
                 }
             }
-            System.out.println(String.format(Locale.ROOT, "%18s: %s", name, value));
+            System.out.println(String.format(Locale.ROOT, "%18s: %s", name, value.toString()));
         }
     }
-
-
 }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/PropertiesFileServiceDiscovery.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/PropertiesFileServiceDiscovery.java b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/PropertiesFileServiceDiscovery.java
index 6bef201..fa9a717 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/PropertiesFileServiceDiscovery.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/topology/discovery/test/extension/PropertiesFileServiceDiscovery.java
@@ -156,9 +156,9 @@ class PropertiesFileServiceDiscovery implements ServiceDiscovery {
         }
 
         private static class ZooKeeperConfigImpl implements ZooKeeperConfig {
-            private boolean isEnabled = false;
-            private String  ensemble  = null;
-            private String  namespace = null;
+            private boolean isEnabled;
+            private String  ensemble;
+            private String  namespace;
 
             ZooKeeperConfigImpl(boolean enabled, String ensemble, String namespace) {
                 this.isEnabled = enabled;

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java b/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java
index ec1864e..9e7921f 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/util/KnoxCLITest.java
@@ -395,7 +395,6 @@ public class KnoxCLITest {
     outContent.reset();
 
     final String descriptorName = "my-topology.json";
-    final String descriptorContent = testDescriptorContentJSON;
 
     final File testRoot = TestUtils.createTempDir(this.getClass().getName());
     try {
@@ -406,7 +405,7 @@ public class KnoxCLITest {
                              "--registry-client", "test_client",
                              "--master", "master"};
 
-      FileUtils.writeStringToFile(testDescriptor, descriptorContent, StandardCharsets.UTF_8);
+      FileUtils.writeStringToFile(testDescriptor, testDescriptorContentJSON, StandardCharsets.UTF_8);
 
       KnoxCLI cli = new KnoxCLI();
       Configuration config = new GatewayConfigImpl();
@@ -446,7 +445,7 @@ public class KnoxCLITest {
   public void testSuccessfulAliasLifecycle() throws Exception {
     outContent.reset();
     String[] args1 = {"create-alias", "alias1", "--value", "testvalue1", "--master", "master"};
-    int rc = 0;
+    int rc;
     KnoxCLI cli = new KnoxCLI();
     cli.setConf(new GatewayConfigImpl());
     rc = cli.run(args1);
@@ -481,7 +480,7 @@ public class KnoxCLITest {
     String[] args1 =
         { "create-alias", "alias1", "--cluster", "cluster1", "--value", "testvalue1", "--master",
             "master" };
-    int rc = 0;
+    int rc;
     KnoxCLI cli = new KnoxCLI();
     cli.setConf(new GatewayConfigImpl());
     rc = cli.run(args1);
@@ -512,7 +511,7 @@ public class KnoxCLITest {
     KnoxCLI cli = new KnoxCLI();
     cli.setConf(new GatewayConfigImpl());
     try {
-      int rc = 0;
+      int rc;
       outContent.reset();
       String[] args1 =
           { "create-alias", "alias1", "--cluster", "cluster1", "--value", "testvalue1", "--master",
@@ -537,7 +536,7 @@ public class KnoxCLITest {
     KnoxCLI cli = new KnoxCLI();
     cli.setConf(new GatewayConfigImpl());
     try {
-      int rc = 0;
+      int rc;
       outContent.reset();
       String[] args1 = { "create-alias", "alias1", "--value", "testvalue1", "--master", "master" };
       cli.run(args1);
@@ -572,7 +571,7 @@ public class KnoxCLITest {
     String[] args1 =
         { "create-alias", "alias1", "--cluster", "cluster1", "--value", "testvalue1", "--master",
             "master" };
-    int rc = 0;
+    int rc;
     KnoxCLI cli = new KnoxCLI();
     cli.setConf(new GatewayConfigImpl());
     rc = cli.run(args1);
@@ -609,7 +608,7 @@ public class KnoxCLITest {
 
     outContent.reset();
     String[] gwCreateArgs = {"create-alias", "alias1", "--value", "testvalue1", "--master", "master"};
-    int rc = 0;
+    int rc;
     KnoxCLI cli = new KnoxCLI();
     cli.setConf( config );
     rc = cli.run(gwCreateArgs);
@@ -687,7 +686,7 @@ public class KnoxCLITest {
     KnoxCLI cli = new KnoxCLI();
     cli.setConf( config );
     String[] gwCreateArgs = {"create-cert", "--hostname", "hostname1", "--master", "master"};
-    int rc = 0;
+    int rc;
     rc = cli.run(gwCreateArgs);
     assertEquals(0, rc);
     assertTrue(outContent.toString(StandardCharsets.UTF_8.name()), outContent.toString(StandardCharsets.UTF_8.name()).contains("gateway-identity has been successfully " +
@@ -767,7 +766,7 @@ public class KnoxCLITest {
     FileUtils.deleteQuietly( new File( config.getGatewaySecurityDir() ) );
     outContent.reset();
     String[] args = {"create-master", "--master", "master"};
-    int rc = 0;
+    int rc;
     KnoxCLI cli = new KnoxCLI();
     cli.setConf( config );
     rc = cli.run(args);
@@ -781,7 +780,7 @@ public class KnoxCLITest {
   @Test
   public void testCreateMasterGenerate() throws Exception {
     String[] args = {"create-master", "--generate" };
-    int rc = 0;
+    int rc;
     GatewayConfigImpl config = new GatewayConfigImpl();
     File masterFile = new File( config.getGatewaySecurityDir(), "master" );
 
@@ -833,7 +832,7 @@ public class KnoxCLITest {
     KnoxCLI cli = new KnoxCLI();
     cli.setConf(config);
     MasterService ms;
-    int rc = 0;
+    int rc;
     outContent.reset();
 
     String[] args = { "create-master", "--master", "test-master-1" };
@@ -889,7 +888,7 @@ public class KnoxCLITest {
   }
 
   private static XMLTag createBadTopology() {
-    XMLTag xml = XMLDoc.newDocument(true)
+    return XMLDoc.newDocument(true)
         .addRoot( "topology" )
         .addTag( "gateway" )
 
@@ -921,11 +920,10 @@ public class KnoxCLITest {
         .addTag( "service" )
         .addTag( "role" ).addText( "test-service-role" )
         .gotoRoot();
-    return xml;
   }
 
   private static XMLTag createGoodTopology() {
-    XMLTag xml = XMLDoc.newDocument( true )
+    return XMLDoc.newDocument( true )
         .addRoot( "topology" )
         .addTag( "gateway" )
 
@@ -957,7 +955,6 @@ public class KnoxCLITest {
         .addTag( "service" )
         .addTag( "role" ).addText( "test-service-role" )
         .gotoRoot();
-    return xml;
   }
 
   private File writeTestTopology( String name, XMLTag xml ) throws IOException {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java
index 0382a88..e61ddde 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/BadUrlTest.java
@@ -264,11 +264,10 @@ public class BadUrlTest {
    * Intentionally add bad URL
    */
   private static XMLTag createKnoxTopology(final String backend) {
-    XMLTag xml = XMLDoc.newDocument(true).addRoot("topology").addTag("service")
+    // System.out.println( "GATEWAY=" + xml.toString() );
+    return XMLDoc.newDocument(true).addRoot("topology").addTag("service")
         .addTag("role").addText("WEBSOCKET").addTag("url").addText(backend)
         .gotoParent().gotoRoot();
-    // System.out.println( "GATEWAY=" + xml.toString() );
-    return xml;
   }
 
   private static class TestTopologyListener implements TopologyListener {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTest.java
index 9891985..b8bfd2e 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketEchoTest.java
@@ -346,11 +346,10 @@ public class WebsocketEchoTest {
   }
 
   private static XMLTag createKnoxTopology(final String backend) {
-    XMLTag xml = XMLDoc.newDocument(true).addRoot("topology").addTag("service")
+    // System.out.println( "GATEWAY=" + xml.toString() );
+    return XMLDoc.newDocument(true).addRoot("topology").addTag("service")
         .addTag("role").addText("WEBSOCKET").addTag("url").addText(backend)
         .gotoParent().gotoRoot();
-    // System.out.println( "GATEWAY=" + xml.toString() );
-    return xml;
   }
 
   private static class TestTopologyListener implements TopologyListener {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java
----------------------------------------------------------------------
diff --git a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java
index fd28e7f..eb635ef 100644
--- a/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java
+++ b/gateway-server/src/test/java/org/apache/knox/gateway/websockets/WebsocketMultipleConnectionTest.java
@@ -343,11 +343,10 @@ public class WebsocketMultipleConnectionTest {
   }
 
   private static XMLTag createKnoxTopology(final String backend) {
-    XMLTag xml = XMLDoc.newDocument(true).addRoot("topology").addTag("service")
+    // System.out.println( "GATEWAY=" + xml.toString() );
+    return XMLDoc.newDocument(true).addRoot("topology").addTag("service")
         .addTag("role").addText("WEBSOCKET").addTag("url").addText(backend)
         .gotoParent().gotoRoot();
-    // System.out.println( "GATEWAY=" + xml.toString() );
-    return xml;
   }
 
   private static class TestTopologyListener implements TopologyListener {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java
----------------------------------------------------------------------
diff --git a/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java b/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java
index 0d67788..b9e0e00 100644
--- a/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java
+++ b/gateway-service-admin/src/main/java/org/apache/knox/gateway/service/admin/TopologiesResource.java
@@ -266,7 +266,7 @@ public class TopologiesResource {
     }
 
     if (providerConfigFile != null) {
-      byte[] content = null;
+      byte[] content;
       try {
         content = FileUtils.readFileToByteArray(providerConfigFile);
         response = ok().entity(content).build();
@@ -461,7 +461,7 @@ public class TopologiesResource {
     if (descriptorFile != null) {
       String mediaType = APPLICATION_JSON;
 
-      byte[] content = null;
+      byte[] content;
       try {
         if ("yml".equals(FilenameUtils.getExtension(descriptorFile.getName()))) {
           mediaType = TEXT_PLAIN;

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/MetricsResource.java
----------------------------------------------------------------------
diff --git a/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/MetricsResource.java b/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/MetricsResource.java
index 1a24f2b..49d9a0d 100644
--- a/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/MetricsResource.java
+++ b/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/MetricsResource.java
@@ -110,11 +110,8 @@ public class MetricsResource {
       response.setHeader("Cache-Control", "must-revalidate,no-cache,no-store");
       response.setStatus(HttpServletResponse.SC_OK);
 
-      final OutputStream output = response.getOutputStream();
-      try {
+      try (OutputStream output = response.getOutputStream()) {
         getWriter(request).writeValue(output, registry);
-      } finally {
-        output.close();
       }
     } catch (IOException ioe) {
       log.logException("metrics", ioe);

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/PingResource.java
----------------------------------------------------------------------
diff --git a/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/PingResource.java b/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/PingResource.java
index 0aaf29e..5a73ef2 100644
--- a/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/PingResource.java
+++ b/gateway-service-health/src/main/java/org/apache/knox/gateway/service/health/PingResource.java
@@ -71,17 +71,11 @@ public class PingResource {
     response.setStatus(HttpServletResponse.SC_OK);
     response.setHeader(CACHE_CONTROL, NO_CACHE);
     response.setContentType(CONTENT_TYPE);
-    PrintWriter writer = null;
-    try {
-      writer = response.getWriter();
+    try (PrintWriter writer = response.getWriter()) {
       writer.println(getPingContent());
     } catch (IOException ioe) {
       log.logException("ping", ioe);
       return Response.serverError().entity(String.format(Locale.ROOT, "Failed to reply correctly due to : %s ", ioe)).build();
-    } finally {
-      if (writer != null) {
-        writer.close();
-      }
     }
     return Response.ok().build();
   }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java
----------------------------------------------------------------------
diff --git a/gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java b/gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java
index 1a583f4..9371c4a 100644
--- a/gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java
+++ b/gateway-service-knoxtoken/src/main/java/org/apache/knox/gateway/service/knoxtoken/TokenResource.java
@@ -80,8 +80,8 @@ public class TokenResource {
     String audiences = context.getInitParameter(TOKEN_AUDIENCES_PARAM);
     if (audiences != null) {
       String[] auds = audiences.split(",");
-      for (int i = 0; i < auds.length; i++) {
-        targetAudiences.add(auds[i].trim());
+      for (String aud : auds) {
+        targetAudiences.add(aud.trim());
       }
     }
 
@@ -91,8 +91,8 @@ public class TokenResource {
     String principals = context.getInitParameter(TOKEN_ALLOWED_PRINCIPALS);
     if (principals != null) {
       String[] dns = principals.split(";");
-      for (int i = 0; i < dns.length; i++) {
-        allowedDNs.add(dns[i].replaceAll("\\s+",""));
+      for (String dn : dns) {
+        allowedDNs.add(dn.replaceAll("\\s+", ""));
       }
     }
 
@@ -165,7 +165,7 @@ public class TokenResource {
     long expires = getExpiry();
 
     try {
-      JWT token = null;
+      JWT token;
       if (targetAudiences.isEmpty()) {
         token = ts.issueToken(p, signatureAlgorithm, expires);
       } else {
@@ -202,9 +202,9 @@ public class TokenResource {
 
   void addClientDataToMap(String[] tokenClientData,
       Map<String,Object> map) {
-    String[] kv = null;
-    for (int i = 0; i < tokenClientData.length; i++) {
-      kv = tokenClientData[i].split("=");
+    String[] kv;
+    for (String tokenClientDatum : tokenClientData) {
+      kv = tokenClientDatum.split("=");
       if (kv.length == 2) {
         map.put(kv[0], kv[1]);
       }

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiDispatch.java b/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiDispatch.java
index ef02bd0..5d53e1e 100644
--- a/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiDispatch.java
+++ b/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiDispatch.java
@@ -76,7 +76,7 @@ public class NiFiDispatch extends DefaultDispatch {
   }
 
   /**
-   * Overriden due to {@link DefaultDispatch#getInboundResponseContentType(HttpEntity) having private access, and the method is used by
+   * Overriden due to DefaultDispatch#getInboundResponseContentType(HttpEntity) having private access, and the method is used by
    * {@link #writeOutboundResponse(HttpUriRequest, HttpServletRequest, HttpServletResponse, HttpResponse)}}
    */
   private String getInboundResponseContentType( final HttpEntity entity ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiHaDispatch.java
----------------------------------------------------------------------
diff --git a/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiHaDispatch.java b/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiHaDispatch.java
index c79124c..a423708 100644
--- a/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiHaDispatch.java
+++ b/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiHaDispatch.java
@@ -87,7 +87,7 @@ public class NiFiHaDispatch extends DefaultHaDispatch {
   }
 
   /**
-   * Overriden due to {@link DefaultDispatch#getInboundResponseContentType(HttpEntity) having private access, and the method is used by
+   * Overriden due to DefaultDispatch#getInboundResponseContentType(HttpEntity) having private access, and the method is used by
    * {@link #writeOutboundResponse(HttpUriRequest, HttpServletRequest, HttpServletResponse, HttpResponse)}}
    */
   private String getInboundResponseContentType( final HttpEntity entity ) {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiResponseUtil.java
----------------------------------------------------------------------
diff --git a/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiResponseUtil.java b/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiResponseUtil.java
index b2d9ebb..93441af 100644
--- a/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiResponseUtil.java
+++ b/gateway-service-nifi/src/main/java/org/apache/knox/gateway/dispatch/NiFiResponseUtil.java
@@ -45,7 +45,7 @@ class NiFiResponseUtil {
         } catch (URISyntaxException e) {
           throw new RuntimeException("Unable to parse URI from Location header", e);
         }
-        URIBuilder inboundRequestUriBuilder = null;
+        URIBuilder inboundRequestUriBuilder;
         try {
           inboundRequestUriBuilder = new URIBuilder(inboundRequest.getRequestURI());
         } catch (URISyntaxException e) {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java b/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java
index a8c5448..b419c9c 100644
--- a/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java
+++ b/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/CuratorClientService.java
@@ -70,10 +70,8 @@ class CuratorClientService implements ZooKeeperClientService {
     @Override
     public void init(GatewayConfig config, Map<String, String> options) throws ServiceLifecycleException {
 
-        List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>();
-
-        // Load the remote registry configurations
-        registryConfigs.addAll(RemoteConfigurationRegistriesAccessor.getRemoteRegistryConfigurations(config));
+      // Load the remote registry configurations
+      List<RemoteConfigurationRegistryConfig> registryConfigs = new ArrayList<>(RemoteConfigurationRegistriesAccessor.getRemoteRegistryConfigurations(config));
 
         // Configure registry authentication
         RemoteConfigurationRegistryJAASConfig.configure(registryConfigs, aliasService);

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryJAASConfig.java
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryJAASConfig.java b/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryJAASConfig.java
index 1558b5c..0c0d8c0 100644
--- a/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryJAASConfig.java
+++ b/gateway-service-remoteconfig/src/main/java/org/apache/knox/gateway/service/config/remote/zk/RemoteConfigurationRegistryJAASConfig.java
@@ -79,7 +79,7 @@ class RemoteConfigurationRegistryJAASConfig extends Configuration {
 
     @Override
     public AppConfigurationEntry[] getAppConfigurationEntry(String name) {
-        AppConfigurationEntry[] result = null;
+        AppConfigurationEntry[] result;
 
         // First, try the delegate's context entries
         result = delegate.getAppConfigurationEntry(name);
@@ -92,7 +92,7 @@ class RemoteConfigurationRegistryJAASConfig extends Configuration {
     }
 
     private AppConfigurationEntry[] createEntries(RemoteConfigurationRegistryConfig config) {
-        AppConfigurationEntry[] result = null;
+        AppConfigurationEntry[] result;
 
         AppConfigurationEntry entry = createEntry(config);
         if (entry != null) {

http://git-wip-us.apache.org/repos/asf/knox/blob/f54e9d2d/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/util/RemoteRegistryConfigTestUtils.java
----------------------------------------------------------------------
diff --git a/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/util/RemoteRegistryConfigTestUtils.java b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/util/RemoteRegistryConfigTestUtils.java
index 96c1473..4caef66 100644
--- a/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/util/RemoteRegistryConfigTestUtils.java
+++ b/gateway-service-remoteconfig/src/test/java/org/apache/knox/gateway/service/config/remote/util/RemoteRegistryConfigTestUtils.java
@@ -34,37 +34,35 @@ public class RemoteRegistryConfigTestUtils {
     public static final String PROPERTY_USE_TICKET_CACHE = "useTicketCache";
 
     public static String createRemoteConfigRegistriesXML(Collection<Map<String, String>> configProperties) {
-        String result = "<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
-                        "<remote-configuration-registries>\n";
+        StringBuilder result = new StringBuilder("<?xml version=\"1.0\" encoding=\"utf-8\"?>\n" +
+                                                     "<remote-configuration-registries>\n");
 
         for (Map<String, String> props : configProperties) {
             String authType = props.get(PROPERTY_AUTH_TYPE);
             if ("Kerberos".equalsIgnoreCase(authType)) {
-                result +=
-                   createRemoteConfigRegistryXMLWithKerberosAuth(props.get(PROPERTY_TYPE),
-                                                                 props.get(PROPERTY_NAME),
-                                                                 props.get(PROPERTY_ADDRESS),
-                                                                 props.get(PROPERTY_PRINCIPAL),
-                                                                 props.get(PROPERTY_KEYTAB),
-                                                                 Boolean.valueOf(props.get(PROPERTY_USE_KEYTAB)),
-                                                                 Boolean.valueOf(props.get(PROPERTY_USE_TICKET_CACHE)));
+                result.append(createRemoteConfigRegistryXMLWithKerberosAuth(props.get(PROPERTY_TYPE),
+                    props.get(PROPERTY_NAME),
+                    props.get(PROPERTY_ADDRESS),
+                    props.get(PROPERTY_PRINCIPAL),
+                    props.get(PROPERTY_KEYTAB),
+                    Boolean.valueOf(props.get(PROPERTY_USE_KEYTAB)),
+                    Boolean.valueOf(props.get(PROPERTY_USE_TICKET_CACHE))));
             } else if ("Digest".equalsIgnoreCase(authType)) {
-                result +=
-                    createRemoteConfigRegistryXMLWithDigestAuth(props.get(PROPERTY_TYPE),
-                                                                props.get(PROPERTY_NAME),
-                                                                props.get(PROPERTY_ADDRESS),
-                                                                props.get(PROPERTY_PRINCIPAL),
-                                                                props.get(PROPERTY_CRED_ALIAS));
+                result.append(createRemoteConfigRegistryXMLWithDigestAuth(props.get(PROPERTY_TYPE),
+                    props.get(PROPERTY_NAME),
+                    props.get(PROPERTY_ADDRESS),
+                    props.get(PROPERTY_PRINCIPAL),
+                    props.get(PROPERTY_CRED_ALIAS)));
             } else {
-                result += createRemoteConfigRegistryXMLNoAuth(props.get(PROPERTY_TYPE),
-                                                              props.get(PROPERTY_NAME),
-                                                              props.get(PROPERTY_ADDRESS));
+                result.append(createRemoteConfigRegistryXMLNoAuth(props.get(PROPERTY_TYPE),
+                    props.get(PROPERTY_NAME),
+                    props.get(PROPERTY_ADDRESS)));
             }
         }
 
-        result += "</remote-configuration-registries>\n";
+        result.append("</remote-configuration-registries>\n");
 
-        return result;
+        return result.toString();
     }
 
     public static String createRemoteConfigRegistryXMLWithKerberosAuth(String type,
@@ -82,8 +80,8 @@ public class RemoteRegistryConfigTestUtils {
                "    <auth-type>" + "Kerberos" + "</auth-type>\n" +
                "    <principal>" + principal + "</principal>\n" +
                "    <keytab>" + keyTab + "</keytab>\n" +
-               "    <use-keytab>" + String.valueOf(userKeyTab) + "</use-keytab>\n" +
-               "    <use-ticket-cache>" + String.valueOf(useTicketCache) + "</use-ticket-cache>\n" +
+               "    <use-keytab>" + userKeyTab + "</use-keytab>\n" +
+               "    <use-ticket-cache>" + useTicketCache + "</use-ticket-cache>\n" +
                "  </remote-configuration-registry>\n";
     }
 


Mime
View raw message