From 77181eadfe5b110df766dbd2cfa7b70e83b09054 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Wed, 20 May 2009 23:07:08 +0000 Subject: [PATCH] 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 --- VERSION.txt | 2 + .../jetty/webapp/FragmentConfiguration.java | 11 +++- .../jetty/webapp/MetaInfConfiguration.java | 65 +++++++++---------- .../jetty/webapp/TagLibConfiguration.java | 2 +- .../eclipse/jetty/webapp/WebAppContext.java | 33 ++++++++-- .../jetty/webapp/WebInfConfiguration.java | 22 +++++++ 6 files changed, 91 insertions(+), 44 deletions(-) diff --git a/VERSION.txt b/VERSION.txt index 51c12796bc1..4aa8134a266 100644 --- a/VERSION.txt +++ b/VERSION.txt @@ -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 diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java index c262d940907..cc220308435 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/FragmentConfiguration.java @@ -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 urls = (List)context.getAttribute(MetaInfConfiguration.__webFragJars); + List urls = (List)context.getAttribute(MetaInfConfiguration.JARS_WITH_FRAGMENTS); JarScanner fragScanner = new JarScanner() { diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java index 77f7df09b41..4b9a49608da 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaInfConfiguration.java @@ -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 tldJars = new ArrayList(); - final List webFragJars = new ArrayList(); - final List metaResourceJars = new ArrayList(); - 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 list) + public void addJar (WebAppContext context, String attribute, URL jar) { - if (!list.contains(jarUrl)) - list.add(jarUrl); + List list = (List)context.getAttribute(attribute); + if (list==null) + { + list=new ArrayList(); + 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); + } } } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/TagLibConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/TagLibConfiguration.java index c6c5123055e..2b2d0e07657 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/TagLibConfiguration.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/TagLibConfiguration.java @@ -311,7 +311,7 @@ public class TagLibConfiguration implements Configuration tmp = context.getInitParameter(__container_pattern); Pattern containerPattern = (tmp==null?null:Pattern.compile(tmp)); - List tldJars = (List)context.getAttribute(MetaInfConfiguration.__tldJars); + List tldJars = (List)context.getAttribute(MetaInfConfiguration.JARS_WITH_TLDS); TagLibJarScanner tldScanner = new TagLibJarScanner(context); try diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java index 730a7875f3e..e8ea7079c5b 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java @@ -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:
    + *
  • Web Fragments
  • + *
  • META-INF/resource directories
  • + *
+ * @param servlet3autoConfig the servlet3autoConfig to set + */ + public void setConfigurationDiscovered(boolean discovered) + { + _configurationDiscovered = discovered; + } + /* ------------------------------------------------------------ */ /* * @see org.eclipse.thread.AbstractLifeCycle#doStart() 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 e9c8f5fa29b..3b1574b7573 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 @@ -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 urls = (List)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); + } }