\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 jakarta.servlet.http.HttpServletRequest;\r
+import jakarta.servlet.http.HttpServletResponse;\r
import org.json.JSONException;\r
import org.json.JSONObject;\r
import org.onap.dmaap.datarouter.authz.AuthorizationResponse;\r
import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord;\r
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
+import org.onap.dmaap.datarouter.provisioning.utils.SynchronizerTask;\r
\r
/**\r
* This servlet handles provisioning for the <subscriptionURL> which is generated by the provisioning server to\r
* @author Robert Eby\r
* @version $Id$\r
*/\r
-@SuppressWarnings("serial")\r
public class SubscriptionServlet extends ProxyServlet {\r
\r
private static final String SUBCNTRL_CONTENT_TYPE = "application/vnd.dmaap-dr.subscription-control";\r
//Adding EELF Logger Rally:US664892\r
- private static EELFLogger eelfLogger = EELFManager.getInstance()\r
+ private static final EELFLogger eelfLogger = EELFManager.getInstance()\r
.getLogger(SubscriptionServlet.class);\r
\r
-\r
-\r
-\r
-\r
/**\r
* DELETE on the <subscriptionUrl> -- 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
setIpFqdnRequestIDandInvocationIDForEelf("doDelete", req);\r
eelfLogger.info(EelfMsgs.ENTRY);\r
try {\r
- eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");\r
+ eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID,\r
+ req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");\r
EventLogRecord elr = new EventLogRecord(req);\r
String message = isAuthorizedForProvisioning(req);\r
if (message != null) {\r
setIpFqdnRequestIDandInvocationIDForEelf("doGet", req);\r
eelfLogger.info(EelfMsgs.ENTRY);\r
try {\r
- eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");\r
+ eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID,\r
+ req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");\r
EventLogRecord elr = new EventLogRecord(req);\r
String message = isAuthorizedForProvisioning(req);\r
if (message != null) {\r
setIpFqdnRequestIDandInvocationIDForEelf("doPut", req);\r
eelfLogger.info(EelfMsgs.ENTRY);\r
try {\r
- eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");\r
+ eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID,\r
+ req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");\r
EventLogRecord elr = new EventLogRecord(req);\r
String message = isAuthorizedForProvisioning(req);\r
if (message != null) {\r
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);\r
return;\r
}\r
- if (intlogger.isDebugEnabled()) {\r
- intlogger.debug(jo.toString());\r
- }\r
- Subscription sub = null;\r
+ Subscription sub;\r
try {\r
sub = new Subscription(jo);\r
} catch (InvalidObjectException e) {\r
sub.setSubid(oldsub.getSubid());\r
sub.setFeedid(oldsub.getFeedid());\r
sub.setSubscriber(bhdr); // set from X-DMAAP-DR-ON-BEHALF-OF header\r
-\r
- String subjectgroup = (req.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP")); //Adding for group feature:Rally US708115\r
+ //Adding for group feature:Rally US708115\r
+ String subjectgroup = (req.getHeader("X-DMAAP-DR-ON-BEHALF-OF-GROUP"));\r
if (!oldsub.getSubscriber().equals(sub.getSubscriber()) && subjectgroup == null) {\r
message = "This subscriber must be modified by the same subscriber that created it.";\r
elr.setMessage(message);\r
eventlogger.error("PROV0192 SubscriptionServlet.doPut: " + ioe.getMessage(), ioe);\r
}\r
\r
- /**Change Owner ship of Subscriber Adding for group feature:Rally US708115*/\r
+ /**Change Owner ship of Subscriber. Adding for group feature:Rally US708115*/\r
if (jo.has("changeowner") && subjectgroup != null) {\r
try {\r
Boolean changeowner = (Boolean) jo.get("changeowner");\r
eventlogger.error("PROV0193 SubscriptionServlet.doPut: " + je.getMessage(), je);\r
}\r
}\r
- /***End of change ownership*/\r
+ /***End of change ownership.*/\r
\r
provisioningDataChanged();\r
} else {\r
try {\r
// Only the active POD sends notifications\r
boolean active = SynchronizerTask.getSynchronizer().isActive();\r
- boolean b = jo.getBoolean("failed");\r
- if (active && !b) {\r
+ boolean bool = jo.getBoolean("failed");\r
+ if (active && !bool) {\r
// Notify all nodes to reset the subscription\r
- SubscriberNotifyThread t = new SubscriberNotifyThread();\r
- t.resetSubscription(subid);\r
- t.start();\r
+ SubscriberNotifyThread thread = new SubscriberNotifyThread();\r
+ thread.resetSubscription(subid);\r
+ thread.start();\r
}\r
// send response\r
elr.setResult(HttpServletResponse.SC_ACCEPTED);\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
+ 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
+ String url = String.format(URL_TEMPLATE, nodename, subid);\r
+ urls.add(url);\r
}\r
}\r
\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