diff options
author | egernug <gerard.nugent@est.tech> | 2019-05-29 16:13:44 +0000 |
---|---|---|
committer | egernug <gerard.nugent@est.tech> | 2019-05-29 16:13:44 +0000 |
commit | 9c6f3aa2db3c3bc632038f69ff680f48b5f28ec2 (patch) | |
tree | 4a9db197aaa875983ef2994c778f9cf0771b087a /datarouter-prov/src/main/java | |
parent | 3ebd2534167e73426d2b19efb05eaf9892f6f9d6 (diff) |
Remove major and minor code smells in dr-prov
Change-Id: I547b757719131447c055604672896452fdbc10e5
Issue-ID: DMAAP-1195
Signed-off-by: egernug <gerard.nugent@est.tech>
Diffstat (limited to 'datarouter-prov/src/main/java')
13 files changed, 272 insertions, 301 deletions
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java index 66a7c360..7475b6b9 100755 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java @@ -132,6 +132,32 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { private static final String DEFAULT_PROVSRVR_NAME = "dmaap-dr-prov"; private static final String STATIC_ROUTING_NODES = ""; //Adding new param for static Routing - Rally:US664862-1610 + //Common Errors + public static final String MISSING_ON_BEHALF = "Missing X-DMAAP-DR-ON-BEHALF-OF header."; + public static final String MISSING_FEED = "Missing or bad feed number."; + public static final String POLICY_ENGINE = "Policy Engine disallows access."; + public static final String UNAUTHORIZED = "Unauthorized."; + public static final String BAD_SUB = "Missing or bad subscription number."; + public static final String BAD_JSON = "Badly formed JSON"; + public static final String BAD_URL = "Bad URL."; + + public static final String API = "/api/"; + public static final String LOGS = "/logs/"; + public static final String TEXT_CT = "text/plain"; + public static final String INGRESS = "/ingress/"; + public static final String EGRESS = "/egress/"; + public static final String NETWORK = "/network/"; + public static final String GROUPID = "groupid"; + public static final String FEEDID = "feedid"; + public static final String FEEDIDS = "feedids"; + public static final String SUBID = "subid"; + public static final String EVENT_TYPE = "eventType"; + public static final String OUTPUT_TYPE = "output_type"; + public static final String START_TIME = "start_time"; + public static final String END_TIME = "end_time"; + public static final String REASON_SQL = "reasonSQL"; + + /** * A boolean to trigger one time "provisioning changed" event on startup */ @@ -285,7 +311,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { try { thishost = InetAddress.getLocalHost(); loopback = InetAddress.getLoopbackAddress(); - //checkHttpsRelaxation(); //Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. } catch (UnknownHostException e) { intlogger.info("BaseServlet.init: " + e.getMessage(), e); } @@ -590,26 +615,6 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { } } - /** - * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. Check if HTTPS Relexaction is enabled - * - * @author vs215k - **/ - private void checkHttpsRelaxation() { - if (!mailSendFlag) { - Properties p = (new DB()).getProperties(); - intlogger.info("HTTPS relaxation: " + p.get("org.onap.dmaap.datarouter.provserver.https.relaxation")); - - if (p.get("org.onap.dmaap.datarouter.provserver.https.relaxation").equals("true")) { - try { - notifyPSTeam(p.get("org.onap.dmaap.datarouter.provserver.https.relax.notify").toString()); - } catch (Exception e) { - intlogger.warn("Exception: " + e.getMessage(), e); - } - } - mailSendFlag = true; - } - } /** * Data Router Subscriber HTTPS Relaxation feature USERSTORYID:US674047. @@ -646,7 +651,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { mp.addBodyPart(htmlPart); msg.setContent(mp); - System.out.println(mailprops.get("com.att.dmaap.datarouter.mail.body").toString() + intlogger.info(mailprops.get("com.att.dmaap.datarouter.mail.body").toString() .replace("[SERVER]", InetAddress.getLocalHost().getHostName())); Transport.send(msg); @@ -809,7 +814,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { private static boolean getBoolean(Map<String, String> map, String name) { String s = map.get(name); - return (s != null) && s.equalsIgnoreCase("true"); + return (s != null) && "true".equalsIgnoreCase(s); } private static String getString(Map<String, String> map, String name, String dflt) { @@ -1088,7 +1093,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { default: action = "*"; } - if (aafInstance == null || aafInstance.equals("")) { + if (aafInstance == null || "".equals(aafInstance)) { aafInstance = props.getProperty(AAF_INSTANCE, "org.onap.dmaap-dr.NoInstanceDefined"); } return type + "|" + aafInstance + "|" + action; @@ -1136,7 +1141,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider { default: action = "*"; } - if (aafInstance == null || aafInstance.equals("")) { + if (aafInstance == null || "".equals(aafInstance)) { aafInstance = props.getProperty(AAF_INSTANCE, "org.onap.dmaap-dr.NoInstanceDefined"); } return type + "|" + aafInstance + "|" + action; diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java index 058c7621..960d5094 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java @@ -109,8 +109,8 @@ public class DRFeedsServlet extends ProxyServlet { } // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?) String path = req.getRequestURI(); - if (path != null && !path.equals("/")) { - message = "Bad URL."; + if (path != null && !"/".equals(path)) { + message = BAD_URL; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_NOT_FOUND); eventlogger.error(elr.toString()); @@ -120,7 +120,7 @@ public class DRFeedsServlet extends ProxyServlet { // Check with the Authorizer AuthorizationResponse aresp = authz.decide(req); if (!aresp.isAuthorized()) { - message = "Policy Engine disallows access."; + message = POLICY_ENGINE; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); @@ -236,8 +236,8 @@ public class DRFeedsServlet extends ProxyServlet { } // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?) String path = req.getRequestURI(); - if (path != null && !path.equals("/")) { - message = "Bad URL."; + if (path != null && !"/".equals(path)) { + message = BAD_URL; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_NOT_FOUND); eventlogger.error(elr.toString()); @@ -247,7 +247,7 @@ public class DRFeedsServlet extends ProxyServlet { // check content type is FEED_CONTENT_TYPE, version 1.0 ContentHeader ch = getContentHeader(req); String ver = ch.getAttribute("version"); - if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) { + if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) { message = "Incorrect content-type"; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); @@ -257,7 +257,7 @@ public class DRFeedsServlet extends ProxyServlet { } JSONObject jo = getJSONfromInput(req); if (jo == null) { - message = "Badly formed JSON"; + message = BAD_JSON; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -295,11 +295,11 @@ public class DRFeedsServlet extends ProxyServlet { */ String aafInstance = feed.getAafInstance(); if (Boolean.parseBoolean(isCadiEnabled)) { - if ((aafInstance == null || aafInstance.equals("") || (aafInstance.equalsIgnoreCase("legacy")) && req.getHeader(EXCLUDE_AAF_HEADER).equalsIgnoreCase("true"))) { + if ((aafInstance == null || "".equals(aafInstance) || ("legacy".equalsIgnoreCase(aafInstance)) && "true".equalsIgnoreCase(req.getHeader(EXCLUDE_AAF_HEADER)))) { // Check with the Authorizer AuthorizationResponse aresp = authz.decide(req); if (!aresp.isAuthorized()) { - message = "Policy Engine disallows access."; + message = POLICY_ENGINE; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); @@ -307,7 +307,7 @@ public class DRFeedsServlet extends ProxyServlet { return; } } else { - if (req.getHeader(EXCLUDE_AAF_HEADER).equalsIgnoreCase("true")) { + if ("true".equalsIgnoreCase(req.getHeader(EXCLUDE_AAF_HEADER))) { message = "DRFeedsServlet.doPost() -Invalid request exclude_AAF should not be true if passing AAF_Instance value= " + aafInstance; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_FORBIDDEN); @@ -329,7 +329,7 @@ public class DRFeedsServlet extends ProxyServlet { } else { AuthorizationResponse aresp = authz.decide(req); if (!aresp.isAuthorized()) { - message = "Policy Engine disallows access."; + message = POLICY_ENGINE; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java index 4fc0b7fa..e1938cd8 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java @@ -82,7 +82,7 @@ public class FeedServlet extends ProxyServlet { } String bhdr = req.getHeader(BEHALF_HEADER); if (bhdr == null) { - message = "Missing "+BEHALF_HEADER+" header."; + message = MISSING_ON_BEHALF; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -91,7 +91,7 @@ public class FeedServlet extends ProxyServlet { } int feedid = getIdFromPath(req); if (feedid < 0) { - message = "Missing or bad feed number."; + message = MISSING_FEED; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -100,7 +100,7 @@ public class FeedServlet extends ProxyServlet { } Feed feed = Feed.getFeedById(feedid); if (feed == null || feed.isDeleted()) { - message = "Missing or bad feed number."; + message = MISSING_FEED; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_NOT_FOUND); eventlogger.error(elr.toString()); @@ -113,10 +113,10 @@ public class FeedServlet extends ProxyServlet { * CADI code - check on permissions based on Legacy/AAF users to allow to delete/remove feed */ String aafInstance = feed.getAafInstance(); - if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) { + if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) { AuthorizationResponse aresp = authz.decide(req); if (! aresp.isAuthorized()) { - message = "Policy Engine disallows access."; + message = POLICY_ENGINE; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); @@ -183,7 +183,7 @@ public class FeedServlet extends ProxyServlet { } String bhdr = req.getHeader(BEHALF_HEADER); if (bhdr == null) { - message = "Missing "+BEHALF_HEADER+" header."; + message = MISSING_ON_BEHALF; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -192,7 +192,7 @@ public class FeedServlet extends ProxyServlet { } int feedid = getIdFromPath(req); if (feedid < 0) { - message = "Missing or bad feed number."; + message = MISSING_FEED; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -201,7 +201,7 @@ public class FeedServlet extends ProxyServlet { } Feed feed = Feed.getFeedById(feedid); if (feed == null || feed.isDeleted()) { - message = "Missing or bad feed number."; + message = MISSING_FEED; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_NOT_FOUND); eventlogger.error(elr.toString()); @@ -211,7 +211,7 @@ public class FeedServlet extends ProxyServlet { // Check with the Authorizer AuthorizationResponse aresp = authz.decide(req); if (! aresp.isAuthorized()) { - message = "Policy Engine disallows access."; + message = POLICY_ENGINE; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); @@ -259,7 +259,7 @@ public class FeedServlet extends ProxyServlet { } String bhdr = req.getHeader(BEHALF_HEADER); if (bhdr == null) { - message = "Missing "+BEHALF_HEADER+" header."; + message = MISSING_ON_BEHALF; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -268,7 +268,7 @@ public class FeedServlet extends ProxyServlet { } int feedid = getIdFromPath(req); if (feedid < 0) { - message = "Missing or bad feed number."; + message = MISSING_FEED; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -277,7 +277,7 @@ public class FeedServlet extends ProxyServlet { } Feed oldFeed = Feed.getFeedById(feedid); if (oldFeed == null || oldFeed.isDeleted()) { - message = "Missing or bad feed number."; + message = MISSING_FEED; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_NOT_FOUND); eventlogger.error(elr.toString()); @@ -287,7 +287,7 @@ public class FeedServlet extends ProxyServlet { // check content type is FEED_CONTENT_TYPE, version 1.0 ContentHeader ch = getContentHeader(req); String ver = ch.getAttribute("version"); - if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) { + if (!ch.getType().equals(FEED_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) { message = "Incorrect content-type"; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); @@ -297,7 +297,7 @@ public class FeedServlet extends ProxyServlet { } JSONObject jo = getJSONfromInput(req); if (jo == null) { - message = "Badly formed JSON"; + message = BAD_JSON; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -355,11 +355,11 @@ public class FeedServlet extends ProxyServlet { * CADI code - check on permissions based on Legacy/AAF users to allow feed edit/update/modify */ String aafInstance = feed.getAafInstance(); - if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) { + if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) { // Check with the Authorizer AuthorizationResponse aresp = authz.decide(req); if (!aresp.isAuthorized()) { - message = "Policy Engine disallows access."; + message = POLICY_ENGINE; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java index 5cd54811..544a4800 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/GroupServlet.java @@ -91,7 +91,7 @@ public class GroupServlet extends ProxyServlet { // Check with the Authorizer /*AuthorizationResponse aresp = authz.decide(req); if (! aresp.isAuthorized()) { - message = "Policy Engine disallows access."; + message = POLICY_ENGINE; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); @@ -135,16 +135,6 @@ public class GroupServlet extends ProxyServlet { eventlogger.error("PROV0121 GroupServlet.doGet: " + ioe.getMessage(), ioe); } - // Display a list of Groups - /*Collection<Group> list = Group.getGroupById(groupid); - String t = JSONUtilities.createJSONArray(list); - - // send response - elr.setResult(HttpServletResponse.SC_OK); - eventlogger.info(elr.toString()); - resp.setStatus(HttpServletResponse.SC_OK); - resp.setContentType(GROUPLIST_CONTENT_TYPE); - resp.getOutputStream().print(t);*/ } /** * PUT on the <GROUPS> -- not supported. @@ -191,20 +181,11 @@ public class GroupServlet extends ProxyServlet { sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, message, eventlogger); return; } - // Check with the Authorizer - /*AuthorizationResponse aresp = authz.decide(req); - if (! aresp.isAuthorized()) { - message = "Policy Engine disallows access."; - elr.setMessage(message); - elr.setResult(HttpServletResponse.SC_FORBIDDEN); - eventlogger.error(elr.toString()); - resp.sendError(HttpServletResponse.SC_FORBIDDEN, message); - return; - }*/ + // check content type is SUB_CONTENT_TYPE, version 1.0 ContentHeader ch = getContentHeader(req); String ver = ch.getAttribute("version"); - if (!ch.getType().equals(GROUP_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) { + if (!ch.getType().equals(GROUP_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) { message = "Incorrect content-type"; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); @@ -214,7 +195,7 @@ public class GroupServlet extends ProxyServlet { } JSONObject jo = getJSONfromInput(req); if (jo == null) { - message = "Badly formed JSON"; + message = BAD_JSON; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -292,34 +273,6 @@ public class GroupServlet extends ProxyServlet { sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger); return; } - /*int feedid = getIdFromPath(req); - if (feedid < 0) { - message = "Missing or bad feed number."; - elr.setMessage(message); - elr.setResult(HttpServletResponse.SC_BAD_REQUEST); - eventlogger.info(elr.toString()); - resp.sendError(HttpServletResponse.SC_BAD_REQUEST, message); - return; - } - Feed feed = Feed.getFeedById(feedid); - if (feed == null || feed.isDeleted()) { - message = "Missing or bad feed number."; - elr.setMessage(message); - elr.setResult(HttpServletResponse.SC_NOT_FOUND); - eventlogger.info(elr.toString()); - resp.sendError(HttpServletResponse.SC_NOT_FOUND, message); - return; - }*/ - // Check with the Authorizer - /*AuthorizationResponse aresp = authz.decide(req); - if (! aresp.isAuthorized()) { - message = "Policy Engine disallows access."; - elr.setMessage(message); - elr.setResult(HttpServletResponse.SC_FORBIDDEN); - eventlogger.info(elr.toString()); - resp.sendError(HttpServletResponse.SC_FORBIDDEN, message); - return; - }*/ // check content type is SUB_CONTENT_TYPE, version 1.0 ContentHeader ch = getContentHeader(req); @@ -335,7 +288,7 @@ public class GroupServlet extends ProxyServlet { } JSONObject jo = getJSONfromInput(req); if (jo == null) { - message = "Badly formed JSON"; + message = BAD_JSON; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java index 005acadb..8ae9fa20 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java @@ -156,6 +156,7 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send @SuppressWarnings("serial") public class InternalServlet extends ProxyServlet { + private static final Object lock = new Object(); private static Integer logseq = 0; // another piece of info to make log spool file names unique //Adding EELF Logger Rally:US664892 @@ -174,15 +175,15 @@ public class InternalServlet extends ProxyServlet { eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + ""); EventLogRecord elr = new EventLogRecord(req); if (!isAuthorizedForInternal(req)) { - elr.setMessage("Unauthorized."); + elr.setMessage(UNAUTHORIZED); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); - sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger); + sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger); return; } String path = req.getPathInfo(); - if (path.startsWith("/api/")) { + if (path.startsWith(API)) { if (isProxyOK(req) && isProxyServer()) { super.doDelete(req, resp); return; @@ -207,7 +208,7 @@ public class InternalServlet extends ProxyServlet { } } } - sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger); + sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger); } finally { eelfLogger.info(EelfMsgs.EXIT); } @@ -225,7 +226,7 @@ public class InternalServlet extends ProxyServlet { eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + ""); String path = req.getPathInfo(); Properties props = (new DB()).getProperties(); - if (path.equals("/halt") && !req.isSecure()) { + if ("/halt".equals(path) && !req.isSecure()) { // request to halt the server - can ONLY come from localhost String remote = req.getRemoteAddr(); if (remote.equals(props.getProperty("org.onap.dmaap.datarouter.provserver.localhost"))) { @@ -241,20 +242,20 @@ public class InternalServlet extends ProxyServlet { EventLogRecord elr = new EventLogRecord(req); if (!isAuthorizedForInternal(req)) { - elr.setMessage("Unauthorized."); + elr.setMessage(UNAUTHORIZED); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); - sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger); + sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger); return; } - if (path.equals("/fetchProv") && !req.isSecure()) { + if ("/fetchProv".equals(path) && !req.isSecure()) { // if request came from active_pod or standby_pod and it is not us, reload prov data SynchronizerTask s = SynchronizerTask.getSynchronizer(); s.doFetch(); resp.setStatus(HttpServletResponse.SC_OK); return; } - if (path.equals("/prov")) { + if ("/prov".equals(path)) { if (isProxyOK(req) && isProxyServer()) { if (super.doGetWithFallback(req, resp)) { return; @@ -272,7 +273,7 @@ public class InternalServlet extends ProxyServlet { } return; } - if (path.equals("/logs") || path.equals("/logs/")) { + if ("/logs".equals(path) || LOGS.equals(path)) { resp.setStatus(HttpServletResponse.SC_OK); resp.setContentType("application/json"); try { @@ -282,14 +283,14 @@ public class InternalServlet extends ProxyServlet { } return; } - if (path.startsWith("/logs/")) { + if (path.startsWith(LOGS)) { String logdir = props.getProperty("org.onap.dmaap.datarouter.provserver.accesslog.dir"); String logfile = path.substring(6); if (logdir != null && logfile != null && logfile.indexOf('/') < 0) { File log = new File(logdir + "/" + logfile); if (log.exists() && log.isFile()) { resp.setStatus(HttpServletResponse.SC_OK); - resp.setContentType("text/plain"); + resp.setContentType(TEXT_CT); Path logpath = Paths.get(log.getAbsolutePath()); try { Files.copy(logpath, resp.getOutputStream()); @@ -302,7 +303,7 @@ public class InternalServlet extends ProxyServlet { sendResponseError(resp, HttpServletResponse.SC_NO_CONTENT, "No file.", eventlogger); return; } - if (path.startsWith("/api/")) { + if (path.startsWith(API)) { if (isProxyOK(req) && isProxyServer()) { super.doGet(req, resp); return; @@ -312,7 +313,7 @@ public class InternalServlet extends ProxyServlet { Parameters param = Parameters.getParameter(key); if (param != null) { resp.setStatus(HttpServletResponse.SC_OK); - resp.setContentType("text/plain"); + resp.setContentType(TEXT_CT); try { resp.getOutputStream().print(param.getValue() + "\n"); } catch (IOException ioe) { @@ -322,11 +323,11 @@ public class InternalServlet extends ProxyServlet { } } } - if (path.equals("/drlogs") || path.equals("/drlogs/")) { + if ("/drlogs".equals(path) || "/drlogs/".equals(path)) { // Special POD <=> POD API to determine what log file records are loaded here LogfileLoader lfl = LogfileLoader.getLoader(); resp.setStatus(HttpServletResponse.SC_OK); - resp.setContentType("text/plain"); + resp.setContentType(TEXT_CT); try { resp.getOutputStream().print(lfl.getBitSet().toString()); } catch (IOException ioe) { @@ -334,7 +335,7 @@ public class InternalServlet extends ProxyServlet { } return; } - sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger); + sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger); } finally { eelfLogger.info(EelfMsgs.EXIT); } @@ -352,14 +353,14 @@ public class InternalServlet extends ProxyServlet { eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + ""); EventLogRecord elr = new EventLogRecord(req); if (!isAuthorizedForInternal(req)) { - elr.setMessage("Unauthorized."); + elr.setMessage(UNAUTHORIZED); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); - sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger); + sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger); return; } String path = req.getPathInfo(); - if (path.startsWith("/api/")) { + if (path.startsWith(API)) { if (isProxyOK(req) && isProxyServer()) { super.doPut(req, resp); return; @@ -386,7 +387,7 @@ public class InternalServlet extends ProxyServlet { } } } - sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger); + sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger); } finally { eelfLogger.info(EelfMsgs.EXIT); } @@ -405,15 +406,15 @@ public class InternalServlet extends ProxyServlet { eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER)); EventLogRecord elr = new EventLogRecord(req); if (!isAuthorizedForInternal(req)) { - elr.setMessage("Unauthorized."); + elr.setMessage(UNAUTHORIZED); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); - sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger); + sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger); return; } String path = req.getPathInfo(); - if (path.startsWith("/api/")) { + if (path.startsWith(API)) { if (isProxyOK(req) && isProxyServer()) { super.doPost(req, resp); return; @@ -441,9 +442,9 @@ public class InternalServlet extends ProxyServlet { } } - if (path.equals("/logs") || path.equals("/logs/")) { + if ("/logs".equals(path) || LOGS.equals(path)) { String ctype = req.getHeader("Content-Type"); - if (ctype == null || !ctype.equals("text/plain")) { + if (ctype == null || !TEXT_CT.equals(ctype)) { elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); elr.setMessage("Bad media type: " + ctype); resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); @@ -459,7 +460,7 @@ public class InternalServlet extends ProxyServlet { } String encoding = req.getHeader("Content-Encoding"); if (encoding != null) { - if (encoding.trim().equals("gzip")) { + if ("gzip".equals(encoding.trim())) { spoolname += ".gz"; } else { elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); @@ -506,10 +507,10 @@ public class InternalServlet extends ProxyServlet { return; } - if (path.equals("/drlogs") || path.equals("/drlogs/")) { + if ("/drlogs".equals(path) || "/drlogs/".equals(path)) { // Receive post request and generate log entries String ctype = req.getHeader("Content-Type"); - if (ctype == null || !ctype.equals("text/plain")) { + if (ctype == null || !TEXT_CT.equals(ctype)) { elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); elr.setMessage("Bad media type: " + ctype); resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE); @@ -526,7 +527,7 @@ public class InternalServlet extends ProxyServlet { RLEBitSet bs = new RLEBitSet(bos.toString()); // The set of records to retrieve elr.setResult(HttpServletResponse.SC_OK); resp.setStatus(HttpServletResponse.SC_OK); - resp.setContentType("text/plain"); + resp.setContentType(TEXT_CT); LogRecord.printLogRecords(resp.getOutputStream(), bs); eventlogger.info(elr.toString()); } catch (IOException ioe) { @@ -536,7 +537,7 @@ public class InternalServlet extends ProxyServlet { } elr.setResult(HttpServletResponse.SC_NOT_FOUND); - sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger); + sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger); eventlogger.error(elr.toString()); } finally { eelfLogger.info(EelfMsgs.EXIT); diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java index 74441dac..762ab4e5 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java @@ -68,6 +68,12 @@ public class LogServlet extends BaseServlet { private static final long TWENTYFOUR_HOURS = (24 * 60 * 60 * 1000L);
private static final String FMT_1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";
private static final String FMT_2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
+ private static final String PUBLISHSQL = "publishSQL";
+ private static final String STATUSSQL = "statusSQL";
+ private static final String RESULTSQL = "resultSQL";
+ private static final String FILENAMESQL = "filenameSQL";
+ private static final String TIMESQL = "timeSQL";
+ private static final String LOG_RECORDSSQL = "select * from LOG_RECORDS where FEEDID = ";
private final boolean isfeedlog;
@@ -275,7 +281,7 @@ public class LogServlet extends BaseServlet { Map<String, String> map = new HashMap<>();
String s = req.getParameter("type");
if (s != null) {
- if (s.equals("pub") || s.equals("del") || s.equals("exp")) {
+ if ("pub".equals(s) || "del".equals(s) || "exp".equals(s)) {
map.put("type", s);
} else {
map.put("err", "bad type");
@@ -284,11 +290,11 @@ public class LogServlet extends BaseServlet { } else {
map.put("type", "all");
}
- map.put("publishSQL", "");
- map.put("statusSQL", "");
- map.put("resultSQL", "");
- map.put("reasonSQL", "");
- map.put("filenameSQL", "");
+ map.put(PUBLISHSQL, "");
+ map.put(STATUSSQL, "");
+ map.put(RESULTSQL, "");
+ map.put(REASON_SQL, "");
+ map.put(FILENAMESQL, "");
s = req.getParameter("publishId");
if (s != null) {
@@ -296,22 +302,22 @@ public class LogServlet extends BaseServlet { map.put("err", "bad publishId");
return map;
}
- map.put("publishSQL", " AND PUBLISH_ID = '"+s+"'");
+ map.put(PUBLISHSQL, " AND PUBLISH_ID = '"+s+"'");
}
s = req.getParameter("filename");
if (s != null) {
- map.put("filenameSQL", " AND FILENAME = '"+s+"'");
+ map.put(FILENAMESQL, " AND FILENAME = '"+s+"'");
}
s = req.getParameter("statusCode");
if (s != null) {
String sql = null;
- if (s.equals("success")) {
+ if ("success".equals(s)) {
sql = " AND STATUS >= 200 AND STATUS < 300";
- } else if (s.equals("redirect")) {
+ } else if ("redirect".equals(s)) {
sql = " AND STATUS >= 300 AND STATUS < 400";
- } else if (s.equals("failure")) {
+ } else if ("failure".equals(s)) {
sql = " AND STATUS >= 400";
} else {
try {
@@ -325,21 +331,21 @@ public class LogServlet extends BaseServlet { map.put("err", "bad statusCode");
return map;
}
- map.put("statusSQL", sql);
- map.put("resultSQL", sql.replaceAll("STATUS", "RESULT"));
+ map.put(STATUSSQL, sql);
+ map.put(RESULTSQL, sql.replaceAll("STATUS", "RESULT"));
}
s = req.getParameter("expiryReason");
if (s != null) {
map.put("type", "exp");
- if (s.equals("notRetryable")) {
- map.put("reasonSQL", " AND REASON = 'notRetryable'");
- } else if (s.equals("retriesExhausted")) {
- map.put("reasonSQL", " AND REASON = 'retriesExhausted'");
- } else if (s.equals("diskFull")) {
- map.put("reasonSQL", " AND REASON = 'diskFull'");
- } else if (s.equals("other")) {
- map.put("reasonSQL", " AND REASON = 'other'");
+ if ("notRetryable".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'notRetryable'");
+ } else if ("retriesExhausted".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'retriesExhausted'");
+ } else if ("diskFull".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'diskFull'");
+ } else if ("other".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'other'");
} else {
map.put("err", "bad expiryReason");
return map;
@@ -364,7 +370,7 @@ public class LogServlet extends BaseServlet { } else if (etime == 0) {
etime = stime + TWENTYFOUR_HOURS;
}
- map.put("timeSQL", String.format(" AND EVENT_TIME >= %d AND EVENT_TIME <= %d", stime, etime));
+ map.put(TIMESQL, String.format(" AND EVENT_TIME >= %d AND EVENT_TIME <= %d", stime, etime));
return map;
}
private long getTimeFromParam(final String s) {
@@ -381,8 +387,7 @@ public class LogServlet extends BaseServlet { }
try {
// Also allow a long (in ms); useful for testing
- long n = Long.parseLong(s);
- return n;
+ return Long.parseLong(s);
} catch (NumberFormatException numberFormatException) {
intlogger.error("Exception in getting Time :- "+numberFormatException.getMessage(),numberFormatException);
}
@@ -392,51 +397,51 @@ public class LogServlet extends BaseServlet { private void getPublishRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {
String type = map.get("type");
- if (type.equals("all") || type.equals("pub")) {
- String sql = "select * from LOG_RECORDS where FEEDID = "+feedid
+ if ("all".equals(type) || "pub".equals(type)) {
+ String sql = LOG_RECORDSSQL+feedid
+ " AND TYPE = 'pub'"
- + map.get("timeSQL") + map.get("publishSQL") + map.get("statusSQL") + map.get("filenameSQL");
+ + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(STATUSSQL) + map.get(FILENAMESQL);
getRecordsForSQL(sql, rh);
}
}
private void getDeliveryRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {
String type = map.get("type");
- if (type.equals("all") || type.equals("del")) {
- String sql = "select * from LOG_RECORDS where FEEDID = "+feedid
+ if ("all".equals(type) || "del".equals(type)) {
+ String sql = LOG_RECORDSSQL+feedid
+ " AND TYPE = 'del'"
- + map.get("timeSQL") + map.get("publishSQL") + map.get("resultSQL");
+ + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(RESULTSQL);
getRecordsForSQL(sql, rh);
}
}
private void getDeliveryRecordsForSubscription(int subid, RowHandler rh, Map<String, String> map) {
String type = map.get("type");
- if (type.equals("all") || type.equals("del")) {
+ if ("all".equals(type) || "del".equals(type)) {
String sql = "select * from LOG_RECORDS where DELIVERY_SUBID = "+subid
+ " AND TYPE = 'del'"
- + map.get("timeSQL") + map.get("publishSQL") + map.get("resultSQL");
+ + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(RESULTSQL);
getRecordsForSQL(sql, rh);
}
}
private void getExpiryRecordsForFeed(int feedid, RowHandler rh, Map<String, String> map) {
String type = map.get("type");
- if (type.equals("all") || type.equals("exp")) {
- String st = map.get("statusSQL");
+ if ("all".equals(type) || "exp".equals(type)) {
+ String st = map.get(STATUSSQL);
if (st == null || st.length() == 0) {
- String sql = "select * from LOG_RECORDS where FEEDID = "+feedid
+ String sql = LOG_RECORDSSQL+feedid
+ " AND TYPE = 'exp'"
- + map.get("timeSQL") + map.get("publishSQL") + map.get("reasonSQL");
+ + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(REASON_SQL);
getRecordsForSQL(sql, rh);
}
}
}
private void getExpiryRecordsForSubscription(int subid, RowHandler rh, Map<String, String> map) {
String type = map.get("type");
- if (type.equals("all") || type.equals("exp")) {
- String st = map.get("statusSQL");
+ if ("all".equals(type) || "exp".equals(type)) {
+ String st = map.get(STATUSSQL);
if (st == null || st.length() == 0) {
String sql = "select * from LOG_RECORDS where DELIVERY_SUBID = "+subid
+ " AND TYPE = 'exp'"
- + map.get("timeSQL") + map.get("publishSQL") + map.get("reasonSQL");
+ + map.get(TIMESQL) + map.get(PUBLISHSQL) + map.get(REASON_SQL);
getRecordsForSQL(sql, rh);
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java index 6177df28..8afa18a1 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/Poker.java @@ -66,6 +66,7 @@ public class Poker extends TimerTask { private static final String POKE_URL_TEMPLATE = "http://%s/internal/fetchProv";
private static final Object lock = new Object();
+ private static final String CARRIAGE_RETURN = "\n],\n";
/**
* This is a singleton -- there is only one Poker object in the server
@@ -77,6 +78,7 @@ public class Poker extends TimerTask { private EELFLogger logger;
private String provString;
+
private Poker() {
timer1 = timer2 = 0;
Timer rolex = new Timer();
@@ -215,7 +217,7 @@ public class Poker extends TimerTask { sb.append(f.asJSONObject().toString());
pfx = ",\n";
}
- sb.append("\n],\n");
+ sb.append(CARRIAGE_RETURN);
//Append groups to the string - Rally:US708115 - 1610
pfx = "\n";
@@ -225,7 +227,7 @@ public class Poker extends TimerTask { sb.append(s.asJSONObject().toString());
pfx = ",\n";
}
- sb.append("\n],\n");
+ sb.append(CARRIAGE_RETURN);
// Append Subscriptions to the string
pfx = "\n";
@@ -237,13 +239,13 @@ public class Poker extends TimerTask { }
pfx = ",\n";
}
- sb.append("\n],\n");
+ sb.append(CARRIAGE_RETURN);
// Append Parameters to the string
pfx = "\n";
sb.append("\"parameters\": {");
Map<String, String> props = Parameters.getParameters();
- Set<String> ivals = new HashSet<String>();
+ Set<String> ivals = new HashSet<>();
String intv = props.get("_INT_VALUES");
if (intv != null) {
ivals.addAll(Arrays.asList(intv.split("\\|")));
@@ -280,7 +282,7 @@ public class Poker extends TimerTask { sb.append(in.asJSONObject().toString());
pfx = ",\n";
}
- sb.append("\n],\n");
+ sb.append(CARRIAGE_RETURN);
pfx = "\n";
sb.append("\"egress\": {");
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java index 96dae255..77917771 100755 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/ProxyServlet.java @@ -130,7 +130,7 @@ public class ProxyServlet extends BaseServlet { if (t != null) { t = t.replaceAll("&", "&"); for (String s : t.split("&")) { - if (s.equals("noproxy") || s.startsWith("noproxy=")) { + if ("noproxy".equals(s) || s.startsWith("noproxy=")) { return false; } } @@ -234,7 +234,7 @@ public class ProxyServlet extends BaseServlet { // Copy request headers and request body copyRequestHeaders(req, proxy); - if (method.equals("POST") || method.equals("PUT")) { + if ("POST".equals(method) || "PUT".equals(method)) { BasicHttpEntity body = new BasicHttpEntity(); body.setContent(req.getInputStream()); body.setContentLength(-1); // -1 = unknown @@ -279,7 +279,7 @@ public class ProxyServlet extends BaseServlet { List<String> list = Collections.list(from.getHeaderNames()); for (String name : list) { // Proxy code will add this one - if (!name.equalsIgnoreCase("Content-Length")) { + if (!"Content-Length".equalsIgnoreCase(name)) { to.addHeader(name, from.getHeader(name)); } } @@ -288,7 +288,7 @@ public class ProxyServlet extends BaseServlet { private void copyResponseHeaders(HttpResponse from, HttpServletResponse to) { for (Header hdr : from.getAllHeaders()) { // Don't copy Date: our Jetty will add another Date header - if (!hdr.getName().equals("Date")) { + if (!"Date".equals(hdr.getName())) { to.addHeader(hdr.getName(), hdr.getValue()); } } diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java index 176cef55..383798fb 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/RouteServlet.java @@ -129,6 +129,7 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send */
@SuppressWarnings("serial")
public class RouteServlet extends ProxyServlet {
+
/**
* DELETE route table entries by deleting part of the route table tree.
*/
@@ -136,10 +137,10 @@ public class RouteServlet extends ProxyServlet { public void doDelete(HttpServletRequest req, HttpServletResponse resp) {
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
if (isProxyOK(req) && isProxyServer()) {
@@ -150,7 +151,7 @@ public class RouteServlet extends ProxyServlet { String path = req.getPathInfo();
String[] parts = path.substring(1).split("/");
Deleteable[] d = null;
- if (parts[0].equals("ingress")) {
+ if ("ingress".equals(parts[0])) {
if (parts.length == 4) {
// /internal/route/ingress/<feed>/<user>/<subnet>
try {
@@ -179,7 +180,7 @@ public class RouteServlet extends ProxyServlet { sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Invalid number of arguments in 'delete ingress' command.", eventlogger);
return;
}
- } else if (parts[0].equals("egress")) {
+ } else if ("egress".equals(parts[0])) {
if (parts.length == 2) {
// /internal/route/egress/<sub>
try {
@@ -198,7 +199,7 @@ public class RouteServlet extends ProxyServlet { sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Invalid number of arguments in 'delete egress' command.", eventlogger);
return;
}
- } else if (parts[0].equals("network")) {
+ } else if ("network".equals(parts[0])) {
if (parts.length == 3) {
// /internal/route/network/<from>/<to>
try {//
@@ -219,7 +220,7 @@ public class RouteServlet extends ProxyServlet { }
}
if (d == null) {
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
return;
}
boolean rv = true;
@@ -246,10 +247,10 @@ public class RouteServlet extends ProxyServlet { public void doGet(HttpServletRequest req, HttpServletResponse resp) {
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
if (isProxyOK(req) && isProxyServer()) {
@@ -260,14 +261,14 @@ public class RouteServlet extends ProxyServlet { String path = req.getPathInfo();
if (!path.endsWith("/"))
path += "/";
- if (!path.equals("/") && !path.equals("/ingress/") && !path.equals("/egress/") && !path.equals("/network/")) {
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ if (!"/".equals(path) && !INGRESS.equals(path) && !EGRESS.equals(path) && !NETWORK.equals(path)) {
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
return;
}
StringBuilder sb = new StringBuilder("{\n");
String px2 = "";
- if (path.equals("/") || path.equals("/ingress/")) {
+ if ("/".equals(path) || INGRESS.equals(path)) {
String pfx = "\n";
sb.append("\"ingress\": [");
for (IngressRoute in : IngressRoute.getAllIngressRoutes()) {
@@ -279,7 +280,7 @@ public class RouteServlet extends ProxyServlet { px2 = ",\n";
}
- if (path.equals("/") || path.equals("/egress/")) {
+ if ("/".equals(path) || EGRESS.equals(path)) {
String pfx = "\n";
sb.append(px2);
sb.append("\"egress\": {");
@@ -300,7 +301,7 @@ public class RouteServlet extends ProxyServlet { px2 = ",\n";
}
- if (path.equals("/") || path.equals("/network/")) {
+ if ("/".equals(path) || NETWORK.equals(path)) {
String pfx = "\n";
sb.append(px2);
sb.append("\"routing\": [");
@@ -327,13 +328,13 @@ public class RouteServlet extends ProxyServlet { public void doPut(HttpServletRequest req, HttpServletResponse resp) {
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, eventlogger);
}
/**
* POST - modify existing route table entries in the route table tree specified by the URL path.
@@ -342,10 +343,10 @@ public class RouteServlet extends ProxyServlet { public void doPost(HttpServletRequest req, HttpServletResponse resp) {
EventLogRecord elr = new EventLogRecord(req);
if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
+ elr.setMessage(UNAUTHORIZED);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, UNAUTHORIZED, eventlogger);
return;
}
if (isProxyOK(req) && isProxyServer()) {
@@ -354,7 +355,7 @@ public class RouteServlet extends ProxyServlet { }
String path = req.getPathInfo();
Insertable[] ins = null;
- if (path.startsWith("/ingress/")) {
+ if (path.startsWith(INGRESS)) {
// /internal/route/ingress/?feed=%s&user=%s&subnet=%s&nodepatt=%s
try {
// Although it probably doesn't make sense, you can install two identical routes in the IRT
@@ -374,7 +375,7 @@ public class RouteServlet extends ProxyServlet { sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments in 'add ingress' command.", intlogger);
return;
}
- } else if (path.startsWith("/egress/")) {
+ } else if (path.startsWith(EGRESS)) {
// /internal/route/egress/?sub=%s&node=%s
try {
int subid = Integer.parseInt(req.getParameter("sub"));
@@ -390,7 +391,7 @@ public class RouteServlet extends ProxyServlet { sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments in 'add egress' command.", intlogger);
return;
}
- } else if (path.startsWith("/network/")) {
+ } else if (path.startsWith(NETWORK)) {
// /internal/route/network/?from=%s&to=%s&via=%s
try {
String nfrom = req.getParameter("from");
@@ -418,7 +419,7 @@ public class RouteServlet extends ProxyServlet { }
}
if (ins == null) {
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", intlogger);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, BAD_URL, intlogger);
return;
}
boolean rv = true;
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java index 5fa7e169..9cbce0a8 100755 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/StatisticsServlet.java @@ -57,8 +57,9 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send public class StatisticsServlet extends BaseServlet {
private static final long TWENTYFOUR_HOURS = (24 * 60 * 60 * 1000L);
- private static final String fmt1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";
- private static final String fmt2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
+ private static final String FMT1 = "yyyy-MM-dd'T'HH:mm:ss'Z'";
+ private static final String FMT2 = "yyyy-MM-dd'T'HH:mm:ss.SSS'Z'";
+
/**
@@ -92,9 +93,8 @@ public class StatisticsServlet extends BaseServlet { resp.setContentType(LOGLIST_CONTENT_TYPE);
String outputType = "json";
- String feedids = null;
- if (req.getParameter("feedid") == null && req.getParameter("groupid") == null) {
+ if (req.getParameter(FEEDID) == null && req.getParameter(GROUPID) == null) {
try {
resp.getOutputStream().print("Invalid request, Feedid or Group ID is required.");
} catch (IOException ioe) {
@@ -102,69 +102,69 @@ public class StatisticsServlet extends BaseServlet { }
}
- if (req.getParameter("feedid") != null && req.getParameter("groupid") == null) {
- map.put("feedids", req.getParameter("feedid").replace("|", ",").toString());
+ if (req.getParameter(FEEDID) != null && req.getParameter(GROUPID) == null) {
+ map.put(FEEDIDS, req.getParameter(FEEDID).replace("|", ","));
}
- if (req.getParameter("groupid") != null && req.getParameter("feedid") == null) {
+ if (req.getParameter(GROUPID) != null && req.getParameter(FEEDID) == null) {
StringBuffer groupid1 = new StringBuffer();
try {
- groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter("groupid")));
- map.put("feedids", groupid1.toString());
+ groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter(GROUPID)));
+ map.put(FEEDIDS, groupid1.toString());
} catch (NumberFormatException | SQLException e) {
eventlogger.error("PROV0172 StatisticsServlet.doGet: " + e.getMessage(), e);
}
}
- if (req.getParameter("groupid") != null && req.getParameter("feedid") != null) {
+ if (req.getParameter(GROUPID) != null && req.getParameter(FEEDID) != null) {
StringBuffer groupid1 = new StringBuffer();
try {
- groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter("groupid")));
+ groupid1 = this.getFeedIdsByGroupId(Integer.parseInt(req.getParameter(GROUPID)));
groupid1.append(",");
- groupid1.append(req.getParameter("feedid").replace("|", ",").toString());
- map.put("feedids", groupid1.toString());
+ groupid1.append(req.getParameter(FEEDID).replace("|", ","));
+ map.put(FEEDIDS, groupid1.toString());
} catch (NumberFormatException | SQLException e) {
eventlogger.error("PROV0173 StatisticsServlet.doGet: " + e.getMessage(), e);
}
}
- if (req.getParameter("subid") != null && req.getParameter("feedid") != null) {
+ if (req.getParameter(SUBID) != null && req.getParameter(FEEDID) != null) {
StringBuffer subidstr = new StringBuffer();
subidstr.append("and e.DELIVERY_SUBID in(");
- subidstr.append(req.getParameter("subid").replace("|", ",").toString());
+ subidstr.append(req.getParameter(SUBID).replace("|", ","));
subidstr.append(")");
- map.put("subid", subidstr.toString());
+ map.put(SUBID, subidstr.toString());
}
- if (req.getParameter("subid") != null && req.getParameter("groupid") != null) {
+ if (req.getParameter(SUBID) != null && req.getParameter(GROUPID) != null) {
StringBuffer subidstr = new StringBuffer();
subidstr.append("and e.DELIVERY_SUBID in(");
- subidstr.append(req.getParameter("subid").replace("|", ",").toString());
+ subidstr.append(req.getParameter(SUBID).replace("|", ","));
subidstr.append(")");
- map.put("subid", subidstr.toString());
+ map.put(SUBID, subidstr.toString());
}
if (req.getParameter("type") != null) {
- map.put("eventType", req.getParameter("type").replace("|", ",").toString());
+ map.put(EVENT_TYPE, req.getParameter("type").replace("|", ","));
}
- if (req.getParameter("output_type") != null) {
- map.put("output_type", req.getParameter("output_type").toString());
+ if (req.getParameter(OUTPUT_TYPE) != null) {
+ map.put(OUTPUT_TYPE, req.getParameter(OUTPUT_TYPE));
}
- if (req.getParameter("start_time") != null) {
- map.put("start_time", req.getParameter("start_time").toString());
+ if (req.getParameter(START_TIME) != null) {
+ map.put(START_TIME, req.getParameter(START_TIME));
}
- if (req.getParameter("end_time") != null) {
- map.put("end_time", req.getParameter("end_time").toString());
+ if (req.getParameter(END_TIME) != null) {
+ map.put(END_TIME, req.getParameter(END_TIME));
}
if (req.getParameter("time") != null) {
- map.put("start_time", req.getParameter("time").toString());
- map.put("end_time", null);
+ map.put(START_TIME, req.getParameter("time"));
+ map.put(END_TIME, null);
}
- if (req.getParameter("output_type") != null) {
- outputType = req.getParameter("output_type");
+ if (req.getParameter(OUTPUT_TYPE) != null) {
+ outputType = req.getParameter(OUTPUT_TYPE);
}
try {
this.getRecordsForSQL(map, outputType, resp.getOutputStream(), resp);
@@ -225,7 +225,7 @@ public class StatisticsServlet extends BaseServlet { */
public void rsToJson(ResultSet rs, ServletOutputStream out) throws IOException, SQLException {
- String fields[] = {"FEEDNAME", "FEEDID", "FILES_PUBLISHED", "PUBLISH_LENGTH", "FILES_DELIVERED",
+ String[] fields = {"FEEDNAME", "FEEDID", "FILES_PUBLISHED", "PUBLISH_LENGTH", "FILES_DELIVERED",
"DELIVERED_LENGTH", "SUBSCRIBER_URL", "SUBID", "PUBLISH_TIME", "DELIVERY_TIME",
"AverageDelay"};
StringBuffer line = new StringBuffer();
@@ -258,7 +258,6 @@ public class StatisticsServlet extends BaseServlet { DB db = null;
Connection conn = null;
- //PreparedStatement prepareStatement = null;
ResultSet resultSet = null;
String sqlGoupid = null;
StringBuffer feedIds = new StringBuffer();
@@ -309,23 +308,23 @@ public class StatisticsServlet extends BaseServlet { String start_time = null;
String end_time = null;
String subid = " ";
- if (map.get("eventType") != null) {
- eventType = (String) map.get("eventType");
+ if (map.get(EVENT_TYPE) != null) {
+ eventType = map.get(EVENT_TYPE);
}
- if (map.get("feedids") != null) {
- feedids = (String) map.get("feedids");
+ if (map.get(FEEDIDS) != null) {
+ feedids = map.get(FEEDIDS);
}
- if (map.get("start_time") != null) {
- start_time = (String) map.get("start_time");
+ if (map.get(START_TIME) != null) {
+ start_time = map.get(START_TIME);
}
- if (map.get("end_time") != null) {
- end_time = (String) map.get("end_time");
+ if (map.get(END_TIME) != null) {
+ end_time = map.get(END_TIME);
}
if ("all".equalsIgnoreCase(eventType)) {
eventType = "PUB','DEL, EXP, PBF";
}
- if (map.get("subid") != null) {
- subid = (String) map.get("subid");
+ if (map.get(SUBID) != null) {
+ subid = map.get(SUBID);
}
eventlogger.info("Generating sql query to get Statistics resultset. ");
@@ -412,10 +411,10 @@ public class StatisticsServlet extends BaseServlet { }
private Map<String, String> buildMapFromRequest(HttpServletRequest req) {
- Map<String, String> map = new HashMap<String, String>();
+ Map<String, String> map = new HashMap<>();
String s = req.getParameter("type");
if (s != null) {
- if (s.equals("pub") || s.equals("del") || s.equals("exp")) {
+ if ("pub".equals(s) || "del".equals(s) || "exp".equals(s)) {
map.put("type", s);
} else {
map.put("err", "bad type");
@@ -427,7 +426,7 @@ public class StatisticsServlet extends BaseServlet { map.put("publishSQL", "");
map.put("statusSQL", "");
map.put("resultSQL", "");
- map.put("reasonSQL", "");
+ map.put(REASON_SQL, "");
s = req.getParameter("publishId");
if (s != null) {
@@ -441,11 +440,11 @@ public class StatisticsServlet extends BaseServlet { s = req.getParameter("statusCode");
if (s != null) {
String sql = null;
- if (s.equals("success")) {
+ if ("success".equals(s)) {
sql = " AND STATUS >= 200 AND STATUS < 300";
- } else if (s.equals("redirect")) {
+ } else if ("redirect".equals(s)) {
sql = " AND STATUS >= 300 AND STATUS < 400";
- } else if (s.equals("failure")) {
+ } else if ("failure".equals(s)) {
sql = " AND STATUS >= 400";
} else {
try {
@@ -467,14 +466,14 @@ public class StatisticsServlet extends BaseServlet { s = req.getParameter("expiryReason");
if (s != null) {
map.put("type", "exp");
- if (s.equals("notRetryable")) {
- map.put("reasonSQL", " AND REASON = 'notRetryable'");
- } else if (s.equals("retriesExhausted")) {
- map.put("reasonSQL", " AND REASON = 'retriesExhausted'");
- } else if (s.equals("diskFull")) {
- map.put("reasonSQL", " AND REASON = 'diskFull'");
- } else if (s.equals("other")) {
- map.put("reasonSQL", " AND REASON = 'other'");
+ if ("notRetryable".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'notRetryable'");
+ } else if ("retriesExhausted".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'retriesExhausted'");
+ } else if ("diskFull".equals(s)) {
+ map.put(REASON_SQL, " AND REASON = 'diskFull'");
+ } else if ("other".equals("other")) {
+ map.put(REASON_SQL, " AND REASON = 'other'");
} else {
map.put("err", "bad expiryReason");
return map;
@@ -509,7 +508,7 @@ public class StatisticsServlet extends BaseServlet { }
try {
// First, look for an RFC 3339 date
- String fmt = (s.indexOf('.') > 0) ? fmt2 : fmt1;
+ String fmt = (s.indexOf('.') > 0) ? FMT2 : FMT1;
SimpleDateFormat sdf = new SimpleDateFormat(fmt);
Date d = sdf.parse(s);
return d.getTime();
@@ -517,8 +516,7 @@ public class StatisticsServlet extends BaseServlet { }
try {
// Also allow a long (in ms); useful for testing
- long n = Long.parseLong(s);
- return n;
+ return Long.parseLong(s);
} catch (NumberFormatException e) {
}
intlogger.info("Error parsing time=" + s);
@@ -535,7 +533,7 @@ public class StatisticsServlet extends BaseServlet { DB db = new DB();
try (Connection conn = db.getConnection()) {
try (ResultSet rs = conn.prepareStatement(filterQuery).executeQuery()) {
- if (outputType.equals("csv")) {
+ if ("csv".equals(outputType)) {
resp.setContentType("application/octet-stream");
Date date = new Date();
SimpleDateFormat dateFormat = new SimpleDateFormat("dd-MM-YYYY HH:mm:ss");
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java index ef3555bc..8e70e693 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java @@ -112,7 +112,7 @@ public class SubscribeServlet extends ProxyServlet { } int feedid = getIdFromPath(req); if (feedid < 0) { - message = "Missing or bad feed number."; + message = MISSING_FEED; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -121,7 +121,7 @@ public class SubscribeServlet extends ProxyServlet { } Feed feed = Feed.getFeedById(feedid); if (feed == null || feed.isDeleted()) { - message = "Missing or bad feed number."; + message = MISSING_FEED; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_NOT_FOUND); eventlogger.error(elr.toString()); @@ -201,7 +201,7 @@ public class SubscribeServlet extends ProxyServlet { } int feedid = getIdFromPath(req); if (feedid < 0) { - message = "Missing or bad feed number."; + message = MISSING_FEED; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -210,7 +210,7 @@ public class SubscribeServlet extends ProxyServlet { } Feed feed = Feed.getFeedById(feedid); if (feed == null || feed.isDeleted()) { - message = "Missing or bad feed number."; + message = MISSING_FEED; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_NOT_FOUND); eventlogger.error(elr.toString()); @@ -220,7 +220,7 @@ public class SubscribeServlet extends ProxyServlet { // check content type is SUB_CONTENT_TYPE, version 1.0 ContentHeader ch = getContentHeader(req); String ver = ch.getAttribute("version"); - if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) { + if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) { intlogger.debug("Content-type is: " + req.getHeader("Content-Type")); message = "Incorrect content-type"; elr.setMessage(message); @@ -231,7 +231,7 @@ public class SubscribeServlet extends ProxyServlet { } JSONObject jo = getJSONfromInput(req); if (jo == null) { - message = "Badly formed JSON"; + message = BAD_JSON; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_BAD_REQUEST); eventlogger.error(elr.toString()); @@ -271,14 +271,14 @@ public class SubscribeServlet extends ProxyServlet { */ String feedAafInstance = feed.getAafInstance(); String subAafInstance = sub.getAafInstance(); - boolean subAafLegacyEmptyOrNull = (subAafInstance == null || subAafInstance.equals("") || subAafInstance.equalsIgnoreCase("legacy")); + boolean subAafLegacyEmptyOrNull = (subAafInstance == null || "".equals(subAafInstance) || "legacy".equalsIgnoreCase(subAafInstance)); // This extra check added to verify AAF feed with AAF subscriber having empty aaf instance check - if (feedAafInstance == null || feedAafInstance.equals("") || feedAafInstance.equalsIgnoreCase("legacy")) { + if (feedAafInstance == null || "".equals(feedAafInstance) || "legacy".equalsIgnoreCase(feedAafInstance)) { if (subAafLegacyEmptyOrNull) { AuthorizationResponse aresp = authz.decide(req); if (!aresp.isAuthorized()) { - message = "Policy Engine disallows access"; + message = POLICY_ENGINE; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); @@ -299,7 +299,7 @@ public class SubscribeServlet extends ProxyServlet { if (subAafLegacyEmptyOrNull) { AuthorizationResponse aresp = authz.decide(req); if (!aresp.isAuthorized()) { - message = "Policy Engine disallows access."; + message = POLICY_ENGINE; elr.setMessage(message); elr.setResult(HttpServletResponse.SC_FORBIDDEN); eventlogger.error(elr.toString()); 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 ff3ed3c1..125c50d8 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 @@ -63,6 +63,10 @@ public class SubscriptionServlet extends ProxyServlet { private static EELFLogger eelfLogger = EELFManager.getInstance()
.getLogger(SubscriptionServlet.class);
+
+
+
+
/**
* DELETE on the <subscriptionUrl> -- delete a subscription. See the <i>Deleting a Subscription</i> section in
* the <b>Provisioning API</b> document for details on how this method should be invoked.
@@ -88,7 +92,7 @@ public class SubscriptionServlet extends ProxyServlet { }
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
+ message = MISSING_ON_BEHALF;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -97,7 +101,7 @@ public class SubscriptionServlet extends ProxyServlet { }
int subid = getIdFromPath(req);
if (subid < 0) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -106,7 +110,7 @@ public class SubscriptionServlet extends ProxyServlet { }
Subscription sub = Subscription.getSubscriptionById(subid);
if (sub == null) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -119,10 +123,10 @@ public class SubscriptionServlet extends ProxyServlet { * CADI code - check on permissions based on Legacy/AAF users to allow to delete/remove subscription
*/
String aafInstance = sub.getAafInstance();
- if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) {
+ if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) {
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -189,7 +193,7 @@ public class SubscriptionServlet extends ProxyServlet { }
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
+ message = MISSING_ON_BEHALF;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -198,7 +202,7 @@ public class SubscriptionServlet extends ProxyServlet { }
int subid = getIdFromPath(req);
if (subid < 0) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -207,7 +211,7 @@ public class SubscriptionServlet extends ProxyServlet { }
Subscription sub = Subscription.getSubscriptionById(subid);
if (sub == null) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -217,7 +221,7 @@ public class SubscriptionServlet extends ProxyServlet { // Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -265,7 +269,7 @@ public class SubscriptionServlet extends ProxyServlet { }
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
+ message = MISSING_ON_BEHALF;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -274,7 +278,7 @@ public class SubscriptionServlet extends ProxyServlet { }
int subid = getIdFromPath(req);
if (subid < 0) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -283,7 +287,7 @@ public class SubscriptionServlet extends ProxyServlet { }
Subscription oldsub = Subscription.getSubscriptionById(subid);
if (oldsub == null) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_NOT_FOUND);
eventlogger.error(elr.toString());
@@ -293,7 +297,7 @@ public class SubscriptionServlet extends ProxyServlet { // check content type is SUB_CONTENT_TYPE, version 1.0
ContentHeader ch = getContentHeader(req);
String ver = ch.getAttribute("version");
- if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !(ver.equals("1.0") || ver.equals("2.0"))) {
+ if (!ch.getType().equals(SUB_BASECONTENT_TYPE) || !("1.0".equals(ver) || "2.0".equals(ver))) {
message = "Incorrect content-type";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -303,7 +307,7 @@ public class SubscriptionServlet extends ProxyServlet { }
JSONObject jo = getJSONfromInput(req);
if (jo == null) {
- message = "Badly formed JSON";
+ message = BAD_JSON;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -331,10 +335,10 @@ public class SubscriptionServlet extends ProxyServlet { * CADI code - check on permissions based on Legacy/AAF users to allow to delete/remove subscription
*/
String aafInstance = sub.getAafInstance();
- if (aafInstance == null || aafInstance.equals("") || aafInstance.equalsIgnoreCase("legacy")) {
+ if (aafInstance == null || "".equals(aafInstance) || "legacy".equalsIgnoreCase(aafInstance)) {
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -435,7 +439,7 @@ public class SubscriptionServlet extends ProxyServlet { }
String bhdr = req.getHeader(BEHALF_HEADER);
if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
+ message = MISSING_ON_BEHALF;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -444,7 +448,7 @@ public class SubscriptionServlet extends ProxyServlet { }
final int subid = getIdFromPath(req);
if (subid < 0 || Subscription.getSubscriptionById(subid) == null) {
- message = "Missing or bad subscription number.";
+ message = BAD_SUB;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -454,7 +458,7 @@ public class SubscriptionServlet extends ProxyServlet { // check content type is SUBCNTRL_CONTENT_TYPE, version 1.0
ContentHeader ch = getContentHeader(req);
String ver = ch.getAttribute("version");
- if (!ch.getType().equals(SUBCNTRL_CONTENT_TYPE) || !ver.equals("1.0")) {
+ if (!ch.getType().equals(SUBCNTRL_CONTENT_TYPE) || !"1.0".equals(ver)) {
message = "Incorrect content-type";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
@@ -465,7 +469,7 @@ public class SubscriptionServlet extends ProxyServlet { // Check with the Authorizer
AuthorizationResponse aresp = authz.decide(req);
if (!aresp.isAuthorized()) {
- message = "Policy Engine disallows access.";
+ message = POLICY_ENGINE;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_FORBIDDEN);
eventlogger.error(elr.toString());
@@ -474,7 +478,7 @@ public class SubscriptionServlet extends ProxyServlet { }
JSONObject jo = getJSONfromInput(req);
if (jo == null) {
- message = "Badly formed JSON";
+ message = BAD_JSON;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString());
@@ -496,7 +500,7 @@ public class SubscriptionServlet extends ProxyServlet { eventlogger.info(elr.toString());
resp.setStatus(HttpServletResponse.SC_ACCEPTED);
} catch (JSONException e) {
- message = "Badly formed JSON";
+ message = BAD_JSON;
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.error(elr.toString(), e);
@@ -514,7 +518,7 @@ public class SubscriptionServlet extends ProxyServlet { public class SubscriberNotifyThread extends Thread {
public static final String URL_TEMPLATE = "http://%s/internal/resetSubscription/%d";
- private List<String> urls = new Vector<String>();
+ private List<String> urls = new Vector<>();
public SubscriberNotifyThread() {
setName("SubscriberNotifyThread");
@@ -527,7 +531,9 @@ public class SubscriptionServlet extends ProxyServlet { }
}
+ @Override
public void run() {
+
try {
while (!urls.isEmpty()) {
String u = urls.remove(0);
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java index 65526453..d3ae4fe3 100644 --- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java +++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SynchronizerTask.java @@ -588,7 +588,7 @@ public class SynchronizerTask extends TimerTask { String url = URLUtilities.generatePeerLogsURL(); //Fixing if only one Prov is configured, not to give exception to fill logs, return empty bitset. - if (url.equals("")) { + if ("".equals(url)) { return bs; } //End of fix. @@ -603,7 +603,7 @@ public class SynchronizerTask extends TimerTask { } HttpEntity entity = response.getEntity(); String ctype = entity.getContentType().getValue().trim(); - if (!ctype.equals("text/plain")) { + if (!"text/plain".equals(ctype)) { logger.warn("PROV5011: readRemoteLoglist failed, bad content type: " + ctype); return bs; } @@ -649,7 +649,7 @@ public class SynchronizerTask extends TimerTask { } HttpEntity entity = response.getEntity(); String ctype = entity.getContentType().getValue().trim(); - if (!ctype.equals("text/plain")) { + if (!"text/plain".equals(ctype)) { logger.warn("PROV5011: replicateDRLogs failed, bad content type: " + ctype); return; } |