Work in progress on Features

This commit is contained in:
Greg Wilkins 2016-04-21 12:12:24 +10:00
parent adfc430ad4
commit 5ae7da049b
33 changed files with 336 additions and 197 deletions

View File

@ -97,7 +97,6 @@ public class AnnotationConfiguration extends AbstractConfiguration
public AnnotationConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,FragmentConfiguration.class,PlusConfiguration.class);
afterThis(JettyWebXmlConfiguration.class);
protectAndExpose("org.eclipse.jetty.util.annotation.");
@ -437,7 +436,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
* @see org.eclipse.jetty.webapp.AbstractConfiguration#configure(org.eclipse.jetty.webapp.WebAppContext)
*/
@Override
public boolean configure(WebAppContext context) throws Exception
public void configure(WebAppContext context) throws Exception
{
context.getObjectFactory().addDecorator(new AnnotationDecorator(context));
@ -471,9 +470,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
LOG.warn ("ServletContainerInitializers: detected. Class hierarchy: empty");
for (ContainerInitializer i : initializers)
i.resolveClasses(context,map);
}
return true;
}
}

View File

@ -50,7 +50,7 @@ public class AntWebInfConfiguration extends WebInfConfiguration
*
* @see WebXmlConfiguration#configure(WebAppContext)
*/
public boolean configure(WebAppContext context) throws Exception
public void configure(WebAppContext context) throws Exception
{
if (context instanceof AntWebAppContext)
{
@ -67,7 +67,5 @@ public class AntWebInfConfiguration extends WebInfConfiguration
}
}
super.configure(context);
return true;
}
}

View File

@ -31,7 +31,6 @@ public class WebSocketCdiConfiguration extends AbstractConfiguration
{
public WebSocketCdiConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebSocketConfiguration.class);
protectAndExpose("org.eclipse.jetty.cdi.websocket.");
}

View File

@ -72,9 +72,8 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
}
@Override
public boolean configure(WebAppContext context) throws Exception
public void configure(WebAppContext context) throws Exception
{
JettyWebAppContext jwac = (JettyWebAppContext)context;
//put the classes dir and all dependencies into the classpath
@ -87,9 +86,7 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
}
//Set up the quickstart environment for the context
boolean configured = super.configure(context);
return configured;
configure(context);
}
@Override

View File

@ -63,7 +63,7 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
/**
* @see org.eclipse.jetty.webapp.WebInfConfiguration#configure(org.eclipse.jetty.webapp.WebAppContext)
*/
public boolean configure(WebAppContext context) throws Exception
public void configure(WebAppContext context) throws Exception
{
JettyWebAppContext jwac = (JettyWebAppContext)context;
@ -78,8 +78,6 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
}
super.configure(context);
return true;
}

View File

@ -216,7 +216,7 @@ public class OSGiMetaInfConfiguration extends MetaInfConfiguration
* @see org.eclipse.jetty.webapp.WebInfConfiguration#configure(org.eclipse.jetty.webapp.WebAppContext)
*/
@Override
public boolean configure(WebAppContext context) throws Exception
public void configure(WebAppContext context) throws Exception
{
TreeMap<String, Resource> prependedResourcesPath = new TreeMap<String, Resource>();
TreeMap<String, Resource> appendedResourcesPath = new TreeMap<String, Resource>();
@ -272,8 +272,6 @@ public class OSGiMetaInfConfiguration extends MetaInfConfiguration
resources[resources.length-1] = context.getBaseResource();
context.setBaseResource(new ResourceCollection(resources));
}
return true;
}

View File

@ -61,7 +61,6 @@ public class EnvConfiguration extends AbstractConfiguration
public EnvConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,FragmentConfiguration.class);
afterThis(PlusConfiguration.class,JettyWebXmlConfiguration.class);
protectAndExpose("org.eclipse.jetty.jndi.");
@ -80,7 +79,7 @@ public class EnvConfiguration extends AbstractConfiguration
}
@Override
public boolean configure (WebAppContext context) throws Exception
public void configure (WebAppContext context) throws Exception
{
if (LOG.isDebugEnabled())
LOG.debug("Created java:comp/env for webapp "+context.getContextPath());
@ -137,8 +136,6 @@ public class EnvConfiguration extends AbstractConfiguration
//add java:comp/env entries for any EnvEntries that have been defined so far
bindEnvEntries(context);
return true;
}

View File

@ -50,7 +50,6 @@ public class PlusConfiguration extends AbstractConfiguration
public PlusConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(EnvConfiguration.class,WebXmlConfiguration.class,MetaInfConfiguration.class,FragmentConfiguration.class);
afterThis(JettyWebXmlConfiguration.class);
}
@ -69,14 +68,12 @@ public class PlusConfiguration extends AbstractConfiguration
}
@Override
public boolean configure (WebAppContext context)
public void configure (WebAppContext context)
throws Exception
{
bindUserTransaction(context);
context.getMetaData().addDescriptorProcessor(new PlusDescriptorProcessor());
return true;
}
@Override

View File

@ -31,6 +31,7 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.Configurations;
import org.eclipse.jetty.webapp.StandardDescriptorProcessor;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.WebInfConfiguration;
@ -42,7 +43,7 @@ import org.eclipse.jetty.webapp.WebXmlConfiguration;
* Re-inflate a deployable webapp from a saved effective-web.xml
* which combines all pre-parsed web xml descriptors and annotations.
*/
public class QuickStartConfiguration extends AbstractConfiguration
public class QuickStartConfiguration extends AbstractConfiguration implements Configuration.DisabledByDefault
{
private static final Logger LOG = Log.getLogger(QuickStartConfiguration.class);
@ -62,7 +63,6 @@ public class QuickStartConfiguration extends AbstractConfiguration
public QuickStartConfiguration()
{
super(!ENABLE_BY_DEFAULT);
beforeThis(WebInfConfiguration.class);
afterThis(WebXmlConfiguration.class);
}
@ -141,31 +141,31 @@ public class QuickStartConfiguration extends AbstractConfiguration
* @see org.eclipse.jetty.webapp.AbstractConfiguration#configure(org.eclipse.jetty.webapp.WebAppContext)
*/
@Override
public boolean configure(WebAppContext context) throws Exception
public void configure(WebAppContext context) throws Exception
{
if (!_quickStart)
return super.configure(context);
//add the processor to handle normal web.xml content
context.getMetaData().addDescriptorProcessor(new StandardDescriptorProcessor());
//add a processor to handle extended web.xml format
context.getMetaData().addDescriptorProcessor(new QuickStartDescriptorProcessor());
//add a decorator that will find introspectable annotations
context.getObjectFactory().addDecorator(new AnnotationDecorator(context)); //this must be the last Decorator because they are run in reverse order!
//add a context bean that will run ServletContainerInitializers as the context starts
ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter)context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER);
if (starter != null)
throw new IllegalStateException("ServletContainerInitializersStarter already exists");
starter = new ServletContainerInitializersStarter(context);
context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER, starter);
context.addBean(starter, true);
super.configure(context);
else
{
//add the processor to handle normal web.xml content
context.getMetaData().addDescriptorProcessor(new StandardDescriptorProcessor());
LOG.debug("configured {}",this);
//add a processor to handle extended web.xml format
context.getMetaData().addDescriptorProcessor(new QuickStartDescriptorProcessor());
return true;
//add a decorator that will find introspectable annotations
context.getObjectFactory().addDecorator(new AnnotationDecorator(context)); //this must be the last Decorator because they are run in reverse order!
//add a context bean that will run ServletContainerInitializers as the context starts
ServletContainerInitializersStarter starter = (ServletContainerInitializersStarter)context.getAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER);
if (starter != null)
throw new IllegalStateException("ServletContainerInitializersStarter already exists");
starter = new ServletContainerInitializersStarter(context);
context.setAttribute(AnnotationConfiguration.CONTAINER_INITIALIZER_STARTER, starter);
context.addBean(starter, true);
LOG.debug("configured {}",this);
}
}
/**

View File

@ -19,7 +19,6 @@
package org.eclipse.jetty.quickstart;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.FileOutputStream;
import java.io.IOException;
@ -60,6 +59,7 @@ import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.util.security.Constraint;
import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.MetaData;
import org.eclipse.jetty.webapp.MetaData.OriginInfo;
import org.eclipse.jetty.webapp.MetaInfConfiguration;
@ -72,7 +72,7 @@ import org.eclipse.jetty.xml.XmlAppendable;
* Generate an effective web.xml from a WebAppContext, including all components
* from web.xml, web-fragment.xmls annotations etc.
*/
public class QuickStartGeneratorConfiguration extends AbstractConfiguration
public class QuickStartGeneratorConfiguration extends AbstractConfiguration implements Configuration.DisabledByDefault
{
private static final Logger LOG = Log.getLogger(QuickStartGeneratorConfiguration.class);
@ -81,7 +81,6 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
}
/**
* Perform the generation of the xml file
* @param stream the stream to generate the quickstart-web.xml to
@ -704,7 +703,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
}
@Override
public boolean configure(WebAppContext context) throws Exception
public void configure(WebAppContext context) throws Exception
{
MetaData metadata = context.getMetaData();
metadata.resolve(context);
@ -716,7 +715,6 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration
{
generateQuickStartWebXml(context,fos);
}
return true;
}

View File

@ -18,22 +18,10 @@
package org.eclipse.jetty.quickstart;
import java.io.FileOutputStream;
import java.util.Arrays;
import java.util.HashSet;
import java.util.Locale;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jetty.annotations.AnnotationConfiguration;
import org.eclipse.jetty.plus.webapp.EnvConfiguration;
import org.eclipse.jetty.plus.webapp.PlusConfiguration;
import org.eclipse.jetty.quickstart.QuickStartConfiguration.Mode;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.JarResource;
import org.eclipse.jetty.util.resource.Resource;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.WebAppContext;
/**

View File

@ -19,13 +19,8 @@
package org.eclipse.jetty.quickstart;
import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.WebAppContext;
import org.eclipse.jetty.webapp.Configuration;
public class StopContextConfiguration extends AbstractConfiguration
public class StopContextConfiguration extends AbstractConfiguration implements Configuration.AbortConfiguration
{
@Override
public boolean configure(WebAppContext context) throws Exception
{
return false;
}
}

View File

@ -27,7 +27,6 @@ import java.util.stream.Collectors;
public class AbstractConfiguration implements Configuration
{
protected static final boolean ENABLE_BY_DEFAULT = true;
private final boolean _enabledByDefault;
private final List<String> _after=new ArrayList<>();
private final List<String> _beforeThis=new ArrayList<>();
private final ClasspathPattern _system=new ClasspathPattern();
@ -36,12 +35,6 @@ public class AbstractConfiguration implements Configuration
protected AbstractConfiguration()
{
this(!ENABLE_BY_DEFAULT);
}
protected AbstractConfiguration(boolean enableByDefault)
{
_enabledByDefault=enableByDefault;
}
/**
@ -165,9 +158,8 @@ public class AbstractConfiguration implements Configuration
{
}
public boolean configure(WebAppContext context) throws Exception
public void configure(WebAppContext context) throws Exception
{
return true;
}
public void postConfigure(WebAppContext context) throws Exception
@ -184,11 +176,5 @@ public class AbstractConfiguration implements Configuration
public void cloneConfigure(WebAppContext template, WebAppContext context) throws Exception
{
}
@Override
public boolean isEnabledByDefault()
{
return _enabledByDefault;
}
}
}

View File

@ -69,11 +69,6 @@ public interface Configuration
*/
public default ClasspathPattern getServerClasses() { return new ClasspathPattern(); }
/**
* @return true if the Configuration should be added to a Context by default
*/
public default boolean isEnabledByDefault() { return false; }
/* ------------------------------------------------------------------------------- */
/** Set up for configuration.
* <p>
@ -86,17 +81,15 @@ public interface Configuration
*/
public void preConfigure (WebAppContext context) throws Exception;
/* ------------------------------------------------------------------------------- */
/** Configure WebApp.
* <p>
* Typically this step applies the discovered configuration resources to
* either the {@link WebAppContext} or the associated {@link MetaData}.
* @param context The context to configure
* @return True if configuration is successful or false if context should not be started.
* @throws Exception if unable to configure
*/
public boolean configure (WebAppContext context) throws Exception;
public void configure (WebAppContext context) throws Exception;
/* ------------------------------------------------------------------------------- */
@ -124,6 +117,16 @@ public interface Configuration
*/
public void destroy (WebAppContext context) throws Exception;
/**
* A Configuration that is not added by default to a context
*
*/
interface DisabledByDefault extends Configuration {}
/**
* A Configuration that will cause {@link Configurations#configure(WebAppContext) to abort with a false return
*/
interface AbortConfiguration extends DisabledByDefault,Configuration {}
/**
* @deprecated Use {@link Configurations}

View File

@ -40,6 +40,10 @@ import org.eclipse.jetty.util.annotation.Name;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
/**
* @author gregw
*
*/
public class Configurations extends AbstractList<Configuration>
{
private static final Logger LOG = Log.getLogger(Configurations.class);
@ -48,60 +52,19 @@ public class Configurations extends AbstractList<Configuration>
private static final Set<String> __knownByClassName = new HashSet<>();
/* ------------------------------------------------------------ */
/**
* @return
*/
public static List<Configuration> getKnown()
public static synchronized List<Configuration> getKnown()
{
synchronized (Configurations.class)
if (__known.isEmpty())
{
if (__known.isEmpty())
ServiceLoader<Configuration> configs = ServiceLoader.load(Configuration.class);
for (Configuration configuration : configs)
{
ServiceLoader<Configuration> configs = ServiceLoader.load(Configuration.class);
for (Configuration configuration : configs)
{
__known.add(configuration);
__knownByClassName.add(configuration.getClass().getName());
}
sort(__known);
if (LOG.isDebugEnabled())
{
for (Configuration c: __known)
LOG.debug("known {}",c);
}
LOG.debug("Known Configurations {}",__knownByClassName);
}
}
return __known;
}
/**
* @param classes
* @throws Exception
*/
public static void setKnown (String ... classes)
{
synchronized (Configurations.class)
{
if (!__known.isEmpty())
throw new IllegalStateException("Known configuration classes already set");
for (String c:classes)
{
try
{
Class clazz = Thread.currentThread().getContextClassLoader().loadClass(c);
__known.add((Configuration)clazz.newInstance());
__knownByClassName.add(c);
}
catch (Exception e)
{
LOG.warn("Problem loading known class {}", c);
}
__known.add(configuration);
__knownByClassName.add(configuration.getClass().getName());
}
sort(__known);
if (LOG.isDebugEnabled())
@ -109,12 +72,53 @@ public class Configurations extends AbstractList<Configuration>
for (Configuration c: __known)
LOG.debug("known {}",c);
}
LOG.debug("Known Configurations {}",__knownByClassName);
}
return __known;
}
/* ------------------------------------------------------------ */
/**
* @param classes
* @throws Exception
*/
public static synchronized void setKnown (String ... classes)
{
if (!__known.isEmpty())
throw new IllegalStateException("Known configuration classes already set");
for (String c:classes)
{
try
{
Class<?> clazz = Loader.loadClass(c);
__known.add((Configuration)clazz.newInstance());
__knownByClassName.add(c);
}
catch (Exception e)
{
LOG.warn("Problem loading known class",e);
}
}
sort(__known);
if (LOG.isDebugEnabled())
{
for (Configuration c: __known)
LOG.debug("known {}",c);
}
LOG.debug("Known Configurations {}",__knownByClassName);
}
/* ------------------------------------------------------------ */
static synchronized void cleanKnown()
{
__known.clear();
}
/* ------------------------------------------------------------ */
/** Get/Set/Create the server default Configuration ClassList.
* <p>Get the class list from: a Server bean; or the attribute (which can
@ -123,7 +127,8 @@ public class Configurations extends AbstractList<Configuration>
* <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.
* @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 Configurations setServerDefault(Server server)
{
@ -149,7 +154,8 @@ public class Configurations extends AbstractList<Configuration>
* 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.
* @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 Configurations getServerDefault(Server server)
{
@ -173,7 +179,7 @@ public class Configurations extends AbstractList<Configuration>
if (configurations==null)
{
configurations=new Configurations(Configurations.getKnown().stream()
.filter(Configuration::isEnabledByDefault)
.filter(c->!(c instanceof Configuration.DisabledByDefault))
.map(c->c.getClass().getName())
.toArray(String[]::new));
}
@ -271,6 +277,17 @@ public class Configurations extends AbstractList<Configuration>
i.remove();
}
}
public void remove(Class<? extends Configuration>... configClass)
{
List<String> names = Arrays.asList(configClass).stream().map(c->c.getName()).collect(Collectors.toList());
for (ListIterator<Configuration> i=_configurations.listIterator();i.hasNext();)
{
Configuration configuration=i.next();
if (names.contains(configuration.getClass().getName()))
i.remove();
}
}
public void remove(@Name("configClass")String... configClass)
{
@ -306,24 +323,34 @@ public class Configurations extends AbstractList<Configuration>
public static void sort(List<Configuration> configurations)
{
// Sort the configurations
Map<String,Configuration> map = new HashMap<>();
Map<String,Configuration> by_name = new HashMap<>();
Map<String,List<Configuration>> replaced_by = new HashMap<>();
TopologicalSort<Configuration> sort = new TopologicalSort<>();
for (Configuration c:configurations)
map.put(c.getClass().getName(),c);
{
by_name.put(c.getClass().getName(),c);
if (c.replaces()!=null)
replaced_by.computeIfAbsent(c.replaces().getName(),key->new ArrayList<>()).add(c);
}
for (Configuration c:configurations)
{
for (String b:c.getConfigurationsBeforeThis())
{
Configuration before=map.get(b);
Configuration before=by_name.get(b);
if (before!=null)
sort.addBeforeAfter(before,c);
if (replaced_by.containsKey(b))
replaced_by.get(b).forEach(bc->sort.addBeforeAfter(bc,c));
}
for (String a:c.getConfigurationsAfterThis())
{
Configuration after=map.get(a);
Configuration after=by_name.get(a);
if (after!=null)
sort.addBeforeAfter(c,after);
if (replaced_by.containsKey(a))
replaced_by.get(a).forEach(ac->sort.addBeforeAfter(c,ac));
}
}
sort.sort(configurations);
@ -345,7 +372,7 @@ public class Configurations extends AbstractList<Configuration>
{
return getConfigurations().iterator();
}
private void addConfiguration(Configuration configuration)
{
String name=configuration.getClass().getName();
@ -399,13 +426,19 @@ public class Configurations extends AbstractList<Configuration>
}
}
/**
* @param webapp The webapp to configure
* @return false if a {@link Configuration.AbortConfiguration} was encountered, true otherwise
* @throws Exception Thrown by {@link Configuration#configure(WebAppContext)}
*/
public boolean configure(WebAppContext webapp) throws Exception
{
// Configure webapp
for (Configuration configuration : _configurations)
{
LOG.debug("configure {}",configuration);
if (!configuration.configure(webapp))
configuration.configure(webapp);
if (configuration instanceof Configuration.AbortConfiguration)
return false;
}
return true;
@ -421,4 +454,5 @@ public class Configurations extends AbstractList<Configuration>
configuration.postConfigure(webapp);
}
}
}

View File

@ -34,7 +34,6 @@ public class FragmentConfiguration extends AbstractConfiguration
public FragmentConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(MetaInfConfiguration.class,WebXmlConfiguration.class);
}

View File

@ -34,7 +34,6 @@ public class JaasConfiguration extends AbstractConfiguration
{
public JaasConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class,FragmentConfiguration.class);
afterThis(WebAppConfiguration.class);
protectAndExpose("org.eclipse.jetty.jaas.");

View File

@ -48,7 +48,6 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
public JettyWebXmlConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebXmlConfiguration.class,FragmentConfiguration.class,MetaInfConfiguration.class);
}
@ -58,7 +57,7 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
* @see Configuration#configure(WebAppContext)
*/
@Override
public boolean configure (WebAppContext context) throws Exception
public void configure (WebAppContext context) throws Exception
{
LOG.debug("Configuring web-jetty.xml");
@ -96,8 +95,6 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
}
}
}
return true;
}
/**

View File

@ -35,7 +35,6 @@ public class JmxConfiguration extends AbstractConfiguration
{
public JmxConfiguration()
{
super(ENABLE_BY_DEFAULT);
afterThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class);
protectAndExpose("org.eclipse.jetty.jmx.");
}

View File

@ -34,7 +34,6 @@ public class JndiConfiguration extends AbstractConfiguration
{
public JndiConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class,FragmentConfiguration.class);
afterThis(WebAppConfiguration.class);
protectAndExpose("org.eclipse.jetty.jndi.");

View File

@ -35,7 +35,6 @@ public class JspConfiguration extends AbstractConfiguration
{
public JspConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class,FragmentConfiguration.class);
afterThis(WebAppConfiguration.class);
protectAndExpose("org.eclipse.jetty.jsp.");

View File

@ -90,7 +90,6 @@ public class MetaInfConfiguration extends AbstractConfiguration
/* ------------------------------------------------------------------------------- */
public MetaInfConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebXmlConfiguration.class);
}
@ -188,7 +187,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
@Override
public boolean configure(WebAppContext context) throws Exception
public void configure(WebAppContext context) throws Exception
{
// Look for extra resource
@ -203,7 +202,6 @@ public class MetaInfConfiguration extends AbstractConfiguration
collection[i++]=resource;
context.setBaseResource(new ResourceCollection(collection));
}
return true;
}
/**

View File

@ -29,7 +29,6 @@ public class ServletsConfiguration extends AbstractConfiguration
{
public ServletsConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class,WebAppConfiguration.class);
afterThis(JettyWebXmlConfiguration.class);
protectAndExpose();

View File

@ -33,7 +33,6 @@ import java.util.Set;
import javax.servlet.DispatcherType;
import javax.servlet.MultipartConfigElement;
import javax.servlet.ServletException;
import javax.servlet.SessionTrackingMode;
import org.eclipse.jetty.security.ConstraintAware;
@ -51,7 +50,6 @@ import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.servlet.ServletMapping;
import org.eclipse.jetty.util.ArrayUtil;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.security.Constraint;

View File

@ -36,7 +36,6 @@ import java.util.List;
import java.util.Locale;
import java.util.Set;
import java.util.StringTokenizer;
import java.util.concurrent.Callable;
import java.util.concurrent.CopyOnWriteArrayList;
import org.eclipse.jetty.util.IO;

View File

@ -29,7 +29,6 @@ public class WebAppConfiguration extends AbstractConfiguration
{
public WebAppConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class);
afterThis(JettyWebXmlConfiguration.class);
protectAndExpose("org.eclipse.jetty.util.log.",

View File

@ -24,7 +24,6 @@ import java.net.MalformedURLException;
import java.net.URL;
import java.net.URLClassLoader;
import java.security.PermissionCollection;
import java.security.PrivilegedExceptionAction;
import java.util.ArrayList;
import java.util.Collection;
import java.util.Collections;
@ -34,7 +33,6 @@ import java.util.HashSet;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.concurrent.Callable;
import javax.servlet.ServletContext;
import javax.servlet.ServletRegistration.Dynamic;

View File

@ -50,9 +50,7 @@ public class WebInfConfiguration extends AbstractConfiguration
public WebInfConfiguration()
{
super(ENABLE_BY_DEFAULT);
}
@Override
public void preConfigure(final WebAppContext context) throws Exception
@ -62,12 +60,10 @@ public class WebInfConfiguration extends AbstractConfiguration
//Extract webapp if necessary
unpack (context);
}
@Override
public boolean configure(WebAppContext context) throws Exception
public void configure(WebAppContext context) throws Exception
{
Resource web_inf = context.getWebInf();
@ -84,8 +80,6 @@ public class WebInfConfiguration extends AbstractConfiguration
if (lib.exists() || lib.isDirectory())
((WebAppClassLoader)context.getClassLoader()).addJars(lib);
}
return true;
}
@Override

View File

@ -34,7 +34,6 @@ public class WebSocketConfiguration extends AbstractConfiguration
{
public WebSocketConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class,FragmentConfiguration.class);
afterThis("org.eclipse.jetty.annotations.AnnotationConfiguration",WebAppConfiguration.class.getName());
protectAndExpose("org.eclipse.jetty.websocket.");

View File

@ -35,14 +35,11 @@ public class WebXmlConfiguration extends AbstractConfiguration
{
private static final Logger LOG = Log.getLogger(WebXmlConfiguration.class);
/* ------------------------------------------------------------------------------- */
public WebXmlConfiguration()
{
super(ENABLE_BY_DEFAULT);
beforeThis(WebInfConfiguration.class);
}
/* ------------------------------------------------------------------------------- */
/**
@ -89,10 +86,9 @@ public class WebXmlConfiguration extends AbstractConfiguration
*
*/
@Override
public boolean configure (WebAppContext context) throws Exception
public void configure (WebAppContext context) throws Exception
{
context.getMetaData().addDescriptorProcessor(new StandardDescriptorProcessor());
return true;
}
/* ------------------------------------------------------------------------------- */

View File

@ -0,0 +1,180 @@
//
// ========================================================================
// Copyright (c) 1995-2016 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.webapp;
import static java.util.stream.Collectors.toList;
import static org.eclipse.jetty.webapp.Configurations.getKnown;
import static org.hamcrest.Matchers.contains;
import static org.junit.Assert.assertThat;
import org.junit.Test;
public class ConfigurationsTest
{
@Test
public void testSetKnown()
{
Configurations.cleanKnown();
Configurations.setKnown(
ConfigBar.class.getName(),
ConfigZ.class.getName(),
ConfigY.class.getName(),
ConfigX.class.getName(),
ConfigTom.class.getName(),
ConfigDick.class.getName(),
ConfigHarry.class.getName(),
ConfigAdditionalHarry.class.getName(),
ConfigExtendedDick.class.getName(),
ConfigFoo.class.getName()
);
assertThat(getKnown().stream().map(c->c.getClass().getName()).collect(toList()),
contains(
ConfigFoo.class.getName(),
ConfigBar.class.getName(),
ConfigX.class.getName(),
ConfigY.class.getName(),
ConfigZ.class.getName(),
ConfigTom.class.getName(),
ConfigDick.class.getName(),
ConfigExtendedDick.class.getName(),
ConfigHarry.class.getName(),
ConfigAdditionalHarry.class.getName()
));
}
@Test
public void testConfigurations()
{
Configurations.cleanKnown();
Configurations.setKnown(
ConfigBar.class.getName(),
ConfigZ.class.getName(),
ConfigY.class.getName(),
ConfigX.class.getName(),
ConfigTom.class.getName(),
ConfigDick.class.getName(),
ConfigHarry.class.getName(),
ConfigAdditionalHarry.class.getName(),
ConfigExtendedDick.class.getName(),
ConfigFoo.class.getName()
);
Configurations configs = new Configurations(
ConfigBar.class.getName(),
ConfigZ.class.getName(),
ConfigY.class.getName(),
ConfigX.class.getName(),
ConfigTom.class.getName(),
ConfigDick.class.getName(),
ConfigHarry.class.getName(),
ConfigAdditionalHarry.class.getName(),
ConfigFoo.class.getName()
);
configs.add(ConfigExtendedDick.class.getName());
configs.sort();
assertThat(configs.stream().map(c->c.getClass().getName()).collect(toList()),
contains(
ConfigFoo.class.getName(),
ConfigBar.class.getName(),
ConfigX.class.getName(),
ConfigY.class.getName(),
ConfigZ.class.getName(),
ConfigTom.class.getName(),
ConfigExtendedDick.class.getName(),
ConfigHarry.class.getName(),
ConfigAdditionalHarry.class.getName()
));
}
public static class ConfigFoo extends AbstractConfiguration
{
{afterThis(ConfigBar.class); }
}
public static class ConfigBar extends AbstractConfiguration
{
}
public static class ConfigX extends AbstractConfiguration
{
{
beforeThis(ConfigBar.class);
}
}
public static class ConfigY extends AbstractConfiguration
{
{
beforeThis(ConfigX.class);
afterThis(ConfigZ.class);
}
}
public static class ConfigZ extends AbstractConfiguration
{
}
public static class ConfigTom extends AbstractConfiguration
{
}
public static class ConfigDick extends AbstractConfiguration
{
{
beforeThis(ConfigTom.class);
}
}
public static class ConfigHarry extends AbstractConfiguration
{
{
beforeThis(ConfigDick.class);
}
}
public static class ConfigExtendedDick extends ConfigDick
{
{
beforeThis(ConfigTom.class);
}
@Override
public Class<? extends Configuration> replaces()
{
return ConfigDick.class;
}
}
public static class ConfigAdditionalHarry extends ConfigHarry
{
}
}

View File

@ -18,9 +18,12 @@
package org.eclipse.jetty.webapp;
import static org.eclipse.jetty.toolchain.test.ExtraMatchers.*;
import static org.hamcrest.Matchers.*;
import static org.junit.Assert.*;
import static org.eclipse.jetty.toolchain.test.ExtraMatchers.ordered;
import static org.hamcrest.Matchers.contains;
import static org.hamcrest.Matchers.notNullValue;
import static org.hamcrest.Matchers.nullValue;
import static org.junit.Assert.assertThat;
import static org.junit.Assert.assertTrue;
import java.lang.instrument.ClassFileTransformer;
import java.lang.instrument.IllegalClassFormatException;

View File

@ -57,9 +57,9 @@ public class WebAppContextTest
public void testConfigurationClassesFromDefault ()
{
String[] known_and_enabled=Configurations.getKnown().stream()
.filter(Configuration::isEnabledByDefault)
.map(c->c.getClass().getName())
.toArray(String[]::new);
.filter(c->!(c instanceof Configuration.DisabledByDefault))
.map(c->c.getClass().getName())
.toArray(String[]::new);
Server server = new Server();
@ -190,7 +190,6 @@ public class WebAppContextTest
assertFalse(context.isProtectedTarget("/something-else/web-inf"));
}
@Test
public void testNullPath() throws Exception
{
@ -208,6 +207,7 @@ public class WebAppContextTest
server.addConnector(connector);
server.start();
try
{
String response = connector.getResponses("GET http://localhost:8080 HTTP/1.1\r\nHost: localhost:8080\r\nConnection: close\r\n\r\n");
@ -219,7 +219,6 @@ public class WebAppContextTest
}
}
class ServletA extends GenericServlet
{
@Override