Remove major and minor code smells in dr-node
[dmaap/datarouter.git] / datarouter-node / src / main / java / org / onap / dmaap / datarouter / node / NodeServlet.java
index d665080..3f2fc09 100644 (file)
 
 package org.onap.dmaap.datarouter.node;
 
+import static org.onap.dmaap.datarouter.node.NodeUtils.sendResponseError;
+
 import com.att.eelf.configuration.EELFLogger;
 import com.att.eelf.configuration.EELFManager;
-import org.jetbrains.annotations.Nullable;
-import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
-import org.slf4j.MDC;
-
-import javax.servlet.http.HttpServlet;
-import javax.servlet.http.HttpServletRequest;
-import javax.servlet.http.HttpServletResponse;
 import java.io.File;
 import java.io.FileOutputStream;
 import java.io.FileWriter;
@@ -45,8 +40,12 @@ import java.nio.file.Path;
 import java.nio.file.Paths;
 import java.util.Enumeration;
 import java.util.regex.Pattern;
-
-import static org.onap.dmaap.datarouter.node.NodeUtils.sendResponseError;
+import javax.servlet.http.HttpServlet;
+import javax.servlet.http.HttpServletRequest;
+import javax.servlet.http.HttpServletResponse;
+import org.jetbrains.annotations.Nullable;
+import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
+import org.slf4j.MDC;
 
 /**
  * Servlet for handling all http and https requests to the data router node
@@ -61,23 +60,27 @@ import static org.onap.dmaap.datarouter.node.NodeUtils.sendResponseError;
  */
 public class NodeServlet extends HttpServlet {
 
+    private static final String FROM = " from ";
+    private static final String INVALID_REQUEST_URI = "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.";
+    private static final String IO_EXCEPTION = "IOException";
+    private static final String ON_BEHALF_OF = "X-DMAAP-DR-ON-BEHALF-OF";
     private static NodeConfigManager config;
-    private static Pattern MetaDataPattern;
+    private static Pattern metaDataPattern;
     private static EELFLogger eelfLogger = EELFManager.getInstance().getLogger(NodeServlet.class);
-    private final Delivery delivery;
 
     static {
         final String ws = "\\s*";
         // assume that \\ and \" have been replaced by X
         final String string = "\"[^\"]*\"";
-        //String string = "\"(?:[^\"\\\\]|\\\\.)*\"";
         final String number = "[+-]?(?:\\.\\d+|(?:0|[1-9]\\d*)(?:\\.\\d*)?)(?:[eE][+-]?\\d+)?";
         final String value = "(?:" + string + "|" + number + "|null|true|false)";
         final String item = string + ws + ":" + ws + value + ws;
         final String object = ws + "\\{" + ws + "(?:" + item + "(?:" + "," + ws + item + ")*)?\\}" + ws;
-        MetaDataPattern = Pattern.compile(object, Pattern.DOTALL);
+        metaDataPattern = Pattern.compile(object, Pattern.DOTALL);
     }
 
+    private final Delivery delivery;
+
     NodeServlet(Delivery delivery) {
         this.delivery = delivery;
     }
@@ -91,7 +94,7 @@ public class NodeServlet extends HttpServlet {
         eelfLogger.info("NODE0101 Node Servlet Configured");
     }
 
-    private boolean down(HttpServletResponse resp) throws IOException {
+    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");
@@ -109,15 +112,10 @@ public class NodeServlet extends HttpServlet {
         NodeUtils.setRequestIdAndInvocationId(req);
         eelfLogger.info(EelfMsgs.ENTRY);
         try {
-            eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-DMAAP-DR-ON-BEHALF-OF"),
+            eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
                     getIdFromPath(req) + "");
-            try {
-                if (down(resp)) {
-                    return;
-                }
-
-            } catch (IOException ioe) {
-                eelfLogger.error("IOException", ioe);
+            if (down(resp)) {
+                return;
             }
             String path = req.getPathInfo();
             String qs = req.getQueryString();
@@ -138,7 +136,7 @@ public class NodeServlet extends HttpServlet {
                 }
             }
 
-            eelfLogger.info("NODE0103 Rejecting invalid GET of " + path + " from " + ip);
+            eelfLogger.info("NODE0103 Rejecting invalid GET of " + path + FROM + ip);
             sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, eelfLogger);
         } finally {
             eelfLogger.info(EelfMsgs.EXIT);
@@ -153,12 +151,12 @@ public class NodeServlet extends HttpServlet {
         NodeUtils.setIpAndFqdnForEelf("doPut");
         NodeUtils.setRequestIdAndInvocationId(req);
         eelfLogger.info(EelfMsgs.ENTRY);
-        eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-DMAAP-DR-ON-BEHALF-OF"),
+        eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
                 getIdFromPath(req) + "");
         try {
             common(req, resp, true);
         } catch (IOException ioe) {
-            eelfLogger.error("IOException", ioe);
+            eelfLogger.error(IO_EXCEPTION, ioe);
             eelfLogger.info(EelfMsgs.EXIT);
         }
     }
@@ -171,25 +169,30 @@ public class NodeServlet extends HttpServlet {
         NodeUtils.setIpAndFqdnForEelf("doDelete");
         NodeUtils.setRequestIdAndInvocationId(req);
         eelfLogger.info(EelfMsgs.ENTRY);
-        eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-DMAAP-DR-ON-BEHALF-OF"),
+        eelfLogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader(ON_BEHALF_OF),
                 getIdFromPath(req) + "");
         try {
             common(req, resp, false);
         } catch (IOException ioe) {
-            eelfLogger.error("IOException", ioe);
+            eelfLogger.error(IO_EXCEPTION, ioe);
             eelfLogger.info(EelfMsgs.EXIT);
         }
     }
 
     private void common(HttpServletRequest req, HttpServletResponse resp, boolean isput) throws IOException {
+        final String PUBLISH = "/publish/";
+        final String INTERNAL_PUBLISH = "/internal/publish/";
+        final String HTTPS = "https://";
+        final String USER = " user ";
         String fileid = getFileId(req, resp);
-        if (fileid == null) return;
+        if (fileid == null) {
+            return;
+        }
         String feedid = null;
         String user = null;
         String ip = req.getRemoteAddr();
         String lip = req.getLocalAddr();
         String pubid = null;
-        String xpubid = null;
         String rcvd = NodeUtils.logts(System.currentTimeMillis()) + ";from=" + ip + ";by=" + lip;
         Target[] targets = null;
         boolean isAAFFeed = false;
@@ -199,17 +202,17 @@ public class NodeServlet extends HttpServlet {
         }
         String credentials = req.getHeader("Authorization");
         if (credentials == null) {
-            eelfLogger.error("NODE0106 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo() + " from " + req
+            eelfLogger.error("NODE0306 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo() + FROM + req
                     .getRemoteAddr());
             resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Authorization header required");
             eelfLogger.info(EelfMsgs.EXIT);
             return;
         }
-        if (fileid.startsWith("/publish/")) {
+        if (fileid.startsWith(PUBLISH)) {
             fileid = fileid.substring(9);
             int i = fileid.indexOf('/');
             if (i == -1 || i == fileid.length() - 1) {
-                eelfLogger.error("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
+                eelfLogger.error("NODE0205 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + FROM + req
                         .getRemoteAddr());
                 resp.sendError(HttpServletResponse.SC_NOT_FOUND,
                         "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.  Possible missing fileid.");
@@ -218,18 +221,19 @@ public class NodeServlet extends HttpServlet {
             }
             feedid = fileid.substring(0, i);
 
-            if (config.getCadiEnabeld()) {
+            if (config.getCadiEnabled()) {
                 String path = req.getPathInfo();
                 if (!path.startsWith("/internal") && feedid != null) {
                     String aafInstance = config.getAafInstance(feedid);
-                    if (!(aafInstance.equalsIgnoreCase("legacy"))) {
+                    if (!("legacy".equalsIgnoreCase(aafInstance))) {
                         isAAFFeed = true;
                         String permission = config.getPermission(aafInstance);
                         eelfLogger.info("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;
-                            eelfLogger.error("NODE0106 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo() + " from " + req.getRemoteAddr());
+                            eelfLogger.error("NODE0307 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo()
+                                    + FROM + req.getRemoteAddr());
                             resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
                             eelfLogger.info(EelfMsgs.EXIT);
                             return;
@@ -240,9 +244,8 @@ public class NodeServlet extends HttpServlet {
 
             fileid = fileid.substring(i + 1);
             pubid = config.getPublishId();
-            xpubid = req.getHeader("X-DMAAP-DR-PUBLISH-ID");
             targets = config.getTargets(feedid);
-        } else if (fileid.startsWith("/internal/publish/")) {
+        } else if (fileid.startsWith(INTERNAL_PUBLISH)) {
             if (!config.isAnotherNode(credentials, ip)) {
                 eelfLogger.error("NODE0107 Rejecting unauthorized node-to-node transfer attempt from " + ip);
                 resp.sendError(HttpServletResponse.SC_FORBIDDEN);
@@ -254,18 +257,18 @@ public class NodeServlet extends HttpServlet {
             user = "datartr";   // SP6 : Added usr as datartr to avoid null entries for internal routing
             targets = config.parseRouting(req.getHeader("X-DMAAP-DR-ROUTING"));
         } else {
-            eelfLogger.error("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
+            eelfLogger.error("NODE0204 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + FROM + req
                     .getRemoteAddr());
             resp.sendError(HttpServletResponse.SC_NOT_FOUND,
-                    "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.");
+                    INVALID_REQUEST_URI);
             eelfLogger.info(EelfMsgs.EXIT);
             return;
         }
         if (fileid.indexOf('/') != -1) {
-            eelfLogger.error("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
+            eelfLogger.error("NODE0202 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + FROM + req
                     .getRemoteAddr());
             resp.sendError(HttpServletResponse.SC_NOT_FOUND,
-                    "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.");
+                    INVALID_REQUEST_URI);
             eelfLogger.info(EelfMsgs.EXIT);
             return;
         }
@@ -278,14 +281,16 @@ public class NodeServlet extends HttpServlet {
         if (xp != 443) {
             hp = hp + ":" + xp;
         }
-        String logurl = "https://" + hp + "/internal/publish/" + fileid;
+        String logurl = HTTPS + hp + INTERNAL_PUBLISH + fileid;
         if (feedid != null) {
-            logurl = "https://" + hp + "/publish/" + feedid + "/" + fileid;
+            logurl = HTTPS + hp + PUBLISH + feedid + "/" + fileid;
             //Cadi code starts
             if (!isAAFFeed) {
                 String reason = config.isPublishPermitted(feedid, credentials, ip);
                 if (reason != null) {
-                    eelfLogger.error("NODE0111 Rejecting unauthorized publish attempt to feed " + PathUtil.cleanString(feedid) + " fileid " + PathUtil.cleanString(fileid) + " from " + PathUtil.cleanString(ip) + " reason " + PathUtil.cleanString(reason));
+                    eelfLogger.error("NODE0111 Rejecting unauthorized publish attempt to feed " + PathUtil
+                            .cleanString(feedid) + " fileid " + PathUtil.cleanString(fileid) + FROM + PathUtil
+                            .cleanString(ip) + " reason " + PathUtil.cleanString(reason));
                     resp.sendError(HttpServletResponse.SC_FORBIDDEN, reason);
                     eelfLogger.info(EelfMsgs.EXIT);
                     return;
@@ -294,9 +299,12 @@ public class NodeServlet extends HttpServlet {
             } else {
                 String reason = config.isPublishPermitted(feedid, ip);
                 if (reason != null) {
-                    eelfLogger.error("NODE0111 Rejecting unauthorized publish attempt to feed " + PathUtil.cleanString(feedid) + " fileid " + PathUtil.cleanString(fileid) + " from " + PathUtil.cleanString(ip) + " reason   Invalid AAF user- " + PathUtil.cleanString(reason));
+                    eelfLogger.error("NODE0111 Rejecting unauthorized publish attempt to feed " + PathUtil
+                            .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("NODE0106 Rejecting unauthenticated PUT or DELETE of " + PathUtil.cleanString(req.getPathInfo()) + " from " + PathUtil.cleanString(req.getRemoteAddr()));
+                    eelfLogger.info("NODE0308 Rejecting unauthenticated PUT or DELETE of " + PathUtil
+                            .cleanString(req.getPathInfo()) + FROM + PathUtil.cleanString(req.getRemoteAddr()));
                     resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
                     return;
                 }
@@ -316,25 +324,26 @@ public class NodeServlet extends HttpServlet {
                 if (iport != 443) {
                     port = ":" + iport;
                 }
-                String redirto = "https://" + newnode + port + "/publish/" + feedid + "/" + fileid;
-                eelfLogger.info("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
+                String redirto = HTTPS + newnode + port + PUBLISH + feedid + "/" + fileid;
+                eelfLogger
+                        .info("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
                 eelfLogger.info(EelfMsgs.EXIT);
                 return;
             }
             resp.setHeader("X-DMAAP-DR-PUBLISH-ID", pubid);
         }
-        if (req.getPathInfo().startsWith("/internal/publish/")) {
+        if (req.getPathInfo().startsWith(INTERNAL_PUBLISH)) {
             feedid = req.getHeader("X-DMAAP-DR-FEED-ID");
         }
         String fbase = PathUtil.cleanString(config.getSpoolDir() + "/" + pubid);  //Fortify scan fixes-Path manipulation
         File data = new File(fbase);
         File meta = new File(fbase + ".M");
-        OutputStream dos = null;
         Writer mw = null;
-        InputStream is = null;
         try {
-            StringBuffer mx = new StringBuffer();
+            StringBuilder mx = new StringBuilder();
             mx.append(req.getMethod()).append('\t').append(fileid).append('\n');
             Enumeration hnames = req.getHeaderNames();
             String ctype = null;
@@ -364,13 +373,17 @@ public class NodeServlet extends HttpServlet {
                         }
                         if ("x-dmaap-dr-meta".equals(hnlc)) {
                             if (hv.length() > 4096) {
-                                eelfLogger.error("NODE0109 Rejecting publish attempt with metadata too long for feed " + PathUtil.cleanString(feedid) + " user " + PathUtil.cleanString(user) + " ip " + PathUtil.cleanString(ip));  //Fortify scan fixes - log forging
+                                eelfLogger.error("NODE0109 Rejecting publish attempt with metadata too long for feed "
+                                        + PathUtil.cleanString(feedid) + USER + PathUtil.cleanString(user) + " ip "
+                                        + PathUtil.cleanString(ip));  //Fortify scan fixes - log forging
                                 resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Metadata too long");
                                 eelfLogger.info(EelfMsgs.EXIT);
                                 return;
                             }
-                            if (!MetaDataPattern.matcher(hv.replaceAll("\\\\.", "X")).matches()) {
-                                eelfLogger.error("NODE0109 Rejecting publish attempt with malformed metadata for feed " + PathUtil.cleanString(feedid) + " user " + PathUtil.cleanString(user) + " ip " + PathUtil.cleanString(ip));  //Fortify scan fixes - log forging
+                            if (!metaDataPattern.matcher(hv.replaceAll("\\\\.", "X")).matches()) {
+                                eelfLogger.error("NODE0109 Rejecting publish attempt with malformed metadata for feed "
+                                        + PathUtil.cleanString(feedid) + USER + PathUtil.cleanString(user) + " ip "
+                                        + PathUtil.cleanString(ip));  //Fortify scan fixes - log forging
                                 resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Malformed metadata");
                                 eelfLogger.info(EelfMsgs.EXIT);
                                 return;
@@ -388,28 +401,12 @@ public class NodeServlet extends HttpServlet {
             }
             mx.append("X-DMAAP-DR-RECEIVED\t").append(rcvd).append('\n');
             String metadata = mx.toString();
-            byte[] buf = new byte[1024 * 1024];
-            int i;
-            try {
-                is = req.getInputStream();
-                dos = new FileOutputStream(data);
-                while ((i = is.read(buf)) > 0) {
-                    dos.write(buf, 0, i);
-                }
-                is.close();
-                is = null;
-                dos.close();
-                dos = null;
-            } catch (IOException ioe) {
-                long exlen = -1;
-                try {
-                    exlen = Long.parseLong(req.getHeader("Content-Length"));
-                } catch (Exception e) {
-                    eelfLogger.error("NODE0529 Exception common: " + e);
-                }
-                StatusLog.logPubFail(pubid, feedid, logurl, req.getMethod(), ctype, exlen, data.length(), ip, user, ioe.getMessage());
-                eelfLogger.info(EelfMsgs.EXIT);
-                throw ioe;
+            long exlen = getExlen(req);
+            String message = writeInputStreamToFile(req, data);
+            if (message != null) {
+                StatusLog.logPubFail(pubid, feedid, logurl, req.getMethod(), ctype, exlen, data.length(), ip, user,
+                        message);
+                throw new IOException(message);
             }
             Path dpath = Paths.get(fbase);
             for (Target t : targets) {
@@ -418,7 +415,8 @@ public class NodeServlet extends HttpServlet {
                     // TODO: unknown destination
                     continue;
                 }
-                String dbase = PathUtil.cleanString(di.getSpool() + "/" + pubid);  //Fortify scan fixes-Path Manipulation
+                String dbase = PathUtil
+                        .cleanString(di.getSpool() + "/" + pubid);  //Fortify scan fixes-Path Manipulation
                 Files.createLink(Paths.get(dbase), dpath);
                 mw = new FileWriter(meta);
                 mw.write(metadata);
@@ -427,45 +425,28 @@ public class NodeServlet extends HttpServlet {
                 }
                 mw.close();
                 meta.renameTo(new File(dbase + ".M"));
-
             }
             resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
             try {
                 resp.getOutputStream().close();
             } catch (IOException ioe) {
-                long exlen = -1;
-                try {
-                    exlen = Long.parseLong(req.getHeader("Content-Length"));
-                } catch (Exception e) {
-                    eelfLogger.error("NODE00000 Exception common", e);
-                }
-                StatusLog.logPubFail(pubid, feedid, logurl, req.getMethod(), ctype, exlen, data.length(), ip, user, ioe.getMessage());
+                StatusLog.logPubFail(pubid, feedid, logurl, req.getMethod(), ctype, exlen, data.length(), ip, user,
+                        ioe.getMessage());
                 //Fortify scan fixes - log forging
-                eelfLogger.error("NODE0110 IO Exception while closing IO stream " + PathUtil.cleanString(feedid) + " user " + PathUtil.cleanString(user) + " ip " + PathUtil.cleanString(ip) + " " + ioe.toString(), ioe);
-
+                eelfLogger.error("NODE0110 IO Exception while closing IO stream " + PathUtil.cleanString(feedid)
+                        + USER + PathUtil.cleanString(user) + " ip " + PathUtil.cleanString(ip) + " " + ioe
+                        .toString(), ioe);
                 throw ioe;
             }
 
-            StatusLog.logPub(pubid, feedid, logurl, req.getMethod(), ctype, data.length(), ip, user, HttpServletResponse.SC_NO_CONTENT);
+            StatusLog.logPub(pubid, feedid, logurl, req.getMethod(), ctype, data.length(), ip, user,
+                    HttpServletResponse.SC_NO_CONTENT);
         } catch (IOException ioe) {
-            eelfLogger.error("NODE0110 IO Exception receiving publish attempt for feed " + feedid + " user " + user + " ip " + ip + " " + ioe.toString(), ioe);
+            eelfLogger.error("NODE0110 IO Exception receiving publish attempt for feed " + feedid + USER + user
+                    + " ip " + ip + " " + ioe.toString(), ioe);
             eelfLogger.info(EelfMsgs.EXIT);
             throw ioe;
         } finally {
-            if (is != null) {
-                try {
-                    is.close();
-                } catch (Exception e) {
-                    eelfLogger.error("NODE0530 Exception common: " + e);
-                }
-            }
-            if (dos != null) {
-                try {
-                    dos.close();
-                } catch (Exception e) {
-                    eelfLogger.error("NODE0531 Exception common: " + e);
-                }
-            }
             if (mw != null) {
                 try {
                     mw.close();
@@ -486,12 +467,39 @@ public class NodeServlet extends HttpServlet {
         }
     }
 
+    private String writeInputStreamToFile(HttpServletRequest req, File data) {
+        byte[] buf = new byte[1024 * 1024];
+        int i;
+        try (OutputStream dos = new FileOutputStream(data);
+                InputStream is = req.getInputStream()) {
+            while ((i = is.read(buf)) > 0) {
+                dos.write(buf, 0, i);
+            }
+        } catch (IOException ioe) {
+            eelfLogger.error("NODE0530 Exception common: " + ioe, ioe);
+            eelfLogger.info(EelfMsgs.EXIT);
+            return ioe.getMessage();
+        }
+        return null;
+    }
+
+    private long getExlen(HttpServletRequest req) {
+        long exlen = -1;
+        try {
+            exlen = Long.parseLong(req.getHeader("Content-Length"));
+        } catch (Exception e) {
+            eelfLogger.error("NODE0529 Exception common: " + e);
+        }
+        return exlen;
+    }
+
     private void deleteFile(HttpServletRequest req, HttpServletResponse resp, String fileid, String pubid) {
+        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) {
-                eelfLogger.error("NODE0112 Rejecting bad URI for DELETE of " + req.getPathInfo() + " from " + req
+                eelfLogger.error("NODE0112 Rejecting bad URI for DELETE of " + req.getPathInfo() + FROM + req
                         .getRemoteAddr());
                 resp.sendError(HttpServletResponse.SC_NOT_FOUND,
                         "Invalid request URI. Expecting <subId>/<pubId>.");
@@ -501,7 +509,7 @@ public class NodeServlet extends HttpServlet {
             String subscriptionId = fileid.substring(0, i);
             int subId = Integer.parseInt(subscriptionId);
             pubid = fileid.substring(i + 1);
-            String errorMessage = "Unable to delete files (" + pubid + ", " + pubid + ".M) from DR Node: "
+            String errorMessage = "Unable to delete files (" + pubid + ", " + pubid + FROM_DR_MESSAGE
                     + config.getMyName() + ".";
             int subIdDir = subId - (subId % 100);
             if (!isAuthorizedToDelete(resp, subscriptionId, errorMessage)) {
@@ -509,7 +517,7 @@ public class NodeServlet extends HttpServlet {
             }
             boolean result = delivery.markTaskSuccess(config.getSpoolBase() + "/s/" + subIdDir + "/" + subId, pubid);
             if (result) {
-                eelfLogger.info("NODE0115 Successfully deleted files (" + pubid + ", " + pubid + ".M) from DR Node: "
+                eelfLogger.info("NODE0115 Successfully deleted files (" + pubid + ", " + pubid + FROM_DR_MESSAGE
                         + config.getMyName());
                 resp.setStatus(HttpServletResponse.SC_OK);
                 eelfLogger.info(EelfMsgs.EXIT);
@@ -519,7 +527,7 @@ public class NodeServlet extends HttpServlet {
                 eelfLogger.info(EelfMsgs.EXIT);
             }
         } catch (IOException ioe) {
-            eelfLogger.error("NODE0117 Unable to delete files (" + pubid + ", " + pubid + ".M) from DR Node: "
+            eelfLogger.error("NODE0117 Unable to delete files (" + pubid + ", " + pubid + FROM_DR_MESSAGE
                     + config.getMyName(), ioe);
             eelfLogger.info(EelfMsgs.EXIT);
         }
@@ -533,7 +541,7 @@ public class NodeServlet extends HttpServlet {
         }
         if (!req.isSecure()) {
             eelfLogger.error(
-                    "NODE0104 Rejecting insecure PUT or DELETE of " + req.getPathInfo() + " from " + req
+                    "NODE0104 Rejecting insecure PUT or DELETE of " + req.getPathInfo() + FROM + req
                             .getRemoteAddr());
             resp.sendError(HttpServletResponse.SC_FORBIDDEN, "https required on publish requests");
             eelfLogger.info(EelfMsgs.EXIT);
@@ -541,17 +549,18 @@ public class NodeServlet extends HttpServlet {
         }
         String fileid = req.getPathInfo();
         if (fileid == null) {
-            eelfLogger.error("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
+            eelfLogger.error("NODE0201 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + FROM + req
                     .getRemoteAddr());
             resp.sendError(HttpServletResponse.SC_NOT_FOUND,
-                    "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.");
+                    INVALID_REQUEST_URI);
             eelfLogger.info(EelfMsgs.EXIT);
             return null;
         }
         return fileid;
     }
 
-    private boolean isAuthorizedToDelete(HttpServletResponse resp, String subscriptionId, String errorMessage) throws IOException {
+    private boolean isAuthorizedToDelete(HttpServletResponse resp, String subscriptionId, String errorMessage)
+            throws IOException {
         try {
             boolean deletePermitted = config.isDeletePermitted(subscriptionId);
             if (!deletePermitted) {