diff options
author | Amaresh Kumar <kamaresh@in.ibm.com> | 2018-09-15 11:39:42 +0530 |
---|---|---|
committer | Amaresh Kumar <kamaresh@in.ibm.com> | 2018-09-15 11:39:54 +0530 |
commit | e77cb7c48b7deb7900a587ff217ea7bd5145a6a5 (patch) | |
tree | 8843bafe2df760857e63f0592faadc84293a6d67 | |
parent | 23bdd1ef418e486c7306862dbba8766df11690bc (diff) |
Added Sonar fixe for JetttyServer.java
https://sonar.onap.org/project/issues?id=org.onap.dmaap.dbcapi%3Adbcapi&open=AWGB3zDS8TZzbCgU6dNh&resolved=false&severities=BLOCKER&types=BUG
Issue-ID: DMAAP-778
Change-Id: I5cd3c3b875931deee51730ef6eb86654aee7e710
Signed-off-by: Amaresh Kumar <kamaresh@in.ibm.com>
-rw-r--r-- | src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java | 89 |
1 files changed, 46 insertions, 43 deletions
diff --git a/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java b/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java index 519fa4a..748eedc 100644 --- a/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java +++ b/src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java @@ -69,6 +69,9 @@ public class JettyServer extends BaseLoggingClass { boolean allowHttp = Boolean.valueOf(params.getProperty("HttpAllowed", "false")); serverLogger.info( "port params: http=" + httpPort + " https=" + sslPort ); serverLogger.info( "allowHttp=" + allowHttp ); + String keystore=null; + String keystorePwd = null; + String keyPwd = null; // HTTP Server @@ -79,50 +82,50 @@ public class JettyServer extends BaseLoggingClass { - ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(http_config)); - httpConnector.setPort(httpPort); - httpConnector.setIdleTimeout(30000); - - - // HTTPS Server - - HttpConfiguration https_config = new HttpConfiguration(http_config); - https_config.addCustomizer(new SecureRequestCustomizer()); - SslContextFactory sslContextFactory = new SslContextFactory(); - String keystore = params.getProperty("KeyStoreFile", "etc/keystore"); - logger.info( "https Server using keystore at " + keystore ); - String keystorePwd = params.getProperty( "KeyStorePassword", "changeit"); - String keyPwd = params.getProperty("KeyPassword", "changeit"); - - - sslContextFactory.setKeyStorePath(keystore); - sslContextFactory.setKeyStorePassword(keystorePwd); - sslContextFactory.setKeyManagerPassword(keyPwd); - - - ServerConnector sslConnector = null; - if ( sslPort != 0 ) { - sslConnector = new ServerConnector(server, - new SslConnectionFactory(sslContextFactory, "http/1.1"), - new HttpConnectionFactory(https_config)); - sslConnector.setPort(sslPort); - if ( allowHttp ) { - logger.info("Starting httpConnector on port " + httpPort ); - logger.info("Starting sslConnector on port " + sslPort + " for https"); - server.setConnectors( new Connector[] { httpConnector, sslConnector }); - } else { - logger.info("NOT starting httpConnector because HttpAllowed param is " + allowHttp ); - logger.info("Starting sslConnector on port " + sslPort + " for https"); - server.setConnectors( new Connector[] { sslConnector }); - } + try(ServerConnector httpConnector = new ServerConnector(server, new HttpConnectionFactory(http_config))) { + httpConnector.setPort(httpPort); + httpConnector.setIdleTimeout(30000); + + + // HTTPS Server + + HttpConfiguration https_config = new HttpConfiguration(http_config); + https_config.addCustomizer(new SecureRequestCustomizer()); + SslContextFactory sslContextFactory = new SslContextFactory(); + keystore = params.getProperty("KeyStoreFile", "etc/keystore"); + logger.info("https Server using keystore at " + keystore); + keystorePwd = params.getProperty("KeyStorePassword", "changeit"); + keyPwd = params.getProperty("KeyPassword", "changeit"); + + + sslContextFactory.setKeyStorePath(keystore); + sslContextFactory.setKeyStorePassword(keystorePwd); + sslContextFactory.setKeyManagerPassword(keyPwd); + + + if (sslPort != 0) { + try(ServerConnector sslConnector = new ServerConnector(server, + new SslConnectionFactory(sslContextFactory, "http/1.1"), + new HttpConnectionFactory(https_config))) { + sslConnector.setPort(sslPort); + if (allowHttp) { + logger.info("Starting httpConnector on port " + httpPort); + logger.info("Starting sslConnector on port " + sslPort + " for https"); + server.setConnectors(new Connector[]{httpConnector, sslConnector}); + } else { + logger.info("NOT starting httpConnector because HttpAllowed param is " + allowHttp); + logger.info("Starting sslConnector on port " + sslPort + " for https"); + server.setConnectors(new Connector[]{sslConnector}); + } + } + } else { + serverLogger.info("NOT starting sslConnector on port " + sslPort + " for https"); + if (allowHttp) { + serverLogger.info("Starting httpConnector on port " + httpPort); + server.setConnectors(new Connector[]{httpConnector}); + } + } } - else { - serverLogger.info("NOT starting sslConnector on port " + sslPort + " for https"); - if ( allowHttp ) { - serverLogger.info("Starting httpConnector on port " + httpPort ); - server.setConnectors( new Connector[] { httpConnector }); - } - } // Set context for servlet. This is shared for http and https ServletContextHandler context = new ServletContextHandler(ServletContextHandler.SESSIONS); |