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 17d5e39 commit c1869f4
Showing 1 changed file with 12 additions and 4 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -36,6 +36,12 @@
import javax.servlet.ServletContext;
import java.net.MalformedURLException;
import java.util.*;
import java.net.URL;
import java.util.Collections;
import java.util.HashMap;
import java.util.LinkedHashMap;
import java.util.List;
import java.util.Map;

/**
* <p>
Expand Down Expand Up @@ -313,16 +319,18 @@ protected Result findResult(String path, String resultCode, String ext, ActionCo
try {
LOG.trace("Checking ServletContext for {}", path);

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

LOG.trace("Checking ClassLoader for {}", path);

String classLoaderPath = path.startsWith("/") ? path.substring(1, path.length()) : path;
if (ClassLoaderUtil.getResource(classLoaderPath, getClass()) != null) {
LOG.trace("Found");
resource = ClassLoaderUtil.getResource(classLoaderPath, getClass());
if (resource != null && resource.getPath().endsWith(classLoaderPath)) {
LOG.trace("Found resource {}", resource);
return buildResult(path, resultCode, resultsByExtension.get(ext), actionContext);
}
} catch (MalformedURLException e) {
Expand Down

0 comments on commit c1869f4

Please sign in to comment.