Commit 488bc953 authored by Mathijs den Burger's avatar Mathijs den Burger

CMS-10585 Refactor not-found case into separate helper method

parent 7d09a08c
...@@ -364,15 +364,13 @@ public class ResourceServlet extends HttpServlet { ...@@ -364,15 +364,13 @@ public class ResourceServlet extends HttpServlet {
final URL resource = getResourceURL(resourcePath, queryParams); final URL resource = getResourceURL(resourcePath, queryParams);
if (resource == null) { if (resource == null) {
log.debug("Resource not found: {}", resourcePath); notFound(response, resourcePath);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return; return;
} }
final URLConnection conn = resource.openConnection(); final URLConnection conn = resource.openConnection();
if (conn == null) { if (conn == null) {
log.debug("Resource not found: {}", resourcePath); notFound(response, resourcePath);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return; return;
} }
...@@ -387,8 +385,7 @@ public class ResourceServlet extends HttpServlet { ...@@ -387,8 +385,7 @@ public class ResourceServlet extends HttpServlet {
final HttpURLConnection httpConn = (HttpURLConnection) conn; final HttpURLConnection httpConn = (HttpURLConnection) conn;
try { try {
if (httpConn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { if (httpConn.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) {
log.debug("Resource not found: {}", resourcePath); notFound(response, resourcePath);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return; return;
} }
} catch (ConnectException e) { } catch (ConnectException e) {
...@@ -420,6 +417,11 @@ public class ResourceServlet extends HttpServlet { ...@@ -420,6 +417,11 @@ public class ResourceServlet extends HttpServlet {
} }
} }
private void notFound(final HttpServletResponse response, final String resourcePath) throws IOException {
log.debug("Resource not found: {}", resourcePath);
response.sendError(HttpServletResponse.SC_NOT_FOUND);
}
private Set<Pattern> initPatterns(final String paramName, Set<Pattern> defaultPatterns) { private Set<Pattern> initPatterns(final String paramName, Set<Pattern> defaultPatterns) {
final String param = getInitParameter(paramName, null); final String param = getInitParameter(paramName, null);
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment