Update for OOM integration
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / SubscriptionServlet.java
index 8e49e30..3294580 100644 (file)
@@ -45,30 +45,30 @@ import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;\r
 \r
 /**\r
- * This servlet handles provisioning for the <subscriptionURL> which is generated by the provisioning\r
- * server to handle the inspection, modification, and deletion of a particular subscription to a feed.\r
- * It supports DELETE to delete a subscription, GET to retrieve information about the subscription,\r
- * and PUT to modify the subscription.  In DR 3.0, POST is also supported in order to reset the subscription\r
- * timers for individual subscriptions.\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
+ * delete a subscription, GET to retrieve information about the subscription, and PUT to modify the subscription.  In DR\r
+ * 3.0, POST is also supported in order to reset the subscription timers for individual subscriptions.\r
  *\r
  * @author Robert Eby\r
  * @version $Id$\r
  */\r
 @SuppressWarnings("serial")\r
 public class SubscriptionServlet extends ProxyServlet {\r
+\r
     public static final String SUBCNTRL_CONTENT_TYPE = "application/vnd.att-dr.subscription-control";\r
     //Adding EELF Logger Rally:US664892\r
-    private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.SubscriptionServlet");\r
+    private static EELFLogger eelflogger = EELFManager.getInstance()\r
+        .getLogger("org.onap.dmaap.datarouter.provisioning.SubscriptionServlet");\r
 \r
     /**\r
-     * DELETE on the <subscriptionUrl> -- delete a subscription.\r
-     * See the <i>Deleting a Subscription</i> section in the <b>Provisioning API</b>\r
-     * document for details on how this method should be invoked.\r
+     * DELETE on the &lt;subscriptionUrl&gt; -- delete a subscription. See the <i>Deleting a Subscription</i> section in\r
+     * the <b>Provisioning API</b> document for details on how this method should be invoked.\r
      */\r
     @Override\r
     public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
         setIpAndFqdnForEelf("doDelete");\r
-        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");\r
+        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");\r
         EventLogRecord elr = new EventLogRecord(req);\r
         String message = isAuthorizedForProvisioning(req);\r
         if (message != null) {\r
@@ -84,7 +84,7 @@ public class SubscriptionServlet extends ProxyServlet {
         }\r
         String bhdr = req.getHeader(BEHALF_HEADER);\r
         if (bhdr == null) {\r
-            message = "Missing "+BEHALF_HEADER+" header.";\r
+            message = "Missing " + BEHALF_HEADER + " header.";\r
             elr.setMessage(message);\r
             elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
             eventlogger.info(elr);\r
@@ -111,7 +111,7 @@ public class SubscriptionServlet extends ProxyServlet {
         }\r
         // Check with the Authorizer\r
         AuthorizationResponse aresp = authz.decide(req);\r
-        if (! aresp.isAuthorized()) {\r
+        if (!aresp.isAuthorized()) {\r
             message = "Policy Engine disallows access.";\r
             elr.setMessage(message);\r
             elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
@@ -122,7 +122,7 @@ public class SubscriptionServlet extends ProxyServlet {
 \r
         // Delete Subscription\r
         if (doDelete(sub)) {\r
-            active_subs--;\r
+            activeSubs--;\r
             // send response\r
             elr.setResult(HttpServletResponse.SC_NO_CONTENT);\r
             eventlogger.info(elr);\r
@@ -135,15 +135,16 @@ public class SubscriptionServlet extends ProxyServlet {
             resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG);\r
         }\r
     }\r
+\r
     /**\r
-     * GET on the &lt;subscriptionUrl&gt; -- get information about a subscription.\r
-     * See the <i>Retreiving Information about a Subscription</i> section in the <b>Provisioning API</b>\r
-     * document for details on how this method should be invoked.\r
+     * GET on the &lt;subscriptionUrl&gt; -- get information about a subscription. See the <i>Retreiving Information\r
+     * about a Subscription</i> section in the <b>Provisioning API</b> document for details on how this method should be\r
+     * invoked.\r
      */\r
     @Override\r
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
         setIpAndFqdnForEelf("doGet");\r
-        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");\r
+        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");\r
         EventLogRecord elr = new EventLogRecord(req);\r
         String message = isAuthorizedForProvisioning(req);\r
         if (message != null) {\r
@@ -159,7 +160,7 @@ public class SubscriptionServlet extends ProxyServlet {
         }\r
         String bhdr = req.getHeader(BEHALF_HEADER);\r
         if (bhdr == null) {\r
-            message = "Missing "+BEHALF_HEADER+" header.";\r
+            message = "Missing " + BEHALF_HEADER + " header.";\r
             elr.setMessage(message);\r
             elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
             eventlogger.info(elr);\r
@@ -186,7 +187,7 @@ public class SubscriptionServlet extends ProxyServlet {
         }\r
         // Check with the Authorizer\r
         AuthorizationResponse aresp = authz.decide(req);\r
-        if (! aresp.isAuthorized()) {\r
+        if (!aresp.isAuthorized()) {\r
             message = "Policy Engine disallows access.";\r
             elr.setMessage(message);\r
             elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
@@ -202,15 +203,15 @@ public class SubscriptionServlet extends ProxyServlet {
         resp.setContentType(SUBFULL_CONTENT_TYPE);\r
         resp.getOutputStream().print(sub.asJSONObject(true).toString());\r
     }\r
+\r
     /**\r
-     * PUT on the &lt;subscriptionUrl&gt; -- modify a subscription.\r
-     * See the <i>Modifying a Subscription</i> section in the <b>Provisioning API</b>\r
-     * document for details on how this method should be invoked.\r
+     * PUT on the &lt;subscriptionUrl&gt; -- modify a subscription. See the <i>Modifying a Subscription</i> section in\r
+     * the <b>Provisioning API</b> document for details on how this method should be invoked.\r
      */\r
     @Override\r
     public void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
         setIpAndFqdnForEelf("doPut");\r
-        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");\r
+        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");\r
         EventLogRecord elr = new EventLogRecord(req);\r
         String message = isAuthorizedForProvisioning(req);\r
         if (message != null) {\r
@@ -226,7 +227,7 @@ public class SubscriptionServlet extends ProxyServlet {
         }\r
         String bhdr = req.getHeader(BEHALF_HEADER);\r
         if (bhdr == null) {\r
-            message = "Missing "+BEHALF_HEADER+" header.";\r
+            message = "Missing " + BEHALF_HEADER + " header.";\r
             elr.setMessage(message);\r
             elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
             eventlogger.info(elr);\r
@@ -253,7 +254,7 @@ public class SubscriptionServlet extends ProxyServlet {
         }\r
         // Check with the Authorizer\r
         AuthorizationResponse aresp = authz.decide(req);\r
-        if (! aresp.isAuthorized()) {\r
+        if (!aresp.isAuthorized()) {\r
             message = "Policy Engine disallows access.";\r
             elr.setMessage(message);\r
             elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
@@ -281,8 +282,9 @@ public class SubscriptionServlet extends ProxyServlet {
             resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message);\r
             return;\r
         }\r
-        if (intlogger.isDebugEnabled())\r
+        if (intlogger.isDebugEnabled()) {\r
             intlogger.debug(jo.toString());\r
+        }\r
         Subscription sub = null;\r
         try {\r
             sub = new Subscription(jo);\r
@@ -335,10 +337,10 @@ public class SubscriptionServlet extends ProxyServlet {
             resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG);\r
         }\r
     }\r
+\r
     /**\r
-     * POST on the &lt;subscriptionUrl&gt; -- control a subscription.\r
-     * See the <i>Resetting a Subscription's Retry Schedule</i> section in the <b>Provisioning API</b>\r
-     * document for details on how this method should be invoked.\r
+     * POST on the &lt;subscriptionUrl&gt; -- control a subscription. See the <i>Resetting a Subscription's Retry\r
+     * Schedule</i> section in the <b>Provisioning API</b> document for details on how this method should be invoked.\r
      */\r
     @Override\r
     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {\r
@@ -367,7 +369,7 @@ public class SubscriptionServlet extends ProxyServlet {
         }\r
         String bhdr = req.getHeader(BEHALF_HEADER);\r
         if (bhdr == null) {\r
-            message = "Missing "+BEHALF_HEADER+" header.";\r
+            message = "Missing " + BEHALF_HEADER + " header.";\r
             elr.setMessage(message);\r
             elr.setResult(HttpServletResponse.SC_BAD_REQUEST);\r
             eventlogger.info(elr);\r
@@ -396,7 +398,7 @@ public class SubscriptionServlet extends ProxyServlet {
         }\r
         // Check with the Authorizer\r
         AuthorizationResponse aresp = authz.decide(req);\r
-        if (! aresp.isAuthorized()) {\r
+        if (!aresp.isAuthorized()) {\r
             message = "Policy Engine disallows access.";\r
             elr.setMessage(message);\r
             elr.setResult(HttpServletResponse.SC_FORBIDDEN);\r
@@ -437,22 +439,25 @@ public class SubscriptionServlet extends ProxyServlet {
     }\r
 \r
     /**\r
-     * A Thread class used to serially send reset notifications to all nodes in the DR network,\r
-     * when a POST is received for a subscription.\r
+     * 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
+\r
         public static final String URL_TEMPLATE = "http://%s/internal/resetSubscription/%d";\r
         private List<String> urls = new Vector<String>();\r
 \r
         public SubscriberNotifyThread() {\r
             setName("SubscriberNotifyThread");\r
         }\r
+\r
         public void resetSubscription(int subid) {\r
             for (String nodename : BaseServlet.getNodes()) {\r
                 String u = String.format(URL_TEMPLATE, nodename, subid);\r
                 urls.add(u);\r
             }\r
         }\r
+\r
         public void run() {\r
             try {\r
                 while (!urls.isEmpty()) {\r
@@ -464,11 +469,11 @@ public class SubscriptionServlet extends ProxyServlet {
                         conn.getContentLength();    // Force the GET through\r
                         conn.disconnect();\r
                     } catch (IOException e) {\r
-                        intlogger.info("IOException Error accessing URL: "+u+": " + e.getMessage());\r
+                        intlogger.info("IOException Error accessing URL: " + u + ": " + e.getMessage());\r
                     }\r
                 }\r
             } catch (Exception e) {\r
-                intlogger.warn("Caught exception in SubscriberNotifyThread: "+e);\r
+                intlogger.warn("Caught exception in SubscriberNotifyThread: " + e);\r
                 e.printStackTrace();\r
             }\r
         }\r