Ensure an inputstream is returned, when calling ServletContext.getResourceAsStream() on a jar file.
diff --git a/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java b/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java
index 91b51b1..18981f3 100644
--- a/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java
+++ b/org.eclipse.gemini.web.test/src/test/java/org/eclipse/gemini/web/test/tomcat/TomcatServletContainerTests.java
@@ -172,7 +172,8 @@
validateURLExpectedContent("http://localhost:8080/war-with-servlet/", new String[] { "path info: /", "servlet path: ", "context path: " });
validateURLExpectedContent("http://localhost:8080/war-with-servlet/alabala", new String[] { "path info: null", "servlet path: /alabala",
"context path: /war-with-servlet" });
- validateURLExpectedContent("http://localhost:8080/war-with-servlet/test.jsp", new String[] { "Found resources 2" });
+ validateURLExpectedContent("http://localhost:8080/war-with-servlet/test.jsp",
+ new String[] { "Found resources 2", "Found input sources 3" });
} finally {
this.container.stopWebApplication((WebApplicationHandle) result[1]);
((Bundle) result[0]).uninstall();
diff --git a/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/bundleresources/BundleWebResource.java b/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/bundleresources/BundleWebResource.java
index e90a6b8..a80557c 100644
--- a/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/bundleresources/BundleWebResource.java
+++ b/org.eclipse.gemini.web.tomcat/src/main/java/org/eclipse/gemini/web/tomcat/internal/bundleresources/BundleWebResource.java
@@ -19,8 +19,10 @@
import java.io.File;
import java.io.IOException;
import java.io.InputStream;
+import java.net.JarURLConnection;
import java.net.MalformedURLException;
import java.net.URL;
+import java.net.URLConnection;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.cert.Certificate;
@@ -409,7 +411,16 @@
@Override
protected InputStream doGetInputStream() {
try {
- return getURL().openStream();
+ URL url = getURL();
+ if ("jar".equals(url.getProtocol()) || url.getPath().endsWith(".jar")) {
+ JarURLConnection jarConn = (JarURLConnection) url.openConnection();
+ URL jarURL = jarConn.getJarFileURL();
+ URLConnection conn = jarURL.openConnection();
+ conn.setUseCaches(false);
+ return conn.getInputStream();
+ } else {
+ return url.openStream();
+ }
} catch (IOException e) {
return null;
}
diff --git a/test-bundles/war-with-servlet/src/main/webapp/test.jsp b/test-bundles/war-with-servlet/src/main/webapp/test.jsp
index 2f054e2..65a39e3 100644
--- a/test-bundles/war-with-servlet/src/main/webapp/test.jsp
+++ b/test-bundles/war-with-servlet/src/main/webapp/test.jsp
@@ -15,6 +15,19 @@
i++;
}
out.println("Found resources " + i);
+
+ int j = 0;
+ if (config.getServletContext().getResourceAsStream("/test.jsp") != null) {
+ j++;
+ }
+ if (config.getServletContext().getResourceAsStream("/WEB-INF/lib/resource.jar") != null) {
+ j++;
+ }
+ if (config.getServletContext().getResourceAsStream("WEB-INF/lib/resource.jar") != null) {
+ j++;
+ }
+ out.println("Found input sources " + j);
%>
+
</body>
</html>
\ No newline at end of file