handle resources that could not be found and return 404

bug5221
This commit is contained in:
Georg Herdt committed 2020-08-18 10:58:02 +02:00
1 parent 003936f1a4
commit 605cdfc3b3
1 file changed
+7
@@ -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<String, String> 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);
}
}
}