From 605cdfc3b3336cf68ded71fe4dda765c6a79bc93 Mon Sep 17 00:00:00 2001 From: Georg Herdt Date: Tue, 18 Aug 2020 10:58:02 +0200 Subject: [PATCH] handle resources that could not be found and return 404 bug5221 --- .../com/sap/sse/debranding/ClientConfigurationServlet.java | 7 +++++++ 1 file changed, 7 insertions(+) diff --git a/java/com.sap.sse.debranding/src/com/sap/sse/debranding/ClientConfigurationServlet.java b/java/com.sap.sse.debranding/src/com/sap/sse/debranding/ClientConfigurationServlet.java index b1da779bda8..952ab1df0e0 100644 --- a/java/com.sap.sse.debranding/src/com/sap/sse/debranding/ClientConfigurationServlet.java +++ b/java/com.sap.sse.debranding/src/com/sap/sse/debranding/ClientConfigurationServlet.java @@ -1,5 +1,6 @@ package com.sap.sse.debranding; +import java.io.FileNotFoundException; import java.io.IOException; import java.io.InputStream; import java.util.HashMap; @@ -88,6 +89,9 @@ public class ClientConfigurationServlet extends HttpServlet { IOUtils.write(cachedPage, resp.getOutputStream()); } else { try (InputStream in = this.getServletContext().getResourceAsStream(servletPath)) { + if (in == null) { + throw new FileNotFoundException(servletPath); + } byte[] buffer = IOUtils.toByteArray(in); String content = new String(buffer); for (Map.Entry item : createReplacementMap(deBrandingActive).entrySet()) { @@ -99,6 +103,9 @@ public class ClientConfigurationServlet extends HttpServlet { } catch (RuntimeException e) { logger.log(Level.WARNING, "could not process or read resource " + servletPath, e); resp.sendError(HttpStatus.SC_INTERNAL_SERVER_ERROR); + } catch (FileNotFoundException f) { + logger.log(Level.WARNING, "could not find resource " + servletPath); + resp.sendError(HttpStatus.SC_NOT_FOUND); } } }