From c1869f4989942dd33fa4e189e0ac1f766fb5ac14 Mon Sep 17 00:00:00 2001 From: Lukasz Lenart Date: Wed, 17 Aug 2016 15:35:11 +0200 Subject: [PATCH] Adds double check if resource exists --- .../convention/ConventionUnknownHandler.java | 16 ++++++++++++---- 1 file changed, 12 insertions(+), 4 deletions(-) diff --git a/plugins/convention/src/main/java/org/apache/struts2/convention/ConventionUnknownHandler.java b/plugins/convention/src/main/java/org/apache/struts2/convention/ConventionUnknownHandler.java index ace9446dd9..cb10f1b48a 100644 --- a/plugins/convention/src/main/java/org/apache/struts2/convention/ConventionUnknownHandler.java +++ b/plugins/convention/src/main/java/org/apache/struts2/convention/ConventionUnknownHandler.java @@ -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; /** *

@@ -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) {