309153 Hide extracted WEB-INF/lib when running a non-extracted war

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@1646 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2010-05-03 12:34:29 +00:00
parent 7908935011
commit 5662d548f6
2 changed files with 36 additions and 3 deletions

View File

@ -14,6 +14,7 @@ jetty-7.1.0.RC1-SNAPSHOT
+ 310918 Synchronize content exchange
+ 311154 Use Appendable in preference to StringBuilder/StringBuffer in APIs
+ 308865 Update test suite to JUnit4 - Module jetty-start
+ 309153 Hide extracted WEB-INF/lib when running a non-extracted war
jetty-7.1.0.RC0 27 April 2010
+ 294563 Websocket client connection

View File

@ -16,10 +16,12 @@ package org.eclipse.jetty.webapp;
import java.io.File;
import java.io.IOException;
import java.net.MalformedURLException;
import java.net.URL;
import java.security.PermissionCollection;
import java.util.EventListener;
import java.util.HashMap;
import java.util.Map;
import java.util.jar.JarFile;
import javax.servlet.http.HttpSessionActivationListener;
import javax.servlet.http.HttpSessionAttributeListener;
@ -42,6 +44,7 @@ import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
/* ------------------------------------------------------------ */
/** Web Application Context Handler.
@ -116,14 +119,14 @@ public class WebAppContext extends ServletContextHandler
private boolean _configurationClassesSet=false;
private boolean _configurationsSet=false;
public static ContextHandler getCurrentWebAppContext()
public static WebAppContext getCurrentWebAppContext()
{
ContextHandler.Context context=ContextHandler.getCurrentContext();
if (context!=null)
{
ContextHandler handler = context.getContextHandler();
if (handler instanceof WebAppContext)
return handler;
return (WebAppContext)handler;
}
return null;
}
@ -132,6 +135,7 @@ public class WebAppContext extends ServletContextHandler
public WebAppContext()
{
super(SESSIONS|SECURITY);
_scontext=new Context();
setErrorHandler(new ErrorPageErrorHandler());
}
@ -143,6 +147,7 @@ public class WebAppContext extends ServletContextHandler
public WebAppContext(String webApp,String contextPath)
{
super(null,contextPath,SESSIONS|SECURITY);
_scontext=new Context();
setContextPath(contextPath);
setWar(webApp);
setErrorHandler(new ErrorPageErrorHandler());
@ -157,6 +162,7 @@ public class WebAppContext extends ServletContextHandler
public WebAppContext(HandlerContainer parent, String webApp, String contextPath)
{
super(parent,contextPath,SESSIONS|SECURITY);
_scontext=new Context();
setWar(webApp);
setErrorHandler(new ErrorPageErrorHandler());
}
@ -167,7 +173,7 @@ public class WebAppContext extends ServletContextHandler
public WebAppContext(SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
{
super(null,sessionHandler,securityHandler,servletHandler,errorHandler);
_scontext=new Context();
setErrorHandler(errorHandler!=null?errorHandler:new ErrorPageErrorHandler());
}
@ -992,4 +998,30 @@ public class WebAppContext extends ServletContextHandler
super.startContext();
}
/* ------------------------------------------------------------ */
public class Context extends ServletContextHandler.Context
{
/* ------------------------------------------------------------ */
public URL getResource(String path) throws MalformedURLException
{
Resource resource=WebAppContext.this.getResource(path);
if (resource==null || !resource.exists())
return null;
// Should we go to the original war?
if (resource.isDirectory() && resource instanceof ResourceCollection && !WebAppContext.this.isExtractWAR())
{
Resource[] resources = ((ResourceCollection)resource).getResources();
for (int i=resources.length;i-->0;)
{
if (resources[i].getName().startsWith("jar:file"))
return resources[i].getURL();
}
}
return resource.getURL();
}
}
}