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