Remaining checkstyle changes 69/93669/1
authoregernug <gerard.nugent@est.tech>
Fri, 16 Aug 2019 07:45:53 +0000 (07:45 +0000)
committeregernug <gerard.nugent@est.tech>
Fri, 16 Aug 2019 07:45:53 +0000 (07:45 +0000)
Change-Id: I5392355aa45502e978f2ae8118ac8402202a0584
Issue-ID: DMAAP-1250
Signed-off-by: egernug <gerard.nugent@est.tech>
datarouter-node/src/main/java/org/onap/dmaap/datarouter/node/DeliveryQueue.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/DRProvCadiFilter.java
datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/utils/PasswordProcessor.java
datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SampleSubscriberServlet.java
datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SubscriberMain.java
datarouter-subscriber/src/main/java/org/onap/dmaap/datarouter/subscriber/SubscriberProps.java

index 0b9ea49..e06ec5a 100644 (file)
@@ -53,7 +53,6 @@ import org.jetbrains.annotations.Nullable;
  * delivery fails while the delay was active, it will not change the delay
  * or change the duration of any subsequent delay.
  * If, however, it succeeds, it will cancel the delay.
- *
  * The queue maintains 3 collections of files to deliver: A todoList of
  * files that will be attempted, a working set of files that are being
  * attempted, and a retry set of files that were attempted and failed.
index 321df9d..4b94159 100644 (file)
@@ -403,7 +403,7 @@ public class FeedServlet extends ProxyServlet {
                 }
 
 
-                /**Change Owner ship of Feed //Adding for group feature:Rally US708115*/
+                /**Change Owner ship of Feed //Adding for group feature:Rally US708115*/
                 if (jo.has("changeowner") && subjectgroup != null) {
                     try {
                         Boolean changeowner = (Boolean) jo.get("changeowner");
@@ -415,7 +415,7 @@ public class FeedServlet extends ProxyServlet {
                         eventlogger.error("PROV0103 FeedServlet.doPut: " + je.getMessage(), je);
                     }
                 }
-                /***End of change ownership*/
+                /***End of change ownership.*/
 
                 provisioningDataChanged();
             } else {
index 62c2f62..03bc983 100644 (file)
@@ -387,7 +387,7 @@ public class SubscriptionServlet extends ProxyServlet {
                     eventlogger.error("PROV0192 SubscriptionServlet.doPut: " + ioe.getMessage(), ioe);\r
                 }\r
 \r
-                /**Change Owner ship of Subscriber     Adding for group feature:Rally US708115*/\r
+                /**Change Owner ship of Subscriber.     Adding for group feature:Rally US708115*/\r
                 if (jo.has("changeowner") && subjectgroup != null) {\r
                     try {\r
                         Boolean changeowner = (Boolean) jo.get("changeowner");\r
@@ -399,7 +399,7 @@ public class SubscriptionServlet extends ProxyServlet {
                         eventlogger.error("PROV0193 SubscriptionServlet.doPut: " + je.getMessage(), je);\r
                     }\r
                 }\r
-                /***End of change ownership*/\r
+                /***End of change ownership.*/\r
 \r
                 provisioningDataChanged();\r
             } else {\r
index 8301bf9..8b3d4eb 100644 (file)
@@ -6,16 +6,16 @@
  * Licensed under the Apache License, Version 2.0 (the "License");
  * you may not use this file except in compliance with the License.
  * You may obtain a copy of the License at
- * <p>
- * http://www.apache.org/licenses/LICENSE-2.0
- * <p>
- * Unless required by applicable law or agreed to in writing, software
+ *
+ * <p>* http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * <p>Unless required by applicable law or agreed to in writing, software
  * distributed under the License is distributed on an "AS IS" BASIS,
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
  * See the License for the specific language governing permissions and
  * limitations under the License.
- * <p>
- * SPDX-License-Identifier: Apache-2.0
+ *
+ * <p>* SPDX-License-Identifier: Apache-2.0
  * ============LICENSE_END=========================================================
  */
 
index f87a9b9..b8b668d 100644 (file)
@@ -6,16 +6,16 @@
  * Licensed under the Apache License, Version 2.0 (the "License");\r
  * you may not use this file except in compliance with the License.\r
  * You may obtain a copy of the License at\r
- * <p>\r
- * http://www.apache.org/licenses/LICENSE-2.0\r
- * <p>\r
- * Unless required by applicable law or agreed to in writing, software\r
+ *\r
+ * <p>http://www.apache.org/licenses/LICENSE-2.0\r
+ *\r
+ * <p>* Unless required by applicable law or agreed to in writing, software\r
  * distributed under the License is distributed on an "AS IS" BASIS,\r
  * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.\r
  * See the License for the specific language governing permissions and\r
  * limitations under the License.\r
- * <p>\r
- * SPDX-License-Identifier: Apache-2.0\r
+ *\r
+ * <p>* SPDX-License-Identifier: Apache-2.0\r
  * ============LICENSE_END=========================================================\r
  */\r
 \r
index e9a0bf9..993d325 100644 (file)
  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
  * *
  ******************************************************************************/
-package org.onap.dmaap.datarouter.subscriber;
 
-import org.apache.commons.codec.binary.Base64;
-import org.apache.log4j.Logger;
+package org.onap.dmaap.datarouter.subscriber;
 
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-import java.io.*;
+import java.io.File;
+import java.io.FileOutputStream;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.io.PrintWriter;
 import java.net.URLEncoder;
 import java.nio.file.Files;
 import java.nio.file.Paths;
 import java.nio.file.StandardCopyOption;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.apache.commons.codec.binary.Base64;
+import org.apache.log4j.Logger;
+
 
 public class SampleSubscriberServlet extends HttpServlet {
 
-  private static Logger logger =
-      Logger.getLogger("org.onap.dmaap.datarouter.subscriber.SampleSubscriberServlet");
-  private static String outputDirectory;
-  private static String basicAuth;
+    private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.subscriber.SampleSubscriberServlet");
+    private static String outputDirectory;
+    private static String basicAuth;
 
-  /**
-   * Configure the SampleSubscriberServlet.
-   *
-   * <ul>
-   *   <li>Login - The login expected in the Authorization header (default "LOGIN").
-   *   <li>Password - The password expected in the Authorization header (default "PASSWORD").
-   *   <li>outputDirectory - The directory where files are placed (default
-   *       "/opt/app/subscriber/delivery").
-   * </ul>
-   */
-  @Override
-  public void init() {
-    SubscriberProps props = SubscriberProps.getInstance();
-    String login = props.getValue("org.onap.dmaap.datarouter.subscriber.auth.user", "LOGIN");
-    String password =
-        props.getValue("org.onap.dmaap.datarouter.subscriber.auth.password", "PASSWORD");
-    outputDirectory =
-        props.getValue(
-            "org.onap.dmaap.datarouter.subscriber.delivery.dir", "/opt/app/subscriber/delivery");
-    try {
-      Files.createDirectory(Paths.get(outputDirectory));
-    } catch (IOException e) {
-      logger.info("SubServlet: Failed to create delivery dir: " + e.getMessage(), e);
+    /**
+     * Configure the SampleSubscriberServlet.
+     *
+     * <ul>
+     * <li>Login - The login expected in the Authorization header (default "LOGIN").
+     * <li>Password - The password expected in the Authorization header (default "PASSWORD").
+     * <li>outputDirectory - The directory where files are placed (default
+     * "/opt/app/subscriber/delivery").
+     * </ul>
+     */
+    @Override
+    public void init() {
+        SubscriberProps props = SubscriberProps.getInstance();
+        String login = props.getValue("org.onap.dmaap.datarouter.subscriber.auth.user", "LOGIN");
+        String password = props.getValue("org.onap.dmaap.datarouter.subscriber.auth.password", "PASSWORD");
+        outputDirectory =
+                props.getValue("org.onap.dmaap.datarouter.subscriber.delivery.dir", "/opt/app/subscriber/delivery");
+        try {
+            Files.createDirectory(Paths.get(outputDirectory));
+        } catch (IOException e) {
+            logger.info("SubServlet: Failed to create delivery dir: " + e.getMessage(), e);
+        }
+        basicAuth = "Basic " + Base64.encodeBase64String((login + ":" + password).getBytes());
     }
-    basicAuth = "Basic " + Base64.encodeBase64String((login + ":" + password).getBytes());
-  }
 
-  @Override
-  protected void doPut(HttpServletRequest req, HttpServletResponse resp) {
-    try {
-      common(req, resp, false);
-    } catch (IOException e) {
-      logger.info(
-          "SampleSubServlet: Failed to doPut: " + req.getRemoteAddr() + " : " + req.getPathInfo(),
-          e);
+    @Override
+    protected void doPut(HttpServletRequest req, HttpServletResponse resp) {
+        try {
+            common(req, resp, false);
+        } catch (IOException e) {
+            logger.info("SampleSubServlet: Failed to doPut: " + req.getRemoteAddr() + " : " + req.getPathInfo(), e);
+        }
     }
-  }
 
-  @Override
-  protected void doDelete(HttpServletRequest req, HttpServletResponse resp) {
-    try {
-      common(req, resp, true);
-    } catch (IOException e) {
-      logger.info(
-          "SampleSubServlet: Failed to doDelete: "
-              + req.getRemoteAddr()
-              + " : "
-              + req.getPathInfo(),
-          e);
-    }
-  }
-  /**
-   * Process a PUT or DELETE request.
-   *
-   * <ol>
-   *   <li>Verify that the request contains an Authorization header or else UNAUTHORIZED.
-   *   <li>Verify that the Authorization header matches the configured Login and Password or else
-   *       FORBIDDEN.
-   *   <li>If the request is PUT, store the message body as a file in the configured outputDirectory
-   *       directory protecting against evil characters in the received FileID. The file is created
-   *       initially with its name prefixed with a ".", and once it is complete, it is renamed to
-   *       remove the leading "." character.
-   *   <li>If the request is DELETE, instead delete the file (if it exists) from the configured
-   *       outputDirectory directory.
-   *   <li>Respond with NO_CONTENT.
-   * </ol>
-   */
-  private void common(HttpServletRequest req, HttpServletResponse resp, boolean isdelete)
-      throws IOException {
-    String authHeader = req.getHeader("Authorization");
-    if (authHeader == null) {
-      logger.info(
-          "SampleSubServlet: Rejecting request with no Authorization header from "
-              + req.getRemoteAddr()
-              + ": "
-              + req.getPathInfo());
-      resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
-      return;
-    }
-    if (!basicAuth.equals(authHeader)) {
-      logger.info(
-          "SampleSubServlet: Rejecting request with incorrect Authorization header from "
-              + req.getRemoteAddr()
-              + ": "
-              + req.getPathInfo());
-      resp.sendError(HttpServletResponse.SC_FORBIDDEN);
-      return;
-    }
-    String fileid = req.getPathInfo();
-    fileid = fileid.substring(fileid.lastIndexOf('/') + 1);
-    String queryString = req.getQueryString();
-    if (queryString != null) {
-      fileid = fileid + "?" + queryString;
+    @Override
+    protected void doDelete(HttpServletRequest req, HttpServletResponse resp) {
+        try {
+            common(req, resp, true);
+        } catch (IOException e) {
+            logger.info("SampleSubServlet: Failed to doDelete: " + req.getRemoteAddr() + " : " + req.getPathInfo(), e);
+        }
     }
-    String publishid = req.getHeader("X-DMAAP-DR-PUBLISH-ID");
-    String filename =
-        URLEncoder.encode(fileid, "UTF-8").replaceAll("^\\.", "%2E").replaceAll("\\*", "%2A");
-    String fullPath = outputDirectory + "/" + filename;
-    String tmpPath = outputDirectory + "/." + filename;
-    String fullMetaDataPath = outputDirectory + "/" + filename + ".M";
-    String tmpMetaDataPath = outputDirectory + "/." + filename + ".M";
-    try {
-      if (isdelete) {
-        Files.deleteIfExists(Paths.get(fullPath));
-        Files.deleteIfExists(Paths.get(fullMetaDataPath));
-        logger.info(
-            "SampleSubServlet: Received delete for file id "
-                + fileid
-                + " from "
-                + req.getRemoteAddr()
-                + " publish id "
-                + publishid
-                + " as "
-                + fullPath);
-      } else {
-        new File(tmpPath).createNewFile();
-        new File(tmpMetaDataPath).createNewFile();
-        try (InputStream is = req.getInputStream();
-            OutputStream os = new FileOutputStream(tmpPath)) {
-          byte[] buf = new byte[65536];
-          int i;
-          while ((i = is.read(buf)) > 0) {
-            os.write(buf, 0, i);
-          }
+
+    /**
+     * Process a PUT or DELETE request.
+     *
+     * <ol>
+     * <li>Verify that the request contains an Authorization header or else UNAUTHORIZED.
+     * <li>Verify that the Authorization header matches the configured Login and Password or else
+     * FORBIDDEN.
+     * <li>If the request is PUT, store the message body as a file in the configured outputDirectory
+     * directory protecting against evil characters in the received FileID. The file is created
+     * initially with its name prefixed with a ".", and once it is complete, it is renamed to
+     * remove the leading "." character.
+     * <li>If the request is DELETE, instead delete the file (if it exists) from the configured
+     * outputDirectory directory.
+     * <li>Respond with NO_CONTENT.
+     * </ol>
+     */
+    private void common(HttpServletRequest req, HttpServletResponse resp, boolean isdelete) throws IOException {
+        String authHeader = req.getHeader("Authorization");
+        if (authHeader == null) {
+            logger.info("SampleSubServlet: Rejecting request with no Authorization header from " + req.getRemoteAddr()
+                                + ": " + req.getPathInfo());
+            resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
+            return;
+        }
+        if (!basicAuth.equals(authHeader)) {
+            logger.info("SampleSubServlet: Rejecting request with incorrect Authorization header from "
+                                + req.getRemoteAddr() + ": " + req.getPathInfo());
+            resp.sendError(HttpServletResponse.SC_FORBIDDEN);
+            return;
+        }
+        String fileid = req.getPathInfo();
+        fileid = fileid.substring(fileid.lastIndexOf('/') + 1);
+        String queryString = req.getQueryString();
+        if (queryString != null) {
+            fileid = fileid + "?" + queryString;
         }
-        Files.move(Paths.get(tmpPath), Paths.get(fullPath), StandardCopyOption.REPLACE_EXISTING);
-        try (PrintWriter writer = new PrintWriter(new FileOutputStream(tmpMetaDataPath))) {
-          String metaData = req.getHeader("X-DMAAP-DR-META");
-          writer.print(metaData);
+        String publishid = req.getHeader("X-DMAAP-DR-PUBLISH-ID");
+        String filename = URLEncoder.encode(fileid, "UTF-8").replaceAll("^\\.", "%2E").replaceAll("\\*", "%2A");
+        String fullPath = outputDirectory + "/" + filename;
+        String tmpPath = outputDirectory + "/." + filename;
+        String fullMetaDataPath = outputDirectory + "/" + filename + ".M";
+        String tmpMetaDataPath = outputDirectory + "/." + filename + ".M";
+        try {
+            if (isdelete) {
+                Files.deleteIfExists(Paths.get(fullPath));
+                Files.deleteIfExists(Paths.get(fullMetaDataPath));
+                logger.info("SampleSubServlet: Received delete for file id " + fileid + " from " + req.getRemoteAddr()
+                                    + " publish id " + publishid + " as " + fullPath);
+            } else {
+                new File(tmpPath).createNewFile();
+                new File(tmpMetaDataPath).createNewFile();
+                try (InputStream is = req.getInputStream(); OutputStream os = new FileOutputStream(tmpPath)) {
+                    byte[] buf = new byte[65536];
+                    int bufferSize;
+                    while ((bufferSize = is.read(buf)) > 0) {
+                        os.write(buf, 0, bufferSize);
+                    }
+                }
+                Files.move(Paths.get(tmpPath), Paths.get(fullPath), StandardCopyOption.REPLACE_EXISTING);
+                try (PrintWriter writer = new PrintWriter(new FileOutputStream(tmpMetaDataPath))) {
+                    String metaData = req.getHeader("X-DMAAP-DR-META");
+                    writer.print(metaData);
+                }
+                Files.move(Paths.get(tmpMetaDataPath), Paths.get(fullMetaDataPath),
+                        StandardCopyOption.REPLACE_EXISTING);
+                logger.info(
+                        "SampleSubServlet: Received file id " + fileid + " from " + req.getRemoteAddr() + " publish id "
+                                + publishid + " as " + fullPath);
+                resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
+            }
+            resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
+        } catch (IOException ioe) {
+            Files.deleteIfExists(Paths.get(tmpPath));
+            Files.deleteIfExists(Paths.get(tmpMetaDataPath));
+            logger.info("SampleSubServlet: Failed to process file " + fullPath + " from " + req.getRemoteAddr() + ": "
+                                + req.getPathInfo());
+            throw ioe;
         }
-        Files.move(Paths.get(tmpMetaDataPath), Paths.get(fullMetaDataPath), StandardCopyOption.REPLACE_EXISTING);
-        logger.info(
-            "SampleSubServlet: Received file id "
-                + fileid
-                + " from "
-                + req.getRemoteAddr()
-                + " publish id "
-                + publishid
-                + " as "
-                + fullPath);
-        resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
-      }
-      resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
-    } catch (IOException ioe) {
-      Files.deleteIfExists(Paths.get(tmpPath));
-      Files.deleteIfExists(Paths.get(tmpMetaDataPath));
-      logger.info(
-          "SampleSubServlet: Failed to process file "
-              + fullPath
-              + " from "
-              + req.getRemoteAddr()
-              + ": "
-              + req.getPathInfo());
-      throw ioe;
     }
-  }
 }
index bbe5e32..2e02c88 100644 (file)
 
 package org.onap.dmaap.datarouter.subscriber;
 
+import java.util.Arrays;
 import org.apache.log4j.Logger;
 import org.eclipse.jetty.http.HttpVersion;
-import org.eclipse.jetty.server.*;
+import org.eclipse.jetty.server.Connector;
+import org.eclipse.jetty.server.HttpConfiguration;
+import org.eclipse.jetty.server.HttpConnectionFactory;
+import org.eclipse.jetty.server.SecureRequestCustomizer;
+import org.eclipse.jetty.server.Server;
+import org.eclipse.jetty.server.ServerConnector;
+import org.eclipse.jetty.server.SslConnectionFactory;
 import org.eclipse.jetty.servlet.ServletContextHandler;
 import org.eclipse.jetty.servlet.ServletHolder;
 import org.eclipse.jetty.util.ssl.SslContextFactory;
 
-import java.util.Arrays;
 
 public class SubscriberMain {
 
     private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.subscriber.SubscriberMain");
 
+    /**
+     * Main class for Subscriber.
+     * @param args standard args array
+     * @throws Exception generic exception
+     */
     public static void main(String[] args) throws Exception {
         SubscriberProps props = SubscriberProps.getInstance(
                 System.getProperty("org.onap.dmaap.datarouter.subscriber.properties", "subscriber.properties"));
@@ -69,7 +80,8 @@ public class SubscriberMain {
 
             /*Skip SSLv3 Fixes*/
             sslContextFactory.addExcludeProtocols("SSLv3");
-            logger.info("Excluded protocols for SubscriberMain:" + Arrays.toString(sslContextFactory.getExcludeProtocols()));
+            logger.info("Excluded protocols for SubscriberMain:"
+                                + Arrays.toString(sslContextFactory.getExcludeProtocols()));
             /*End of SSLv3 Fixes*/
 
             // HTTPS Configuration
@@ -89,10 +101,10 @@ public class SubscriberMain {
         try {
             server.start();
         } catch ( Exception e ) {
-            logger.info("Jetty failed to start. Reporting will be unavailable-"+e);
+            logger.info("Jetty failed to start. Reporting will be unavailable-" + e);
         }
         server.join();
-        logger.info("org.onap.dmaap.datarouter.subscriber.SubscriberMain started-"+ server.getState());
+        logger.info("org.onap.dmaap.datarouter.subscriber.SubscriberMain started-" + server.getState());
 
     }
 }
\ No newline at end of file
index f05ca5d..ba7aa7a 100644 (file)
@@ -34,14 +34,19 @@ public class SubscriberProps {
     private static Logger subLogger = Logger.getLogger("org.onap.dmaap.datarouter.subscriber.internal");
     private Properties properties;
 
-    private SubscriberProps(String propsPath) throws IOException{
+    private SubscriberProps(String propsPath) throws IOException {
         properties = new Properties();
         properties.load(getClass().getClassLoader().getResourceAsStream(propsPath));
 
     }
 
+    /**
+     * Get instance of subscriber properties.
+     * @param propsPath path to properties file
+     * @return SubscriberProps object
+     */
     public static SubscriberProps getInstance(String propsPath) {
-        if(instance == null) {
+        if (instance == null) {
             try {
                 instance = new SubscriberProps(propsPath);
             } catch (IOException ioe) {