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=1851d03a61879ae93a8bbcbb31ef96fd79307bdf;hb=bda6aeaa60607ab4fe5af508156019d7bd5c0ce4;hp=125c50d85379c0e4f6d750ac3df7b41184dc55c4;hpb=52c5c5ab9ba33755e26f06f41de608f825866a53;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 125c50d8..1851d03a 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
@@ -24,27 +24,25 @@
package org.onap.dmaap.datarouter.provisioning;
+import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.sendResponseError;
+
+import com.att.eelf.configuration.EELFLogger;
+import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
import java.io.InvalidObjectException;
import java.net.HttpURLConnection;
import java.net.URL;
+import java.util.ArrayList;
import java.util.List;
-import java.util.Vector;
-
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
-
+import jakarta.servlet.http.HttpServletRequest;
+import jakarta.servlet.http.HttpServletResponse;
import org.json.JSONException;
import org.json.JSONObject;
import org.onap.dmaap.datarouter.authz.AuthorizationResponse;
import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord;
import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
import org.onap.dmaap.datarouter.provisioning.eelf.EelfMsgs;
-
-import com.att.eelf.configuration.EELFLogger;
-import com.att.eelf.configuration.EELFManager;
-
-import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.sendResponseError;
+import org.onap.dmaap.datarouter.provisioning.utils.SynchronizerTask;
/**
* This servlet handles provisioning for the <subscriptionURL> which is generated by the provisioning server to
@@ -55,18 +53,13 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send
* @author Robert Eby
* @version $Id$
*/
-@SuppressWarnings("serial")
public class SubscriptionServlet extends ProxyServlet {
private static final String SUBCNTRL_CONTENT_TYPE = "application/vnd.dmaap-dr.subscription-control";
//Adding EELF Logger Rally:US664892
- private static EELFLogger eelfLogger = EELFManager.getInstance()
+ private static final EELFLogger eelfLogger = EELFManager.getInstance()
.getLogger(SubscriptionServlet.class);
-
-
-
-
/**
* 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.
@@ -76,7 +69,8 @@ public class SubscriptionServlet extends ProxyServlet {
setIpFqdnRequestIDandInvocationIDForEelf("doDelete", req);
eelfLogger.info(EelfMsgs.ENTRY);
try {
- 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) {
@@ -177,7 +171,8 @@ public class SubscriptionServlet extends ProxyServlet {
setIpFqdnRequestIDandInvocationIDForEelf("doGet", req);
eelfLogger.info(EelfMsgs.ENTRY);
try {
- 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) {
@@ -253,7 +248,8 @@ public class SubscriptionServlet extends ProxyServlet {
setIpFqdnRequestIDandInvocationIDForEelf("doPut", req);
eelfLogger.info(EelfMsgs.ENTRY);
try {
- 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) {
@@ -314,10 +310,7 @@ public class SubscriptionServlet extends ProxyServlet {
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
return;
}
- if (intlogger.isDebugEnabled()) {
- intlogger.debug(jo.toString());
- }
- Subscription sub = null;
+ Subscription sub;
try {
sub = new Subscription(jo);
} catch (InvalidObjectException e) {
@@ -363,8 +356,8 @@ public class SubscriptionServlet extends ProxyServlet {
sub.setSubid(oldsub.getSubid());
sub.setFeedid(oldsub.getFeedid());
sub.setSubscriber(bhdr); // set from X-DMAAP-DR-ON-BEHALF-OF header
-
- String subjectgroup = (req.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")); //Adding for group feature:Rally US708115
+ //Adding for group feature:Rally US708115
+ String subjectgroup = (req.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP"));
if (!oldsub.getSubscriber().equals(sub.getSubscriber()) && subjectgroup == null) {
message = "This subscriber must be modified by the same subscriber that created it.";
elr.setMessage(message);
@@ -387,7 +380,7 @@ public class SubscriptionServlet extends ProxyServlet {
eventlogger.error("PROV0192 SubscriptionServlet.doPut: " + ioe.getMessage(), ioe);
}
- /**Change Owner ship of Subscriber Adding for group feature:Rally US708115*/
+ /**Change Owner ship of Subscriber. Adding for group feature:Rally US708115*/
if (jo.has("changeowner") && subjectgroup != null) {
try {
Boolean changeowner = (Boolean) jo.get("changeowner");
@@ -399,7 +392,7 @@ public class SubscriptionServlet extends ProxyServlet {
eventlogger.error("PROV0193 SubscriptionServlet.doPut: " + je.getMessage(), je);
}
}
- /***End of change ownership*/
+ /***End of change ownership.*/
provisioningDataChanged();
} else {
@@ -488,12 +481,12 @@ public class SubscriptionServlet extends ProxyServlet {
try {
// Only the active POD sends notifications
boolean active = SynchronizerTask.getSynchronizer().isActive();
- boolean b = jo.getBoolean("failed");
- if (active && !b) {
+ boolean bool = jo.getBoolean("failed");
+ if (active && !bool) {
// Notify all nodes to reset the subscription
- SubscriberNotifyThread t = new SubscriberNotifyThread();
- t.resetSubscription(subid);
- t.start();
+ SubscriberNotifyThread thread = new SubscriberNotifyThread();
+ thread.resetSubscription(subid);
+ thread.start();
}
// send response
elr.setResult(HttpServletResponse.SC_ACCEPTED);
@@ -515,41 +508,44 @@ 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.
*/
- public class SubscriberNotifyThread extends Thread {
+ public static class SubscriberNotifyThread extends Thread {
- public static final String URL_TEMPLATE = "http://%s/internal/resetSubscription/%d";
- private List urls = new Vector<>();
+ static final String URL_TEMPLATE = "http://%s/internal/resetSubscription/%d";
+ private List urls = new ArrayList<>();
- public SubscriberNotifyThread() {
+ SubscriberNotifyThread() {
setName("SubscriberNotifyThread");
}
- public void resetSubscription(int subid) {
+ void resetSubscription(int subid) {
for (String nodename : BaseServlet.getNodes()) {
- String u = String.format(URL_TEMPLATE, nodename, subid);
- urls.add(u);
+ String url = String.format(URL_TEMPLATE, nodename, subid);
+ urls.add(url);
}
}
@Override
public void run() {
-
try {
while (!urls.isEmpty()) {
- String u = urls.remove(0);
- try {
- URL url = new URL(u);
- HttpURLConnection conn = (HttpURLConnection) url.openConnection();
- conn.connect();
- conn.getContentLength(); // Force the GET through
- conn.disconnect();
- } catch (IOException e) {
- intlogger.info("PROV0194 Error accessing URL: " + u + ": " + e.getMessage(), e);
- }
+ String url = urls.remove(0);
+ forceGetThrough(url);
}
} catch (Exception e) {
intlogger.warn("PROV0195 Caught exception in SubscriberNotifyThread: " + e.getMessage(), e);
}
}
+
+ private void forceGetThrough(String url) {
+ try {
+ URL urlObj = new URL(url);
+ HttpURLConnection conn = (HttpURLConnection) urlObj.openConnection();
+ conn.connect();
+ conn.getContentLength(); // Force the GET through
+ conn.disconnect();
+ } catch (IOException e) {
+ intlogger.info("PROV0194 Error accessing URL: " + url + ": " + e.getMessage(), e);
+ }
+ }
}
}