diff options
author | EmmettCox <emmett.cox@est.tech> | 2019-01-14 17:19:45 +0000 |
---|---|---|
committer | ezcoxem <emmett.cox@est.tech> | 2019-01-31 16:15:21 +0000 |
commit | 14b8d9552808063686e0c22760cec6e35b960b59 (patch) | |
tree | 286336813c8da64ca8a8b5d27f21f2bc83f26e0f /datarouter-prov/src/main/java/org/onap | |
parent | 72cd9f3033731242779e708a05f9519f36cf8d43 (diff) |
Add RequestId and InvocationId to DR
Change-Id: I42575123396ce4b07c824846a8b2b3ca49dfbd85
Issue-ID: DMAAP-941
Signed-off-by: EmmettCox <emmett.cox@est.tech>
Diffstat (limited to 'datarouter-prov/src/main/java/org/onap')
9 files changed, 1566 insertions, 1389 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/<feednumber>. @@ -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/<parameter>. 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 <publishURL> 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 <subscribeUrl> -- 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 <subscriptionUrl> -- 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;
/**
|