Skip to content

Commit

Permalink
Adds double check if resource exists
Browse files Browse the repository at this point in the history
  • Loading branch information
lukaszlenart committed Aug 17, 2016
1 parent 77017cd commit 8e67b91
Showing 1 changed file with 18 additions and 10 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -43,6 +43,7 @@

import javax.servlet.ServletContext;
import java.net.MalformedURLException;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
Expand Down Expand Up @@ -332,27 +333,34 @@ protected Result findResult(String path, String resultCode, String ext, ActionCo
Map<String, ResultTypeConfig> resultsByExtension) {
try {
boolean traceEnabled = LOG.isTraceEnabled();
if (traceEnabled)
if (traceEnabled) {
LOG.trace("Checking ServletContext for [#0]", path);
}

if (servletContext.getResource(path) != null) {
if (traceEnabled)
LOG.trace("Found");
URL resource = servletContext.getResource(path);
if (resource != null && resource.getPath().endsWith(path)) {
if (traceEnabled) {
LOG.trace("Found resource #0", resource);
}
return buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
}

if (traceEnabled)
LOG.trace("Checking ClasLoader for #0", path);
if (traceEnabled) {
LOG.trace("Checking ClassLoader for #0", path);
}

String classLoaderPath = path.startsWith("/") ? path.substring(1, path.length()) : path;
if (ClassLoaderUtil.getResource(classLoaderPath, getClass()) != null) {
if (traceEnabled)
LOG.trace("Found");
resource = ClassLoaderUtil.getResource(classLoaderPath, getClass());
if (resource != null && resource.getPath().endsWith(classLoaderPath)) {
if (traceEnabled) {
LOG.trace("Found resource #0", resource);
}
return buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
}
} catch (MalformedURLException e) {
if (LOG.isErrorEnabled())
if (LOG.isErrorEnabled()) {
LOG.error("Unable to parse template path: [#0] skipping...", path);
}
}

return null;
Expand Down

0 comments on commit 8e67b91

Please # to comment.