Removing code smells
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / SubscriptionServlet.java
index 125c50d..715c5e1 100644 (file)
 \r
 package org.onap.dmaap.datarouter.provisioning;\r
 \r
+import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.sendResponseError;\r
+\r
+import com.att.eelf.configuration.EELFLogger;\r
+import com.att.eelf.configuration.EELFManager;\r
 import java.io.IOException;\r
 import java.io.InvalidObjectException;\r
 import java.net.HttpURLConnection;\r
 import java.net.URL;\r
+import java.util.ArrayList;\r
 import java.util.List;\r
-import java.util.Vector;\r
-\r
 import javax.servlet.http.HttpServletRequest;\r
 import javax.servlet.http.HttpServletResponse;\r
-\r
 import org.json.JSONException;\r
 import org.json.JSONObject;\r
 import org.onap.dmaap.datarouter.authz.AuthorizationResponse;\r
@@ -41,11 +43,6 @@ import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord;
 import org.onap.dmaap.datarouter.provisioning.beans.Subscription;\r
 import org.onap.dmaap.datarouter.provisioning.eelf.EelfMsgs;\r
 \r
-import com.att.eelf.configuration.EELFLogger;\r
-import com.att.eelf.configuration.EELFManager;\r
-\r
-import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.sendResponseError;\r
-\r
 /**\r
  * This servlet handles provisioning for the <subscriptionURL> which is generated by the provisioning server to\r
  * handle the inspection, modification, and deletion of a particular subscription to a feed. It supports DELETE to\r
@@ -515,16 +512,16 @@ public class SubscriptionServlet extends ProxyServlet {
      * A Thread class used to serially send reset notifications to all nodes in the DR network, when a POST is received\r
      * for a subscription.\r
      */\r
-    public class SubscriberNotifyThread extends Thread {\r
+    public static class SubscriberNotifyThread extends Thread {\r
 \r
-        public static final String URL_TEMPLATE = "http://%s/internal/resetSubscription/%d";\r
-        private List<String> urls = new Vector<>();\r
+        static final String URL_TEMPLATE = "http://%s/internal/resetSubscription/%d";\r
+        private List<String> urls = new ArrayList<>();\r
 \r
-        public SubscriberNotifyThread() {\r
+        SubscriberNotifyThread() {\r
             setName("SubscriberNotifyThread");\r
         }\r
 \r
-        public void resetSubscription(int subid) {\r
+        void resetSubscription(int subid) {\r
             for (String nodename : BaseServlet.getNodes()) {\r
                 String u = String.format(URL_TEMPLATE, nodename, subid);\r
                 urls.add(u);\r
@@ -533,23 +530,26 @@ public class SubscriptionServlet extends ProxyServlet {
 \r
         @Override\r
         public void run() {\r
-\r
             try {\r
                 while (!urls.isEmpty()) {\r
-                    String u = urls.remove(0);\r
-                    try {\r
-                        URL url = new URL(u);\r
-                        HttpURLConnection conn = (HttpURLConnection) url.openConnection();\r
-                        conn.connect();\r
-                        conn.getContentLength();    // Force the GET through\r
-                        conn.disconnect();\r
-                    } catch (IOException e) {\r
-                        intlogger.info("PROV0194 Error accessing URL: " + u + ": " + e.getMessage(), e);\r
-                    }\r
+                    String url = urls.remove(0);\r
+                    forceGetThrough(url);\r
                 }\r
             } catch (Exception e) {\r
                 intlogger.warn("PROV0195 Caught exception in SubscriberNotifyThread: " + e.getMessage(), e);\r
             }\r
         }\r
+\r
+        private void forceGetThrough(String url) {\r
+            try {\r
+                URL urlObj = new URL(url);\r
+                HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();\r
+                conn.connect();\r
+                conn.getContentLength();    // Force the GET through\r
+                conn.disconnect();\r
+            } catch (IOException e) {\r
+                intlogger.info("PROV0194 Error accessing URL: " + url + ": " + e.getMessage(), e);\r
+            }\r
+        }\r
     }\r
 }\r