summaryrefslogtreecommitdiffstats
path: root/datarouter-prov
diff options
context:
space:
mode:
Diffstat (limited to 'datarouter-prov')
-rwxr-xr-xdatarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/BaseServlet.java44
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServlet.java442
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/FeedServlet.java570
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/InternalServlet.java578
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/LogServlet.java138
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java59
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscribeServlet.java432
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServlet.java686
-rw-r--r--datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/eelf/EelfMsgs.java6
-rw-r--r--datarouter-prov/src/main/resources/EelfMessages.properties8
-rw-r--r--datarouter-prov/src/main/resources/logback.xml4
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java33
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java12
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java28
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java12
-rw-r--r--datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java17
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java10
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/PublishServletTest.java47
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java11
-rwxr-xr-xdatarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java29
-rw-r--r--datarouter-prov/src/test/resources/logback-test.xml122
21 files changed, 1879 insertions, 1409 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 be87e133..d916a21c 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
@@ -28,6 +28,9 @@ import static com.att.eelf.configuration.Configuration.MDC_SERVER_FQDN;
import static com.att.eelf.configuration.Configuration.MDC_SERVER_IP_ADDRESS;
import static com.att.eelf.configuration.Configuration.MDC_SERVICE_NAME;
+import static com.att.eelf.configuration.Configuration.MDC_KEY_REQUEST_ID;
+
+
import java.io.IOException;
import java.io.InputStream;
@@ -36,18 +39,13 @@ import java.net.UnknownHostException;
import java.security.cert.X509Certificate;
import java.sql.Connection;
import java.sql.SQLException;
-import java.util.HashMap;
-import java.util.HashSet;
-import java.util.Map;
-import java.util.Set;
-import java.util.List;
-import java.util.ArrayList;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
+import org.apache.commons.lang3.StringUtils;
import org.apache.log4j.Logger;
import org.json.JSONObject;
import org.json.JSONTokener;
@@ -66,8 +64,17 @@ import org.onap.dmaap.datarouter.provisioning.utils.DB;
import org.onap.dmaap.datarouter.provisioning.utils.ThrottleFilter;
import org.json.JSONException;
import org.slf4j.MDC;
+import org.slf4j.Marker;
+import org.slf4j.MarkerFactory;
+import java.util.HashSet;
+import java.util.Map;
import java.util.Properties;
+import java.util.Set;
+import java.util.List;
+import java.util.ArrayList;
+import java.util.HashMap;
+import java.util.UUID;
import java.util.regex.Pattern;
import javax.mail.Message;
import javax.mail.MessagingException;
@@ -103,9 +110,7 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
//Adding groups functionality, ...1610
static final String GROUP_BASECONTENT_TYPE = "application/vnd.att-dr.group";
- public static final String GROUP_CONTENT_TYPE = "application/vnd.att-dr.group; version=2.0";
static final String GROUPFULL_CONTENT_TYPE = "application/vnd.att-dr.group-full; version=2.0";
- public static final String GROUPLIST_CONTENT_TYPE = "application/vnd.att-dr.fegrouped-list; version=1.0";
public static final String LOGLIST_CONTENT_TYPE = "application/vnd.att-dr.log-list; version=1.0";
@@ -966,10 +971,29 @@ public class BaseServlet extends HttpServlet implements ProvDataProvider {
}
/*
- * @Method - setIpAndFqdnForEelf - Rally:US664892
+ * @Method - setIpFqdnRequestIDandInvocationIDForEelf
+ * @Params - method, prints method name in EELF log.
+ * @Params- Req, Request used to get RequestId and InvocationId
+ */
+ void setIpFqdnRequestIDandInvocationIDForEelf(String method, HttpServletRequest req) {
+ setIpFqdnForEelf(method);
+ setMDC(req, "X-ONAP-RequestID", MDC_KEY_REQUEST_ID);
+ setMDC(req, "X-InvocationID", "InvocationId");
+ }
+
+ void setMDC(HttpServletRequest req, String headerName, String keyName) {
+ String mdcId = req.getHeader(headerName);
+ if (StringUtils.isBlank(mdcId)) {
+ mdcId = UUID.randomUUID().toString();
+ }
+ MDC.put(keyName, mdcId);
+ }
+
+ /*
+ * @Method - setIpFqdnRequestIdForEelf - Rally:US664892
* @Params - method, prints method name in EELF log.
*/
- void setIpAndFqdnForEelf(String method) {
+ void setIpFqdnForEelf(String method) {
MDC.clear();
MDC.put(MDC_SERVICE_NAME, method);
try {
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 68c81d84..28b2a3ca 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
@@ -55,21 +55,26 @@ public class DRFeedsServlet extends ProxyServlet {
//Adding EELF Logger Rally:US664892
private static EELFLogger eelflogger = EELFManager.getInstance()
- .getLogger("org.onap.dmaap.datarouter.provisioning.DRFeedsServlet");
+ .getLogger(DRFeedsServlet.class);
/**
* DELETE on the <drFeedsURL> -- not supported.
*/
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doDelete");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
- String message = "DELETE not allowed for the drFeedsURL.";
- EventLogRecord elr = new EventLogRecord(req);
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ setIpFqdnRequestIDandInvocationIDForEelf("doDelete", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
+ String message = "DELETE not allowed for the drFeedsURL.";
+ EventLogRecord elr = new EventLogRecord(req);
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
/**
@@ -78,99 +83,104 @@ public class DRFeedsServlet extends ProxyServlet {
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doGet");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
- EventLogRecord elr = new EventLogRecord(req);
- String message = isAuthorizedForProvisioning(req);
- if (message != null) {
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- if (isProxyServer()) {
- super.doGet(req, resp);
- return;
- }
- String bhdr = req.getHeader(BEHALF_HEADER);
- if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- String path = req
- .getRequestURI(); // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
- if (path != null && !path.equals("/")) {
- message = "Bad URL.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_NOT_FOUND);
- eventlogger.info(elr);
- 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.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
-
- String name = req.getParameter("name");
- String vers = req.getParameter("version");
- String publ = req.getParameter("publisher");
- String subs = req.getParameter("subscriber");
- if (name != null && vers != null) {
- // Display a specific feed
- Feed feed = Feed.getFeedByNameVersion(name, vers);
- if (feed == null || feed.isDeleted()) {
- message = "This feed does not exist in the database.";
+ setIpFqdnRequestIDandInvocationIDForEelf("doGet", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
+ EventLogRecord elr = new EventLogRecord(req);
+ String message = isAuthorizedForProvisioning(req);
+ if (message != null) {
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ if (isProxyServer()) {
+ super.doGet(req, resp);
+ return;
+ }
+ String bhdr = req.getHeader(BEHALF_HEADER);
+ if (bhdr == null) {
+ message = "Missing " + BEHALF_HEADER + " header.";
elr.setMessage(message);
elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
eventlogger.info(elr);
sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ String path = req
+ .getRequestURI(); // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
+ if (path != null && !path.equals("/")) {
+ message = "Bad URL.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_NOT_FOUND);
+ eventlogger.info(elr);
+ 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.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+
+ String name = req.getParameter("name");
+ String vers = req.getParameter("version");
+ String publ = req.getParameter("publisher");
+ String subs = req.getParameter("subscriber");
+ if (name != null && vers != null) {
+ // Display a specific feed
+ Feed feed = Feed.getFeedByNameVersion(name, vers);
+ if (feed == null || feed.isDeleted()) {
+ message = "This feed does not exist in the database.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ } else {
+ // send response
+ elr.setResult(HttpServletResponse.SC_OK);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.setContentType(FEEDFULL_CONTENT_TYPE);
+ try {
+ resp.getOutputStream().print(feed.asJSONObject(true).toString());
+ } catch (IOException ioe) {
+ eventlogger.error("IOException" + ioe.getMessage());
+ }
+ }
} else {
+ // Display a list of URLs
+ List<String> list = null;
+ if (name != null) {
+ list = Feed.getFilteredFeedUrlList("name", name);
+ } else if (publ != null) {
+ list = Feed.getFilteredFeedUrlList("publ", publ);
+ } else if (subs != null) {
+ list = Feed.getFilteredFeedUrlList("subs", subs);
+ } else {
+ list = Feed.getFilteredFeedUrlList("all", null);
+ }
+ String t = JSONUtilities.createJSONArray(list);
// send response
elr.setResult(HttpServletResponse.SC_OK);
eventlogger.info(elr);
resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType(FEEDFULL_CONTENT_TYPE);
+ resp.setContentType(FEEDLIST_CONTENT_TYPE);
try {
- resp.getOutputStream().print(feed.asJSONObject(true).toString());
+ resp.getOutputStream().print(t);
} catch (IOException ioe) {
eventlogger.error("IOException" + ioe.getMessage());
}
}
- } else {
- // Display a list of URLs
- List<String> list = null;
- if (name != null) {
- list = Feed.getFilteredFeedUrlList("name", name);
- } else if (publ != null) {
- list = Feed.getFilteredFeedUrlList("publ", publ);
- } else if (subs != null) {
- list = Feed.getFilteredFeedUrlList("subs", subs);
- } else {
- list = Feed.getFilteredFeedUrlList("all", null);
- }
- String t = JSONUtilities.createJSONArray(list);
- // send response
- elr.setResult(HttpServletResponse.SC_OK);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType(FEEDLIST_CONTENT_TYPE);
- try {
- resp.getOutputStream().print(t);
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
- }
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
@@ -179,14 +189,19 @@ public class DRFeedsServlet extends ProxyServlet {
*/
@Override
public void doPut(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPut");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
- String message = "PUT not allowed for the drFeedsURL.";
- EventLogRecord elr = new EventLogRecord(req);
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ setIpFqdnRequestIDandInvocationIDForEelf("doPut", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
+ String message = "PUT not allowed for the drFeedsURL.";
+ EventLogRecord elr = new EventLogRecord(req);
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
/**
@@ -195,125 +210,130 @@ public class DRFeedsServlet extends ProxyServlet {
*/
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPost");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
- EventLogRecord elr = new EventLogRecord(req);
- String message = isAuthorizedForProvisioning(req);
- if (message != null) {
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- if (isProxyServer()) {
- super.doPost(req, resp);
- return;
- }
- String bhdr = req.getHeader(BEHALF_HEADER);
- if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- String path = req
- .getRequestURI(); // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
- if (path != null && !path.equals("/")) {
- message = "Bad URL.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_NOT_FOUND);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, message, eventlogger);
- return;
- }
- // 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"))) {
- message = "Incorrect content-type";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, 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.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- JSONObject jo = getJSONfromInput(req);
- if (jo == null) {
- message = "Badly formed JSON";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- if (intlogger.isDebugEnabled()) {
- intlogger.debug(jo.toString());
- }
- if (++activeFeeds > maxFeeds) {
- activeFeeds--;
- message = "Cannot create feed; the maximum number of feeds has been configured.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_CONFLICT);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_CONFLICT, message, eventlogger);
- return;
- }
- Feed feed = null;
+ setIpFqdnRequestIDandInvocationIDForEelf("doPost", req);
+ eelflogger.info(EelfMsgs.ENTRY);
try {
- feed = new Feed(jo);
- } catch (InvalidObjectException e) {
- message = e.getMessage();
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- feed.setPublisher(bhdr); // set from X-ATT-DR-ON-BEHALF-OF header
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
+ EventLogRecord elr = new EventLogRecord(req);
+ String message = isAuthorizedForProvisioning(req);
+ if (message != null) {
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ if (isProxyServer()) {
+ super.doPost(req, resp);
+ return;
+ }
+ String bhdr = req.getHeader(BEHALF_HEADER);
+ if (bhdr == null) {
+ message = "Missing " + BEHALF_HEADER + " header.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ String path = req
+ .getRequestURI(); // Note: I think this should be getPathInfo(), but that doesn't work (Jetty bug?)
+ if (path != null && !path.equals("/")) {
+ message = "Bad URL.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_NOT_FOUND);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, message, eventlogger);
+ return;
+ }
+ // 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"))) {
+ message = "Incorrect content-type";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, 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.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ JSONObject jo = getJSONfromInput(req);
+ if (jo == null) {
+ message = "Badly formed JSON";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ if (intlogger.isDebugEnabled()) {
+ intlogger.debug(jo.toString());
+ }
+ if (++activeFeeds > maxFeeds) {
+ activeFeeds--;
+ message = "Cannot create feed; the maximum number of feeds has been configured.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_CONFLICT);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_CONFLICT, message, eventlogger);
+ return;
+ }
+ Feed feed = null;
+ try {
+ feed = new Feed(jo);
+ } catch (InvalidObjectException e) {
+ message = e.getMessage();
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ feed.setPublisher(bhdr); // set from X-ATT-DR-ON-BEHALF-OF header
- // Check if this feed already exists
- Feed feed2 = Feed.getFeedByNameVersion(feed.getName(), feed.getVersion());
- if (feed2 != null) {
- message = "This feed already exists in the database.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
+ // Check if this feed already exists
+ Feed feed2 = Feed.getFeedByNameVersion(feed.getName(), feed.getVersion());
+ if (feed2 != null) {
+ message = "This feed already exists in the database.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
- // Create FEED table entries
- if (doInsert(feed)) {
- // send response
- elr.setResult(HttpServletResponse.SC_CREATED);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_CREATED);
- resp.setContentType(FEEDFULL_CONTENT_TYPE);
- resp.setHeader("Location", feed.getLinks().getSelf());
- try {
- resp.getOutputStream().print(feed.asLimitedJSONObject().toString());
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ // Create FEED table entries
+ if (doInsert(feed)) {
+ // send response
+ elr.setResult(HttpServletResponse.SC_CREATED);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_CREATED);
+ resp.setContentType(FEEDFULL_CONTENT_TYPE);
+ resp.setHeader("Location", feed.getLinks().getSelf());
+ try {
+ resp.getOutputStream().print(feed.asLimitedJSONObject().toString());
+ } catch (IOException ioe) {
+ eventlogger.error("IOException" + ioe.getMessage());
+ }
+ provisioningDataChanged();
+ } else {
+ // Something went wrong with the INSERT
+ elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
}
- provisioningDataChanged();
- } else {
- // Something went wrong with the INSERT
- elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
}
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 827f0091..33097cd5 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
@@ -54,7 +54,7 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send
public class FeedServlet extends ProxyServlet {
//Adding EELF Logger Rally:US664892
- private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.FeedServlet");
+ private static EELFLogger eelflogger = EELFManager.getInstance().getLogger(FeedServlet.class);
/**
* Delete the Feed at the address /feed/&lt;feednumber&gt;.
@@ -63,73 +63,78 @@ public class FeedServlet extends ProxyServlet {
*/
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doDelete");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
- EventLogRecord elr = new EventLogRecord(req);
- String message = isAuthorizedForProvisioning(req);
- if (message != null) {
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- if (isProxyServer()) {
- super.doDelete(req, resp);
- return;
- }
- String bhdr = req.getHeader(BEHALF_HEADER);
- if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- 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);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- 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);
- 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.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
+ setIpFqdnRequestIDandInvocationIDForEelf("doDelete", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ EventLogRecord elr = new EventLogRecord(req);
+ String message = isAuthorizedForProvisioning(req);
+ if (message != null) {
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ if (isProxyServer()) {
+ super.doDelete(req, resp);
+ return;
+ }
+ String bhdr = req.getHeader(BEHALF_HEADER);
+ if (bhdr == null) {
+ message = "Missing "+BEHALF_HEADER+" header.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ 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);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ 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);
+ 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.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
- // Delete FEED table entry (set DELETED flag)
- feed.setDeleted(true);
- if (doUpdate(feed)) {
- activeFeeds--;
- // send response
- elr.setResult(HttpServletResponse.SC_NO_CONTENT);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
- provisioningDataChanged();
- } else {
- // Something went wrong with the UPDATE
- elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
+ // Delete FEED table entry (set DELETED flag)
+ feed.setDeleted(true);
+ if (doUpdate(feed)) {
+ activeFeeds--;
+ // send response
+ elr.setResult(HttpServletResponse.SC_NO_CONTENT);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
+ provisioningDataChanged();
+ } else {
+ // Something went wrong with the UPDATE
+ elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
+ }
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
/**
@@ -139,68 +144,73 @@ public class FeedServlet extends ProxyServlet {
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doGet");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
- EventLogRecord elr = new EventLogRecord(req);
- String message = isAuthorizedForProvisioning(req);
- if (message != null) {
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- if (isProxyServer()) {
- super.doGet(req, resp);
- return;
- }
- String bhdr = req.getHeader(BEHALF_HEADER);
- if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- 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);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- 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);
- 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.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
-
- // send response
- elr.setResult(HttpServletResponse.SC_OK);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType(FEEDFULL_CONTENT_TYPE);
+ setIpFqdnRequestIDandInvocationIDForEelf("doGet", req);
+ eelflogger.info(EelfMsgs.ENTRY);
try {
- resp.getOutputStream().print(feed.asJSONObject(true).toString());
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ EventLogRecord elr = new EventLogRecord(req);
+ String message = isAuthorizedForProvisioning(req);
+ if (message != null) {
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ if (isProxyServer()) {
+ super.doGet(req, resp);
+ return;
+ }
+ String bhdr = req.getHeader(BEHALF_HEADER);
+ if (bhdr == null) {
+ message = "Missing "+BEHALF_HEADER+" header.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ 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);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ 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);
+ 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.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+
+ // send response
+ elr.setResult(HttpServletResponse.SC_OK);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.setContentType(FEEDFULL_CONTENT_TYPE);
+ try {
+ resp.getOutputStream().print(feed.asJSONObject(true).toString());
+ } catch (IOException ioe) {
+ eventlogger.error("IOException" + ioe.getMessage());
+ }
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
/**
@@ -210,154 +220,159 @@ public class FeedServlet extends ProxyServlet {
*/
@Override
public void doPut(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPut");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
- EventLogRecord elr = new EventLogRecord(req);
- String message = isAuthorizedForProvisioning(req);
- if (message != null) {
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- if (isProxyServer()) {
- super.doPut(req, resp);
- return;
- }
- String bhdr = req.getHeader(BEHALF_HEADER);
- if (bhdr == null) {
- message = "Missing "+BEHALF_HEADER+" header.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- 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);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- Feed oldFeed = Feed.getFeedById(feedid);
- if (oldFeed == null || oldFeed.isDeleted()) {
- message = "Missing or bad feed number.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_NOT_FOUND);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, message, eventlogger);
- return;
- }
- // 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"))) {
- message = "Incorrect content-type";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message, eventlogger);
- return;
- }
- JSONObject jo = getJSONfromInput(req);
- if (jo == null) {
- message = "Badly formed JSON";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- if (intlogger.isDebugEnabled())
- intlogger.debug(jo.toString());
- Feed feed = null;
+ setIpFqdnRequestIDandInvocationIDForEelf("doPut", req);
+ eelflogger.info(EelfMsgs.ENTRY);
try {
- feed = new Feed(jo);
- } catch (InvalidObjectException e) {
- message = e.getMessage();
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- feed.setFeedid(feedid);
- feed.setPublisher(bhdr); // set from X-ATT-DR-ON-BEHALF-OF header
-
- String subjectgroup = (req.getHeader("X-ATT-DR-ON-BEHALF-OF-GROUP")); //Adding for group feature:Rally US708115
- if (!oldFeed.getPublisher().equals(feed.getPublisher()) && subjectgroup == null) {
- message = "This feed must be modified by the same publisher that created it.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- if (!oldFeed.getName().equals(feed.getName())) {
- message = "The name of the feed may not be updated.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- if (!oldFeed.getVersion().equals(feed.getVersion())) {
- message = "The version of the feed may not be updated.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, 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.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
-
- // Update FEEDS table entries
- if (doUpdate(feed)) {
- // send response
- elr.setResult(HttpServletResponse.SC_OK);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType(FEEDFULL_CONTENT_TYPE);
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
+ EventLogRecord elr = new EventLogRecord(req);
+ String message = isAuthorizedForProvisioning(req);
+ if (message != null) {
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ if (isProxyServer()) {
+ super.doPut(req, resp);
+ return;
+ }
+ String bhdr = req.getHeader(BEHALF_HEADER);
+ if (bhdr == null) {
+ message = "Missing "+BEHALF_HEADER+" header.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ 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);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ Feed oldFeed = Feed.getFeedById(feedid);
+ if (oldFeed == null || oldFeed.isDeleted()) {
+ message = "Missing or bad feed number.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_NOT_FOUND);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, message, eventlogger);
+ return;
+ }
+ // 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"))) {
+ message = "Incorrect content-type";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message, eventlogger);
+ return;
+ }
+ JSONObject jo = getJSONfromInput(req);
+ if (jo == null) {
+ message = "Badly formed JSON";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ if (intlogger.isDebugEnabled())
+ intlogger.debug(jo.toString());
+ Feed feed = null;
try {
- resp.getOutputStream().print(feed.asLimitedJSONObject().toString());
- } catch (IOException ioe) {
- eventlogger.error("IOException" + ioe.getMessage());
+ feed = new Feed(jo);
+ } catch (InvalidObjectException e) {
+ message = e.getMessage();
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
}
+ feed.setFeedid(feedid);
+ feed.setPublisher(bhdr); // set from X-ATT-DR-ON-BEHALF-OF header
+ String subjectgroup = (req.getHeader("X-ATT-DR-ON-BEHALF-OF-GROUP")); //Adding for group feature:Rally US708115
+ if (!oldFeed.getPublisher().equals(feed.getPublisher()) && subjectgroup == null) {
+ message = "This feed must be modified by the same publisher that created it.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ if (!oldFeed.getName().equals(feed.getName())) {
+ message = "The name of the feed may not be updated.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ if (!oldFeed.getVersion().equals(feed.getVersion())) {
+ message = "The version of the feed may not be updated.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, 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.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
- /**Change Owner ship of Feed //Adding for group feature:Rally US708115*/
- if (jo.has("changeowner") && subjectgroup != null) {
+ // Update FEEDS table entries
+ if (doUpdate(feed)) {
+ // send response
+ elr.setResult(HttpServletResponse.SC_OK);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.setContentType(FEEDFULL_CONTENT_TYPE);
try {
- Boolean changeowner = (Boolean) jo.get("changeowner");
- if (changeowner != null && changeowner.equals(true)) {
- feed.setPublisher(req.getHeader(BEHALF_HEADER));
- feed.changeOwnerShip();
+ resp.getOutputStream().print(feed.asLimitedJSONObject().toString());
+ } catch (IOException ioe) {
+ eventlogger.error("IOException" + ioe.getMessage());
+ }
+
+
+ /**Change Owner ship of Feed //Adding for group feature:Rally US708115*/
+ if (jo.has("changeowner") && subjectgroup != null) {
+ try {
+ Boolean changeowner = (Boolean) jo.get("changeowner");
+ if (changeowner != null && changeowner.equals(true)) {
+ feed.setPublisher(req.getHeader(BEHALF_HEADER));
+ feed.changeOwnerShip();
+ }
+ } catch (JSONException je) {
+ eventlogger.error("JSONException" + je.getMessage());
}
- } catch (JSONException je) {
- eventlogger.error("JSONException" + je.getMessage());
}
- }
- /***End of change ownership*/
+ /***End of change ownership*/
- provisioningDataChanged();
- } else {
- // Something went wrong with the UPDATE
- elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
+ provisioningDataChanged();
+ } else {
+ // Something went wrong with the UPDATE
+ elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
+ }
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
/**
@@ -365,13 +380,18 @@ public class FeedServlet extends ProxyServlet {
*/
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPost");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
- String message = "POST not allowed for the feedURL.";
- EventLogRecord elr = new EventLogRecord(req);
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ setIpFqdnRequestIDandInvocationIDForEelf("doPost", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
+ String message = "POST not allowed for the feedURL.";
+ EventLogRecord elr = new EventLogRecord(req);
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
}
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 0d8ed66f..4e727f1d 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
@@ -160,7 +160,7 @@ public class InternalServlet extends ProxyServlet {
private static Integer logseq = 0; // another piece of info to make log spool file names unique
//Adding EELF Logger Rally:US664892
private static EELFLogger eelflogger = EELFManager.getInstance()
- .getLogger("org.onap.dmaap.datarouter.provisioning.InternalServlet");
+ .getLogger(InternalServlet.class);
/**
* Delete a parameter at the address /internal/api/&lt;parameter&gt;. See the <b>Internal API</b> document for
@@ -168,44 +168,49 @@ public class InternalServlet extends ProxyServlet {
*/
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doDelete");
- 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.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
- return;
- }
-
- String path = req.getPathInfo();
- if (path.startsWith("/api/")) {
- if (isProxyOK(req) && isProxyServer()) {
- super.doDelete(req, resp);
+ setIpFqdnRequestIDandInvocationIDForEelf("doDelete", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ 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.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
return;
}
- String key = path.substring(5);
- if (key.length() > 0) {
- Parameters param = Parameters.getParameter(key);
- if (param != null) {
- if (doDelete(param)) {
- elr.setResult(HttpServletResponse.SC_OK);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_OK);
- provisioningDataChanged();
- provisioningParametersChanged();
- } else {
- // Something went wrong with the DELETE
- elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
- }
+
+ String path = req.getPathInfo();
+ if (path.startsWith("/api/")) {
+ if (isProxyOK(req) && isProxyServer()) {
+ super.doDelete(req, resp);
return;
}
+ String key = path.substring(5);
+ if (key.length() > 0) {
+ Parameters param = Parameters.getParameter(key);
+ if (param != null) {
+ if (doDelete(param)) {
+ elr.setResult(HttpServletResponse.SC_OK);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_OK);
+ provisioningDataChanged();
+ provisioningParametersChanged();
+ } else {
+ // Something went wrong with the DELETE
+ elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
+ }
+ return;
+ }
+ }
}
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
}
/**
@@ -214,120 +219,125 @@ public class InternalServlet extends ProxyServlet {
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doGet");
- 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()) {
- // 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"))) {
- intlogger.info("PROV0009 Request to HALT received.");
- resp.setStatus(HttpServletResponse.SC_OK);
- Main.shutdown();
- } else {
- intlogger.info("PROV0010 Disallowed request to HALT received from " + remote);
- resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
- }
- return;
- }
-
- EventLogRecord elr = new EventLogRecord(req);
- if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
- return;
- }
- if (path.equals("/fetchProv") && !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 (isProxyOK(req) && isProxyServer()) {
- if (super.doGetWithFallback(req, resp)) {
- return;
+ setIpFqdnRequestIDandInvocationIDForEelf("doGet",req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ 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()) {
+ // 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"))) {
+ intlogger.info("PROV0009 Request to HALT received.");
+ resp.setStatus(HttpServletResponse.SC_OK);
+ Main.shutdown();
+ } else {
+ intlogger.info("PROV0010 Disallowed request to HALT received from " + remote);
+ resp.setStatus(HttpServletResponse.SC_FORBIDDEN);
}
- // fall back to returning the local data if the remote is unreachable
- intlogger.info("Active server unavailable; falling back to local copy.");
+ return;
}
- Poker p = Poker.getPoker();
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType(PROVFULL_CONTENT_TYPE2);
- try {
- resp.getOutputStream().print(p.getProvisioningString());
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+
+ EventLogRecord elr = new EventLogRecord(req);
+ if (!isAuthorizedForInternal(req)) {
+ elr.setMessage("Unauthorized.");
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
+ return;
}
- return;
- }
- if (path.equals("/logs") || path.equals("/logs/")) {
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType("application/json");
- try {
- resp.getOutputStream().print(generateLogfileList().toString());
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ if (path.equals("/fetchProv") && !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;
}
- return;
- }
- 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");
- Path logpath = Paths.get(log.getAbsolutePath());
- try {
- Files.copy(logpath, resp.getOutputStream());
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ if (path.equals("/prov")) {
+ if (isProxyOK(req) && isProxyServer()) {
+ if (super.doGetWithFallback(req, resp)) {
+ return;
}
- return;
+ // fall back to returning the local data if the remote is unreachable
+ intlogger.info("Active server unavailable; falling back to local copy.");
}
+ Poker p = Poker.getPoker();
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.setContentType(PROVFULL_CONTENT_TYPE2);
+ try {
+ resp.getOutputStream().print(p.getProvisioningString());
+ } catch (IOException ioe) {
+ intlogger.error("IOException" + ioe.getMessage());
+ }
+ return;
}
- sendResponseError(resp, HttpServletResponse.SC_NO_CONTENT, "No file.", eventlogger);
- return;
- }
- if (path.startsWith("/api/")) {
- if (isProxyOK(req) && isProxyServer()) {
- super.doGet(req, resp);
+ if (path.equals("/logs") || path.equals("/logs/")) {
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.setContentType("application/json");
+ try {
+ resp.getOutputStream().print(generateLogfileList().toString());
+ } catch (IOException ioe) {
+ intlogger.error("IOException" + ioe.getMessage());
+ }
return;
}
- String key = path.substring(5);
- if (key.length() > 0) {
- Parameters param = Parameters.getParameter(key);
- if (param != null) {
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType("text/plain");
- try {
- resp.getOutputStream().print(param.getValue() + "\n");
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ 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");
+ Path logpath = Paths.get(log.getAbsolutePath());
+ try {
+ Files.copy(logpath, resp.getOutputStream());
+ } catch (IOException ioe) {
+ intlogger.error("IOException" + ioe.getMessage());
+ }
+ return;
}
+ }
+ sendResponseError(resp, HttpServletResponse.SC_NO_CONTENT, "No file.", eventlogger);
+ return;
+ }
+ if (path.startsWith("/api/")) {
+ if (isProxyOK(req) && isProxyServer()) {
+ super.doGet(req, resp);
return;
}
+ String key = path.substring(5);
+ if (key.length() > 0) {
+ Parameters param = Parameters.getParameter(key);
+ if (param != null) {
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.setContentType("text/plain");
+ try {
+ resp.getOutputStream().print(param.getValue() + "\n");
+ } catch (IOException ioe) {
+ intlogger.error("IOException" + ioe.getMessage());
+ }
+ return;
+ }
+ }
}
- }
- if (path.equals("/drlogs") || path.equals("/drlogs/")) {
- // 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");
- try {
- resp.getOutputStream().print(lfl.getBitSet().toString());
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
+ if (path.equals("/drlogs") || path.equals("/drlogs/")) {
+ // 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");
+ try {
+ resp.getOutputStream().print(lfl.getBitSet().toString());
+ } catch (IOException ioe) {
+ intlogger.error("IOException" + ioe.getMessage());
+ }
+ return;
}
- return;
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
}
/**
@@ -336,45 +346,50 @@ public class InternalServlet extends ProxyServlet {
*/
@Override
public void doPut(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPut");
- 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.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
- return;
- }
- String path = req.getPathInfo();
- if (path.startsWith("/api/")) {
- if (isProxyOK(req) && isProxyServer()) {
- super.doPut(req, resp);
+ setIpFqdnRequestIDandInvocationIDForEelf("doPut", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ 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.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
return;
}
- String key = path.substring(5);
- if (key.length() > 0) {
- Parameters param = Parameters.getParameter(key);
- if (param != null) {
- String t = catValues(req.getParameterValues("val"));
- param.setValue(t);
- if (doUpdate(param)) {
- elr.setResult(HttpServletResponse.SC_OK);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_OK);
- provisioningDataChanged();
- provisioningParametersChanged();
- } else {
- // Something went wrong with the UPDATE
- elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
- }
+ String path = req.getPathInfo();
+ if (path.startsWith("/api/")) {
+ if (isProxyOK(req) && isProxyServer()) {
+ super.doPut(req, resp);
return;
}
+ String key = path.substring(5);
+ if (key.length() > 0) {
+ Parameters param = Parameters.getParameter(key);
+ if (param != null) {
+ String t = catValues(req.getParameterValues("val"));
+ param.setValue(t);
+ if (doUpdate(param)) {
+ elr.setResult(HttpServletResponse.SC_OK);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_OK);
+ provisioningDataChanged();
+ provisioningParametersChanged();
+ } else {
+ // Something went wrong with the UPDATE
+ elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
+ }
+ return;
+ }
+ }
}
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
}
/**
@@ -384,142 +399,147 @@ public class InternalServlet extends ProxyServlet {
@SuppressWarnings("resource")
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPost");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
- EventLogRecord elr = new EventLogRecord(req);
- if (!isAuthorizedForInternal(req)) {
- elr.setMessage("Unauthorized.");
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
- return;
- }
-
- String path = req.getPathInfo();
- if (path.startsWith("/api/")) {
- if (isProxyOK(req) && isProxyServer()) {
- super.doPost(req, resp);
+ setIpFqdnRequestIDandInvocationIDForEelf("doPost", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
+ EventLogRecord elr = new EventLogRecord(req);
+ if (!isAuthorizedForInternal(req)) {
+ elr.setMessage("Unauthorized.");
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, "Unauthorized.", eventlogger);
return;
}
- String key = path.substring(5);
- if (key.length() > 0) {
- Parameters param = Parameters.getParameter(key);
- if (param == null) {
- String t = catValues(req.getParameterValues("val"));
- param = new Parameters(key, t);
- if (doInsert(param)) {
- elr.setResult(HttpServletResponse.SC_OK);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_OK);
- provisioningDataChanged();
- provisioningParametersChanged();
+
+ String path = req.getPathInfo();
+ if (path.startsWith("/api/")) {
+ if (isProxyOK(req) && isProxyServer()) {
+ super.doPost(req, resp);
+ return;
+ }
+ String key = path.substring(5);
+ if (key.length() > 0) {
+ Parameters param = Parameters.getParameter(key);
+ if (param == null) {
+ String t = catValues(req.getParameterValues("val"));
+ param = new Parameters(key, t);
+ if (doInsert(param)) {
+ elr.setResult(HttpServletResponse.SC_OK);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_OK);
+ provisioningDataChanged();
+ provisioningParametersChanged();
+ } else {
+ // Something went wrong with the INSERT
+ elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
+ }
+ return;
+ }
+ }
+ }
+
+ if (path.equals("/logs") || path.equals("/logs/")) {
+ String ctype = req.getHeader("Content-Type");
+ if (ctype == null || !ctype.equals("text/plain")) {
+ elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
+ elr.setMessage("Bad media type: " + ctype);
+ resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
+ eventlogger.info(elr);
+ return;
+ }
+ String spooldir = (new DB()).getProperties().getProperty("org.onap.dmaap.datarouter.provserver.spooldir");
+ String spoolname = String.format("%d-%d-", System.currentTimeMillis(), Thread.currentThread().getId());
+ synchronized (lock) {
+ // perhaps unnecessary, but it helps make the name unique
+ spoolname += logseq.toString();
+ logseq++;
+ }
+ String encoding = req.getHeader("Content-Encoding");
+ if (encoding != null) {
+ if (encoding.trim().equals("gzip")) {
+ spoolname += ".gz";
} else {
- // Something went wrong with the INSERT
- elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
+ resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
+ return;
}
+ }
+ // Determine space available -- available space must be at least 5%
+ FileSystem fs = (Paths.get(spooldir)).getFileSystem();
+ long total = 0;
+ long avail = 0;
+ for (FileStore store : fs.getFileStores()) {
+ try {
+ total += store.getTotalSpace();
+ avail += store.getUsableSpace();
+ } catch (IOException ioe) {
+ intlogger.error("IOException" + ioe.getMessage());
+ }
+ }
+ try {
+ fs.close();
+ } catch (Exception e) {
+ }
+ if (((avail * 100) / total) < 5) {
+ elr.setResult(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
+ resp.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
+ eventlogger.info(elr);
return;
}
- }
- }
-
- if (path.equals("/logs") || path.equals("/logs/")) {
- String ctype = req.getHeader("Content-Type");
- if (ctype == null || !ctype.equals("text/plain")) {
- elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- elr.setMessage("Bad media type: " + ctype);
- resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- eventlogger.info(elr);
+ Path tmppath = Paths.get(spooldir, spoolname);
+ Path donepath = Paths.get(spooldir, "IN." + spoolname);
+ try {
+ Files.copy(req.getInputStream(), Paths.get(spooldir, spoolname), StandardCopyOption.REPLACE_EXISTING);
+ Files.move(tmppath, donepath, StandardCopyOption.REPLACE_EXISTING);
+ elr.setResult(HttpServletResponse.SC_CREATED);
+ resp.setStatus(HttpServletResponse.SC_CREATED);
+ eventlogger.info(elr);
+ LogfileLoader.getLoader(); // This starts the logfile loader "task"
+ } catch (IOException ioe) {
+ intlogger.error("IOException" + ioe.getMessage());
+ }
return;
}
- String spooldir = (new DB()).getProperties().getProperty("org.onap.dmaap.datarouter.provserver.spooldir");
- String spoolname = String.format("%d-%d-", System.currentTimeMillis(), Thread.currentThread().getId());
- synchronized (lock) {
- // perhaps unnecessary, but it helps make the name unique
- spoolname += logseq.toString();
- logseq++;
- }
- String encoding = req.getHeader("Content-Encoding");
- if (encoding != null) {
- if (encoding.trim().equals("gzip")) {
- spoolname += ".gz";
- } else {
+
+ if (path.equals("/drlogs") || path.equals("/drlogs/")) {
+ // Receive post request and generate log entries
+ String ctype = req.getHeader("Content-Type");
+ if (ctype == null || !ctype.equals("text/plain")) {
elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
+ elr.setMessage("Bad media type: " + ctype);
resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
eventlogger.info(elr);
return;
}
- }
- // Determine space available -- available space must be at least 5%
- FileSystem fs = (Paths.get(spooldir)).getFileSystem();
- long total = 0;
- long avail = 0;
- for (FileStore store : fs.getFileStores()) {
try {
- total += store.getTotalSpace();
- avail += store.getUsableSpace();
+ InputStream is = req.getInputStream();
+ ByteArrayOutputStream bos = new ByteArrayOutputStream();
+ int ch;
+ while ((ch = is.read()) >= 0) {
+ bos.write(ch);
+ }
+ 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");
+ LogRecord.printLogRecords(resp.getOutputStream(), bs);
+ eventlogger.info(elr);
} catch (IOException ioe) {
intlogger.error("IOException" + ioe.getMessage());
}
- }
- try {
- fs.close();
- } catch (Exception e) {
- }
- if (((avail * 100) / total) < 5) {
- elr.setResult(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
- resp.setStatus(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
- eventlogger.info(elr);
return;
}
- Path tmppath = Paths.get(spooldir, spoolname);
- Path donepath = Paths.get(spooldir, "IN." + spoolname);
- try {
- Files.copy(req.getInputStream(), Paths.get(spooldir, spoolname), StandardCopyOption.REPLACE_EXISTING);
- Files.move(tmppath, donepath, StandardCopyOption.REPLACE_EXISTING);
- elr.setResult(HttpServletResponse.SC_CREATED);
- resp.setStatus(HttpServletResponse.SC_CREATED);
- eventlogger.info(elr);
- LogfileLoader.getLoader(); // This starts the logfile loader "task"
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
- }
- return;
- }
- if (path.equals("/drlogs") || path.equals("/drlogs/")) {
- // Receive post request and generate log entries
- String ctype = req.getHeader("Content-Type");
- if (ctype == null || !ctype.equals("text/plain")) {
- elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- elr.setMessage("Bad media type: " + ctype);
- resp.setStatus(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- eventlogger.info(elr);
- return;
- }
- try {
- InputStream is = req.getInputStream();
- ByteArrayOutputStream bos = new ByteArrayOutputStream();
- int ch;
- while ((ch = is.read()) >= 0) {
- bos.write(ch);
- }
- 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");
- LogRecord.printLogRecords(resp.getOutputStream(), bs);
- eventlogger.info(elr);
- } catch (IOException ioe) {
- intlogger.error("IOException" + ioe.getMessage());
- }
- return;
+ elr.setResult(HttpServletResponse.SC_NOT_FOUND);
+ sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
+ eventlogger.info(elr);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
-
- elr.setResult(HttpServletResponse.SC_NOT_FOUND);
- sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, "Bad URL.", eventlogger);
- eventlogger.info(elr);
}
private String catValues(String[] v) {
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 cdc23311..eceab571 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
@@ -64,7 +64,7 @@ import static org.onap.dmaap.datarouter.provisioning.utils.HttpServletUtils.send
@SuppressWarnings("serial")
public class LogServlet extends BaseServlet {
//Adding EELF Logger Rally:US664892
- private static EELFLogger eelflogger = EELFManager.getInstance().getLogger("org.onap.dmaap.datarouter.provisioning.LogServlet");
+ private static EELFLogger eelflogger = EELFManager.getInstance().getLogger(LogServlet.class);
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'";
@@ -147,14 +147,19 @@ public class LogServlet extends BaseServlet {
*/
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doDelete");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
- String message = "DELETE not allowed for the logURL.";
- EventLogRecord elr = new EventLogRecord(req);
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ setIpFqdnRequestIDandInvocationIDForEelf("doDelete", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
+ String message = "DELETE not allowed for the logURL.";
+ EventLogRecord elr = new EventLogRecord(req);
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
/**
* GET a logging URL -- retrieve logging data for a feed or subscription.
@@ -162,64 +167,69 @@ public class LogServlet extends BaseServlet {
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doGet");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
- int id = getIdFromPath(req);
- if (id < 0) {
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Missing or bad feed/subscription number.", eventlogger);
- return;
- }
- Map<String, String> map = buildMapFromRequest(req);
- if (map.get("err") != null) {
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments: "+map.get("err"), eventlogger);
- return;
- }
- // check Accept: header??
+ setIpFqdnRequestIDandInvocationIDForEelf("doGet", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
+ int id = getIdFromPath(req);
+ if (id < 0) {
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Missing or bad feed/subscription number.", eventlogger);
+ return;
+ }
+ Map<String, String> map = buildMapFromRequest(req);
+ if (map.get("err") != null) {
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, "Invalid arguments: " + map.get("err"), eventlogger);
+ return;
+ }
+ // check Accept: header??
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType(LOGLIST_CONTENT_TYPE);
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.setContentType(LOGLIST_CONTENT_TYPE);
- try (ServletOutputStream out = resp.getOutputStream()) {
- final String fields = req.getParameter("fields");
+ try (ServletOutputStream out = resp.getOutputStream()) {
+ final String fields = req.getParameter("fields");
- out.print("[");
- if (isfeedlog) {
- // Handle /feedlog/feedid request
- boolean firstrow = true;
+ out.print("[");
+ if (isfeedlog) {
+ // Handle /feedlog/feedid request
+ boolean firstrow = true;
- // 1. Collect publish records for this feed
- RowHandler rh = new PublishRecordRowHandler(out, fields, firstrow);
- getPublishRecordsForFeed(id, rh, map);
- firstrow = rh.firstrow;
+ // 1. Collect publish records for this feed
+ RowHandler rh = new PublishRecordRowHandler(out, fields, firstrow);
+ getPublishRecordsForFeed(id, rh, map);
+ firstrow = rh.firstrow;
- // 2. Collect delivery records for subscriptions to this feed
- rh = new DeliveryRecordRowHandler(out, fields, firstrow);
- getDeliveryRecordsForFeed(id, rh, map);
- firstrow = rh.firstrow;
+ // 2. Collect delivery records for subscriptions to this feed
+ rh = new DeliveryRecordRowHandler(out, fields, firstrow);
+ getDeliveryRecordsForFeed(id, rh, map);
+ firstrow = rh.firstrow;
- // 3. Collect expiry records for subscriptions to this feed
- rh = new ExpiryRecordRowHandler(out, fields, firstrow);
- getExpiryRecordsForFeed(id, rh, map);
- } else {
- // Handle /sublog/subid request
- Subscription sub = Subscription.getSubscriptionById(id);
- if (sub != null) {
- // 1. Collect publish records for the feed this subscription feeds
- RowHandler rh = new PublishRecordRowHandler(out, fields, true);
- getPublishRecordsForFeed(sub.getFeedid(), rh, map);
+ // 3. Collect expiry records for subscriptions to this feed
+ rh = new ExpiryRecordRowHandler(out, fields, firstrow);
+ getExpiryRecordsForFeed(id, rh, map);
+ } else {
+ // Handle /sublog/subid request
+ Subscription sub = Subscription.getSubscriptionById(id);
+ if (sub != null) {
+ // 1. Collect publish records for the feed this subscription feeds
+ RowHandler rh = new PublishRecordRowHandler(out, fields, true);
+ getPublishRecordsForFeed(sub.getFeedid(), rh, map);
- // 2. Collect delivery records for this subscription
- rh = new DeliveryRecordRowHandler(out, fields, rh.firstrow);
- getDeliveryRecordsForSubscription(id, rh, map);
+ // 2. Collect delivery records for this subscription
+ rh = new DeliveryRecordRowHandler(out, fields, rh.firstrow);
+ getDeliveryRecordsForSubscription(id, rh, map);
- // 3. Collect expiry records for this subscription
- rh = new ExpiryRecordRowHandler(out, fields, rh.firstrow);
- getExpiryRecordsForSubscription(id, rh, map);
+ // 3. Collect expiry records for this subscription
+ rh = new ExpiryRecordRowHandler(out, fields, rh.firstrow);
+ getExpiryRecordsForSubscription(id, rh, map);
+ }
}
+ out.print("]");
+ } catch (IOException ioe) {
+ eventlogger.error("IOException: " + ioe.getMessage());
}
- out.print("]");
- } catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
/**
@@ -227,7 +237,9 @@ public class LogServlet extends BaseServlet {
*/
@Override
public void doPut(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPut");
+ setIpFqdnRequestIDandInvocationIDForEelf("doPut", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER),getIdFromPath(req)+"");
String message = "PUT not allowed for the logURL.";
EventLogRecord elr = new EventLogRecord(req);
@@ -235,13 +247,18 @@ public class LogServlet extends BaseServlet {
elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
eventlogger.info(elr);
sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
/**
* POST a logging URL -- not supported.
*/
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPost");
+ setIpFqdnRequestIDandInvocationIDForEelf("doPost", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
String message = "POST not allowed for the logURL.";
EventLogRecord elr = new EventLogRecord(req);
@@ -249,6 +266,9 @@ public class LogServlet extends BaseServlet {
elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
eventlogger.info(elr);
sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
private Map<String, String> buildMapFromRequest(HttpServletRequest req) {
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
index 3ae63bb2..96e523df 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/PublishServlet.java
@@ -27,13 +27,13 @@ package org.onap.dmaap.datarouter.provisioning;
import com.att.eelf.configuration.EELFLogger;
import com.att.eelf.configuration.EELFManager;
import java.io.IOException;
-import java.util.ArrayList;
-import java.util.Collection;
-import java.util.List;
+import java.util.*;
import javax.servlet.ServletConfig;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
+import org.apache.commons.lang3.StringUtils;
import org.json.JSONArray;
import org.json.JSONException;
import org.json.JSONObject;
@@ -42,6 +42,7 @@ import org.onap.dmaap.datarouter.provisioning.beans.EventLogRecord;
import org.onap.dmaap.datarouter.provisioning.beans.IngressRoute;
import org.onap.dmaap.datarouter.provisioning.eelf.EelfMsgs;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.slf4j.MDC;
/**
* This servlet handles redirects for the &lt;publishURL&gt; on the provisioning server, which is generated by the
@@ -59,7 +60,7 @@ public class PublishServlet extends BaseServlet {
private List<IngressRoute> irt;
//Adding EELF Logger Rally:US664892
private static EELFLogger eelflogger = EELFManager.getInstance()
- .getLogger("org.onap.dmaap.datarouter.provisioning.PublishServlet");
+ .getLogger(PublishServlet.class);
private static final Object lock = new Object();
@@ -73,35 +74,63 @@ public class PublishServlet extends BaseServlet {
}
@Override
- public void doDelete(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doDelete");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
- redirect(req, resp);
+ public void doDelete(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
+ setUpEelfForPublishServlet(req, "doDelete");
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
+ redirect(req, resp);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
@Override
- public void doGet(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doGet");
+ public void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
+ setUpEelfForPublishServlet(req, "doGet");
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
redirect(req, resp);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
@Override
- public void doPut(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPut");
+ public void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
+ setUpEelfForPublishServlet(req, "doPut");
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
redirect(req, resp);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
@Override
- public void doPost(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPost");
+ public void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
+ setUpEelfForPublishServlet(req, "doPost");
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
redirect(req, resp);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
- private void redirect(HttpServletRequest req, HttpServletResponse resp) {
+ private void setUpEelfForPublishServlet(HttpServletRequest req, String method) {
+ if (StringUtils.isBlank(req.getHeader("X-ONAP-RequestID")) || StringUtils.isBlank(req.getHeader("X-InvocationID"))) {
+ setIpFqdnForEelf(method);
+ } else {
+ setIpFqdnRequestIDandInvocationIDForEelf(method, req);
+ }
+ }
+
+ private void redirect(HttpServletRequest req, HttpServletResponse resp) throws ServletException {
try {
String[] nodes = getNodes();
if (nodes == null || nodes.length == 0) {
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 1ab45a98..226b5fc9 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
@@ -56,21 +56,26 @@ public class SubscribeServlet extends ProxyServlet {
//Adding EELF Logger Rally:US664892
private static EELFLogger eelflogger = EELFManager.getInstance()
- .getLogger("org.onap.dmaap.datarouter.provisioning.SubscribeServlet");
+ .getLogger(SubscribeServlet.class);
/**
* DELETE on the &lt;subscribeUrl&gt; -- not supported.
*/
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doDelete");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
- String message = "DELETE not allowed for the subscribeURL.";
- EventLogRecord elr = new EventLogRecord(req);
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ setIpFqdnRequestIDandInvocationIDForEelf("doDelete", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
+ String message = "DELETE not allowed for the subscribeURL.";
+ EventLogRecord elr = new EventLogRecord(req);
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
/**
@@ -79,72 +84,77 @@ public class SubscribeServlet extends ProxyServlet {
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doGet");
- 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) {
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- if (isProxyServer()) {
- super.doGet(req, resp);
- return;
- }
- String bhdr = req.getHeader(BEHALF_HEADER);
- if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- 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);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- 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);
- 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.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
+ setIpFqdnRequestIDandInvocationIDForEelf("doGet", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ 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) {
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ if (isProxyServer()) {
+ super.doGet(req, resp);
+ return;
+ }
+ String bhdr = req.getHeader(BEHALF_HEADER);
+ if (bhdr == null) {
+ message = "Missing " + BEHALF_HEADER + " header.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ 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);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ 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);
+ 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.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
- // Display a list of URLs
- Collection<String> list = Subscription.getSubscriptionUrlList(feedid);
- String t = JSONUtilities.createJSONArray(list);
+ // Display a list of URLs
+ Collection<String> list = Subscription.getSubscriptionUrlList(feedid);
+ String t = JSONUtilities.createJSONArray(list);
- // send response
- elr.setResult(HttpServletResponse.SC_OK);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType(SUBLIST_CONTENT_TYPE);
- try {
- resp.getOutputStream().print(t);
- } catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ // send response
+ elr.setResult(HttpServletResponse.SC_OK);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.setContentType(SUBLIST_CONTENT_TYPE);
+ try {
+ resp.getOutputStream().print(t);
+ } catch (IOException ioe) {
+ eventlogger.error("IOException: " + ioe.getMessage());
+ }
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
@@ -153,14 +163,19 @@ public class SubscribeServlet extends ProxyServlet {
*/
@Override
public void doPut(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPut");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
- String message = "PUT not allowed for the subscribeURL.";
- EventLogRecord elr = new EventLogRecord(req);
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ setIpFqdnRequestIDandInvocationIDForEelf("doPut", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_SUBID, req.getHeader(BEHALF_HEADER), getIdFromPath(req) + "");
+ String message = "PUT not allowed for the subscribeURL.";
+ EventLogRecord elr = new EventLogRecord(req);
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_METHOD_NOT_ALLOWED);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_METHOD_NOT_ALLOWED, message, eventlogger);
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
+ }
}
/**
@@ -169,136 +184,141 @@ public class SubscribeServlet extends ProxyServlet {
*/
@Override
public void doPost(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPost");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
- EventLogRecord elr = new EventLogRecord(req);
- String message = isAuthorizedForProvisioning(req);
- if (message != null) {
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- if (isProxyServer()) {
- super.doPost(req, resp);
- return;
- }
- String bhdr = req.getHeader(BEHALF_HEADER);
- if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- 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);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- 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);
- 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.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
-
- // 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"))) {
- intlogger.debug("Content-type is: " + req.getHeader("Content-Type"));
- message = "Incorrect content-type";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message, eventlogger);
- return;
- }
- JSONObject jo = getJSONfromInput(req);
- if (jo == null) {
- message = "Badly formed JSON";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- if (intlogger.isDebugEnabled()) {
- intlogger.debug(jo.toString());
- }
- if (++activeSubs > maxSubs) {
- activeSubs--;
- message = "Cannot create subscription; the maximum number of subscriptions has been configured.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_CONFLICT);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_CONFLICT, message, eventlogger);
- return;
- }
- Subscription sub = null;
+ setIpFqdnRequestIDandInvocationIDForEelf("doPost", req);
+ eelflogger.info(EelfMsgs.ENTRY);
try {
- sub = new Subscription(jo);
- } catch (InvalidObjectException e) {
- activeSubs--;
- message = e.getMessage();
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- sub.setFeedid(feedid);
- sub.setSubscriber(bhdr); // set from X-ATT-DR-ON-BEHALF-OF header
-
- // Check if this subscription already exists; not an error (yet), just warn
- Subscription sub2 = Subscription.getSubscriptionMatching(sub);
- if (sub2 != null) {
- intlogger.warn(
- "PROV0011 Creating a duplicate subscription: new subid=" + sub.getSubid() + ", old subid=" + sub2
- .getSubid());
- }
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
+ EventLogRecord elr = new EventLogRecord(req);
+ String message = isAuthorizedForProvisioning(req);
+ if (message != null) {
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ if (isProxyServer()) {
+ super.doPost(req, resp);
+ return;
+ }
+ String bhdr = req.getHeader(BEHALF_HEADER);
+ if (bhdr == null) {
+ message = "Missing " + BEHALF_HEADER + " header.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ 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);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ 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);
+ 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.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
- // Create SUBSCRIPTIONS table entries
- if (doInsert(sub)) {
- // send response
- elr.setResult(HttpServletResponse.SC_CREATED);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_CREATED);
- resp.setContentType(SUBFULL_CONTENT_TYPE);
- resp.setHeader("Location", sub.getLinks().getSelf());
+ // 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"))) {
+ intlogger.debug("Content-type is: " + req.getHeader("Content-Type"));
+ message = "Incorrect content-type";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message, eventlogger);
+ return;
+ }
+ JSONObject jo = getJSONfromInput(req);
+ if (jo == null) {
+ message = "Badly formed JSON";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ if (intlogger.isDebugEnabled()) {
+ intlogger.debug(jo.toString());
+ }
+ if (++activeSubs > maxSubs) {
+ activeSubs--;
+ message = "Cannot create subscription; the maximum number of subscriptions has been configured.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_CONFLICT);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_CONFLICT, message, eventlogger);
+ return;
+ }
+ Subscription sub = null;
try {
- resp.getOutputStream().print(sub.asLimitedJSONObject().toString());
- } catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ sub = new Subscription(jo);
+ } catch (InvalidObjectException e) {
+ activeSubs--;
+ message = e.getMessage();
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
}
+ sub.setFeedid(feedid);
+ sub.setSubscriber(bhdr); // set from X-ATT-DR-ON-BEHALF-OF header
- provisioningDataChanged();
- } else {
- // Something went wrong with the INSERT
- activeSubs--;
- elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
+ // Check if this subscription already exists; not an error (yet), just warn
+ Subscription sub2 = Subscription.getSubscriptionMatching(sub);
+ if (sub2 != null) {
+ intlogger.warn(
+ "PROV0011 Creating a duplicate subscription: new subid=" + sub.getSubid() + ", old subid=" + sub2
+ .getSubid());
+ }
+
+ // Create SUBSCRIPTIONS table entries
+ if (doInsert(sub)) {
+ // send response
+ elr.setResult(HttpServletResponse.SC_CREATED);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_CREATED);
+ resp.setContentType(SUBFULL_CONTENT_TYPE);
+ resp.setHeader("Location", sub.getLinks().getSelf());
+ try {
+ resp.getOutputStream().print(sub.asLimitedJSONObject().toString());
+ } catch (IOException ioe) {
+ eventlogger.error("IOException: " + ioe.getMessage());
+ }
+
+ provisioningDataChanged();
+ } else {
+ // Something went wrong with the INSERT
+ activeSubs--;
+ elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, eventlogger);
+ }
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
}
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 5fa370d1..be79e2ff 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
@@ -61,7 +61,7 @@ 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");
+ .getLogger(SubscriptionServlet.class);
/**
* DELETE on the &lt;subscriptionUrl&gt; -- delete a subscription. See the <i>Deleting a Subscription</i> section in
@@ -69,72 +69,77 @@ public class SubscriptionServlet extends ProxyServlet {
*/
@Override
public void doDelete(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doDelete");
- 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) {
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- if (isProxyServer()) {
- super.doDelete(req, resp);
- return;
- }
- String bhdr = req.getHeader(BEHALF_HEADER);
- if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- int subid = getIdFromPath(req);
- if (subid < 0) {
- message = "Missing or bad subscription number.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- Subscription sub = Subscription.getSubscriptionById(subid);
- if (sub == null) {
- message = "Missing or bad subscription number.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_NOT_FOUND);
- eventlogger.info(elr);
- 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.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
+ setIpFqdnRequestIDandInvocationIDForEelf("doDelete", req);
+ eelflogger.info(EelfMsgs.ENTRY);
+ try {
+ 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) {
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ if (isProxyServer()) {
+ super.doDelete(req, resp);
+ return;
+ }
+ String bhdr = req.getHeader(BEHALF_HEADER);
+ if (bhdr == null) {
+ message = "Missing " + BEHALF_HEADER + " header.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ int subid = getIdFromPath(req);
+ if (subid < 0) {
+ message = "Missing or bad subscription number.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ Subscription sub = Subscription.getSubscriptionById(subid);
+ if (sub == null) {
+ message = "Missing or bad subscription number.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_NOT_FOUND);
+ eventlogger.info(elr);
+ 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.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
- // Delete Subscription
- if (doDelete(sub)) {
- activeSubs--;
- // send response
- elr.setResult(HttpServletResponse.SC_NO_CONTENT);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
- provisioningDataChanged();
- } else {
- // Something went wrong with the DELETE
- elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, intlogger);
+ // Delete Subscription
+ if (doDelete(sub)) {
+ activeSubs--;
+ // send response
+ elr.setResult(HttpServletResponse.SC_NO_CONTENT);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
+ provisioningDataChanged();
+ } else {
+ // Something went wrong with the DELETE
+ elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, intlogger);
+ }
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
@@ -145,68 +150,73 @@ public class SubscriptionServlet extends ProxyServlet {
*/
@Override
public void doGet(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doGet");
- 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) {
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- if (isProxyServer()) {
- super.doGet(req, resp);
- return;
- }
- String bhdr = req.getHeader(BEHALF_HEADER);
- if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- int subid = getIdFromPath(req);
- if (subid < 0) {
- message = "Missing or bad subscription number.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- Subscription sub = Subscription.getSubscriptionById(subid);
- if (sub == null) {
- message = "Missing or bad subscription number.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_NOT_FOUND);
- eventlogger.info(elr);
- 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.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
-
- // send response
- elr.setResult(HttpServletResponse.SC_OK);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType(SUBFULL_CONTENT_TYPE);
+ setIpFqdnRequestIDandInvocationIDForEelf("doGet", req);
+ eelflogger.info(EelfMsgs.ENTRY);
try {
- resp.getOutputStream().print(sub.asJSONObject(true).toString());
- } catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ 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) {
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ if (isProxyServer()) {
+ super.doGet(req, resp);
+ return;
+ }
+ String bhdr = req.getHeader(BEHALF_HEADER);
+ if (bhdr == null) {
+ message = "Missing " + BEHALF_HEADER + " header.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ int subid = getIdFromPath(req);
+ if (subid < 0) {
+ message = "Missing or bad subscription number.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ Subscription sub = Subscription.getSubscriptionById(subid);
+ if (sub == null) {
+ message = "Missing or bad subscription number.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_NOT_FOUND);
+ eventlogger.info(elr);
+ 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.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+
+ // send response
+ elr.setResult(HttpServletResponse.SC_OK);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.setContentType(SUBFULL_CONTENT_TYPE);
+ try {
+ resp.getOutputStream().print(sub.asJSONObject(true).toString());
+ } catch (IOException ioe) {
+ eventlogger.error("IOException: " + ioe.getMessage());
+ }
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
@@ -216,139 +226,144 @@ public class SubscriptionServlet extends ProxyServlet {
*/
@Override
public void doPut(HttpServletRequest req, HttpServletResponse resp) {
- setIpAndFqdnForEelf("doPut");
- 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) {
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- if (isProxyServer()) {
- super.doPut(req, resp);
- return;
- }
- String bhdr = req.getHeader(BEHALF_HEADER);
- if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- int subid = getIdFromPath(req);
- if (subid < 0) {
- message = "Missing or bad subscription number.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- Subscription oldsub = Subscription.getSubscriptionById(subid);
- if (oldsub == null) {
- message = "Missing or bad subscription number.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_NOT_FOUND);
- eventlogger.info(elr);
- 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.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- // 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"))) {
- message = "Incorrect content-type";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message, eventlogger);
- return;
- }
- JSONObject jo = getJSONfromInput(req);
- if (jo == null) {
- message = "Badly formed JSON";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- if (intlogger.isDebugEnabled()) {
- intlogger.debug(jo.toString());
- }
- Subscription sub = null;
+ setIpFqdnRequestIDandInvocationIDForEelf("doPut", req);
+ eelflogger.info(EelfMsgs.ENTRY);
try {
- sub = new Subscription(jo);
- } catch (InvalidObjectException e) {
- message = e.getMessage();
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- sub.setSubid(oldsub.getSubid());
- sub.setFeedid(oldsub.getFeedid());
- sub.setSubscriber(bhdr); // set from X-ATT-DR-ON-BEHALF-OF header
-
- String subjectgroup = (req.getHeader("X-ATT-DR-ON-BEHALF-OF-GROUP")); //Adding for group feature:Rally US708115
- if (!oldsub.getSubscriber().equals(sub.getSubscriber()) && subjectgroup == null) {
- message = "This subscriber must be modified by the same subscriber that created it.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
-
- // Update SUBSCRIPTIONS table entries
- if (doUpdate(sub)) {
- // send response
- elr.setResult(HttpServletResponse.SC_OK);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_OK);
- resp.setContentType(SUBFULL_CONTENT_TYPE);
+ 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) {
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ if (isProxyServer()) {
+ super.doPut(req, resp);
+ return;
+ }
+ String bhdr = req.getHeader(BEHALF_HEADER);
+ if (bhdr == null) {
+ message = "Missing " + BEHALF_HEADER + " header.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ int subid = getIdFromPath(req);
+ if (subid < 0) {
+ message = "Missing or bad subscription number.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ Subscription oldsub = Subscription.getSubscriptionById(subid);
+ if (oldsub == null) {
+ message = "Missing or bad subscription number.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_NOT_FOUND);
+ eventlogger.info(elr);
+ 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.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ // 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"))) {
+ message = "Incorrect content-type";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, message, eventlogger);
+ return;
+ }
+ JSONObject jo = getJSONfromInput(req);
+ if (jo == null) {
+ message = "Badly formed JSON";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ if (intlogger.isDebugEnabled()) {
+ intlogger.debug(jo.toString());
+ }
+ Subscription sub = null;
try {
- resp.getOutputStream().print(sub.asLimitedJSONObject().toString());
- } catch (IOException ioe) {
- eventlogger.error("IOException: " + ioe.getMessage());
+ sub = new Subscription(jo);
+ } catch (InvalidObjectException e) {
+ message = e.getMessage();
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
}
+ sub.setSubid(oldsub.getSubid());
+ sub.setFeedid(oldsub.getFeedid());
+ sub.setSubscriber(bhdr); // set from X-ATT-DR-ON-BEHALF-OF header
- /**Change Owner ship of Subscriber Adding for group feature:Rally US708115*/
- if (jo.has("changeowner") && subjectgroup != null) {
+ String subjectgroup = (req.getHeader("X-ATT-DR-ON-BEHALF-OF-GROUP")); //Adding for group feature:Rally US708115
+ if (!oldsub.getSubscriber().equals(sub.getSubscriber()) && subjectgroup == null) {
+ message = "This subscriber must be modified by the same subscriber that created it.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+
+ // Update SUBSCRIPTIONS table entries
+ if (doUpdate(sub)) {
+ // send response
+ elr.setResult(HttpServletResponse.SC_OK);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_OK);
+ resp.setContentType(SUBFULL_CONTENT_TYPE);
try {
- Boolean changeowner = (Boolean) jo.get("changeowner");
- if (changeowner != null && changeowner.equals(true)) {
- sub.setSubscriber(req.getHeader(BEHALF_HEADER));
- sub.changeOwnerShip();
+ resp.getOutputStream().print(sub.asLimitedJSONObject().toString());
+ } catch (IOException ioe) {
+ eventlogger.error("IOException: " + ioe.getMessage());
+ }
+
+ /**Change Owner ship of Subscriber Adding for group feature:Rally US708115*/
+ if (jo.has("changeowner") && subjectgroup != null) {
+ try {
+ Boolean changeowner = (Boolean) jo.get("changeowner");
+ if (changeowner != null && changeowner.equals(true)) {
+ sub.setSubscriber(req.getHeader(BEHALF_HEADER));
+ sub.changeOwnerShip();
+ }
+ } catch (JSONException je) {
+ eventlogger.error("JSONException: " + je.getMessage());
}
- } catch (JSONException je) {
- eventlogger.error("JSONException: " + je.getMessage());
}
- }
- /***End of change ownership*/
+ /***End of change ownership*/
- provisioningDataChanged();
- } else {
- // Something went wrong with the UPDATE
- elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, intlogger);
+ provisioningDataChanged();
+ } else {
+ // Something went wrong with the UPDATE
+ elr.setResult(HttpServletResponse.SC_INTERNAL_SERVER_ERROR);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_INTERNAL_SERVER_ERROR, DB_PROBLEM_MSG, intlogger);
+ }
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
@@ -366,89 +381,94 @@ public class SubscriptionServlet extends ProxyServlet {
// eventlogger.info(elr);
// resp.sendError(HttpServletResponse.SC_METHOD_NOT_ALLOWED, message);
- setIpAndFqdnForEelf("doPost");
- eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
- EventLogRecord elr = new EventLogRecord(req);
- String message = isAuthorizedForProvisioning(req);
- if (message != null) {
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_FORBIDDEN);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- if (isProxyServer()) {
- super.doPost(req, resp);
- return;
- }
- String bhdr = req.getHeader(BEHALF_HEADER);
- if (bhdr == null) {
- message = "Missing " + BEHALF_HEADER + " header.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- final int subid = getIdFromPath(req);
- if (subid < 0 || Subscription.getSubscriptionById(subid) == null) {
- message = "Missing or bad subscription number.";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
- // 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")) {
- message = "Incorrect content-type";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, 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.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
- return;
- }
- JSONObject jo = getJSONfromInput(req);
- if (jo == null) {
- message = "Badly formed JSON";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
- return;
- }
+ setIpFqdnRequestIDandInvocationIDForEelf("doPost", req);
+ eelflogger.info(EelfMsgs.ENTRY);
try {
- // Only the active POD sends notifications
- boolean active = SynchronizerTask.getSynchronizer().isActive();
- boolean b = jo.getBoolean("failed");
- if (active && !b) {
- // Notify all nodes to reset the subscription
- SubscriberNotifyThread t = new SubscriberNotifyThread();
- t.resetSubscription(subid);
- t.start();
+ eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF, req.getHeader(BEHALF_HEADER));
+ EventLogRecord elr = new EventLogRecord(req);
+ String message = isAuthorizedForProvisioning(req);
+ if (message != null) {
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_FORBIDDEN);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
}
- // send response
- elr.setResult(HttpServletResponse.SC_ACCEPTED);
- eventlogger.info(elr);
- resp.setStatus(HttpServletResponse.SC_ACCEPTED);
- } catch (JSONException e) {
- message = "Badly formed JSON";
- elr.setMessage(message);
- elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
- eventlogger.info(elr);
- sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ if (isProxyServer()) {
+ super.doPost(req, resp);
+ return;
+ }
+ String bhdr = req.getHeader(BEHALF_HEADER);
+ if (bhdr == null) {
+ message = "Missing " + BEHALF_HEADER + " header.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ final int subid = getIdFromPath(req);
+ if (subid < 0 || Subscription.getSubscriptionById(subid) == null) {
+ message = "Missing or bad subscription number.";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ // 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")) {
+ message = "Incorrect content-type";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_UNSUPPORTED_MEDIA_TYPE, 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.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_FORBIDDEN, message, eventlogger);
+ return;
+ }
+ JSONObject jo = getJSONfromInput(req);
+ if (jo == null) {
+ message = "Badly formed JSON";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ return;
+ }
+ try {
+ // Only the active POD sends notifications
+ boolean active = SynchronizerTask.getSynchronizer().isActive();
+ boolean b = jo.getBoolean("failed");
+ if (active && !b) {
+ // Notify all nodes to reset the subscription
+ SubscriberNotifyThread t = new SubscriberNotifyThread();
+ t.resetSubscription(subid);
+ t.start();
+ }
+ // send response
+ elr.setResult(HttpServletResponse.SC_ACCEPTED);
+ eventlogger.info(elr);
+ resp.setStatus(HttpServletResponse.SC_ACCEPTED);
+ } catch (JSONException e) {
+ message = "Badly formed JSON";
+ elr.setMessage(message);
+ elr.setResult(HttpServletResponse.SC_BAD_REQUEST);
+ eventlogger.info(elr);
+ sendResponseError(resp, HttpServletResponse.SC_BAD_REQUEST, message, eventlogger);
+ }
+ } finally {
+ eelflogger.info(EelfMsgs.EXIT);
}
}
diff --git a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/eelf/EelfMsgs.java b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/eelf/EelfMsgs.java
index de16ca4b..b1d856c5 100644
--- a/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/eelf/EelfMsgs.java
+++ b/datarouter-prov/src/main/java/org/onap/dmaap/datarouter/provisioning/eelf/EelfMsgs.java
@@ -42,7 +42,11 @@ public enum EelfMsgs implements EELFResolvableErrorEnum {
* Application message prints user and SUBID (accepts two arguments)
*/
- MESSAGE_WITH_BEHALF_AND_SUBID;
+ MESSAGE_WITH_BEHALF_AND_SUBID,
+
+ ENTRY,
+
+ EXIT;
/**
diff --git a/datarouter-prov/src/main/resources/EelfMessages.properties b/datarouter-prov/src/main/resources/EelfMessages.properties
index b0afa488..889cc9be 100644
--- a/datarouter-prov/src/main/resources/EelfMessages.properties
+++ b/datarouter-prov/src/main/resources/EelfMessages.properties
@@ -2,7 +2,7 @@
# ============LICENSE_START==================================================
# * org.onap.dmaap
# * ===========================================================================
-# * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+# * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
# * ===========================================================================
# * Licensed under the Apache License, Version 2.0 (the "License");
# * you may not use this file except in compliance with the License.
@@ -50,6 +50,12 @@ MESSAGE_WITH__FEEDID=EELF0001I| FeedID = {0}
#Prints User in the EELF apilog
MESSAGE_WITH_BEHALF=EELF0002I| User = {0}
+#Prints api entry point for data router in the EELF apicalls log,
+ENTRY=EELF0004I| Entering data router provisioning component with RequestId and InvocationId
+
+#Prints api exit point for data router in the EELF apicalls log,
+EXIT=EELF0005I| Exiting data router provisioning component with RequestId and InvocationId
+
#Prints User and FeedID in the EELF apilog
MESSAGE_WITH_BEHALF_AND_FEEDID=EELF0003I| User = {0} FeedID = {1}
diff --git a/datarouter-prov/src/main/resources/logback.xml b/datarouter-prov/src/main/resources/logback.xml
index e3d17128..2a3cd821 100644
--- a/datarouter-prov/src/main/resources/logback.xml
+++ b/datarouter-prov/src/main/resources/logback.xml
@@ -45,10 +45,10 @@
<!-- name="auditLogName" value="audit" -->
<!-- name="debugLogName" value="debug" -->
<property name="jettyLogName" value="jetty"></property>
- <property name="defaultPattern" value="%d{MM/dd-HH:mm:ss.SSS}|%logger|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{Timer}|%msg%n" />
+ <property name="defaultPattern" value="%d{MM/dd-HH:mm:ss.SSS}|%logger|%X{RequestId}|%X{InvocationId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{Timer}|%msg%n" />
<property name="jettyLoggerPattern" value="%d{MM/dd-HH:mm:ss.SSS}|%logger|%thread|%.-5level|%msg%n" />
- <property name="debugLoggerPattern" value="%d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{Timer}|[%caller{3}]|%msg%n" />
+ <property name="debugLoggerPattern" value="%d{MM/dd-HH:mm:ss.SSS}|%X{RequestId}|%X{InvocationId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{Timer}|[%caller{3}]|%msg%n" />
<property name="logDirectory" value="${logDir}" />
<!-- property name="debugLogDirectory" value="${debugDir}/${componentName}" /-->
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
index 8cc48683..79c3d219 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/BaseServletTest.java
@@ -24,6 +24,7 @@
package org.onap.dmaap.datarouter.provisioning;
import org.apache.commons.lang3.reflect.FieldUtils;
+import org.junit.Assert;
import org.junit.Before;
import org.junit.Test;
import org.junit.runner.RunWith;
@@ -33,11 +34,16 @@ import org.onap.dmaap.datarouter.provisioning.beans.FeedAuthorization;
import org.onap.dmaap.datarouter.provisioning.beans.Group;
import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
import org.powermock.api.mockito.PowerMockito;
+import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.core.classloader.annotations.SuppressStaticInitializationFor;
import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.MDC;
+
import javax.servlet.http.HttpServletRequest;
import java.util.HashSet;
import java.util.Set;
+import java.util.UUID;
+
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertNull;
@@ -45,11 +51,14 @@ import static org.junit.Assert.assertThat;
import static org.mockito.Matchers.anyInt;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
@RunWith(PowerMockRunner.class)
@SuppressStaticInitializationFor({"org.onap.dmaap.datarouter.provisioning.beans.Feed",
"org.onap.dmaap.datarouter.provisioning.beans.Subscription",
- "org.onap.dmaap.datarouter.provisioning.beans.Group"})
+ "org.onap.dmaap.datarouter.provisioning.beans.Group",
+ "org.onap.dmaap.datarouter.provisioning.BaseServlet"})
+@PrepareForTest({ UUID.class})
public class BaseServletTest extends DrServletTestBase {
private BaseServlet baseServlet;
@@ -193,4 +202,26 @@ public class BaseServletTest extends DrServletTestBase {
when(group.getAuthid()).thenReturn("stub_authID");
assertThat(baseServlet.getGroupBySubGroupId("stub_user", "3"), is(nullValue()));
}
+
+ @Test
+ public void Given_Request_Has_Empty_RequestId_And_InvocationId_Headers_Generate_MDC_Values() {
+ when(request.getHeader("X-ONAP-RequestID")).thenReturn("");
+ when(request.getHeader("X-InvocationID")).thenReturn("");
+ mockStatic(UUID.class);
+ when(UUID.randomUUID().toString()).thenReturn("123", "456");
+ baseServlet.setIpFqdnRequestIDandInvocationIDForEelf("doDelete", request);
+ Assert.assertEquals("123", MDC.get("RequestId"));
+ Assert.assertEquals("456", MDC.get("InvocationId"));
+ }
+
+ @Test
+ public void Given_Request_Has_RequestId_And_InvocationId_Headers_Set_MDC_Values() {
+ when(request.getHeader("X-ONAP-RequestID")).thenReturn("123");
+ when(request.getHeader("X-InvocationID")).thenReturn("456");
+ baseServlet.setIpFqdnRequestIDandInvocationIDForEelf("doDelete", request);
+ Assert.assertEquals("123", MDC.get("RequestId"));
+ Assert.assertEquals("456", MDC.get("InvocationId"));
+ }
+
+
}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java
index 87390bc5..1c8040f6 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DRFeedsServletTest.java
@@ -37,6 +37,9 @@ import java.util.Set;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
@@ -65,9 +68,12 @@ public class DRFeedsServletTest extends DrServletTestBase {
@Mock
private HttpServletResponse response;
+ ListAppender<ILoggingEvent> listAppender;
+
@Before
public void setUp() throws Exception {
super.setUp();
+ listAppender = setTestLogger(DRFeedsServlet.class);
drfeedsServlet = new DRFeedsServlet();
setAuthoriserToReturnRequestIsAuthorized();
setPokerToNotCreateTimersWhenDeleteFeedIsCalled();
@@ -80,6 +86,7 @@ public class DRFeedsServletTest extends DrServletTestBase {
public void Given_Request_Is_HTTP_DELETE_SC_METHOD_NOT_ALLOWED_Response_Is_Generated() throws Exception {
drfeedsServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -89,6 +96,7 @@ public class DRFeedsServletTest extends DrServletTestBase {
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true);
drfeedsServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -137,6 +145,7 @@ public class DRFeedsServletTest extends DrServletTestBase {
when(feed.asJSONObject(true)).thenReturn(mock(JSONObject.class));
drfeedsServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ verifyEnteringExitCalled(listAppender);
}
@@ -153,6 +162,7 @@ public class DRFeedsServletTest extends DrServletTestBase {
public void Given_Request_Is_HTTP_PUT_SC_METHOD_NOT_ALLOWED_Response_Is_Generated() throws Exception {
drfeedsServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@@ -163,6 +173,7 @@ public class DRFeedsServletTest extends DrServletTestBase {
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true);
drfeedsServlet.doPost(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -301,6 +312,7 @@ public class DRFeedsServletTest extends DrServletTestBase {
};
drfeedsServlet.doPost(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_CREATED));
+ verifyEnteringExitCalled(listAppender);
}
@NotNull
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
index c7f639ed..265a2ee9 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/DrServletTestBase.java
@@ -23,17 +23,30 @@
package org.onap.dmaap.datarouter.provisioning;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.After;
+import org.junit.AfterClass;
+import org.junit.Assert;
import org.junit.Before;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.slf4j.LoggerFactory;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
import java.util.Properties;
+import java.util.Scanner;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.mock;
import static org.mockito.Mockito.when;
public class DrServletTestBase {
+
@Before
public void setUp() throws Exception {
Properties props = new Properties();
@@ -48,8 +61,21 @@ public class DrServletTestBase {
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "synctask", synchronizerTask, true);
}
+ public ListAppender<ILoggingEvent> setTestLogger(Class c) {
+ Logger logger = (Logger) LoggerFactory.getLogger(c);
+ ListAppender<ILoggingEvent> listAppender = new ListAppender<>();
+ listAppender.start();
+ logger.addAppender(listAppender);
+ return listAppender;
+ }
+
+ public void verifyEnteringExitCalled(ListAppender<ILoggingEvent> listAppender) {
+ assertEquals("EELF0004I Entering data router provisioning component with RequestId and InvocationId", listAppender.list.get(0).getMessage());
+ assertEquals("EELF0005I Exiting data router provisioning component with RequestId and InvocationId", listAppender.list.get(2).getMessage());
+ assertEquals(3, listAppender.list.size());
+ }
+
@After
public void tearDown() throws Exception {
-
}
}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java
index 78ac0939..ca4ccd8c 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/FeedServletTest.java
@@ -22,6 +22,8 @@
******************************************************************************/
package org.onap.dmaap.datarouter.provisioning;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.jetbrains.annotations.NotNull;
import org.json.JSONArray;
@@ -69,6 +71,8 @@ public class FeedServletTest extends DrServletTestBase {
private static EntityManager em;
private DB db;
+ ListAppender<ILoggingEvent> listAppender;
+
@BeforeClass
public static void init() {
emf = Persistence.createEntityManagerFactory("dr-unit-tests");
@@ -87,6 +91,7 @@ public class FeedServletTest extends DrServletTestBase {
@Before
public void setUp() throws Exception {
+ listAppender = setTestLogger(FeedServlet.class);
feedServlet = new FeedServlet();
db = new DB();
setAuthoriserToReturnRequestIsAuthorized();
@@ -101,6 +106,7 @@ public class FeedServletTest extends DrServletTestBase {
when(request.isSecure()).thenReturn(false);
feedServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@@ -160,6 +166,7 @@ public class FeedServletTest extends DrServletTestBase {
feedServlet.doDelete(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_NO_CONTENT));
reinsertFeedIntoDb();
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -168,6 +175,7 @@ public class FeedServletTest extends DrServletTestBase {
when(request.isSecure()).thenReturn(false);
feedServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -212,6 +220,7 @@ public class FeedServletTest extends DrServletTestBase {
when(response.getOutputStream()).thenReturn(outStream);
feedServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ verifyEnteringExitCalled(listAppender);
}
@@ -221,6 +230,7 @@ public class FeedServletTest extends DrServletTestBase {
when(request.isSecure()).thenReturn(false);
feedServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -387,12 +397,14 @@ public class FeedServletTest extends DrServletTestBase {
};
feedServlet.doPut(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ verifyEnteringExitCalled(listAppender);
}
@Test
public void Given_Request_Is_HTTP_POST_SC_METHOD_NOT_ALLOWED_Response_Is_Generated() throws Exception {
feedServlet.doPost(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@NotNull
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java
index 591dcc3d..b421e99e 100644
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/InternalServletTest.java
@@ -41,6 +41,8 @@ import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.junit.Before;
import org.junit.Test;
@@ -70,6 +72,8 @@ public class InternalServletTest extends DrServletTestBase {
@Mock
private HttpServletResponse response;
+ ListAppender<ILoggingEvent> listAppender;
+
@BeforeClass
public static void init() {
emf = Persistence.createEntityManagerFactory("dr-unit-tests");
@@ -88,8 +92,9 @@ public class InternalServletTest extends DrServletTestBase {
@Before
public void setUp() throws Exception {
- internalServlet = new InternalServlet();
- setUpValidAuthorisedRequest();
+ listAppender = setTestLogger(InternalServlet.class);
+ internalServlet = new InternalServlet();
+ setUpValidAuthorisedRequest();
}
@Test
@@ -99,6 +104,7 @@ public class InternalServletTest extends DrServletTestBase {
internalServlet.doGet(request, response);
verify(response)
.sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -127,6 +133,7 @@ public class InternalServletTest extends DrServletTestBase {
when(request.isSecure()).thenReturn(false);
internalServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -207,6 +214,7 @@ public class InternalServletTest extends DrServletTestBase {
internalServlet.doPut(request, response);
verify(response)
.sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -218,6 +226,7 @@ public class InternalServletTest extends DrServletTestBase {
setPokerToNotCreateTimers();
internalServlet.doPut(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -249,6 +258,7 @@ public class InternalServletTest extends DrServletTestBase {
internalServlet.doDelete(request, response);
verify(response)
.sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -261,6 +271,7 @@ public class InternalServletTest extends DrServletTestBase {
setPokerToNotCreateTimers();
internalServlet.doDelete(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -291,6 +302,7 @@ public class InternalServletTest extends DrServletTestBase {
internalServlet.doPost(request, response);
verify(response)
.sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -302,6 +314,7 @@ public class InternalServletTest extends DrServletTestBase {
setPokerToNotCreateTimers();
internalServlet.doPost(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ verifyEnteringExitCalled(listAppender);
}
@Test
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java
index e411bdc0..03e3d4f2 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/LogServletTest.java
@@ -23,6 +23,8 @@
package org.onap.dmaap.datarouter.provisioning;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
import org.junit.Before;
import org.junit.BeforeClass;
import org.junit.AfterClass;
@@ -58,6 +60,8 @@ public class LogServletTest extends DrServletTestBase {
@Mock
private HttpServletResponse response;
+ ListAppender<ILoggingEvent> listAppender;
+
@BeforeClass
public static void init() {
emf = Persistence.createEntityManagerFactory("dr-unit-tests");
@@ -76,6 +80,7 @@ public class LogServletTest extends DrServletTestBase {
@Before
public void setUp() throws Exception {
+ listAppender = setTestLogger(LogServlet.class);
logServlet = new LogServlet(true);
setUpValidParameterValuesForMap();
}
@@ -85,6 +90,7 @@ public class LogServletTest extends DrServletTestBase {
throws Exception {
logServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -93,6 +99,7 @@ public class LogServletTest extends DrServletTestBase {
when(request.getPathInfo()).thenReturn(null);
logServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_BAD_REQUEST), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -148,6 +155,7 @@ public class LogServletTest extends DrServletTestBase {
throws Exception {
logServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -155,6 +163,7 @@ public class LogServletTest extends DrServletTestBase {
throws Exception {
logServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -162,6 +171,7 @@ public class LogServletTest extends DrServletTestBase {
throws Exception {
logServlet.doPost(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/PublishServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/PublishServletTest.java
index cee09e5c..b99e63c0 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/PublishServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/PublishServletTest.java
@@ -23,15 +23,17 @@
package org.onap.dmaap.datarouter.provisioning;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
import org.apache.commons.lang3.reflect.FieldUtils;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.*;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
+import org.powermock.core.classloader.annotations.PrepareForTest;
import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.LoggerFactory;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -40,17 +42,25 @@ import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
+import java.net.InetAddress;
+
import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Matchers.*;
import static org.mockito.Mockito.verify;
import static org.mockito.Mockito.when;
+import static org.powermock.api.mockito.PowerMockito.mockStatic;
/**
* Created by ezcoxem on 21/08/2018.
*/
@RunWith(PowerMockRunner.class)
-public class PublishServletTest {
+@PrepareForTest({InetAddress.class })
+public class PublishServletTest extends DrServletTestBase {
private PublishServlet publishServlet;
@Mock
@@ -63,6 +73,8 @@ public class PublishServletTest {
private static EntityManager em;
private DB db;
+ ListAppender<ILoggingEvent> listAppender;
+
@BeforeClass
public static void init() {
emf = Persistence.createEntityManagerFactory("dr-unit-tests");
@@ -73,7 +85,7 @@ public class PublishServletTest {
}
@AfterClass
- public static void tearDownClass() {
+ public static void tearDownClass() throws FileNotFoundException {
em.clear();
em.close();
emf.close();
@@ -82,6 +94,7 @@ public class PublishServletTest {
@Before
public void setUp() throws Exception {
+ listAppender = setTestLogger(PublishServlet.class);
publishServlet = new PublishServlet();
db = new DB();
}
@@ -93,6 +106,7 @@ public class PublishServletTest {
publishServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_SERVICE_UNAVAILABLE), argThat(notNullValue(String.class)));
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "nodes", new String[1], true);
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -135,6 +149,7 @@ public class PublishServletTest {
setConditionsForPositiveSuccessFlow();
publishServlet.doDelete(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_MOVED_PERMANENTLY));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -144,6 +159,7 @@ public class PublishServletTest {
publishServlet.doPut(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_MOVED_PERMANENTLY));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -153,15 +169,32 @@ public class PublishServletTest {
publishServlet.doPost(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_MOVED_PERMANENTLY));
+ verifyEnteringExitCalled(listAppender);
}
@Test
- public void Given_Request_Is_HTTP_GET_And_Request_succeeds()
+ public void Given_Request_Is_HTTP_GET_And_Request_succeeds_And_RequestId_Header_is_empty()
throws Exception {
setConditionsForPositiveSuccessFlow();
+ mockStatic(InetAddress.class);
+ publishServlet.doGet(request, response);
+ verify(response).setStatus(eq(HttpServletResponse.SC_MOVED_PERMANENTLY));
+ verifyEnteringExitCalled(listAppender);
+ assertEquals(null, listAppender.list.get(0).getMDCPropertyMap().get("RequestId"));
+ assertEquals(null, listAppender.list.get(0).getMDCPropertyMap().get("InvocationId"));
+ }
+ @Test
+ public void Given_Request_Is_HTTP_GET_And_Request_succeeds_And_RequestId_Header_Is_Not_Empty()
+ throws Exception {
+ setConditionsForPositiveSuccessFlow();
+ when(request.getHeader("X-ONAP-RequestID")).thenReturn("123");
+ when(request.getHeader("X-InvocationID")).thenReturn("456");
publishServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_MOVED_PERMANENTLY));
+ verifyEnteringExitCalled(listAppender);
+ assertEquals("123", listAppender.list.get(0).getMDCPropertyMap().get("RequestId"));
+ assertEquals("456", listAppender.list.get(0).getMDCPropertyMap().get("InvocationId"));
}
private void setConditionsForPositiveSuccessFlow() throws Exception {
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java
index 25341d42..a3431ce9 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscribeServletTest.java
@@ -22,6 +22,8 @@
******************************************************************************/
package org.onap.dmaap.datarouter.provisioning;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
@@ -61,9 +63,12 @@ public class SubscribeServletTest extends DrServletTestBase {
@Mock
private HttpServletResponse response;
+ ListAppender<ILoggingEvent> listAppender;
+
@Before
public void setUp() throws Exception {
super.setUp();
+ listAppender = setTestLogger(SubscribeServlet.class);
subscribeServlet = new SubscribeServlet();
setAuthoriserToReturnRequestIsAuthorized();
setPokerToNotCreateTimersWhenDeleteFeedIsCalled();
@@ -76,6 +81,7 @@ public class SubscribeServletTest extends DrServletTestBase {
public void Given_Request_Is_HTTP_DELETE_SC_METHOD_NOT_ALLOWED_Response_Is_Generated() throws Exception {
subscribeServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -84,6 +90,7 @@ public class SubscribeServletTest extends DrServletTestBase {
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true);
subscribeServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -127,6 +134,7 @@ public class SubscribeServletTest extends DrServletTestBase {
PowerMockito.when(Subscription.getSubscriptionUrlList(anyInt())).thenReturn(list);
subscribeServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ verifyEnteringExitCalled(listAppender);
}
@@ -134,6 +142,7 @@ public class SubscribeServletTest extends DrServletTestBase {
public void Given_Request_Is_HTTP_PUT_SC_METHOD_NOT_ALLOWED_Response_Is_Generated() throws Exception {
subscribeServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_METHOD_NOT_ALLOWED), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
public void Given_Request_Is_HTTP_POST_And_Is_Not_Secure_When_HTTPS_Is_Required_Then_Forbidden_Response_Is_Generated() throws Exception {
@@ -141,6 +150,7 @@ public class SubscribeServletTest extends DrServletTestBase {
FieldUtils.writeDeclaredStaticField(BaseServlet.class, "isAddressAuthEnabled", "true", true);
subscribeServlet.doPost(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -253,6 +263,7 @@ public class SubscribeServletTest extends DrServletTestBase {
};
subscribeServlet.doPost(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_CREATED));
+ verifyEnteringExitCalled(listAppender);
}
diff --git a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java
index 472be512..02d73cc1 100755
--- a/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java
+++ b/datarouter-prov/src/test/java/org/onap/dmaap/datarouter/provisioning/SubscriptionServletTest.java
@@ -22,13 +22,13 @@
******************************************************************************/
package org.onap.dmaap.datarouter.provisioning;
+import ch.qos.logback.classic.Logger;
+import ch.qos.logback.classic.spi.ILoggingEvent;
+import ch.qos.logback.core.read.ListAppender;
import org.apache.commons.lang3.reflect.FieldUtils;
import org.jetbrains.annotations.NotNull;
import org.json.JSONObject;
-import org.junit.AfterClass;
-import org.junit.Before;
-import org.junit.BeforeClass;
-import org.junit.Test;
+import org.junit.*;
import org.junit.runner.RunWith;
import org.mockito.Mock;
import org.onap.dmaap.datarouter.authz.AuthorizationResponse;
@@ -39,6 +39,7 @@ import org.onap.dmaap.datarouter.provisioning.beans.Subscription;
import org.onap.dmaap.datarouter.provisioning.beans.Updateable;
import org.onap.dmaap.datarouter.provisioning.utils.DB;
import org.powermock.modules.junit4.PowerMockRunner;
+import org.slf4j.LoggerFactory;
import javax.persistence.EntityManager;
import javax.persistence.EntityManagerFactory;
@@ -47,17 +48,21 @@ import javax.servlet.ServletInputStream;
import javax.servlet.ServletOutputStream;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
+import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.PrintWriter;
import java.sql.SQLException;
import java.util.HashSet;
import java.util.Set;
import static org.hamcrest.Matchers.notNullValue;
+import static org.junit.Assert.assertEquals;
import static org.mockito.Mockito.*;
import static org.onap.dmaap.datarouter.provisioning.BaseServlet.BEHALF_HEADER;
@RunWith(PowerMockRunner.class)
-public class SubscriptionServletTest {
+public class SubscriptionServletTest extends DrServletTestBase {
private static EntityManagerFactory emf;
private static EntityManager em;
private SubscriptionServlet subscriptionServlet;
@@ -66,11 +71,14 @@ public class SubscriptionServletTest {
private final String USER = "user1";
private final String PASSWORD="password1";
+
@Mock
private HttpServletRequest request;
@Mock
private HttpServletResponse response;
+ ListAppender<ILoggingEvent> listAppender;
+
@BeforeClass
public static void init() {
emf = Persistence.createEntityManagerFactory("dr-unit-tests");
@@ -81,7 +89,7 @@ public class SubscriptionServletTest {
}
@AfterClass
- public static void tearDownClass() {
+ public static void tearDownClass() throws FileNotFoundException {
em.clear();
em.close();
emf.close();
@@ -89,6 +97,7 @@ public class SubscriptionServletTest {
@Before
public void setUp() throws Exception {
+ listAppender = setTestLogger(SubscriptionServlet.class);
subscriptionServlet = new SubscriptionServlet();
db = new DB();
setAuthoriserToReturnRequestIsAuthorized();
@@ -102,6 +111,7 @@ public class SubscriptionServletTest {
when(request.isSecure()).thenReturn(false);
subscriptionServlet.doDelete(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -147,6 +157,7 @@ public class SubscriptionServletTest {
public void Given_Request_Is_HTTP_DELETE_And_Delete_On_Database_Succeeds_A_NO_CONTENT_Response_Is_Generated() throws Exception {
subscriptionServlet.doDelete(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_NO_CONTENT));
+ verifyEnteringExitCalled(listAppender);
insertSubscriptionIntoDb();
}
@@ -155,6 +166,7 @@ public class SubscriptionServletTest {
when(request.isSecure()).thenReturn(false);
subscriptionServlet.doGet(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -191,6 +203,7 @@ public class SubscriptionServletTest {
when(response.getOutputStream()).thenReturn(outStream);
subscriptionServlet.doGet(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -198,6 +211,7 @@ public class SubscriptionServletTest {
when(request.isSecure()).thenReturn(false);
subscriptionServlet.doPut(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -328,6 +342,7 @@ public class SubscriptionServletTest {
subscriptionServlet.doPut(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_OK));
changeSubscriptionBackToNormal();
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -335,6 +350,7 @@ public class SubscriptionServletTest {
when(request.isSecure()).thenReturn(false);
subscriptionServlet.doPost(request, response);
verify(response).sendError(eq(HttpServletResponse.SC_FORBIDDEN), argThat(notNullValue(String.class)));
+ verifyEnteringExitCalled(listAppender);
}
@Test
@@ -423,6 +439,7 @@ public class SubscriptionServletTest {
};
subscriptionServlet.doPost(request, response);
verify(response).setStatus(eq(HttpServletResponse.SC_ACCEPTED));
+ verifyEnteringExitCalled(listAppender);
}
@NotNull
diff --git a/datarouter-prov/src/test/resources/logback-test.xml b/datarouter-prov/src/test/resources/logback-test.xml
new file mode 100644
index 00000000..c2994ebe
--- /dev/null
+++ b/datarouter-prov/src/test/resources/logback-test.xml
@@ -0,0 +1,122 @@
+<!--
+ ============LICENSE_START==================================================
+ * org.onap.dmaap
+ * ===========================================================================
+ * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
+ * ===========================================================================
+ * Licensed under the Apache License, Version 2.0 (the "License");
+ * you may not use this file except in compliance with the License.
+ * You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing, software
+ * distributed under the License is distributed on an "AS IS" BASIS,
+ * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
+ * See the License for the specific language governing permissions and
+ * limitations under the License.
+ * ============LICENSE_END====================================================
+ *
+ * ECOMP is a trademark and service mark of AT&T Intellectual Property.
+ *
+-->
+<configuration scan="true" scanPeriod="3 seconds" debug="true">
+ <property name="logDir" value="logs/EELF" />
+ <property name="generalLogName" value="application" />
+ <property name="errorLogName" value="errors" />
+ <property name="defaultPattern" value="%d{MM/dd-HH:mm:ss.SSS}|%logger|%X{RequestId}|%X{InvocationId}|%X{ServiceInstanceId}|%thread|%X{ServiceName}|%X{InstanceUUID}|%.-5level|%X{AlertSeverity}|%X{ServerIPAddress}|%X{ServerFQDN}|%X{RemoteHost}|%X{Timer}|%msg%n" />
+ <property name="logDirectory" value="${logDir}" />
+ <appender name="STDOUT" class="ch.qos.logback.core.ConsoleAppender">
+ <encoder>
+ <pattern>${defaultPattern}</pattern>
+ </encoder>
+ </appender>
+
+ <!-- ============================================================================ -->
+ <!-- EELF Appenders -->
+ <!-- ============================================================================ -->
+
+ <!-- The EELFAppender is used to record events to the general application
+ log -->
+
+
+ <appender name="EELF"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${logDirectory}/${generalLogName}.log</file>
+ <filter class="ch.qos.logback.classic.filter.LevelFilter">
+ <level>INFO</level>
+ <onMatch>ACCEPT</onMatch>
+ <onMismatch>DENY</onMismatch>
+ </filter>
+ <rollingPolicy
+ class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${logDirectory}/${generalLogName}.%i.log.zip
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>9</maxIndex>
+ </rollingPolicy>
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>5MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${defaultPattern}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="asyncEELF" class="ch.qos.logback.classic.AsyncAppender">
+ <queueSize>256</queueSize>
+ <appender-ref ref="EELF" />
+ </appender>
+
+ <appender name="EELFError"
+ class="ch.qos.logback.core.rolling.RollingFileAppender">
+ <file>${logDirectory}/${errorLogName}.log</file>
+ <filter class="ch.qos.logback.classic.filter.LevelFilter">
+ <level>ERROR</level>
+ <onMatch>ACCEPT</onMatch>
+ <onMismatch>DENY</onMismatch>
+ </filter>
+ <rollingPolicy
+ class="ch.qos.logback.core.rolling.FixedWindowRollingPolicy">
+ <fileNamePattern>${logDirectory}/${errorLogName}.%i.log.zip
+ </fileNamePattern>
+ <minIndex>1</minIndex>
+ <maxIndex>9</maxIndex>
+ </rollingPolicy>
+ <triggeringPolicy
+ class="ch.qos.logback.core.rolling.SizeBasedTriggeringPolicy">
+ <maxFileSize>5MB</maxFileSize>
+ </triggeringPolicy>
+ <encoder>
+ <pattern>${defaultPattern}</pattern>
+ </encoder>
+ </appender>
+
+ <appender name="asyncEELFError" class="ch.qos.logback.classic.AsyncAppender">
+ <queueSize>256</queueSize>
+ <appender-ref ref="EELFError"/>
+ </appender>
+
+ <!-- ============================================================================ -->
+ <!-- EELF loggers -->
+ <!-- ============================================================================ -->
+ <logger name="com.att.eelf" level="info" additivity="false">
+ <appender-ref ref="asyncEELF" />
+ </logger>
+
+ <logger name="com.att.eelf.error" level="error" additivity="false">
+ <appender-ref ref="asyncEELFError" />
+ </logger>
+
+ <logger name="log4j.logger.org.eclipse.jetty" additivity="false" level="info">
+ <appender-ref ref="asyncEELFjettyAndNodelog"/>
+ </logger>
+
+ <root level="INFO">
+ <appender-ref ref="asyncEELF" />
+ <appender-ref ref="asyncEELFError" />
+ <appender-ref ref="asyncEELFjettyAndNodelog" />
+ </root>
+
+</configuration>