Update for OOM integration
[dmaap/datarouter.git] / datarouter-prov / src / main / java / org / onap / dmaap / datarouter / provisioning / SubscribeServlet.java
index 3ad2242..21d391e 100644 (file)
@@ -43,8 +43,8 @@ import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
 
 /**
- * This servlet handles provisioning for the <subscribeURL> which is generated by the provisioning
- * server to handle the creation and inspection of subscriptions to a specific feed.
+ * This servlet handles provisioning for the <subscribeURL> which is generated by the provisioning server to
+ * handle the creation and inspection of subscriptions to a specific feed.
  *
  * @author Robert Eby
  * @version $Id$
@@ -53,7 +53,8 @@ import com.att.eelf.configuration.EELFManager;
 public class SubscribeServlet extends ProxyServlet {
 
     //Adding EELF Logger Rally:US664892
-    private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.SubscribeServlet");
+    private static EELFLogger eelflogger = EELFManager.getInstance()
+        .getLogger("org.onap.dmaap.datarouter.provisioning.SubscribeServlet");
 
     /**
      * DELETE on the <subscribeUrl> -- not supported.
@@ -61,7 +62,7 @@ public class SubscribeServlet extends ProxyServlet {
     @Override
     public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws IOException {
         setIpAndFqdnForEelf("doDelete");
-        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
         String message = "DELETE not allowed for the subscribeURL.";
         EventLogRecord elr = new EventLogRecord(req);
         elr.setMessage(message);
@@ -69,15 +70,15 @@ public class SubscribeServlet extends ProxyServlet {
         eventlogger.info(elr);
         resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);
     }
+
     /**
-     * GET on the <subscribeUrl> -- get the list of subscriptions to a feed.
-     * See the <i>Subscription Collection Query</i> section in the <b>Provisioning API</b>
-     * document for details on how this method should be invoked.
+     * GET on the &lt;subscribeUrl&gt; -- get the list of subscriptions to a feed. See the <i>Subscription Collection
+     * Query</i> section in the <b>Provisioning API</b> document for details on how this method should be invoked.
      */
     @Override
     public void doGet(HttpServletRequest req, HttpServletResponse resp) throws IOException {
         setIpAndFqdnForEelf("doGet");
-        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
         EventLogRecord elr = new EventLogRecord(req);
         String message = isAuthorizedForProvisioning(req);
         if (message != null) {
@@ -93,7 +94,7 @@ public class SubscribeServlet extends ProxyServlet {
         }
         String bhdr = req.getHeader(BEHALF_HEADER);
         if (bhdr == null) {
-            message = "Missing "+BEHALF_HEADER+" header.";
+            message = "Missing " + BEHALF_HEADER + " header.";
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
             eventlogger.info(elr);
@@ -120,7 +121,7 @@ public class SubscribeServlet extends ProxyServlet {
         }
         // Check with the Authorizer
         AuthorizationResponse aresp = authz.decide(req);
-        if (! aresp.isAuthorized()) {
+        if (!aresp.isAuthorized()) {
             message = "Policy Engine disallows access.";
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -140,13 +141,14 @@ public class SubscribeServlet extends ProxyServlet {
         resp.setContentType(SUBLIST_CONTENT_TYPE);
         resp.getOutputStream().print(t);
     }
+
     /**
      * PUT on the &lt;subscribeUrl&gt; -- not supported.
      */
     @Override
     public void doPut(HttpServletRequest req, HttpServletResponse resp) throws IOException {
         setIpAndFqdnForEelf("doPut");
-        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+        eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
         String message = "PUT not allowed for the subscribeURL.";
         EventLogRecord elr = new EventLogRecord(req);
         elr.setMessage(message);
@@ -154,10 +156,10 @@ public class SubscribeServlet extends ProxyServlet {
         eventlogger.info(elr);
         resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);
     }
+
     /**
-     * POST on the &lt;subscribeUrl&gt; -- create a new subscription to a feed.
-     * See the <i>Creating a Subscription</i> section in the <b>Provisioning API</b>
-     * document for details on how this method should be invoked.
+     * POST on the &lt;subscribeUrl&gt; -- create a new subscription to a feed. See the <i>Creating a Subscription</i>
+     * section in the <b>Provisioning API</b> document for details on how this method should be invoked.
      */
     @Override
     public void doPost(HttpServletRequest req, HttpServletResponse resp) throws IOException {
@@ -178,7 +180,7 @@ public class SubscribeServlet extends ProxyServlet {
         }
         String bhdr = req.getHeader(BEHALF_HEADER);
         if (bhdr == null) {
-            message = "Missing "+BEHALF_HEADER+" header.";
+            message = "Missing " + BEHALF_HEADER + " header.";
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
             eventlogger.info(elr);
@@ -205,7 +207,7 @@ public class SubscribeServlet extends ProxyServlet {
         }
         // Check with the Authorizer
         AuthorizationResponse aresp = authz.decide(req);
-        if (! aresp.isAuthorized()) {
+        if (!aresp.isAuthorized()) {
             message = "Policy Engine disallows access.";
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_FORBIDDEN);
@@ -218,7 +220,7 @@ public class SubscribeServlet extends ProxyServlet {
         ContentHeader ch = getContentHeader(req);
         String ver = ch.getAttribute("version");
         if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
-            intlogger.debug("Content-type is: "+req.getHeader("Content-Type"));
+            intlogger.debug("Content-type is: " + req.getHeader("Content-Type"));
             message = "Incorrect content-type";
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -235,10 +237,11 @@ public class SubscribeServlet extends ProxyServlet {
             resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message);
             return;
         }
-        if (intlogger.isDebugEnabled())
+        if (intlogger.isDebugEnabled()) {
             intlogger.debug(jo.toString());
-        if (++active_subs > max_subs) {
-            active_subs--;
+        }
+        if (++activeSubs > maxSubs) {
+            activeSubs--;
             message = "Cannot create subscription; the maximum number of subscriptions has been configured.";
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_CONFLICT);
@@ -250,7 +253,7 @@ public class SubscribeServlet extends ProxyServlet {
         try {
             sub = new Subscription(jo);
         } catch (InvalidObjectException e) {
-            active_subs--;
+            activeSubs--;
             message = e.getMessage();
             elr.setMessage(message);
             elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
@@ -263,8 +266,11 @@ public class SubscribeServlet extends ProxyServlet {
 
         // Check if this subscription already exists; not an error (yet), just warn
         Subscription sub2 = Subscription.getSubscriptionMatching(sub);
-        if (sub2 != null)
-            intlogger.warn("PROV0011 Creating a duplicate subscription: new subid="+sub.getSubid()+", old subid="+sub2.getSubid());
+        if (sub2 != null) {
+            intlogger.warn(
+                "PROV0011 Creating a duplicate subscription: new subid=" + sub.getSubid() + ", old subid=" + sub2
+                    .getSubid());
+        }
 
         // Create SUBSCRIPTIONS table entries
         if (doInsert(sub)) {
@@ -279,7 +285,7 @@ public class SubscribeServlet extends ProxyServlet {
             provisioningDataChanged();
         } else {
             // Something went wrong with the INSERT
-            active_subs--;
+            activeSubs--;
             elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
             eventlogger.info(elr);
             resp.sendError(HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG);