jetty-9 made WebAppContext configuration additive
This commit is contained in:
parent
728201fa3e
commit
b132663c2b
|
@ -50,6 +50,11 @@
|
|||
<groupId>org.eclipse.jetty.spdy</groupId>
|
||||
<artifactId>spdy-http-server</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty</groupId>
|
||||
<artifactId>jetty-plus</artifactId>
|
||||
<version>${project.version}</version>
|
||||
</dependency>
|
||||
<dependency>
|
||||
<groupId>org.eclipse.jetty.toolchain</groupId>
|
||||
|
|
|
@ -2,24 +2,19 @@
|
|||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
|
||||
<Configure id="Server" class="org.eclipse.jetty.server.Server">
|
||||
|
||||
<!-- ================================================================= -->
|
||||
<!-- Enable annotations - configure deployment steps for every web app -->
|
||||
<!-- ================================================================= -->
|
||||
<Call name="setAttribute">
|
||||
<Arg>org.eclipse.jetty.webapp.configuration</Arg>
|
||||
<!-- =========================================================== -->
|
||||
<!-- Add annotation Configuring classes to all webapps for this Server -->
|
||||
<!-- =========================================================== -->
|
||||
<Call class="org.eclipse.jetty.webapp.Configuration$ClassList" name="setServerDefault">
|
||||
<Arg><Ref refid="Server" /></Arg>
|
||||
<Call name="addBefore">
|
||||
<Arg name="beforeClass">org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Arg>
|
||||
<Arg>
|
||||
<Array type="java.lang.String">
|
||||
<Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
|
||||
</Array>
|
||||
<Array type="String">
|
||||
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Call>
|
||||
|
||||
</Configure>
|
||||
|
|
|
@ -49,7 +49,6 @@ import org.eclipse.jetty.webapp.Configuration;
|
|||
import org.eclipse.jetty.webapp.FragmentConfiguration;
|
||||
import org.eclipse.jetty.webapp.JettyWebXmlConfiguration;
|
||||
import org.eclipse.jetty.webapp.MetaInfConfiguration;
|
||||
import org.eclipse.jetty.webapp.TagLibConfiguration;
|
||||
import org.eclipse.jetty.webapp.WebAppClassLoader;
|
||||
import org.eclipse.jetty.webapp.WebAppContext;
|
||||
import org.eclipse.jetty.webapp.WebInfConfiguration;
|
||||
|
@ -74,7 +73,6 @@ public class AntWebAppContext extends WebAppContext
|
|||
public final PlusConfiguration plusConfiguration = new PlusConfiguration();
|
||||
public final AnnotationConfiguration annotationConfiguration = new AnnotationConfiguration();
|
||||
public final JettyWebXmlConfiguration jettyWebXmlConfiguration = new JettyWebXmlConfiguration();
|
||||
public final TagLibConfiguration tagLibConfiguration = new TagLibConfiguration();
|
||||
|
||||
|
||||
public final Configuration[] DEFAULT_CONFIGURATIONS =
|
||||
|
@ -86,8 +84,7 @@ public class AntWebAppContext extends WebAppContext
|
|||
envConfiguration,
|
||||
plusConfiguration,
|
||||
annotationConfiguration,
|
||||
jettyWebXmlConfiguration,
|
||||
tagLibConfiguration
|
||||
jettyWebXmlConfiguration
|
||||
};
|
||||
|
||||
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configure Jetty Plus features -->
|
||||
|
@ -55,20 +55,6 @@
|
|||
<!-- Uncomment the section entitled "Apply plusConfig to all -->
|
||||
<!-- webapps for this Server". NOTE: this is the default. -->
|
||||
<!-- =========================================================== -->
|
||||
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Sequence of configurations to defining Plus features. -->
|
||||
<!-- =========================================================== -->
|
||||
<Array id="plusConfig" type="java.lang.String">
|
||||
<Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
|
||||
</Array>
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Apply plusConfig to all webapps in webapps-plus -->
|
||||
|
@ -86,7 +72,17 @@
|
|||
<Set name="scanInterval">5</Set>
|
||||
<Set name="parentLoaderPriority">false</Set>
|
||||
<Set name="extractWars">true</Set>
|
||||
<Set name="configurationClasses"><Ref id="plusConfig"/></Set>
|
||||
<Set name="configurationClasses">
|
||||
<Array id="plusConfig" type="java.lang.String">
|
||||
<Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
</New>
|
||||
</Arg>
|
||||
</Call>
|
||||
|
@ -94,14 +90,20 @@
|
|||
-->
|
||||
|
||||
<!-- =========================================================== -->
|
||||
<!-- Apply plusConfig to all webapps for this Server -->
|
||||
<!-- Add plus Configuring classes to all webapps for this Server -->
|
||||
<!-- =========================================================== -->
|
||||
<Call name="setAttribute">
|
||||
<Arg>org.eclipse.jetty.webapp.configuration</Arg>
|
||||
<Call class="org.eclipse.jetty.webapp.Configuration$ClassList" name="setServerDefault">
|
||||
<Arg><Ref refid="Server" /></Arg>
|
||||
<Call name="addAfter">
|
||||
<Arg name="afterClass">org.eclipse.jetty.webapp.FragmentConfiguration</Arg>
|
||||
<Arg>
|
||||
<Ref id="plusConfig"/>
|
||||
<Array type="String">
|
||||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Call>
|
||||
|
||||
</Configure>
|
||||
|
||||
|
|
|
@ -77,8 +77,7 @@ public class Runner
|
|||
org.eclipse.jetty.plus.webapp.EnvConfiguration.class.getCanonicalName(),
|
||||
org.eclipse.jetty.plus.webapp.PlusConfiguration.class.getCanonicalName(),
|
||||
org.eclipse.jetty.annotations.AnnotationConfiguration.class.getCanonicalName(),
|
||||
org.eclipse.jetty.webapp.JettyWebXmlConfiguration.class.getCanonicalName(),
|
||||
org.eclipse.jetty.webapp.TagLibConfiguration.class.getCanonicalName()
|
||||
org.eclipse.jetty.webapp.JettyWebXmlConfiguration.class.getCanonicalName()
|
||||
};
|
||||
public static final String __containerIncludeJarPattern = ".*/jetty-runner-[^/]*\\.jar$";
|
||||
public static final String __defaultContextPath = "/";
|
||||
|
|
|
@ -100,6 +100,8 @@ public class Server extends HandlerWrapper implements Attributes
|
|||
/* ------------------------------------------------------------ */
|
||||
/** Convenience constructor
|
||||
* Creates server and a {@link ServerConnector} at the passed port.
|
||||
* @param port The port of a network HTTP connector (or 0 for a randomly allocated port).
|
||||
* @see NetworkConnector#getLocalPort()
|
||||
*/
|
||||
public Server(@Name("port")int port)
|
||||
{
|
||||
|
|
|
@ -103,6 +103,9 @@ $(jetty.home)/lib/jetty-security-$(version).jar ! available org.eclipse.jetty.
|
|||
[Server,All,servlet,default]
|
||||
$(jetty.home)/lib/servlet-api-3.0.jar ! available javax.servlet.ServletContext
|
||||
$(jetty.home)/lib/jetty-servlet-$(version).jar ! available org.eclipse.jetty.servlet.ServletHandler
|
||||
|
||||
[servlets]
|
||||
$(jetty.home)/lib/jetty-servlets-$(version).jar ! available org.eclipse.jetty.servlets.MultiPartFilter
|
||||
|
||||
[Server,All,webapp,default]
|
||||
$(jetty.home)/lib/jetty-webapp-$(version).jar ! available org.eclipse.jetty.webapp.WebAppContext
|
||||
|
|
|
@ -18,6 +18,14 @@
|
|||
|
||||
package org.eclipse.jetty.webapp;
|
||||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.util.annotation.Name;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/** Base Class for WebApplicationContext Configuration.
|
||||
|
@ -26,7 +34,8 @@ package org.eclipse.jetty.webapp;
|
|||
*/
|
||||
public interface Configuration
|
||||
{
|
||||
|
||||
public final static String ATTR="org.eclipse.jetty.webapp.configuration";
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/** Set up for configuration.
|
||||
* <p>
|
||||
|
@ -84,4 +93,105 @@ public interface Configuration
|
|||
* @throws Exception
|
||||
*/
|
||||
public void cloneConfigure (WebAppContext template, WebAppContext context) throws Exception;
|
||||
|
||||
|
||||
public class ClassList extends ArrayList<String>
|
||||
{
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get/Set/Create the server default Configuration ClassList.
|
||||
* <p>Get the class list from: a Server bean; or the attribute (which can
|
||||
* either be a ClassList instance or an String[] of class names); or a new instance
|
||||
* with default configuration classes.</p>
|
||||
* <p>This method also adds the obtained ClassList instance as a dependent bean
|
||||
* on the server and clears the attribute</p>
|
||||
* @param server The server the default is for
|
||||
* @return the server default ClassList instance of the configuration classes for this server. Changes to this list will change the server default instance.
|
||||
*/
|
||||
public static ClassList setServerDefault(Server server)
|
||||
{
|
||||
ClassList cl=server.getBean(ClassList.class);
|
||||
if (cl!=null)
|
||||
return cl;
|
||||
cl=serverDefault(server);
|
||||
server.addBean(cl);
|
||||
server.setAttribute(ATTR,null);
|
||||
return cl;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Get/Create the server default Configuration ClassList.
|
||||
* <p>Get the class list from: a Server bean; or the attribute (which can
|
||||
* either be a ClassList instance or an String[] of class names); or a new instance
|
||||
* with default configuration classes.
|
||||
* @param server The server the default is for
|
||||
* @return A copy of the server default ClassList instance of the configuration classes for this server. Changes to the returned list will not change the server default.
|
||||
*/
|
||||
public static ClassList serverDefault(Server server)
|
||||
{
|
||||
ClassList cl=server.getBean(ClassList.class);
|
||||
if (cl!=null)
|
||||
return new ClassList(cl);
|
||||
Object attr = server.getAttribute(ATTR);
|
||||
if (attr instanceof ClassList)
|
||||
return new ClassList((ClassList)attr);
|
||||
if (attr instanceof String[])
|
||||
return new ClassList((String[])attr);
|
||||
return new ClassList();
|
||||
}
|
||||
|
||||
public ClassList()
|
||||
{
|
||||
this(WebAppContext.DEFAULT_CONFIGURATION_CLASSES);
|
||||
}
|
||||
|
||||
public ClassList(String[] classes)
|
||||
{
|
||||
addAll(Arrays.asList(classes));
|
||||
}
|
||||
|
||||
public ClassList(List<String> classes)
|
||||
{
|
||||
addAll(classes);
|
||||
}
|
||||
|
||||
public void addAfter(@Name("afterClass") String afterClass,@Name("configClass")String... configClass)
|
||||
{
|
||||
if (configClass!=null && afterClass!=null)
|
||||
{
|
||||
ListIterator<String> iter = listIterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
String cc=iter.next();
|
||||
if (afterClass.equals(cc))
|
||||
{
|
||||
for (int i=0;i<configClass.length;i++)
|
||||
iter.add(configClass[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("afterClass '"+afterClass+"' not found in "+this);
|
||||
}
|
||||
|
||||
public void addBefore(@Name("beforeClass") String beforeClass,@Name("configClass")String... configClass)
|
||||
{
|
||||
if (configClass!=null && beforeClass!=null)
|
||||
{
|
||||
ListIterator<String> iter = listIterator();
|
||||
while (iter.hasNext())
|
||||
{
|
||||
String cc=iter.next();
|
||||
if (beforeClass.equals(cc))
|
||||
{
|
||||
iter.previous();
|
||||
for (int i=0;i<configClass.length;i++)
|
||||
iter.add(configClass[i]);
|
||||
return;
|
||||
}
|
||||
}
|
||||
}
|
||||
throw new IllegalArgumentException("beforeClass '"+beforeClass+"' not found in "+this);
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -61,6 +61,7 @@ import org.eclipse.jetty.xml.XmlParser;
|
|||
* Note- this has been superceded by the new TldScanner in jasper which uses ServletContainerInitializer to
|
||||
* find all the listeners in tag libs and register them.
|
||||
*/
|
||||
@Deprecated
|
||||
public class TagLibConfiguration extends AbstractConfiguration
|
||||
{
|
||||
private static final Logger LOG = Log.getLogger(TagLibConfiguration.class);
|
||||
|
|
|
@ -24,12 +24,14 @@ import java.net.MalformedURLException;
|
|||
import java.net.URL;
|
||||
import java.security.PermissionCollection;
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.EventListener;
|
||||
import java.util.HashMap;
|
||||
import java.util.HashSet;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
import java.util.Map;
|
||||
import java.util.Set;
|
||||
|
||||
|
@ -59,6 +61,7 @@ import org.eclipse.jetty.util.MultiException;
|
|||
import org.eclipse.jetty.util.URIUtil;
|
||||
import org.eclipse.jetty.util.annotation.ManagedAttribute;
|
||||
import org.eclipse.jetty.util.annotation.ManagedObject;
|
||||
import org.eclipse.jetty.util.annotation.Name;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.log.Logger;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
|
@ -86,20 +89,18 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
public static final String BASETEMPDIR = "org.eclipse.jetty.webapp.basetempdir";
|
||||
public final static String WEB_DEFAULTS_XML="org/eclipse/jetty/webapp/webdefault.xml";
|
||||
public final static String ERROR_PAGE="org.eclipse.jetty.server.error_page";
|
||||
public final static String SERVER_CONFIG = "org.eclipse.jetty.webapp.configuration";
|
||||
public final static String SERVER_SYS_CLASSES = "org.eclipse.jetty.webapp.systemClasses";
|
||||
public final static String SERVER_SRV_CLASSES = "org.eclipse.jetty.webapp.serverClasses";
|
||||
|
||||
private String[] __dftProtectedTargets = {"/web-inf", "/meta-inf"};
|
||||
|
||||
private static String[] __dftConfigurationClasses =
|
||||
public static String[] DEFAULT_CONFIGURATION_CLASSES =
|
||||
{
|
||||
"org.eclipse.jetty.webapp.WebInfConfiguration",
|
||||
"org.eclipse.jetty.webapp.WebXmlConfiguration",
|
||||
"org.eclipse.jetty.webapp.MetaInfConfiguration",
|
||||
"org.eclipse.jetty.webapp.FragmentConfiguration",
|
||||
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration"//,
|
||||
//"org.eclipse.jetty.webapp.TagLibConfiguration"
|
||||
"org.eclipse.jetty.webapp.JettyWebXmlConfiguration"
|
||||
} ;
|
||||
|
||||
// System classes are classes that cannot be replaced by
|
||||
|
@ -134,14 +135,14 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
"org.eclipse.jetty." // hide other jetty classes
|
||||
} ;
|
||||
|
||||
private String[] _configurationClasses = __dftConfigurationClasses;
|
||||
private final List<String> _configurationClasses = new ArrayList<>();
|
||||
private ClasspathPattern _systemClasses = null;
|
||||
private ClasspathPattern _serverClasses = null;
|
||||
|
||||
private Configuration[] _configurations;
|
||||
private final List<Configuration> _configurations = new ArrayList<>();
|
||||
private String _defaultsDescriptor=WEB_DEFAULTS_XML;
|
||||
private String _descriptor=null;
|
||||
private final List<String> _overrideDescriptors = new ArrayList<String>();
|
||||
private final List<String> _overrideDescriptors = new ArrayList<>();
|
||||
private boolean _distributable=false;
|
||||
private boolean _extractWAR=true;
|
||||
private boolean _copyDir=false;
|
||||
|
@ -160,8 +161,6 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
private Map<String, String> _resourceAliases;
|
||||
private boolean _ownClassLoader=false;
|
||||
private boolean _configurationDiscovered=true;
|
||||
private boolean _configurationClassesSet=false;
|
||||
private boolean _configurationsSet=false;
|
||||
private boolean _allowDuplicateFragmentNames = false;
|
||||
private boolean _throwUnavailableOnStartupException = false;
|
||||
|
||||
|
@ -184,10 +183,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
/* ------------------------------------------------------------ */
|
||||
public WebAppContext()
|
||||
{
|
||||
super(SESSIONS|SECURITY);
|
||||
_scontext=new Context();
|
||||
setErrorHandler(new ErrorPageErrorHandler());
|
||||
setProtectedTargets(__dftProtectedTargets);
|
||||
this(null,null,null,null,null,new ErrorPageErrorHandler(),SESSIONS|SECURITY);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -197,12 +193,8 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
*/
|
||||
public WebAppContext(String webApp,String contextPath)
|
||||
{
|
||||
super(null,contextPath,SESSIONS|SECURITY);
|
||||
_scontext=new Context();
|
||||
setContextPath(contextPath);
|
||||
this(null,contextPath,null,null,null,new ErrorPageErrorHandler(),SESSIONS|SECURITY);
|
||||
setWar(webApp);
|
||||
setErrorHandler(new ErrorPageErrorHandler());
|
||||
setProtectedTargets(__dftProtectedTargets);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -213,11 +205,8 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
*/
|
||||
public WebAppContext(HandlerContainer parent, String webApp, String contextPath)
|
||||
{
|
||||
super(parent,contextPath,SESSIONS|SECURITY);
|
||||
_scontext=new Context();
|
||||
this(parent,contextPath,null,null,null,new ErrorPageErrorHandler(),SESSIONS|SECURITY);
|
||||
setWar(webApp);
|
||||
setErrorHandler(new ErrorPageErrorHandler());
|
||||
setProtectedTargets(__dftProtectedTargets);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -230,8 +219,23 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
* @param servletHandler ServletHandler for this web app
|
||||
* @param errorHandler ErrorHandler for this web app
|
||||
*/
|
||||
public WebAppContext(SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler) {
|
||||
super(null, sessionHandler, securityHandler, servletHandler, errorHandler);
|
||||
public WebAppContext(SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler)
|
||||
{
|
||||
this(null, null, sessionHandler, securityHandler, servletHandler, errorHandler,0);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* This constructor is used in the geronimo integration.
|
||||
*
|
||||
* @param sessionHandler SessionHandler for this web app
|
||||
* @param securityHandler SecurityHandler for this web app
|
||||
* @param servletHandler ServletHandler for this web app
|
||||
* @param errorHandler ErrorHandler for this web app
|
||||
*/
|
||||
public WebAppContext(HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler,int options)
|
||||
{
|
||||
super(parent, contextPath,sessionHandler, securityHandler, servletHandler, errorHandler,options);
|
||||
_scontext = new Context();
|
||||
setErrorHandler(errorHandler != null ? errorHandler : new ErrorPageErrorHandler());
|
||||
setProtectedTargets(__dftProtectedTargets);
|
||||
|
@ -443,10 +447,10 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
}
|
||||
|
||||
// Prepare for configuration
|
||||
for (int i=0;i<_configurations.length;i++)
|
||||
for (Configuration configuration : _configurations)
|
||||
{
|
||||
LOG.debug("preConfigure {} with {}",this,_configurations[i]);
|
||||
_configurations[i].preConfigure(this);
|
||||
LOG.debug("preConfigure {} with {}",this,configuration);
|
||||
configuration.preConfigure(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -454,10 +458,10 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
public void configure() throws Exception
|
||||
{
|
||||
// Configure webapp
|
||||
for (int i=0;i<_configurations.length;i++)
|
||||
for (Configuration configuration : _configurations)
|
||||
{
|
||||
LOG.debug("configure {} with {}",this,_configurations[i]);
|
||||
_configurations[i].configure(this);
|
||||
LOG.debug("configure {} with {}",this,configuration);
|
||||
configuration.configure(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -465,10 +469,10 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
public void postConfigure() throws Exception
|
||||
{
|
||||
// Clean up after configuration
|
||||
for (int i=0;i<_configurations.length;i++)
|
||||
for (Configuration configuration : _configurations)
|
||||
{
|
||||
LOG.debug("postConfigure {} with {}",this,_configurations[i]);
|
||||
_configurations[i].postConfigure(this);
|
||||
LOG.debug("postConfigure {} with {}",this,configuration);
|
||||
configuration.postConfigure(this);
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -511,8 +515,8 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
|
||||
try
|
||||
{
|
||||
for (int i=_configurations.length;i-->0;)
|
||||
_configurations[i].deconfigure(this);
|
||||
for (int i=_configurations.size();i-->0;)
|
||||
_configurations.get(i).deconfigure(this);
|
||||
|
||||
if (_metadata != null)
|
||||
_metadata.clear();
|
||||
|
@ -537,11 +541,11 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
MultiException mx=new MultiException();
|
||||
if (_configurations!=null)
|
||||
{
|
||||
for (int i=_configurations.length;i-->0;)
|
||||
for (int i=_configurations.size();i-->0;)
|
||||
{
|
||||
try
|
||||
{
|
||||
_configurations[i].destroy(this);
|
||||
_configurations.get(i).destroy(this);
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
|
@ -549,7 +553,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
}
|
||||
}
|
||||
}
|
||||
_configurations=null;
|
||||
_configurations.clear();
|
||||
super.destroy();
|
||||
mx.ifExceptionThrowRuntime();
|
||||
}
|
||||
|
@ -579,7 +583,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
@ManagedAttribute(value="configuration classes used to configure webapp", readonly=true)
|
||||
public String[] getConfigurationClasses()
|
||||
{
|
||||
return _configurationClasses;
|
||||
return _configurationClasses.toArray(new String[_configurationClasses.size()]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -588,7 +592,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
*/
|
||||
public Configuration[] getConfigurations()
|
||||
{
|
||||
return _configurations;
|
||||
return _configurations.toArray(new Configuration[_configurations.size()]);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -879,9 +883,9 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public String[] getDefaultConfigurationClasses ()
|
||||
public static String[] getDefaultConfigurationClasses ()
|
||||
{
|
||||
return __dftConfigurationClasses;
|
||||
return DEFAULT_CONFIGURATION_CLASSES;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -901,18 +905,13 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
throws Exception
|
||||
{
|
||||
//if the configuration instances have been set explicitly, use them
|
||||
if (_configurations!=null)
|
||||
if (_configurations.size()>0)
|
||||
return;
|
||||
|
||||
//if the configuration classnames have been set explicitly use them
|
||||
if (!_configurationClassesSet)
|
||||
_configurationClasses=__dftConfigurationClasses;
|
||||
|
||||
_configurations = new Configuration[_configurationClasses.length];
|
||||
for (int i = 0; i < _configurationClasses.length; i++)
|
||||
{
|
||||
_configurations[i]=(Configuration)Loader.loadClass(this.getClass(), _configurationClasses[i]).newInstance();
|
||||
}
|
||||
|
||||
if (_configurationClasses.size()==0)
|
||||
_configurationClasses.addAll(Configuration.ClassList.serverDefault(getServer()));
|
||||
for (String configClass : _configurationClasses)
|
||||
_configurations.add((Configuration)Loader.loadClass(this.getClass(), configClass).newInstance());
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -938,11 +937,17 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
{
|
||||
if (isRunning())
|
||||
throw new IllegalStateException();
|
||||
_configurationClasses = configurations==null?null:(String[])configurations.clone();
|
||||
_configurationClassesSet = true;
|
||||
_configurations=null;
|
||||
_configurationClasses.clear();
|
||||
if (configurations!=null)
|
||||
_configurationClasses.addAll(Arrays.asList(configurations));
|
||||
_configurations.clear();
|
||||
}
|
||||
|
||||
public void setConfigurationClasses(List<String> configurations)
|
||||
{
|
||||
setConfigurationClasses(configurations.toArray(new String[configurations.size()]));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @param configurations The configurations to set.
|
||||
|
@ -951,8 +956,9 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
{
|
||||
if (isRunning())
|
||||
throw new IllegalStateException();
|
||||
_configurations = configurations==null?null:(Configuration[])configurations.clone();
|
||||
_configurationsSet = true;
|
||||
_configurations.clear();
|
||||
if (configurations!=null)
|
||||
_configurations.addAll(Arrays.asList(configurations));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1264,45 +1270,30 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
this._logUrlOnStart = logOnStart;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void setServer(Server server)
|
||||
{
|
||||
super.setServer(server);
|
||||
//if we haven't been given a set of configuration instances to
|
||||
//use, and we haven't been given a set of configuration classes
|
||||
//to use, use the configuration classes that came from the
|
||||
//Server (if there are any)
|
||||
if (!_configurationsSet && !_configurationClassesSet && server != null)
|
||||
{
|
||||
String[] serverConfigs = (String[])server.getAttribute(SERVER_CONFIG);
|
||||
if (serverConfigs != null)
|
||||
setConfigurationClasses(serverConfigs);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isAllowDuplicateFragmentNames()
|
||||
{
|
||||
return _allowDuplicateFragmentNames;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setAllowDuplicateFragmentNames(boolean allowDuplicateFragmentNames)
|
||||
{
|
||||
_allowDuplicateFragmentNames = allowDuplicateFragmentNames;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void setThrowUnavailableOnStartupException (boolean throwIfStartupException) {
|
||||
_throwUnavailableOnStartupException = throwIfStartupException;
|
||||
}
|
||||
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isThrowUnavailableOnStartupException () {
|
||||
return _throwUnavailableOnStartupException;
|
||||
|
|
|
@ -39,6 +39,7 @@ import org.eclipse.jetty.server.LocalConnector;
|
|||
import org.eclipse.jetty.server.Server;
|
||||
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
|
||||
import org.eclipse.jetty.server.handler.HandlerList;
|
||||
import org.eclipse.jetty.util.log.Log;
|
||||
import org.eclipse.jetty.util.resource.Resource;
|
||||
import org.eclipse.jetty.util.resource.ResourceCollection;
|
||||
import org.junit.Test;
|
||||
|
@ -51,7 +52,7 @@ public class WebAppContextTest
|
|||
Server server = new Server();
|
||||
//test if no classnames set, its the defaults
|
||||
WebAppContext wac = new WebAppContext();
|
||||
assertNull(wac.getConfigurations());
|
||||
Assert.assertEquals(0,wac.getConfigurations().length);
|
||||
String[] classNames = wac.getConfigurationClasses();
|
||||
assertNotNull(classNames);
|
||||
|
||||
|
@ -66,7 +67,7 @@ public class WebAppContextTest
|
|||
String[] classNames = {"x.y.z"};
|
||||
|
||||
Server server = new Server();
|
||||
server.setAttribute(WebAppContext.SERVER_CONFIG, classNames);
|
||||
server.setAttribute(Configuration.ATTR, classNames);
|
||||
|
||||
//test an explicitly set classnames list overrides that from the server
|
||||
WebAppContext wac = new WebAppContext();
|
||||
|
@ -80,6 +81,14 @@ public class WebAppContextTest
|
|||
//test if no explicit classnames, they come from the server
|
||||
WebAppContext wac2 = new WebAppContext();
|
||||
wac2.setServer(server);
|
||||
try
|
||||
{
|
||||
wac2.loadConfigurations();
|
||||
}
|
||||
catch(Exception e)
|
||||
{
|
||||
Log.getRootLogger().ignore(e);
|
||||
}
|
||||
assertTrue(Arrays.equals(classNames, wac2.getConfigurationClasses()));
|
||||
}
|
||||
|
||||
|
@ -94,7 +103,7 @@ public class WebAppContextTest
|
|||
//test that explicit config instances override any from server
|
||||
String[] classNames = {"x.y.z"};
|
||||
Server server = new Server();
|
||||
server.setAttribute(WebAppContext.SERVER_CONFIG, classNames);
|
||||
server.setAttribute(Configuration.ATTR, classNames);
|
||||
wac.setServer(server);
|
||||
assertTrue(Arrays.equals(configs,wac.getConfigurations()));
|
||||
}
|
||||
|
|
|
@ -685,6 +685,8 @@ public class XmlConfiguration
|
|||
oClass = obj.getClass();
|
||||
if (oClass == null)
|
||||
throw new IllegalArgumentException(node.toString());
|
||||
|
||||
System.err.println("class="+oClass);
|
||||
|
||||
int size = 0;
|
||||
int argIndex = node.size();
|
||||
|
@ -810,10 +812,12 @@ public class XmlConfiguration
|
|||
*/
|
||||
private Object refObj(Object obj, XmlParser.Node node) throws Exception
|
||||
{
|
||||
String id = node.getAttribute("id");
|
||||
obj = _idMap.get(id);
|
||||
String refid = node.getAttribute("refid");
|
||||
if (refid==null)
|
||||
refid = node.getAttribute("id");
|
||||
obj = _idMap.get(refid);
|
||||
if (obj == null && node.size()>0)
|
||||
throw new IllegalStateException("No object for id=" + id);
|
||||
throw new IllegalStateException("No object for refid=" + refid);
|
||||
configure(obj,node,0);
|
||||
return obj;
|
||||
}
|
||||
|
|
|
@ -28,6 +28,7 @@ my be specified if a match is not achieved.
|
|||
<!ENTITY % IMPLIEDNAMEATTR "name CDATA #IMPLIED" >
|
||||
<!ENTITY % DEFAULTATTR "default CDATA #IMPLIED" >
|
||||
<!ENTITY % IDATTR "id ID #IMPLIED" >
|
||||
<!ENTITY % REFATTR "refid CDATA #IMPLIED" >
|
||||
<!ENTITY % REQUIREDIDATTR "id ID #REQUIRED" >
|
||||
|
||||
|
||||
|
@ -161,16 +162,18 @@ This is equivalent to:
|
|||
|
||||
<!--
|
||||
Ref Element.
|
||||
This element allows a previously created object to be referenced by id.
|
||||
This element allows a previously created object to be referenced by id. The
|
||||
attribute refid is used to specify the id of another object (the attribute id can
|
||||
also be used, but it's use is deprecated).
|
||||
A Ref element can contain a sequence of elements such as Set, Put, Call, etc.
|
||||
which act on the referenced object:
|
||||
which act on the referenced object.
|
||||
|
||||
<Ref id="myobject">
|
||||
<Ref refid="myobject">
|
||||
<Set name="Test">Value2</Set>
|
||||
</New>
|
||||
-->
|
||||
<!ELEMENT Ref (%CONFIG;)* >
|
||||
<!ATTLIST Ref %REQUIREDIDATTR;>
|
||||
<!ATTLIST Ref %IDATTR; %REFATTR;>
|
||||
|
||||
|
||||
<!--
|
||||
|
|
|
@ -46,5 +46,6 @@
|
|||
<module>test-mock-resources</module>
|
||||
<module>test-servlet-spec</module>
|
||||
<module>test-jaas-webapp</module>
|
||||
<module>test-jndi-webapp</module>
|
||||
</modules>
|
||||
</project>
|
||||
|
|
|
@ -7,29 +7,29 @@
|
|||
<Configure id='wac' class="org.eclipse.jetty.webapp.WebAppContext">
|
||||
|
||||
<New id="tx" class="org.eclipse.jetty.plus.jndi.Transaction">
|
||||
<Arg>
|
||||
<New class="com.acme.MockUserTransaction"/>
|
||||
</Arg>
|
||||
</New>
|
||||
|
||||
<Arg>
|
||||
<New class="com.acme.MockUserTransaction"/>
|
||||
</Arg>
|
||||
</New>
|
||||
|
||||
<!-- =============================================================== -->
|
||||
<!-- Configure the webapp -->
|
||||
<!-- =============================================================== -->
|
||||
<Set name="configurationClasses">
|
||||
<Array type="java.lang.String">
|
||||
<Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.TagLibConfiguration</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
|
||||
<Set name="configurationClasses">
|
||||
<Call class="org.eclipse.jetty.webapp.Configuration$ClassList" name="serverDefault">
|
||||
<Arg><Ref refid="Server" /></Arg>
|
||||
<Call name="addAfter">
|
||||
<Arg name="afterClass">org.eclipse.jetty.webapp.FragmentConfiguration</Arg>
|
||||
<Arg>
|
||||
<Array type="String">
|
||||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Call>
|
||||
</Set>
|
||||
|
||||
<Set name="contextPath">/test-jndi</Set>
|
||||
<Set name="war"><SystemProperty name="jetty.home" default="."/>/webapps/test-jndi.war</Set>
|
||||
|
|
|
@ -1,5 +1,5 @@
|
|||
<?xml version="1.0"?>
|
||||
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure.dtd">
|
||||
<!DOCTYPE Configure PUBLIC "-//Mort Bay Consulting//DTD Configure//EN" "http://www.eclipse.org/jetty/configure_9_0.dtd">
|
||||
|
||||
|
||||
<!-- =============================================================== -->
|
||||
|
@ -18,19 +18,21 @@
|
|||
<!-- =============================================================== -->
|
||||
<!-- Configure the webapp -->
|
||||
<!-- =============================================================== -->
|
||||
<Set name="configurationClasses">
|
||||
<Array type="java.lang.String">
|
||||
<Item>org.eclipse.jetty.webapp.WebInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.WebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.MetaInfConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.FragmentConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.JettyWebXmlConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.webapp.TagLibConfiguration</Item>
|
||||
</Array>
|
||||
</Set>
|
||||
<Set name="configurationClasses">
|
||||
<Call class="org.eclipse.jetty.webapp.Configuration$ClassList" name="serverDefault">
|
||||
<Arg><Ref refid="Server" /></Arg>
|
||||
<Call name="addAfter">
|
||||
<Arg name="afterClass">org.eclipse.jetty.webapp.FragmentConfiguration</Arg>
|
||||
<Arg>
|
||||
<Array type="String">
|
||||
<Item>org.eclipse.jetty.plus.webapp.EnvConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.plus.webapp.PlusConfiguration</Item>
|
||||
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
|
||||
</Array>
|
||||
</Arg>
|
||||
</Call>
|
||||
</Call>
|
||||
</Set>
|
||||
|
||||
<Set name="contextPath">/test-spec</Set>
|
||||
<Set name="war"><SystemProperty name="jetty.home"/>/webapps/test-spec.war</Set>
|
||||
|
|
Loading…
Reference in New Issue