Checkstyle fixes for datarouter prov
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / Main.java
index 1bd3cbf..aefe8cd 100644 (file)
 
 package org.onap.dmaap.datarouter.provisioning;
 
-import org.apache.log4j.Logger;
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
+import java.io.IOException;
+import java.io.InputStream;
+import java.security.Security;
+import java.util.EnumSet;
+import java.util.Properties;
+import java.util.Timer;
+import javax.servlet.DispatcherType;
 import org.eclipse.jetty.http.HttpVersion;
-import org.eclipse.jetty.server.*;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.Handler;
+import org.eclipse.jetty.server.HttpConfiguration;
+import org.eclipse.jetty.server.HttpConnectionFactory;
+import org.eclipse.jetty.server.NCSARequestLog;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.SslConnectionFactory;
 import org.eclipse.jetty.server.handler.ContextHandlerCollection;
 import org.eclipse.jetty.server.handler.DefaultHandler;
 import org.eclipse.jetty.server.handler.HandlerCollection;
@@ -37,15 +52,12 @@ import org.eclipse.jetty.servlet.ServletHolder;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
 import org.eclipse.jetty.util.thread.QueuedThreadPool;
 import org.onap.aaf.cadi.PropAccess;
-import org.onap.dmaap.datarouter.provisioning.utils.*;
 
-import javax.servlet.DispatcherType;
-import java.io.IOException;
-import java.io.InputStream;
-import java.security.Security;
-import java.util.EnumSet;
-import java.util.Properties;
-import java.util.Timer;
+import org.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.onap.dmaap.datarouter.provisioning.utils.DRProvCadiFilter;
+import org.onap.dmaap.datarouter.provisioning.utils.LogfileLoader;
+import org.onap.dmaap.datarouter.provisioning.utils.PurgeLogDirTask;
+import org.onap.dmaap.datarouter.provisioning.utils.ThrottleFilter;
 
 /**
  * <p>
@@ -79,7 +91,7 @@ import java.util.Timer;
 public class Main {
 
     /**
-     * The truststore to use if none is specified
+     * The truststore to use if none is specified.
      */
     static final String DEFAULT_TRUSTSTORE = "/opt/java/jdk/jdk180/jre/lib/security/cacerts";
     static final String KEYSTORE_TYPE_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.type";
@@ -87,10 +99,11 @@ public class Main {
     static final String KEYSTORE_PASS_PROPERTY = "org.onap.dmaap.datarouter.provserver.keystore.password";
     static final String TRUSTSTORE_PATH_PROPERTY = "org.onap.dmaap.datarouter.provserver.truststore.path";
     static final String TRUSTSTORE_PASS_PROPERTY = "org.onap.dmaap.datarouter.provserver.truststore.password";
-    public static final Logger intlogger = Logger.getLogger("org.onap.dmaap.datarouter.provisioning.internal");
+    public static final EELFLogger intlogger = EELFManager.getInstance()
+                                                       .getLogger("org.onap.dmaap.datarouter.provisioning.internal");
 
     /**
-     * The one and only {@link Server} instance in this JVM
+     * The one and only {@link Server} instance in this JVM.
      */
     private static Server server;
 
@@ -100,7 +113,7 @@ public class Main {
             try {
                 in = getClass().getClassLoader().getResourceAsStream("drProvCadi.properties");
             } catch (Exception e) {
-                intlogger.error("Exception in Main.getCadiProps() method ", e);
+                intlogger.error("Exception in Main.getCadiProps(): " + e.getMessage(), e);
             }
             return in;
         }
@@ -113,9 +126,7 @@ public class Main {
      * @throws Exception if Jetty has a problem starting
      */
     public static void main(String[] args) throws Exception {
-        // Get prov properties
-        Properties provProperties = (new DB()).getProperties();
-
+        Security.setProperty("networkaddress.cache.ttl", "4");
         // Check DB is accessible and contains the expected tables
         if (!checkDatabase()) {
             System.exit(1);
@@ -124,8 +135,11 @@ public class Main {
         intlogger.info("PROV0000 **** AT&T Data Router Provisioning Server starting....");
 
         Security.setProperty("networkaddress.cache.ttl", "4");
-        int httpPort = Integer.parseInt(provProperties.getProperty("org.onap.dmaap.datarouter.provserver.http.port", "8080"));
-        int httpsPort = Integer.parseInt(provProperties.getProperty("org.onap.dmaap.datarouter.provserver.https.port", "8443"));
+        Properties provProperties = (new DB()).getProperties();
+        int httpPort = Integer.parseInt(provProperties
+                                             .getProperty("org.onap.dmaap.datarouter.provserver.http.port", "8080"));
+        final int httpsPort = Integer.parseInt(provProperties
+                                             .getProperty("org.onap.dmaap.datarouter.provserver.https.port", "8443"));
 
         // Server's thread pool
         QueuedThreadPool queuedThreadPool = new QueuedThreadPool();
@@ -142,7 +156,9 @@ public class Main {
 
         // Request log configuration
         NCSARequestLog ncsaRequestLog = new NCSARequestLog();
-        ncsaRequestLog.setFilename(provProperties.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir") + "/request.log.yyyy_mm_dd");
+        ncsaRequestLog.setFilename(provProperties
+                                           .getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir")
+                                           + "/request.log.yyyy_mm_dd");
         ncsaRequestLog.setFilenameDateFormat("yyyyMMdd");
         ncsaRequestLog.setRetainDays(90);
         ncsaRequestLog.setAppend(true);
@@ -166,7 +182,8 @@ public class Main {
 
         //HTTP Connector
         HandlerCollection handlerCollection;
-        try (ServerConnector httpServerConnector = new ServerConnector(server, new HttpConnectionFactory(httpConfiguration))) {
+        try (ServerConnector httpServerConnector =
+                     new ServerConnector(server, new HttpConnectionFactory(httpConfiguration))) {
             httpServerConnector.setPort(httpPort);
             httpServerConnector.setAcceptQueueSize(2);
             httpServerConnector.setIdleTimeout(300000);
@@ -176,7 +193,8 @@ public class Main {
             sslContextFactory.setKeyStoreType(provProperties.getProperty(KEYSTORE_TYPE_PROPERTY, "jks"));
             sslContextFactory.setKeyStorePath(provProperties.getProperty(KEYSTORE_PATH_PROPERTY));
             sslContextFactory.setKeyStorePassword(provProperties.getProperty(KEYSTORE_PASS_PROPERTY));
-            sslContextFactory.setKeyManagerPassword(provProperties.getProperty("org.onap.dmaap.datarouter.provserver.keymanager.password"));
+            sslContextFactory.setKeyManagerPassword(provProperties
+                                          .getProperty("org.onap.dmaap.datarouter.provserver.keymanager.password"));
 
             String ts = provProperties.getProperty(TRUSTSTORE_PATH_PROPERTY);
             if (ts != null && ts.length() > 0) {
@@ -200,12 +218,17 @@ public class Main {
             );
             sslContextFactory.addExcludeProtocols("SSLv3");
             sslContextFactory.setIncludeProtocols(provProperties.getProperty(
-                    "org.onap.dmaap.datarouter.provserver.https.include.protocols", "TLSv1.1|TLSv1.2").trim().split("\\|"));
-
-            intlogger.info("Not supported protocols prov server:-" + String.join(",", sslContextFactory.getExcludeProtocols()));
-            intlogger.info("Supported protocols prov server:-" + String.join(",", sslContextFactory.getIncludeProtocols()));
-            intlogger.info("Not supported ciphers prov server:-" + String.join(",", sslContextFactory.getExcludeCipherSuites()));
-            intlogger.info("Supported ciphers prov server:-" + String.join(",", sslContextFactory.getIncludeCipherSuites()));
+                    "org.onap.dmaap.datarouter.provserver.https.include.protocols",
+                    "TLSv1.1|TLSv1.2").trim().split("\\|"));
+
+            intlogger.info("Not supported protocols prov server:-"
+                                   + String.join(",", sslContextFactory.getExcludeProtocols()));
+            intlogger.info("Supported protocols prov server:-"
+                                   + String.join(",", sslContextFactory.getIncludeProtocols()));
+            intlogger.info("Not supported ciphers prov server:-"
+                                   + String.join(",", sslContextFactory.getExcludeCipherSuites()));
+            intlogger.info("Supported ciphers prov server:-"
+                                   + String.join(",", sslContextFactory.getIncludeCipherSuites()));
 
             // HTTPS configuration
             HttpConfiguration httpsConfiguration = new HttpConfiguration(httpConfiguration);
@@ -234,10 +257,12 @@ public class Main {
                 servletContextHandler.addServlet(new ServletHolder(new InternalServlet()), "/internal/*");
                 servletContextHandler.addServlet(new ServletHolder(new RouteServlet()), "/internal/route/*");
                 servletContextHandler.addServlet(new ServletHolder(new DRFeedsServlet()), "/");
-                servletContextHandler.addFilter(new FilterHolder(new ThrottleFilter()), "/publish/*", EnumSet.of(DispatcherType.REQUEST));
+                servletContextHandler.addFilter(new FilterHolder(new ThrottleFilter()),
+                        "/publish/*", EnumSet.of(DispatcherType.REQUEST));
 
                 //CADI Filter activation check
-                if (Boolean.parseBoolean(provProperties.getProperty("org.onap.dmaap.datarouter.provserver.cadi.enabled", "false"))) {
+                if (Boolean.parseBoolean(provProperties.getProperty(
+                        "org.onap.dmaap.datarouter.provserver.cadi.enabled", "false"))) {
                     //Get cadi properties
                     Properties cadiProperties = null;
                     try {
@@ -246,14 +271,15 @@ public class Main {
                         Inner obj = new Main().new Inner();
                         InputStream in = obj.getCadiProps();
                         cadiProperties.load(in);
-                    } catch (IOException e1) {
-                        intlogger.error("PROV0001 Exception loading CADI properties", e1);
+                    } catch (IOException ioe) {
+                        intlogger.error("PROV0001 Exception loading CADI properties: " + ioe.getMessage(), ioe);
                     }
                     cadiProperties.setProperty("aaf_locate_url", provProperties.getProperty("org.onap.dmaap.datarouter.provserver.cadi.aaf.url", "https://aaf-onap-test.osaaf.org:8095"));
                     intlogger.info("PROV0001  aaf_url set to - " + cadiProperties.getProperty("aaf_url"));
 
                     PropAccess access = new PropAccess(cadiProperties);
-                    servletContextHandler.addFilter(new FilterHolder(new DRProvCadiFilter(true, access)), "/*", EnumSet.of(DispatcherType.REQUEST));
+                    servletContextHandler.addFilter(new FilterHolder(new DRProvCadiFilter(true, access)),
+                            "/*", EnumSet.of(DispatcherType.REQUEST));
                 }
 
                 ContextHandlerCollection contextHandlerCollection = new ContextHandlerCollection();
@@ -280,7 +306,7 @@ public class Main {
             server.start();
             intlogger.info("Prov Server started-" + server.getState());
         } catch (Exception e) {
-            intlogger.info("Jetty failed to start. Reporting will we unavailable", e);
+            intlogger.info("Jetty failed to start. Reporting will we unavailable: " + e.getMessage(), e);
         }
         server.join();
         intlogger.info("PROV0001 **** AT&T Data Router Provisioning Server halted.");
@@ -301,7 +327,7 @@ public class Main {
                 Thread.sleep(5000L);
                 System.exit(0);
             } catch (Exception e) {
-                intlogger.error("Exception in Main.shutdown() method " + e);
+                intlogger.error("Exception in Main.shutdown(): " + e.getMessage(), e);
             }
         });
     }