summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRam Koya <rk541m@att.com>2018-09-17 14:32:18 +0000
committerGerrit Code Review <gerrit@onap.org>2018-09-17 14:32:18 +0000
commit5347edeaee65ac740c7d306b82422035c7bfa863 (patch)
tree756759d70f91e411585bf7509e1e64e5dfc3ac44 /src
parent08d41a3fdcf909466e82c43ba30fefa0cf80c41e (diff)
parente77cb7c48b7deb7900a587ff217ea7bd5145a6a5 (diff)
Merge "Added Sonar fixe for JetttyServer.java"
Diffstat (limited to 'src')
-rw-r--r--src/main/java/org/onap/dmaap/dbcapi/server/JettyServer.java89
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);