Fix broken unit test
[dmaap/datarouter.git] / datarouter-node / src / main / java / org / onap / dmaap / datarouter / node / NodeServlet.java
1 /*******************************************************************************
2  * ============LICENSE_START==================================================
3  * * org.onap.dmaap
4  * * ===========================================================================
5  * * Copyright © 2017 AT&T Intellectual Property. All rights reserved.
6  * * ===========================================================================
7  * * Licensed under the Apache License, Version 2.0 (the "License");
8  * * you may not use this file except in compliance with the License.
9  * * You may obtain a copy of the License at
10  * *
11  *  *      http://www.apache.org/licenses/LICENSE-2.0
12  * *
13  *  * Unless required by applicable law or agreed to in writing, software
14  * * distributed under the License is distributed on an "AS IS" BASIS,
15  * * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
16  * * See the License for the specific language governing permissions and
17  * * limitations under the License.
18  * * ============LICENSE_END====================================================
19  * *
20  * * ECOMP is a trademark and service mark of AT&T Intellectual Property.
21  * *
22  ******************************************************************************/
23
24
25 package org.onap.dmaap.datarouter.node;
26
27 import com.att.eelf.configuration.EELFLogger;
28 import com.att.eelf.configuration.EELFManager;
29 import org.apache.log4j.Logger;
30 import org.jetbrains.annotations.Nullable;
31 import org.onap.dmaap.datarouter.node.eelf.EelfMsgs;
32 import org.slf4j.MDC;
33
34 import javax.servlet.http.HttpServlet;
35 import javax.servlet.http.HttpServletRequest;
36 import javax.servlet.http.HttpServletResponse;
37 import java.io.File;
38 import java.io.FileOutputStream;
39 import java.io.FileWriter;
40 import java.io.IOException;
41 import java.io.InputStream;
42 import java.io.OutputStream;
43 import java.io.Writer;
44 import java.nio.file.Files;
45 import java.nio.file.Path;
46 import java.nio.file.Paths;
47 import java.util.Enumeration;
48 import java.util.regex.Pattern;
49
50 import static org.onap.dmaap.datarouter.node.NodeUtils.sendResponseError;
51
52 /**
53  * Servlet for handling all http and https requests to the data router node
54  * <p>
55  * Handled requests are:
56  * <br>
57  * GET http://<i>node</i>/internal/fetchProv - fetch the provisioning data
58  * <br>
59  * PUT/DELETE https://<i>node</i>/internal/publish/<i>fileid</i> - n2n transfer
60  * <br>
61  * PUT/DELETE https://<i>node</i>/publish/<i>feedid</i>/<i>fileid</i> - publsh request
62  */
63 public class NodeServlet extends HttpServlet {
64
65     private static Logger logger = Logger.getLogger("org.onap.dmaap.datarouter.node.NodeServlet");
66     private static NodeConfigManager config;
67     private static Pattern MetaDataPattern;
68     private static EELFLogger eelflogger = EELFManager.getInstance().getLogger(NodeServlet.class);
69     private final Delivery delivery;
70
71     static {
72         final String ws = "\\s*";
73         // assume that \\ and \" have been replaced by X
74         final String string = "\"[^\"]*\"";
75         //String string = "\"(?:[^\"\\\\]|\\\\.)*\"";
76         final String number = "[+-]?(?:\\.\\d+|(?:0|[1-9]\\d*)(?:\\.\\d*)?)(?:[eE][+-]?\\d+)?";
77         final String value = "(?:" + string + "|" + number + "|null|true|false)";
78         final String item = string + ws + ":" + ws + value + ws;
79         final String object = ws + "\\{" + ws + "(?:" + item + "(?:" + "," + ws + item + ")*)?\\}" + ws;
80         MetaDataPattern = Pattern.compile(object, Pattern.DOTALL);
81     }
82
83     NodeServlet(Delivery delivery) {
84         this.delivery = delivery;
85     }
86
87     /**
88      * Get the NodeConfigurationManager
89      */
90     @Override
91     public void init() {
92         config = NodeConfigManager.getInstance();
93         logger.info("NODE0101 Node Servlet Configured");
94     }
95
96     private boolean down(HttpServletResponse resp) throws IOException {
97         if (config.isShutdown() || !config.isConfigured()) {
98             sendResponseError(resp, HttpServletResponse.SC_SERVICE_UNAVAILABLE, logger);
99             logger.info("NODE0102 Rejecting request: Service is being quiesced");
100             return true;
101         }
102         return false;
103     }
104
105     /**
106      * Handle a GET for /internal/fetchProv
107      */
108     @Override
109     protected void doGet(HttpServletRequest req, HttpServletResponse resp) {
110         NodeUtils.setIpAndFqdnForEelf("doGet");
111         NodeUtils.setRequestIdAndInvocationId(req);
112         eelflogger.info(EelfMsgs.ENTRY);
113         try {
114             eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-DMAAP-DR-ON-BEHALF-OF"),
115                     getIdFromPath(req) + "");
116             try {
117                 if (down(resp)) {
118                     return;
119                 }
120
121             } catch (IOException ioe) {
122                 logger.error("IOException" + ioe.getMessage());
123             }
124             String path = req.getPathInfo();
125             String qs = req.getQueryString();
126             String ip = req.getRemoteAddr();
127             if (qs != null) {
128                 path = path + "?" + qs;
129             }
130             if ("/internal/fetchProv".equals(path)) {
131                 config.gofetch(ip);
132                 resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
133                 return;
134             } else if (path.startsWith("/internal/resetSubscription/")) {
135                 String subid = path.substring(28);
136                 if (subid.length() != 0 && subid.indexOf('/') == -1) {
137                     NodeMain.resetQueue(subid, ip);
138                     resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
139                     return;
140                 }
141             }
142
143             logger.info("NODE0103 Rejecting invalid GET of " + path + " from " + ip);
144             sendResponseError(resp, HttpServletResponse.SC_NOT_FOUND, logger);
145         } finally {
146             eelflogger.info(EelfMsgs.EXIT);
147         }
148     }
149
150     /**
151      * Handle all PUT requests
152      */
153     @Override
154     protected void doPut(HttpServletRequest req, HttpServletResponse resp) {
155         NodeUtils.setIpAndFqdnForEelf("doPut");
156         NodeUtils.setRequestIdAndInvocationId(req);
157         eelflogger.info(EelfMsgs.ENTRY);
158         eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-DMAAP-DR-ON-BEHALF-OF"),
159                 getIdFromPath(req) + "");
160         try {
161             common(req, resp, true);
162         } catch (IOException ioe) {
163             logger.error("IOException" + ioe.getMessage());
164             eelflogger.info(EelfMsgs.EXIT);
165         }
166     }
167
168     /**
169      * Handle all DELETE requests
170      */
171     @Override
172     protected void doDelete(HttpServletRequest req, HttpServletResponse resp) {
173         NodeUtils.setIpAndFqdnForEelf("doDelete");
174         NodeUtils.setRequestIdAndInvocationId(req);
175         eelflogger.info(EelfMsgs.ENTRY);
176         eelflogger.info(EelfMsgs.MESSAGE_WITH_BEHALF_AND_FEEDID, req.getHeader("X-DMAAP-DR-ON-BEHALF-OF"),
177                 getIdFromPath(req) + "");
178         try {
179             common(req, resp, false);
180         } catch (IOException ioe) {
181             logger.error("IOException " + ioe.getMessage());
182             eelflogger.info(EelfMsgs.EXIT);
183         }
184     }
185
186     private void common(HttpServletRequest req, HttpServletResponse resp, boolean isput) throws IOException {
187         String fileid = getFileId(req, resp);
188         if (fileid == null) return;
189         String feedid = null;
190         String user = null;
191         String ip = req.getRemoteAddr();
192         String lip = req.getLocalAddr();
193         String pubid = null;
194         String xpubid = null;
195         String rcvd = NodeUtils.logts(System.currentTimeMillis()) + ";from=" + ip + ";by=" + lip;
196         Target[] targets = null;
197         boolean isAAFFeed = false;
198         if (fileid.startsWith("/delete/")) {
199             deleteFile(req, resp, fileid, pubid);
200             return;
201         }
202         String credentials = req.getHeader("Authorization");
203         if (credentials == null) {
204             logger.info("NODE0106 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo() + " from " + req
205                     .getRemoteAddr());
206             resp.sendError(HttpServletResponse.SC_FORBIDDEN, "Authorization header required");
207             eelflogger.info(EelfMsgs.EXIT);
208             return;
209         }
210         if (fileid.startsWith("/publish/")) {
211             fileid = fileid.substring(9);
212             int i = fileid.indexOf('/');
213             if (i == -1 || i == fileid.length() - 1) {
214                 logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
215                         .getRemoteAddr());
216                 resp.sendError(HttpServletResponse.SC_NOT_FOUND,
217                         "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.  Possible missing fileid.");
218                 eelflogger.info(EelfMsgs.EXIT);
219                 return;
220             }
221             feedid = fileid.substring(0, i);
222
223             if (config.getCadiEnabeld()) {
224                 String path = req.getPathInfo();
225                 if (!path.startsWith("/internal") && feedid != null) {
226                     String aafInstance = config.getAafInstance(feedid);
227                     if (!(aafInstance.equalsIgnoreCase("legacy"))) {
228                         isAAFFeed = true;
229                         String permission = config.getPermission(aafInstance);
230                         logger.info("NodeServlet.common() permission string - " + permission);
231                         //Check in CADI Framework API if user has AAF permission or not
232                         if (!req.isUserInRole(permission)) {
233                             String message = "AAF disallows access to permission string - " + permission;
234                             logger.info("NODE0106 Rejecting unauthenticated PUT or DELETE of " + req.getPathInfo() + " from " + req.getRemoteAddr());
235                             resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
236                             eelflogger.info(EelfMsgs.EXIT);
237                             return;
238                         }
239                     }
240                 }
241             }
242
243             fileid = fileid.substring(i + 1);
244             pubid = config.getPublishId();
245             xpubid = req.getHeader("X-DMAAP-DR-PUBLISH-ID");
246             targets = config.getTargets(feedid);
247         } else if (fileid.startsWith("/internal/publish/")) {
248             if (!config.isAnotherNode(credentials, ip)) {
249                 logger.info("NODE0107 Rejecting unauthorized node-to-node transfer attempt from " + ip);
250                 resp.sendError(HttpServletResponse.SC_FORBIDDEN);
251                 eelflogger.info(EelfMsgs.EXIT);
252                 return;
253             }
254             fileid = fileid.substring(18);
255             pubid = req.getHeader("X-DMAAP-DR-PUBLISH-ID");
256             user = "datartr";   // SP6 : Added usr as datartr to avoid null entries for internal routing
257             targets = config.parseRouting(req.getHeader("X-DMAAP-DR-ROUTING"));
258         } else {
259             logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
260                     .getRemoteAddr());
261             resp.sendError(HttpServletResponse.SC_NOT_FOUND,
262                     "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.");
263             eelflogger.info(EelfMsgs.EXIT);
264             return;
265         }
266         if (fileid.indexOf('/') != -1) {
267             logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
268                     .getRemoteAddr());
269             resp.sendError(HttpServletResponse.SC_NOT_FOUND,
270                     "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.");
271             eelflogger.info(EelfMsgs.EXIT);
272             return;
273         }
274         String qs = req.getQueryString();
275         if (qs != null) {
276             fileid = fileid + "?" + qs;
277         }
278         String hp = config.getMyName();
279         int xp = config.getExtHttpsPort();
280         if (xp != 443) {
281             hp = hp + ":" + xp;
282         }
283         String logurl = "https://" + hp + "/internal/publish/" + fileid;
284         if (feedid != null) {
285             logurl = "https://" + hp + "/publish/" + feedid + "/" + fileid;
286             //Cadi code starts
287             if (!isAAFFeed) {
288                 String reason = config.isPublishPermitted(feedid, credentials, ip);
289                 if (reason != null) {
290                     logger.info("NODE0111 Rejecting unauthorized publish attempt to feed " + PathUtil.cleanString(feedid) + " fileid " + PathUtil.cleanString(fileid) + " from " + PathUtil.cleanString(ip) + " reason " + PathUtil.cleanString(reason));
291                     resp.sendError(HttpServletResponse.SC_FORBIDDEN, reason);
292                     eelflogger.info(EelfMsgs.EXIT);
293                     return;
294                 }
295                 user = config.getAuthUser(feedid, credentials);
296             } else {
297                 String reason = config.isPublishPermitted(feedid, ip);
298                 if (reason != null) {
299                     logger.info("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));
300                     String message = "Invalid AAF user- " + PathUtil.cleanString(reason);
301                     logger.info("NODE0106 Rejecting unauthenticated PUT or DELETE of " + PathUtil.cleanString(req.getPathInfo()) + " from " + PathUtil.cleanString(req.getRemoteAddr()));
302                     resp.sendError(HttpServletResponse.SC_FORBIDDEN, message);
303                     return;
304                 }
305                 if ((req.getUserPrincipal() != null) && (req.getUserPrincipal().getName() != null)) {
306                     String userName = req.getUserPrincipal().getName();
307                     String[] attid = userName.split("@");
308                     user = attid[0];
309                 } else {
310                     user = "AAFUser";
311                 }
312             }
313             //Cadi code Ends
314             String newnode = config.getIngressNode(feedid, user, ip);
315             if (newnode != null) {
316                 String port = "";
317                 int iport = config.getExtHttpsPort();
318                 if (iport != 443) {
319                     port = ":" + iport;
320                 }
321                 String redirto = "https://" + newnode + port + "/publish/" + feedid + "/" + fileid;
322                 logger.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
323                 resp.sendRedirect(PathUtil.cleanString(redirto));         //Fortify scan fixes-open redirect - 2 issues
324                 eelflogger.info(EelfMsgs.EXIT);
325                 return;
326             }
327             resp.setHeader("X-DMAAP-DR-PUBLISH-ID", pubid);
328         }
329         if (req.getPathInfo().startsWith("/internal/publish/")) {
330             feedid = req.getHeader("X-DMAAP-DR-FEED-ID");
331         }
332         String fbase = PathUtil.cleanString(config.getSpoolDir() + "/" + pubid);  //Fortify scan fixes-Path manipulation
333         File data = new File(fbase);
334         File meta = new File(fbase + ".M");
335         OutputStream dos = null;
336         Writer mw = null;
337         InputStream is = null;
338         try {
339             StringBuffer mx = new StringBuffer();
340             mx.append(req.getMethod()).append('\t').append(fileid).append('\n');
341             Enumeration hnames = req.getHeaderNames();
342             String ctype = null;
343             boolean hasRequestIdHeader = false;
344             boolean hasInvocationIdHeader = false;
345             while (hnames.hasMoreElements()) {
346                 String hn = (String) hnames.nextElement();
347                 String hnlc = hn.toLowerCase();
348                 if ((isput && ("content-type".equals(hnlc) ||
349                         "content-language".equals(hnlc) ||
350                         "content-md5".equals(hnlc) ||
351                         "content-range".equals(hnlc))) ||
352                         "x-dmaap-dr-meta".equals(hnlc) ||
353                         (feedid == null && "x-dmaap-dr-received".equals(hnlc)) ||
354                         (hnlc.startsWith("x-") && !hnlc.startsWith("x-dmaap-dr-"))) {
355                     Enumeration hvals = req.getHeaders(hn);
356                     while (hvals.hasMoreElements()) {
357                         String hv = (String) hvals.nextElement();
358                         if ("content-type".equals(hnlc)) {
359                             ctype = hv;
360                         }
361                         if ("x-onap-requestid".equals(hnlc)) {
362                             hasRequestIdHeader = true;
363                         }
364                         if ("x-invocationid".equals(hnlc)) {
365                             hasInvocationIdHeader = true;
366                         }
367                         if ("x-dmaap-dr-meta".equals(hnlc)) {
368                             if (hv.length() > 4096) {
369                                 logger.info("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
370                                 resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Metadata too long");
371                                 eelflogger.info(EelfMsgs.EXIT);
372                                 return;
373                             }
374                             if (!MetaDataPattern.matcher(hv.replaceAll("\\\\.", "X")).matches()) {
375                                 logger.info("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
376                                 resp.sendError(HttpServletResponse.SC_BAD_REQUEST, "Malformed metadata");
377                                 eelflogger.info(EelfMsgs.EXIT);
378                                 return;
379                             }
380                         }
381                         mx.append(hn).append('\t').append(hv).append('\n');
382                     }
383                 }
384             }
385             if (!hasRequestIdHeader) {
386                 mx.append("X-ONAP-RequestID\t").append(MDC.get("RequestId")).append('\n');
387             }
388             if (!hasInvocationIdHeader) {
389                 mx.append("X-InvocationID\t").append(MDC.get("InvocationId")).append('\n');
390             }
391             mx.append("X-DMAAP-DR-RECEIVED\t").append(rcvd).append('\n');
392             String metadata = mx.toString();
393             byte[] buf = new byte[1024 * 1024];
394             int i;
395             try {
396                 is = req.getInputStream();
397                 dos = new FileOutputStream(data);
398                 while ((i = is.read(buf)) > 0) {
399                     dos.write(buf, 0, i);
400                 }
401                 is.close();
402                 is = null;
403                 dos.close();
404                 dos = null;
405             } catch (IOException ioe) {
406                 long exlen = -1;
407                 try {
408                     exlen = Long.parseLong(req.getHeader("Content-Length"));
409                 } catch (Exception e) {
410                     logger.error("NODE0529 Exception common: " + e);
411                 }
412                 StatusLog.logPubFail(pubid, feedid, logurl, req.getMethod(), ctype, exlen, data.length(), ip, user, ioe.getMessage());
413                 eelflogger.info(EelfMsgs.EXIT);
414                 throw ioe;
415             }
416             Path dpath = Paths.get(fbase);
417             for (Target t : targets) {
418                 DestInfo di = t.getDestInfo();
419                 if (di == null) {
420                     // TODO: unknown destination
421                     continue;
422                 }
423                 String dbase = PathUtil.cleanString(di.getSpool() + "/" + pubid);  //Fortify scan fixes-Path Manipulation
424                 Files.createLink(Paths.get(dbase), dpath);
425                 mw = new FileWriter(meta);
426                 mw.write(metadata);
427                 if (di.getSubId() == null) {
428                     mw.write("X-DMAAP-DR-ROUTING\t" + t.getRouting() + "\n");
429                 }
430                 mw.close();
431                 meta.renameTo(new File(dbase + ".M"));
432
433             }
434             resp.setStatus(HttpServletResponse.SC_NO_CONTENT);
435             try {
436                 resp.getOutputStream().close();
437             } catch (IOException ioe) {
438                 long exlen = -1;
439                 try {
440                     exlen = Long.parseLong(req.getHeader("Content-Length"));
441                 } catch (Exception e) {
442                     logger.debug("NODE00000 Exception common: " + e);
443                 }
444                 StatusLog.logPubFail(pubid, feedid, logurl, req.getMethod(), ctype, exlen, data.length(), ip, user, ioe.getMessage());
445                 //Fortify scan fixes - log forging
446                 logger.info("NODE0110 IO Exception while closing IO stream " + PathUtil.cleanString(feedid) + " user " + PathUtil.cleanString(user) + " ip " + PathUtil.cleanString(ip) + " " + ioe.toString(), ioe);
447
448                 throw ioe;
449             }
450
451             StatusLog.logPub(pubid, feedid, logurl, req.getMethod(), ctype, data.length(), ip, user, HttpServletResponse.SC_NO_CONTENT);
452         } catch (IOException ioe) {
453             logger.info("NODE0110 IO Exception receiving publish attempt for feed " + feedid + " user " + user + " ip " + ip + " " + ioe.toString(), ioe);
454             eelflogger.info(EelfMsgs.EXIT);
455             throw ioe;
456         } finally {
457             if (is != null) {
458                 try {
459                     is.close();
460                 } catch (Exception e) {
461                     logger.error("NODE0530 Exception common: " + e);
462                 }
463             }
464             if (dos != null) {
465                 try {
466                     dos.close();
467                 } catch (Exception e) {
468                     logger.error("NODE0531 Exception common: " + e);
469                 }
470             }
471             if (mw != null) {
472                 try {
473                     mw.close();
474                 } catch (Exception e) {
475                     logger.error("NODE0532 Exception common: " + e);
476                 }
477             }
478             try {
479                 data.delete();
480             } catch (Exception e) {
481                 logger.error("NODE0533 Exception common: " + e);
482             }
483             try {
484                 meta.delete();
485             } catch (Exception e) {
486                 logger.error("NODE0534 Exception common: " + e);
487             }
488         }
489     }
490
491     private void deleteFile(HttpServletRequest req, HttpServletResponse resp, String fileid, String pubid) {
492         try {
493             fileid = fileid.substring(8);
494             int i = fileid.indexOf('/');
495             if (i == -1 || i == fileid.length() - 1) {
496                 logger.info("NODE0112 Rejecting bad URI for DELETE of " + req.getPathInfo() + " from " + req
497                         .getRemoteAddr());
498                 resp.sendError(HttpServletResponse.SC_NOT_FOUND,
499                         "Invalid request URI. Expecting <subId>/<pubId>.");
500                 eelflogger.info(EelfMsgs.EXIT);
501                 return;
502             }
503             String subscriptionId = fileid.substring(0, i);
504             int subId = Integer.parseInt(subscriptionId);
505             pubid = fileid.substring(i + 1);
506             String errorMessage = "Unable to delete files (" + pubid + ", " + pubid + ".M) from DR Node: "
507                     + config.getMyName() + ".";
508             int subIdDir = subId - (subId % 100);
509             if (!isAuthorizedToDelete(resp, subscriptionId, errorMessage)) {
510                 return;
511             }
512             boolean result = delivery.markTaskSuccess(config.getSpoolBase() + "/s/" + subIdDir + "/" + subId, pubid);
513             if (result) {
514                 logger.info("NODE0115 Successfully deleted files (" + pubid + ", " + pubid + ".M) from DR Node: "
515                         + config.getMyName());
516                 resp.setStatus(HttpServletResponse.SC_OK);
517                 eelflogger.info(EelfMsgs.EXIT);
518             } else {
519                 logger.error("NODE0116 " + errorMessage);
520                 resp.sendError(HttpServletResponse.SC_NOT_FOUND, "File not found on server.");
521                 eelflogger.info(EelfMsgs.EXIT);
522             }
523         } catch (IOException ioe) {
524             logger.error("NODE0117 Unable to delete files (" + pubid + ", " + pubid + ".M) from DR Node: "
525                     + config.getMyName() + ". Error: " + ioe.getMessage());
526             eelflogger.info(EelfMsgs.EXIT);
527         }
528     }
529
530     @Nullable
531     private String getFileId(HttpServletRequest req, HttpServletResponse resp) throws IOException {
532         if (down(resp)) {
533             eelflogger.info(EelfMsgs.EXIT);
534             return null;
535         }
536         if (!req.isSecure()) {
537             logger.info(
538                     "NODE0104 Rejecting insecure PUT or DELETE of " + req.getPathInfo() + " from " + req
539                             .getRemoteAddr());
540             resp.sendError(HttpServletResponse.SC_FORBIDDEN, "https required on publish requests");
541             eelflogger.info(EelfMsgs.EXIT);
542             return null;
543         }
544         String fileid = req.getPathInfo();
545         if (fileid == null) {
546             logger.info("NODE0105 Rejecting bad URI for PUT or DELETE of " + req.getPathInfo() + " from " + req
547                     .getRemoteAddr());
548             resp.sendError(HttpServletResponse.SC_NOT_FOUND,
549                     "Invalid request URI.  Expecting <feed-publishing-url>/<fileid>.");
550             eelflogger.info(EelfMsgs.EXIT);
551             return null;
552         }
553         return fileid;
554     }
555
556     private boolean isAuthorizedToDelete(HttpServletResponse resp, String subscriptionId, String errorMessage) throws IOException {
557         try {
558             boolean deletePermitted = config.isDeletePermitted(subscriptionId);
559             if (!deletePermitted) {
560                 logger.error("NODE0113 " + errorMessage + " Error: Subscription "
561                         + subscriptionId + " is not a privileged subscription");
562                 resp.sendError(HttpServletResponse.SC_UNAUTHORIZED);
563                 eelflogger.info(EelfMsgs.EXIT);
564                 return false;
565             }
566         } catch (NullPointerException npe) {
567             logger.error("NODE0114 " + errorMessage + " Error: Subscription " + subscriptionId + " does not exist");
568             resp.sendError(HttpServletResponse.SC_NOT_FOUND);
569             eelflogger.info(EelfMsgs.EXIT);
570             return false;
571         }
572         return true;
573     }
574
575     private int getIdFromPath(HttpServletRequest req) {
576         String path = req.getPathInfo();
577         if (path == null || path.length() < 2) {
578             return -1;
579         }
580         try {
581             return Integer.parseInt(path.substring(1));
582         } catch (NumberFormatException e) {
583             return -1;
584         }
585     }
586 }