added setConfigurationDiscovered for servlet 3.0 features

git-svn-id: svn+ssh://dev.eclipse.org/svnroot/rt/org.eclipse.jetty/jetty/trunk@244 7e9141cc-0065-0410-87d8-b60c137991c4
This commit is contained in:
Greg Wilkins 2009-05-20 23:07:08 +00:00
parent 64eb0863b1
commit 77181eadfe
6 changed files with 91 additions and 44 deletions

View File

@ -1,5 +1,7 @@
jetty-7.0.0.M3-SNAPSHOT
+ fixed race with expired async listeners
+ refactored configuration mechanism
+ added WebAppContext.setConfigurationDiscovered for servlet 3.0 features
+ 274251 Allow dispatch to welcome files that are servlets (configurable)
jetty-7.0.0.M2 18 May 2009

View File

@ -25,13 +25,18 @@ import org.eclipse.jetty.util.resource.Resource;
/**
* FragmentConfiguration
*
*
* This configuration supports some Servlet 3.0 features in jetty-7.
*
* Process web-fragments in jars
*/
public class FragmentConfiguration implements Configuration
{
public void preConfigure(WebAppContext context) throws Exception
{
if (!context.isConfigurationDiscovered())
return;
WebXmlProcessor processor = (WebXmlProcessor)context.getAttribute(WebXmlProcessor.__web_processor);
if (processor == null)
{
@ -48,6 +53,8 @@ public class FragmentConfiguration implements Configuration
public void configure(WebAppContext context) throws Exception
{
if (!context.isConfigurationDiscovered())
return;
//TODO for jetty-8/servletspec3 the fragments will not be separately processed here, but
//will be done by webXmlConfiguration when it processes the effective merged web.xml
WebXmlProcessor processor = (WebXmlProcessor)context.getAttribute(WebXmlProcessor.__web_processor);
@ -83,7 +90,7 @@ public class FragmentConfiguration implements Configuration
String tmp = (String) context.getInitParameter("org.eclipse.jetty.webapp.WebXmlFragmentPattern");
Pattern webFragPattern = (tmp == null ? null : Pattern.compile(tmp));
List<URL> urls = (List<URL>)context.getAttribute(MetaInfConfiguration.__webFragJars);
List<URL> urls = (List<URL>)context.getAttribute(MetaInfConfiguration.JARS_WITH_FRAGMENTS);
JarScanner fragScanner = new JarScanner()
{

View File

@ -34,16 +34,12 @@ import org.eclipse.jetty.util.resource.Resource;
*/
public class MetaInfConfiguration implements Configuration
{
public static final String __tldJars = "org.eclipse.jetty.tlds";
public static final String __webFragJars = "org.eclipse.jetty.webFragments";
public static final String __metaResourceJars = "org.eclipse.jetty.metaResources";
public static final String JARS_WITH_TLDS = "org.eclipse.jetty.tlds";
public static final String JARS_WITH_FRAGMENTS = "org.eclipse.jetty.webFragments";
public static final String JARS_WITH_RESOURCES = WebInfConfiguration.RESOURCE_URLS;
public void preConfigure(final WebAppContext context) throws Exception
{
//Find all jars in WEB-INF
Resource web_inf = context.getWebInf();
Resource web_inf_lib = web_inf.addPath("/lib");
@ -72,32 +68,13 @@ public class MetaInfConfiguration implements Configuration
}
}
final List<URL> tldJars = new ArrayList<URL>();
final List<URL> webFragJars = new ArrayList<URL>();
final List<URL> metaResourceJars = new ArrayList<URL>();
JarScanner fragScanner = new JarScanner()
{
public void processEntry(URL jarUrl, JarEntry entry)
{
try
{
String name = entry.getName().toLowerCase();
if (name.startsWith("meta-inf"))
{
if (name.equals("meta-inf/web-fragment.xml"))
{
addJar(jarUrl, webFragJars);
}
else if (name.endsWith(".tld"))
{
addJar(jarUrl, tldJars);
}
else if (name.equals("meta-inf/resources"))
{
addJar(jarUrl, metaResourceJars);
}
}
MetaInfConfiguration.this.processEntry(context,jarUrl,entry);
}
catch (Exception e)
{
@ -106,10 +83,6 @@ public class MetaInfConfiguration implements Configuration
}
};
fragScanner.scan(null, urls.toArray(new URL[urls.size()]), true);
context.setAttribute(__tldJars, tldJars);
context.setAttribute(__webFragJars, webFragJars);
context.setAttribute(__metaResourceJars, metaResourceJars);
}
@ -131,10 +104,34 @@ public class MetaInfConfiguration implements Configuration
}
public void addJar (URL jarUrl, List<URL> list)
public void addJar (WebAppContext context, String attribute, URL jar)
{
if (!list.contains(jarUrl))
list.add(jarUrl);
List<URL> list = (List<URL>)context.getAttribute(attribute);
if (list==null)
{
list=new ArrayList<URL>();
context.setAttribute(attribute,list);
}
if (!list.contains(jar))
list.add(jar);
}
protected void processEntry(WebAppContext context, URL jarUrl, JarEntry entry)
{
String name = entry.getName().toLowerCase();
if (name.equals("meta-inf/web-fragment.xml") && context.isConfigurationDiscovered())
{
addJar(context,JARS_WITH_FRAGMENTS,jarUrl);
}
else if (name.endsWith(".tld"))
{
addJar(context,JARS_WITH_TLDS,jarUrl);
}
else if (name.equals("meta-inf/resources") && context.isConfigurationDiscovered())
{
addJar(context,JARS_WITH_RESOURCES,jarUrl);
}
}
}

View File

@ -311,7 +311,7 @@ public class TagLibConfiguration implements Configuration
tmp = context.getInitParameter(__container_pattern);
Pattern containerPattern = (tmp==null?null:Pattern.compile(tmp));
List<URL> tldJars = (List<URL>)context.getAttribute(MetaInfConfiguration.__tldJars);
List<URL> tldJars = (List<URL>)context.getAttribute(MetaInfConfiguration.JARS_WITH_TLDS);
TagLibJarScanner tldScanner = new TagLibJarScanner(context);
try

View File

@ -115,6 +115,7 @@ public class WebAppContext extends ServletContextHandler
private Map _resourceAliases;
private boolean _ownClassLoader=false;
private boolean _configurationDiscovered=false;
public static ContextHandler getCurrentWebAppContext()
{
@ -190,13 +191,6 @@ public class WebAppContext extends ServletContextHandler
{
return _unavailableException;
}
/* ------------------------------------------------------------ */
// public SecurityHandler getConstraintsSecurityHandler()
// {
// return (ConstraintsSecurityHandler)getSecurityHandler();
// }
/* ------------------------------------------------------------ */
@ -286,6 +280,31 @@ public class WebAppContext extends ServletContextHandler
}
/* ------------------------------------------------------------ */
/** Is the context Automatically configured.
*
* @return true if configuration discovery.
*/
public boolean isConfigurationDiscovered()
{
return _configurationDiscovered;
}
/* ------------------------------------------------------------ */
/** Set the configuration discovery mode.
* If configuration discovery is set to true, then the JSR315
* servlet 3.0 discovered configuration features are enabled.
* These are:<ul>
* <li>Web Fragments</li>
* <li>META-INF/resource directories</li>
* </ul>
* @param servlet3autoConfig the servlet3autoConfig to set
*/
public void setConfigurationDiscovered(boolean discovered)
{
_configurationDiscovered = discovered;
}
/* ------------------------------------------------------------ */
/*
* @see org.eclipse.thread.AbstractLifeCycle#doStart()

View File

@ -2,6 +2,8 @@ package org.eclipse.jetty.webapp;
import java.io.File;
import java.io.IOException;
import java.net.URL;
import java.util.List;
import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.util.IO;
@ -9,11 +11,18 @@ import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.resource.JarResource;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.resource.ResourceCollection;
public class WebInfConfiguration implements Configuration
{
public static final String TEMPDIR_CREATED = "org.eclipse.jetty.tmpdirCreated";
/**
* If set, to a list of URLs, these resources are added to the context
* resource base as a resource collection.
*/
public static final String RESOURCE_URLS = "org.eclipse.jetty.resources";
public void preConfigure(WebAppContext context) throws Exception
{
//Make a temp directory for the webapp if one is not already set
@ -60,6 +69,19 @@ public class WebInfConfiguration implements Configuration
if (lib.exists() || lib.isDirectory())
((WebAppClassLoader)context.getClassLoader()).addJars(lib);
}
// Look for extra resource
List<URL> urls = (List<URL>)context.getAttribute(RESOURCE_URLS);
if (urls!=null)
{
Resource[] resources=new Resource[urls.size()+1];
int i=0;
resources[i++]=context.getBaseResource();
for (URL url : urls)
resources[i++]=Resource.newResource(url);
ResourceCollection collection=new ResourceCollection(resources);
context.setBaseResource(collection);
}
}