This is an automated email from the ASF dual-hosted git repository.
svenmeier pushed a commit to branch wicket-8.x
in repository https://gitbox.apache.org/repos/asf/wicket.git
The following commit(s) were added to refs/heads/wicket-8.x by this push:
new 4223b8d WICKET-6714 resources from META-INF/resources
4223b8d is described below
commit 4223b8d075cd6bfa4362914c19dbca5de79e4f69
Author: Sven Meier <[email protected]>
AuthorDate: Sat Dec 7 23:07:41 2019 +0100
WICKET-6714 resources from META-INF/resources
even without web root
---
.../protocol/http/mock/MockServletContext.java | 83 ++++++----------------
.../MetaInfStaticResourceReferenceTest.java | 2 +-
2 files changed, 23 insertions(+), 62 deletions(-)
diff --git
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockServletContext.java
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockServletContext.java
index 8648203..2ff9f7d 100755
---
a/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockServletContext.java
+++
b/wicket-core/src/main/java/org/apache/wicket/protocol/http/mock/MockServletContext.java
@@ -17,8 +17,6 @@
package org.apache.wicket.protocol.http.mock;
import java.io.File;
-import java.io.FileInputStream;
-import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
import java.lang.reflect.InvocationHandler;
@@ -406,25 +404,15 @@ public class MockServletContext implements ServletContext
@Override
public String getRealPath(String name)
{
- if (webappRoot == null)
- {
- return null;
- }
-
- if (name.startsWith("/"))
- {
- name = name.substring(1);
- }
-
- File f = new File(webappRoot, name);
- if (!f.exists())
- {
- return null;
- }
- else
- {
- return f.getPath();
+ try {
+ URL url = getResource(name);
+ if (url != null) {
+ return url.getFile();
+ }
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
}
+ return null;
}
/**
@@ -467,30 +455,21 @@ public class MockServletContext implements ServletContext
@Override
public URL getResource(String name) throws MalformedURLException
{
- if (webappRoot == null)
- {
- return null;
- }
-
- URL result = null;
-
if (name.startsWith("/"))
{
name = name.substring(1);
}
- File f = new File(webappRoot, name);
- if (f.exists())
+ if (webappRoot != null)
{
- result = f.toURI().toURL();
- }
-
- if (result == null)
- {
- result =
getClass().getClassLoader().getResource("META-INF/resources/" + name);
+ File f = new File(webappRoot, name);
+ if (f.exists())
+ {
+ return f.toURI().toURL();
+ }
}
- return result;
+ return
getClass().getClassLoader().getResource("META-INF/resources/" + name);
}
/**
@@ -503,33 +482,15 @@ public class MockServletContext implements ServletContext
@Override
public InputStream getResourceAsStream(String name)
{
- if (webappRoot == null)
- {
- return null;
- }
-
- if (name.startsWith("/"))
- {
- name = name.substring(1);
- }
-
- File f = new File(webappRoot, name);
- if (!f.exists())
- {
- return null;
- }
- else
- {
- try
- {
- return new FileInputStream(f);
- }
- catch (FileNotFoundException e)
- {
- log.error(e.getMessage(), e);
- return null;
+ try {
+ URL url = getResource(name);
+ if (url != null) {
+ return url.openStream();
}
+ } catch (IOException e) {
+ log.error(e.getMessage(), e);
}
+ return null;
}
/**
diff --git
a/wicket-core/src/test/java/org/apache/wicket/request/resource/MetaInfStaticResourceReferenceTest.java
b/wicket-core/src/test/java/org/apache/wicket/request/resource/MetaInfStaticResourceReferenceTest.java
index 5333e31..a6c199e 100644
---
a/wicket-core/src/test/java/org/apache/wicket/request/resource/MetaInfStaticResourceReferenceTest.java
+++
b/wicket-core/src/test/java/org/apache/wicket/request/resource/MetaInfStaticResourceReferenceTest.java
@@ -50,7 +50,7 @@ public class MetaInfStaticResourceReferenceTest
public void testWithServlet30() throws MalformedURLException
{
MockApplication application = new MockApplication();
- MockServletContext servletContext = new
MockServletContext(application, "/");
+ MockServletContext servletContext = new
MockServletContext(application, null);
BaseWicketTester tester = new BaseWicketTester(application,
servletContext);
MetaInfStaticResourceReference metaRes = new
MetaInfStaticResourceReference(getClass(),