From e6b43daf54da82cb09f65e8af434fe997f4f7340 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 31 Jul 2009 02:34:25 +0000 Subject: [PATCH] unpack WEB-INF git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@609 7e9141cc-0065-0410-87d8-b60c137991c4 --- .../jetty/webapp/WebAppClassLoader.java | 33 +------------------ .../jetty/webapp/WebInfConfiguration.java | 33 ++++++++++++------- .../src/main/config/contexts/test.xml | 2 +- .../src/main/webapp/WEB-INF/web.xml | 18 ++++------ 4 files changed, 29 insertions(+), 57 deletions(-) diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java index 0fa9db5fdbf..853ad105afc 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppClassLoader.java @@ -154,38 +154,7 @@ public class WebAppClassLoader extends URLClassLoader // Add resource or expand jar/ if (!resource.isDirectory() && file == null) { - InputStream in= resource.getInputStream(); - File tmp_dir=_context.getTempDirectory(); - if (tmp_dir==null) - { - tmp_dir = File.createTempFile("jetty.cl.lib",null); - tmp_dir.mkdir(); - tmp_dir.deleteOnExit(); - } - File lib= new File(tmp_dir, "lib"); - if (!lib.exists()) - { - lib.mkdir(); - lib.deleteOnExit(); - } - File jar= File.createTempFile("Jetty-", ".jar", lib); - - jar.deleteOnExit(); - if (Log.isDebugEnabled()) - Log.debug("Extract " + resource + " to " + jar); - FileOutputStream out = null; - try - { - out= new FileOutputStream(jar); - IO.copy(in, out); - } - finally - { - IO.close(out); - } - - URL url= jar.toURL(); - addURL(url); + throw new IllegalArgumentException("!file: "+resource); } else { diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java index 1a0105e67a6..30f1f3a1f88 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebInfConfiguration.java @@ -378,22 +378,16 @@ public class WebInfConfiguration implements Configuration // No - then lets see if it can be turned into a jar URL. Resource jarWebApp = context.newResource("jar:" + web_app + "!/"); if (jarWebApp.exists() && jarWebApp.isDirectory()) - { web_app= jarWebApp; - } } // If we should extract or the URL is still not usable - if (web_app.exists() && - ( - (context.isCopyWebDir() && web_app.getFile()!= null && web_app.getFile().isDirectory()) - || - (context.isExtractWAR() && web_app.getFile()!= null && !web_app.getFile().isDirectory()) - || - (context.isExtractWAR() && web_app.getFile() == null) - || - !web_app.isDirectory() - )) + if (web_app.exists() && ( + (context.isCopyWebDir() && web_app.getFile() != null && web_app.getFile().isDirectory()) || + (context.isExtractWAR() && web_app.getFile() != null && !web_app.getFile().isDirectory()) || + (context.isExtractWAR() && web_app.getFile() == null) || + !web_app.isDirectory()) + ) { // Then extract it if necessary to the temporary location File extractedWebAppDir= new File(context.getTempDirectory(), "webapp"); @@ -441,6 +435,21 @@ public class WebInfConfiguration implements Configuration if (Log.isDebugEnabled()) Log.debug("webapp=" + web_app); } + + // Do we need to extract WEB-INF/lib? + Resource web_inf= web_app.addPath("WEB-INF/"); + if (web_inf.exists() && web_inf.isDirectory() && (web_inf.getFile()==null || !web_app.getFile().isDirectory())) + { + File extractedWebInfDir= new File(context.getTempDirectory(), "webinf"); + if (extractedWebInfDir.exists()) + extractedWebInfDir.delete(); + extractedWebInfDir.mkdir(); + Log.info("Extract " + web_inf + " to " + extractedWebInfDir); + JarResource.extract(web_app, extractedWebInfDir, false); + web_inf=Resource.newResource(extractedWebInfDir.toURL()); + ResourceCollection rc = new ResourceCollection(new Resource[]{web_inf,web_app}); + context.setBaseResource(rc); + } } diff --git a/test-jetty-webapp/src/main/config/contexts/test.xml b/test-jetty-webapp/src/main/config/contexts/test.xml index 84dd4307038..fb5f7d31c50 100644 --- a/test-jetty-webapp/src/main/config/contexts/test.xml +++ b/test-jetty-webapp/src/main/config/contexts/test.xml @@ -25,7 +25,7 @@ detected. - false + true false /etc/webdefault.xml /contexts/test.d/override-web.xml diff --git a/test-jetty-webapp/src/main/webapp/WEB-INF/web.xml b/test-jetty-webapp/src/main/webapp/WEB-INF/web.xml index c11e5523eb2..b80331cd0f7 100644 --- a/test-jetty-webapp/src/main/webapp/WEB-INF/web.xml +++ b/test-jetty-webapp/src/main/webapp/WEB-INF/web.xml @@ -2,8 +2,8 @@ + xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" + version="2.5"> Test WebApp @@ -15,7 +15,6 @@ QoSFilter org.eclipse.jetty.servlets.QoSFilter - true maxRequests 20 @@ -30,7 +29,6 @@ MultiPart org.eclipse.jetty.servlets.MultiPartFilter - true deleteFiles true @@ -44,7 +42,6 @@ GzipFilter org.eclipse.jetty.servlets.IncludableGzipFilter - true bufferSize 8192 @@ -105,7 +102,6 @@ Dump com.acme.Dump - true 1 admin @@ -141,7 +137,6 @@ Dispatch com.acme.DispatchServlet - true 1 @@ -164,7 +159,6 @@ Chat com.acme.ChatServlet - true 1 @@ -176,13 +170,13 @@ TransparentProxy org.eclipse.jetty.servlets.ProxyServlet$Transparent - 1 - - ProxyTohttp://jetty.mortbay.org/test - Prefix/jetty + + ProxyTohttp://jetty.mortbay.org/test + + 1