import org.slf4j.MDC;
/**
- * Servlet for handling all http and https requests to the data router node
- * <p>
- * Handled requests are:
+ * Servlet for handling all http and https requests to the data router node.
+ *
+ * <p>Handled requests are:
* <br>
* GET http://<i>node</i>/internal/fetchProv - fetch the provisioning data
* <br>
}
/**
- * Get the NodeConfigurationManager
+ * Get the NodeConfigurationManager.
*/
@Override
public void init() {
config = NodeConfigManager.getInstance();
- eelfLogger.info("NODE0101 Node Servlet Configured");
+ eelfLogger.debug("NODE0101 Node Servlet Configured");
}
private boolean down(HttpServletResponse resp) {
if (config.isShutdown() || !config.isConfigured()) {
sendResponseError(resp, HttpServletResponse.SC_SERVICE_UNAVAILABLE, eelfLogger);
- eelfLogger.info("NODE0102 Rejecting request: Service is being quiesced");
+ eelfLogger.error("NODE0102 Rejecting request: Service is being quiesced");
return true;
}
return false;
}
/**
- * Handle a GET for /internal/fetchProv
+ * Handle a GET for /internal/fetchProv.
*/
@Override
protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
NodeUtils.setRequestIdAndInvocationId(req);
eelfLogger.info(EelfMsgs.ENTRY);
try {
- eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
+ eelfLogger.debug(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
getIdFromPath(req) + "");
if (down(resp)) {
return;
}
}
- eelfLogger.info("NODE0103 Rejecting invalid GET of " + path + FROM + ip);
+ eelfLogger.debug("NODE0103 Rejecting invalid GET of " + path + FROM + ip);
sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, eelfLogger);
} finally {
eelfLogger.info(EelfMsgs.EXIT);
}
/**
- * Handle all PUT requests
+ * Handle all PUT requests.
*/
@Override
protected void doPut(HttpServletRequest req, HttpServletResponse resp) {
NodeUtils.setIpAndFqdnForEelf("doPut");
NodeUtils.setRequestIdAndInvocationId(req);
eelfLogger.info(EelfMsgs.ENTRY);
- eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
+ eelfLogger.debug(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
getIdFromPath(req) + "");
try {
common(req, resp, true);
}
/**
- * Handle all DELETE requests
+ * Handle all DELETE requests.
*/
@Override
protected void doDelete(HttpServletRequest req, HttpServletResponse resp) {
NodeUtils.setIpAndFqdnForEelf("doDelete");
NodeUtils.setRequestIdAndInvocationId(req);
eelfLogger.info(EelfMsgs.ENTRY);
- eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
+ eelfLogger.debug(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
getIdFromPath(req) + "");
try {
common(req, resp, false);
}
if (fileid.startsWith(PUBLISH)) {
fileid = fileid.substring(9);
- int i = fileid.indexOf('/');
- if (i == -1 || i == fileid.length() - 1) {
+ int index = fileid.indexOf('/');
+ if (index == -1 || index == fileid.length() - 1) {
eelfLogger.error("NODE0205 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + FROM + req
.getRemoteAddr());
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
eelfLogger.info(EelfMsgs.EXIT);
return;
}
- feedid = fileid.substring(0, i);
+ feedid = fileid.substring(0, index);
if (config.getCadiEnabled()) {
String path = req.getPathInfo();
if (!("legacy".equalsIgnoreCase(aafInstance))) {
isAAFFeed = true;
String permission = config.getPermission(aafInstance);
- eelfLogger.info("NodeServlet.common() permission string - " + permission);
+ eelfLogger.debug("NodeServlet.common() permission string - " + permission);
//Check in CADI Framework API if user has AAF permission or not
if (!req.isUserInRole(permission)) {
String message = "AAF disallows access to permission string - " + permission;
}
}
- fileid = fileid.substring(i + 1);
+ fileid = fileid.substring(index + 1);
pubid = config.getPublishId();
targets = config.getTargets(feedid);
} else if (fileid.startsWith(INTERNAL_PUBLISH)) {
.cleanString(feedid) + " fileid " + PathUtil.cleanString(fileid) + FROM + PathUtil
.cleanString(ip) + " reason Invalid AAF user- " + PathUtil.cleanString(reason));
String message = "Invalid AAF user- " + PathUtil.cleanString(reason);
- eelfLogger.info("NODE0308 Rejecting unauthenticated PUT or DELETE of " + PathUtil
+ eelfLogger.debug("NODE0308 Rejecting unauthenticated PUT or DELETE of " + PathUtil
.cleanString(req.getPathInfo()) + FROM + PathUtil.cleanString(req.getRemoteAddr()));
resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
return;
}
String redirto = HTTPS + newnode + port + PUBLISH + feedid + "/" + fileid;
eelfLogger
- .info("NODE0108 Redirecting publish attempt for feed " + PathUtil.cleanString(feedid) + USER
+ .debug("NODE0108 Redirecting publish attempt for feed " + PathUtil.cleanString(feedid) + USER
+ PathUtil.cleanString(user) + " ip " + PathUtil.cleanString(ip) + " to " + PathUtil
.cleanString(redirto)); //Fortify scan fixes - log forging
resp.sendRedirect(PathUtil.cleanString(redirto)); //Fortify scan fixes-open redirect - 2 issues
while (hnames.hasMoreElements()) {
String hn = (String) hnames.nextElement();
String hnlc = hn.toLowerCase();
- if ((isput && ("content-type".equals(hnlc) ||
- "content-language".equals(hnlc) ||
- "content-md5".equals(hnlc) ||
- "content-range".equals(hnlc))) ||
- "x-dmaap-dr-meta".equals(hnlc) ||
- (feedid == null && "x-dmaap-dr-received".equals(hnlc)) ||
- (hnlc.startsWith("x-") && !hnlc.startsWith("x-dmaap-dr-"))) {
+ if ((isput && ("content-type".equals(hnlc)
+ || "content-language".equals(hnlc)
+ || "content-md5".equals(hnlc)
+ || "content-range".equals(hnlc)))
+ || "x-dmaap-dr-meta".equals(hnlc)
+ || (feedid == null && "x-dmaap-dr-received".equals(hnlc))
+ || (hnlc.startsWith("x-") && !hnlc.startsWith("x-dmaap-dr-"))) {
Enumeration hvals = req.getHeaders(hn);
while (hvals.hasMoreElements()) {
String hv = (String) hvals.nextElement();
private String writeInputStreamToFile(HttpServletRequest req, File data) {
byte[] buf = new byte[1024 * 1024];
- int i;
+ int bytesRead;
try (OutputStream dos = new FileOutputStream(data);
InputStream is = req.getInputStream()) {
- while ((i = is.read(buf)) > 0) {
- dos.write(buf, 0, i);
+ while ((bytesRead = is.read(buf)) > 0) {
+ dos.write(buf, 0, bytesRead);
}
} catch (IOException ioe) {
eelfLogger.error("NODE0530 Exception common: " + ioe, ioe);
final String FROM_DR_MESSAGE = ".M) from DR Node: ";
try {
fileid = fileid.substring(8);
- int i = fileid.indexOf('/');
- if (i == -1 || i == fileid.length() - 1) {
+ int index = fileid.indexOf('/');
+ if (index == -1 || index == fileid.length() - 1) {
eelfLogger.error("NODE0112 Rejecting bad URI for DELETE of " + req.getPathInfo() + FROM + req
.getRemoteAddr());
resp.sendError(HttpServletResponse.SC_NOT_FOUND,
eelfLogger.info(EelfMsgs.EXIT);
return;
}
- String subscriptionId = fileid.substring(0, i);
+ String subscriptionId = fileid.substring(0, index);
int subId = Integer.parseInt(subscriptionId);
- pubid = fileid.substring(i + 1);
+ pubid = fileid.substring(index + 1);
String errorMessage = "Unable to delete files (" + pubid + ", " + pubid + FROM_DR_MESSAGE
+ config.getMyName() + ".";
int subIdDir = subId - (subId % 100);
}
boolean result = delivery.markTaskSuccess(config.getSpoolBase() + "/s/" + subIdDir + "/" + subId, pubid);
if (result) {
- eelfLogger.info("NODE0115 Successfully deleted files (" + pubid + ", " + pubid + FROM_DR_MESSAGE
+ eelfLogger.debug("NODE0115 Successfully deleted files (" + pubid + ", " + pubid + FROM_DR_MESSAGE
+ config.getMyName());
resp.setStatus(HttpServletResponse.SC_OK);
eelfLogger.info(EelfMsgs.EXIT);
return false;
}
} catch (NullPointerException npe) {
- eelfLogger.error("NODE0114 " + errorMessage + " Error: Subscription " + subscriptionId +
- " does not exist", npe);
+ eelfLogger.error("NODE0114 " + errorMessage + " Error: Subscription " + subscriptionId
+ + " does not exist", npe);
resp.sendError(HttpServletResponse.SC_NOT_FOUND);
eelfLogger.info(EelfMsgs.EXIT);
return false;