general cleanup of Configuration and ClasspathPattern usage
This commit is contained in:
parent
65f8e5dbd0
commit
8e54aad414
|
@ -31,7 +31,6 @@ import java.util.HashSet;
|
|||
import java.util.Iterator;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.ServiceConfigurationError;
|
||||
import java.util.ServiceLoader;
|
||||
import java.util.Set;
|
||||
import java.util.concurrent.Callable;
|
||||
|
@ -98,11 +97,11 @@ public class AnnotationConfiguration extends AbstractConfiguration
|
|||
|
||||
public AnnotationConfiguration()
|
||||
{
|
||||
super(true,
|
||||
new String[]{WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),FragmentConfiguration.class.getName(),PlusConfiguration.class.getName()},
|
||||
new String[]{JettyWebXmlConfiguration.class.getName()},
|
||||
new String[]{"org.eclipse.jetty.util.annotation."},
|
||||
new String[]{"-org.eclipse.jetty.util.annotation.","org.objectweb.asm."});
|
||||
super(ENABLE_BY_DEFAULT);
|
||||
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,FragmentConfiguration.class,PlusConfiguration.class);
|
||||
afterThis(JettyWebXmlConfiguration.class);
|
||||
protectAndExpose("org.eclipse.jetty.util.annotation.");
|
||||
hide("org.objectweb.asm.");
|
||||
}
|
||||
|
||||
/**
|
||||
|
|
|
@ -31,14 +31,8 @@ public class WebSocketCdiConfiguration extends AbstractConfiguration
|
|||
{
|
||||
public WebSocketCdiConfiguration()
|
||||
{
|
||||
super(true,
|
||||
new String[]{WebSocketConfiguration.class.getName()},
|
||||
null,
|
||||
new String[]{
|
||||
"org.eclipse.jetty.cdi.websocket."
|
||||
},
|
||||
new String[]{
|
||||
"-org.eclipse.jetty.cdi.websocket.",
|
||||
});
|
||||
super(ENABLE_BY_DEFAULT);
|
||||
beforeThis(WebSocketConfiguration.class);
|
||||
protectAndExpose("org.eclipse.jetty.cdi.websocket.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -48,14 +48,10 @@ public class MavenWebInfConfiguration extends WebInfConfiguration
|
|||
protected Resource _originalResourceBase;
|
||||
protected List<Resource> _unpackedOverlayResources;
|
||||
|
||||
|
||||
|
||||
public MavenWebInfConfiguration()
|
||||
{
|
||||
super();
|
||||
addServerClass(
|
||||
"org.apache.maven.",
|
||||
"org.codehaus.plexus.");
|
||||
hide("org.apache.maven.",
|
||||
"org.codehaus.plexus.");
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -61,10 +61,10 @@ public class EnvConfiguration extends AbstractConfiguration
|
|||
|
||||
public EnvConfiguration()
|
||||
{
|
||||
super(new String[]{WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),FragmentConfiguration.class.getName()},
|
||||
new String[]{PlusConfiguration.class.getName(),JettyWebXmlConfiguration.class.getName()},
|
||||
new String[]{"org.eclipse.jetty.jndi."},
|
||||
new String[]{"-org.eclipse.jetty.jndi."});
|
||||
super(!ENABLE_BY_DEFAULT);
|
||||
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,FragmentConfiguration.class);
|
||||
afterThis(PlusConfiguration.class,JettyWebXmlConfiguration.class);
|
||||
protectAndExpose("org.eclipse.jetty.jndi.");
|
||||
}
|
||||
|
||||
public void setJettyEnvXml (URL url)
|
||||
|
|
|
@ -50,8 +50,9 @@ public class PlusConfiguration extends AbstractConfiguration
|
|||
|
||||
public PlusConfiguration()
|
||||
{
|
||||
super(new String[]{EnvConfiguration.class.getName(),WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),FragmentConfiguration.class.getName()},
|
||||
new String[]{JettyWebXmlConfiguration.class.getName()});
|
||||
super(!ENABLE_BY_DEFAULT);
|
||||
beforeThis(EnvConfiguration.class,WebXmlConfiguration.class,MetaInfConfiguration.class,FragmentConfiguration.class);
|
||||
afterThis(JettyWebXmlConfiguration.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -62,11 +62,9 @@ public class QuickStartConfiguration extends AbstractConfiguration
|
|||
|
||||
public QuickStartConfiguration()
|
||||
{
|
||||
super(false,
|
||||
new String[]{WebInfConfiguration.class.getName()},
|
||||
new String[]{WebXmlConfiguration.class.getName()},
|
||||
null,null
|
||||
);
|
||||
super(!ENABLE_BY_DEFAULT);
|
||||
beforeThis(WebInfConfiguration.class);
|
||||
afterThis(WebXmlConfiguration.class);
|
||||
}
|
||||
|
||||
public void setMode(Mode mode)
|
||||
|
|
|
@ -162,11 +162,7 @@ public class ServletContextHandler extends ContextHandler
|
|||
if (contextPath!=null)
|
||||
setContextPath(contextPath);
|
||||
|
||||
if (parent instanceof HandlerWrapper)
|
||||
((HandlerWrapper)parent).setHandler(this);
|
||||
else if (parent instanceof HandlerCollection)
|
||||
((HandlerCollection)parent).addHandler(this);
|
||||
|
||||
setParent(parent);
|
||||
|
||||
// Link the handlers
|
||||
relinkHandlers();
|
||||
|
@ -175,6 +171,14 @@ public class ServletContextHandler extends ContextHandler
|
|||
setErrorHandler(errorHandler);
|
||||
}
|
||||
|
||||
protected void setParent(HandlerContainer parent)
|
||||
{
|
||||
if (parent instanceof HandlerWrapper)
|
||||
((HandlerWrapper)parent).setHandler(this);
|
||||
else if (parent instanceof HandlerCollection)
|
||||
((HandlerCollection)parent).addHandler(this);
|
||||
}
|
||||
|
||||
@Override
|
||||
public void setHandler(Handler handler)
|
||||
{
|
||||
|
|
|
@ -20,113 +20,143 @@ package org.eclipse.jetty.webapp;
|
|||
|
||||
import java.util.ArrayList;
|
||||
import java.util.Arrays;
|
||||
import java.util.Collections;
|
||||
import java.util.Collection;
|
||||
import java.util.List;
|
||||
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;
|
||||
private final List<String> _before;
|
||||
private final List<String> _system;
|
||||
private final List<String> _server;
|
||||
private final List<String> _after=new ArrayList<>();
|
||||
private final List<String> _beforeThis=new ArrayList<>();
|
||||
private final ClasspathPattern _system=new ClasspathPattern();
|
||||
private final ClasspathPattern _server=new ClasspathPattern();
|
||||
|
||||
|
||||
protected AbstractConfiguration()
|
||||
{
|
||||
this(false,(String[])null,(String[])null,null,null);
|
||||
this(!ENABLE_BY_DEFAULT);
|
||||
}
|
||||
|
||||
protected AbstractConfiguration(String[] before,String[] after)
|
||||
protected AbstractConfiguration(boolean enableByDefault)
|
||||
{
|
||||
this(false,before,after,null,null);
|
||||
}
|
||||
|
||||
protected AbstractConfiguration(boolean enableByDefault,String[] before,String[] after)
|
||||
{
|
||||
this(enableByDefault,before,after,null,null);
|
||||
}
|
||||
|
||||
/**
|
||||
* @param before Configurations that come before this configuration
|
||||
* @param after Configuration that come after this configuration
|
||||
* @param systemClasses
|
||||
* @param serverClasses
|
||||
*/
|
||||
protected AbstractConfiguration(String[] before,String[] after,String[] systemClasses,String[] serverClasses)
|
||||
{
|
||||
this (false,before,after,systemClasses,serverClasses);
|
||||
_enabledByDefault=enableByDefault;
|
||||
}
|
||||
|
||||
/**
|
||||
* @param enabledByDefault
|
||||
* @param before Configurations that come before this configuration
|
||||
* @param after Configuration that come after this configuration
|
||||
* @param systemClasses
|
||||
* @param serverClasses
|
||||
* Add configuration classes that come before this configuration
|
||||
* @param classes Classname or package name
|
||||
*/
|
||||
protected AbstractConfiguration(
|
||||
boolean enableByDefault,
|
||||
Class<? extends Configuration>[] before,
|
||||
Class<? extends Configuration>[] after,
|
||||
String[] systemClasses,
|
||||
String[] serverClasses)
|
||||
protected void beforeThis(String... classes)
|
||||
{
|
||||
_enabledByDefault=enableByDefault;
|
||||
_after=Collections.unmodifiableList(after==null?Collections.emptyList():Arrays.asList(after).stream().map(Class::getName).collect(Collectors.toList()));
|
||||
_before=Collections.unmodifiableList(before==null?Collections.emptyList():Arrays.asList(before).stream().map(Class::getName).collect(Collectors.toList()));
|
||||
_system=new ArrayList<>(systemClasses==null?Collections.emptyList():Arrays.asList(systemClasses));
|
||||
_server=new ArrayList<>(serverClasses==null?Collections.emptyList():Arrays.asList(serverClasses));
|
||||
for (String c:classes)
|
||||
_beforeThis.add(c);
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* @param enabledByDefault
|
||||
* @param before Configurations that come before this configuration
|
||||
* @param after Configuration that come after this configuration
|
||||
* @param systemClasses
|
||||
* @param serverClasses
|
||||
* Add configuration classes that come before this configuration
|
||||
* @param classes Classes
|
||||
*/
|
||||
protected AbstractConfiguration(boolean enableByDefault,String[] before,String[] after,String[] systemClasses,String[] serverClasses)
|
||||
protected void beforeThis(Class<?>... classes)
|
||||
{
|
||||
_enabledByDefault=enableByDefault;
|
||||
_after=Collections.unmodifiableList(after==null?Collections.emptyList():Arrays.asList(after));
|
||||
_before=Collections.unmodifiableList(before==null?Collections.emptyList():Arrays.asList(before));
|
||||
_system=new ArrayList<>(systemClasses==null?Collections.emptyList():Arrays.asList(systemClasses));
|
||||
_server=new ArrayList<>(serverClasses==null?Collections.emptyList():Arrays.asList(serverClasses));
|
||||
beforeThis(Arrays.asList(classes).stream().map(Class::getName).collect(Collectors.toList()).toArray(new String[classes.length]));
|
||||
}
|
||||
|
||||
/**
|
||||
* Add configuration classes that come after this configuration
|
||||
* @param classes Classname or package name
|
||||
*/
|
||||
protected void afterThis(String... classes)
|
||||
{
|
||||
for (String c:classes)
|
||||
_after.add(c);
|
||||
}
|
||||
|
||||
/**
|
||||
* Add configuration classes that come after this configuration
|
||||
* @param classes Class
|
||||
*/
|
||||
protected void afterThis(Class<?>... classes)
|
||||
{
|
||||
afterThis(Arrays.asList(classes).stream().map(Class::getName).collect(Collectors.toList()).toArray(new String[classes.length]));
|
||||
}
|
||||
|
||||
protected void addSystemClass(String... systemClass)
|
||||
/**
|
||||
* Protect classes from modification by the web application by adding them
|
||||
* to the {@link WebAppConfiguration#getSystemClasses()}
|
||||
* @param classes classname or package pattern
|
||||
*/
|
||||
protected void protect(String... classes)
|
||||
{
|
||||
for (String s:systemClass)
|
||||
_system.add(s);
|
||||
_system.add(classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Hide classes from the web application by adding them
|
||||
* to the {@link WebAppConfiguration#getServerClasses()}
|
||||
* @param classes classname or package pattern
|
||||
*/
|
||||
protected void hide(String... classes)
|
||||
{
|
||||
_server.add(classes);
|
||||
}
|
||||
|
||||
/**
|
||||
* Expose classes to the web application by adding them
|
||||
* as exclusions to the {@link WebAppConfiguration#getServerClasses()}
|
||||
* @param classes classname or package pattern
|
||||
*/
|
||||
protected void expose(String... classes)
|
||||
{
|
||||
for (String c:classes)
|
||||
{
|
||||
if (c.startsWith("-"))
|
||||
throw new IllegalArgumentException();
|
||||
_server.add("-"+c);
|
||||
}
|
||||
}
|
||||
|
||||
/**
|
||||
* Protect classes from modification by the web application by adding them
|
||||
* to the {@link WebAppConfiguration#getSystemClasses()} and
|
||||
* expose them to the web application by adding them
|
||||
* as exclusions to the {@link WebAppConfiguration#getServerClasses()}
|
||||
* @param classes classname or package pattern
|
||||
*/
|
||||
protected void protectAndExpose(String... classes)
|
||||
{
|
||||
for (String c:classes)
|
||||
{
|
||||
if (c.startsWith("-"))
|
||||
throw new IllegalArgumentException();
|
||||
|
||||
_system.add(c);
|
||||
_server.add("-"+c);
|
||||
}
|
||||
}
|
||||
|
||||
protected void addServerClass(String... serverClass)
|
||||
{
|
||||
for (String s:serverClass)
|
||||
_system.add(s);
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getConfigurationsAfterThis()
|
||||
public Collection<String> getConfigurationsAfterThis()
|
||||
{
|
||||
return _after;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getConfigurationsBeforeThis()
|
||||
public Collection<String> getConfigurationsBeforeThis()
|
||||
{
|
||||
return _before;
|
||||
return _beforeThis;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getSystemClasses()
|
||||
public ClasspathPattern getSystemClasses()
|
||||
{
|
||||
return _system;
|
||||
}
|
||||
|
||||
@Override
|
||||
public List<String> getServerClasses()
|
||||
public ClasspathPattern getServerClasses()
|
||||
{
|
||||
return _server;
|
||||
}
|
||||
|
|
|
@ -25,9 +25,9 @@ import java.util.stream.Collectors;
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Classpath classes list performs sequential pattern matching of a class name
|
||||
* against an internal array of classpath pattern entries.
|
||||
* A class pattern is a string of one of the forms:<ul>
|
||||
* Classpath classes list performs pattern matching of a class name
|
||||
* against an classpath pattern entries.
|
||||
* A class pattern is a string of one of the forms/rules:<ul>
|
||||
* <li>'org.package.SomeClass' will match a specific class
|
||||
* <li>'org.package.' will match a specific package hierarchy
|
||||
* <li>'-org.package.Classname' excludes a specific class
|
||||
|
@ -36,6 +36,7 @@ import java.util.stream.Collectors;
|
|||
* are to be explicitly included or excluded (eg. org.example.MyClass$NestedClass).
|
||||
* <li>Nested classes are matched by their containing class. (eg. -org.example.MyClass
|
||||
* would exclude org.example.MyClass$AnyNestedClass)
|
||||
* <li>Package or Class exclusions are applied before inclusive patterns.
|
||||
* </ul>
|
||||
* When class is initialized from a classpath pattern string, entries
|
||||
* in this string should be separated by ':' (semicolon) or ',' (comma).
|
||||
|
@ -63,6 +64,19 @@ public class ClasspathPattern
|
|||
return _inclusive;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean equals(Object o)
|
||||
{
|
||||
if (o instanceof Entry)
|
||||
{
|
||||
Entry e=(Entry)o;
|
||||
if (_pattern==null && e._pattern==null)
|
||||
return true;
|
||||
return _pattern.equals(e._pattern);
|
||||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
@Override
|
||||
public String toString()
|
||||
{
|
||||
|
@ -90,6 +104,43 @@ public class ClasspathPattern
|
|||
add(pattern);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public ClasspathPattern(ClasspathPattern patterns)
|
||||
{
|
||||
add(patterns);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void clear()
|
||||
{
|
||||
_entries.clear();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isEmpty()
|
||||
{
|
||||
return _entries.isEmpty();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void exclude(String... patterns)
|
||||
{
|
||||
if (patterns==null || patterns.length==0)
|
||||
return;
|
||||
|
||||
for (String p :patterns)
|
||||
{
|
||||
if (p.startsWith("-"))
|
||||
throw new IllegalArgumentException();
|
||||
String x="-"+p;
|
||||
if (_entries.stream().anyMatch(e->{return x.equals(e.toString());}))
|
||||
continue;
|
||||
|
||||
Entry e = new Entry(x);
|
||||
_entries.add(0,e);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void add(String... patterns)
|
||||
{
|
||||
|
@ -109,6 +160,55 @@ public class ClasspathPattern
|
|||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void add(ClasspathPattern pattern)
|
||||
{
|
||||
if (pattern==null)
|
||||
return;
|
||||
|
||||
for (Entry e :pattern._entries)
|
||||
{
|
||||
if (_entries.contains(e))
|
||||
continue;
|
||||
|
||||
if (e.isInclusive())
|
||||
_entries.add(e);
|
||||
else
|
||||
_entries.add(0,e);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void addInclusions(ClasspathPattern pattern)
|
||||
{
|
||||
if (pattern==null)
|
||||
return;
|
||||
|
||||
for (Entry e :pattern._entries)
|
||||
{
|
||||
if (_entries.contains(e))
|
||||
continue;
|
||||
|
||||
if (e.isInclusive())
|
||||
_entries.add(e);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void addExclusions(ClasspathPattern pattern)
|
||||
{
|
||||
if (pattern==null)
|
||||
return;
|
||||
|
||||
for (Entry e :pattern._entries)
|
||||
{
|
||||
if (_entries.contains(e))
|
||||
continue;
|
||||
|
||||
if (!e.isInclusive())
|
||||
_entries.add(0,e);
|
||||
}
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean remove(String pattern)
|
||||
|
@ -189,5 +289,4 @@ public class ClasspathPattern
|
|||
}
|
||||
return false;
|
||||
}
|
||||
|
||||
}
|
||||
|
|
|
@ -1,46 +0,0 @@
|
|||
//
|
||||
// ========================================================================
|
||||
// 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;
|
||||
|
||||
public class CloneConfiguration extends AbstractConfiguration
|
||||
{
|
||||
final WebAppContext _template;
|
||||
|
||||
CloneConfiguration(WebAppContext template)
|
||||
{
|
||||
_template=template;
|
||||
}
|
||||
|
||||
@Override
|
||||
public boolean configure(WebAppContext context) throws Exception
|
||||
{
|
||||
for (Configuration configuration : _template.getConfigurations())
|
||||
configuration.cloneConfigure(_template,context);
|
||||
|
||||
return true;
|
||||
}
|
||||
|
||||
|
||||
@Override
|
||||
public void deconfigure(WebAppContext context) throws Exception
|
||||
{
|
||||
for (Configuration configuration : _template.getConfigurations())
|
||||
configuration.deconfigure(context);
|
||||
}
|
||||
}
|
|
@ -18,8 +18,8 @@
|
|||
|
||||
package org.eclipse.jetty.webapp;
|
||||
|
||||
import java.util.Collection;
|
||||
import java.util.Collections;
|
||||
import java.util.List;
|
||||
import java.util.ListIterator;
|
||||
|
||||
import org.eclipse.jetty.util.TopologicalSort;
|
||||
|
@ -35,7 +35,10 @@ public interface Configuration
|
|||
public final static String ATTR="org.eclipse.jetty.webapp.configuration";
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/** Get a class that this class replaces/extends
|
||||
/** Get a class that this class replaces/extends.
|
||||
* If this is added to {@link Configurations} collection that already contains a
|
||||
* configuration of the replaced class or that reports to replace the same class, then
|
||||
* it is replaced with this instance.
|
||||
* @return The class this Configuration replaces/extends or null if it replaces no other configuration
|
||||
*/
|
||||
public default Class<? extends Configuration> replaces() { return null; }
|
||||
|
@ -45,28 +48,26 @@ public interface Configuration
|
|||
* @return The names of Configurations that {@link TopologicalSort} must order
|
||||
* before this configuration.
|
||||
*/
|
||||
public default List<String> getConfigurationsBeforeThis() { return Collections.emptyList(); }
|
||||
public default Collection<String> getConfigurationsBeforeThis() { return Collections.emptyList(); }
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/** Get known Configuration Dependents.
|
||||
* @return The names of Configurations that {@link TopologicalSort} must order
|
||||
* after this configuration.
|
||||
*/
|
||||
public default List<String> getConfigurationsAfterThis(){ return Collections.emptyList(); }
|
||||
public default Collection<String> getConfigurationsAfterThis(){ return Collections.emptyList(); }
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/** Get the system classes associated with this Configuration.
|
||||
* @return A list of class/package names. Exclusions are prepended to the system classes and
|
||||
* inclusions are appended.
|
||||
* @return ClasspathPattern of system classes.
|
||||
*/
|
||||
public default List<String> getSystemClasses() { return Collections.emptyList(); }
|
||||
public default ClasspathPattern getSystemClasses() { return new ClasspathPattern(); }
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/** Get the system classes associated with this Configuration.
|
||||
* @return A list of class/package names. Exclusions are prepended to the system classes and
|
||||
* inclusions are appended.
|
||||
* @return ClasspathPattern of server classes.
|
||||
*/
|
||||
public default List<String> getServerClasses() { return Collections.emptyList(); }
|
||||
public default ClasspathPattern getServerClasses() { return new ClasspathPattern(); }
|
||||
|
||||
/**
|
||||
* @return true if the Configuration should be added to a Context by default
|
||||
|
@ -123,17 +124,6 @@ public interface Configuration
|
|||
*/
|
||||
public void destroy (WebAppContext context) throws Exception;
|
||||
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
/** Clone configuration instance.
|
||||
* <p>
|
||||
* Configure an instance of a WebAppContext, based on a template WebAppContext that
|
||||
* has previously been configured by this Configuration.
|
||||
* @param template The template context
|
||||
* @param context The context to configure
|
||||
* @throws Exception if unable to clone
|
||||
*/
|
||||
public void cloneConfigure (WebAppContext template, WebAppContext context) throws Exception;
|
||||
|
||||
/**
|
||||
* @deprecated Use {@link Configurations}
|
||||
|
|
|
@ -34,7 +34,7 @@ public class FragmentConfiguration extends AbstractConfiguration
|
|||
|
||||
public FragmentConfiguration()
|
||||
{
|
||||
super(new String[]{MetaInfConfiguration.class.getName()},null);
|
||||
beforeThis(MetaInfConfiguration.class,WebXmlConfiguration.class);
|
||||
}
|
||||
|
||||
@Override
|
||||
|
|
|
@ -34,14 +34,9 @@ public class JaasConfiguration extends AbstractConfiguration
|
|||
{
|
||||
public JaasConfiguration()
|
||||
{
|
||||
super(true,
|
||||
new String[]{WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),WebInfConfiguration.class.getName(),FragmentConfiguration.class.getName()},
|
||||
new String[]{WebAppConfiguration.class.getName()},
|
||||
new String[]{
|
||||
"org.eclipse.jetty.jaas."
|
||||
},
|
||||
new String[]{
|
||||
"-org.eclipse.jetty.jaas.",
|
||||
});
|
||||
super(ENABLE_BY_DEFAULT);
|
||||
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class,FragmentConfiguration.class);
|
||||
afterThis(WebAppConfiguration.class);
|
||||
protectAndExpose("org.eclipse.jetty.jaas.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -43,15 +43,13 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
|
|||
* the web-app currently installed.
|
||||
* it is passed as a property to the jetty-web.xml file */
|
||||
public static final String PROPERTY_THIS_WEB_INF_URL = "this.web-inf.url";
|
||||
|
||||
|
||||
public static final String XML_CONFIGURATION = "org.eclipse.jetty.webapp.JettyWebXmlConfiguration";
|
||||
public static final String JETTY_WEB_XML = "jetty-web.xml";
|
||||
|
||||
|
||||
public JettyWebXmlConfiguration()
|
||||
{
|
||||
super(true,new String[]{WebXmlConfiguration.class.getName(),FragmentConfiguration.class.getName(),MetaInfConfiguration.class.getName()},null);
|
||||
super(ENABLE_BY_DEFAULT);
|
||||
beforeThis(WebXmlConfiguration.class,FragmentConfiguration.class,MetaInfConfiguration.class);
|
||||
}
|
||||
|
||||
/**
|
||||
|
@ -77,39 +75,26 @@ public class JettyWebXmlConfiguration extends AbstractConfiguration
|
|||
|
||||
if(jetty.exists())
|
||||
{
|
||||
// No server classes while configuring
|
||||
String[] old_server_classes = context.getServerClasses();
|
||||
if(LOG.isDebugEnabled())
|
||||
LOG.debug("Configure: "+jetty);
|
||||
|
||||
Object xml_attr=context.getAttribute(XML_CONFIGURATION);
|
||||
context.removeAttribute(XML_CONFIGURATION);
|
||||
|
||||
final XmlConfiguration jetty_config = xml_attr instanceof XmlConfiguration
|
||||
?(XmlConfiguration)xml_attr
|
||||
:new XmlConfiguration(jetty.getURI().toURL());
|
||||
setupXmlConfiguration(jetty_config, web_inf);
|
||||
|
||||
try
|
||||
{
|
||||
context.setServerClasses(null);
|
||||
if(LOG.isDebugEnabled())
|
||||
LOG.debug("Configure: "+jetty);
|
||||
|
||||
XmlConfiguration jetty_config = (XmlConfiguration)context.getAttribute(XML_CONFIGURATION);
|
||||
|
||||
if (jetty_config==null)
|
||||
{
|
||||
jetty_config=new XmlConfiguration(jetty.getURI().toURL());
|
||||
}
|
||||
else
|
||||
{
|
||||
context.removeAttribute(XML_CONFIGURATION);
|
||||
}
|
||||
setupXmlConfiguration(jetty_config, web_inf);
|
||||
try
|
||||
{
|
||||
XmlConfiguration config=jetty_config;
|
||||
WebAppClassLoader.runWithServerClassAccess(()->{config.configure(context);return null;});
|
||||
}
|
||||
catch (ClassNotFoundException e)
|
||||
{
|
||||
LOG.warn("Unable to process jetty-web.xml", e);
|
||||
}
|
||||
final XmlConfiguration config=jetty_config;
|
||||
WebAppClassLoader.runWithServerClassAccess(()->{config.configure(context);return null;});
|
||||
}
|
||||
finally
|
||||
catch(Exception e)
|
||||
{
|
||||
if (old_server_classes != null)
|
||||
context.setServerClasses(old_server_classes);
|
||||
LOG.warn("Error applying {}",jetty);
|
||||
throw e;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,10 +35,8 @@ public class JmxConfiguration extends AbstractConfiguration
|
|||
{
|
||||
public JmxConfiguration()
|
||||
{
|
||||
super(true,
|
||||
null,
|
||||
new String[]{WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),WebInfConfiguration.class.getName()},
|
||||
new String[]{"org.eclipse.jetty.jmx."},
|
||||
new String[]{"-org.eclipse.jetty.jmx."});
|
||||
super(ENABLE_BY_DEFAULT);
|
||||
afterThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class);
|
||||
protectAndExpose("org.eclipse.jetty.jmx.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -34,14 +34,9 @@ public class JndiConfiguration extends AbstractConfiguration
|
|||
{
|
||||
public JndiConfiguration()
|
||||
{
|
||||
super(true,
|
||||
new String[]{WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),WebInfConfiguration.class.getName(),FragmentConfiguration.class.getName()},
|
||||
new String[]{WebAppConfiguration.class.getName()},
|
||||
new String[]{
|
||||
"org.eclipse.jetty.jndi."
|
||||
},
|
||||
new String[]{
|
||||
"-org.eclipse.jetty.jndi.",
|
||||
});
|
||||
super(ENABLE_BY_DEFAULT);
|
||||
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class,FragmentConfiguration.class);
|
||||
afterThis(WebAppConfiguration.class);
|
||||
protectAndExpose("org.eclipse.jetty.jndi.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -35,14 +35,11 @@ public class JspConfiguration extends AbstractConfiguration
|
|||
{
|
||||
public JspConfiguration()
|
||||
{
|
||||
super(true,
|
||||
new String[]{WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),WebInfConfiguration.class.getName(),FragmentConfiguration.class.getName()},
|
||||
new String[]{WebAppConfiguration.class.getName()},
|
||||
new String[]{
|
||||
"org.eclipse.jetty.jsp.JettyJspServlet"},
|
||||
new String[]{
|
||||
"-org.eclipse.jetty.jsp.",
|
||||
"-org.eclipse.jetty.apache.",
|
||||
"org.eclipse.jdt."});
|
||||
super(ENABLE_BY_DEFAULT);
|
||||
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class,FragmentConfiguration.class);
|
||||
afterThis(WebAppConfiguration.class);
|
||||
protectAndExpose("org.eclipse.jetty.jsp.");
|
||||
expose("org.eclipse.jetty.apache.");
|
||||
hide("org.eclipse.jdt.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -90,7 +90,7 @@ public class MetaInfConfiguration extends AbstractConfiguration
|
|||
/* ------------------------------------------------------------------------------- */
|
||||
public MetaInfConfiguration()
|
||||
{
|
||||
super(new String[]{WebXmlConfiguration.class.getName()},null);
|
||||
beforeThis(WebXmlConfiguration.class);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -29,16 +29,13 @@ public class ServletsConfiguration extends AbstractConfiguration
|
|||
{
|
||||
public ServletsConfiguration()
|
||||
{
|
||||
super(true,
|
||||
new String[]{WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),WebInfConfiguration.class.getName(),WebAppConfiguration.class.getName()},
|
||||
new String[]{JettyWebXmlConfiguration.class.getName()},
|
||||
new String[]{
|
||||
"org.eclipse.jetty.servlets.PushCacheFilter", //must be loaded by container classpath
|
||||
"org.eclipse.jetty.servlets.PushSessionCacheFilter" //must be loaded by container classpath
|
||||
|
||||
},
|
||||
new String[]{
|
||||
"-org.eclipse.jetty.servlets.", // don't hide jetty servlets
|
||||
});
|
||||
super(ENABLE_BY_DEFAULT);
|
||||
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class,WebAppConfiguration.class);
|
||||
afterThis(JettyWebXmlConfiguration.class);
|
||||
protectAndExpose();
|
||||
protect("org.eclipse.jetty.servlets.PushCacheFilter", //must be loaded by container classpath
|
||||
"org.eclipse.jetty.servlets.PushSessionCacheFilter" //must be loaded by container classpath
|
||||
);
|
||||
expose("org.eclipse.jetty.servlets."); // don't hide jetty servlets
|
||||
}
|
||||
}
|
||||
|
|
|
@ -29,22 +29,14 @@ public class WebAppConfiguration extends AbstractConfiguration
|
|||
{
|
||||
public WebAppConfiguration()
|
||||
{
|
||||
super(true,
|
||||
new String[]{WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),WebInfConfiguration.class.getName()},
|
||||
new String[]{JettyWebXmlConfiguration.class.getName()},
|
||||
new String[]{
|
||||
"org.eclipse.jetty.util.log.",
|
||||
"org.eclipse.jetty.servlet.DefaultServlet",
|
||||
"org.eclipse.jetty.servlet.NoJspServlet",
|
||||
"org.eclipse.jetty.continuation.",
|
||||
},
|
||||
new String[]{
|
||||
"-org.eclipse.jetty.util.log.",
|
||||
"-org.eclipse.jetty.servlet.DefaultServlet",
|
||||
"-org.eclipse.jetty.servlet.NoJspServlet",
|
||||
"-org.eclipse.jetty.servlet.listener.",
|
||||
"-org.eclipse.jetty.continuation.",
|
||||
"-org.eclipse.jetty.alpn.",
|
||||
});
|
||||
super(ENABLE_BY_DEFAULT);
|
||||
beforeThis(WebXmlConfiguration.class,MetaInfConfiguration.class,WebInfConfiguration.class);
|
||||
afterThis(JettyWebXmlConfiguration.class);
|
||||
protectAndExpose("org.eclipse.jetty.util.log.",
|
||||
"org.eclipse.jetty.servlet.DefaultServlet",
|
||||
"org.eclipse.jetty.servlet.NoJspServlet",
|
||||
"org.eclipse.jetty.continuation.");
|
||||
expose("org.eclipse.jetty.servlet.listener.",
|
||||
"org.eclipse.jetty.alpn.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -166,26 +166,26 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
// System classes are classes that cannot be replaced by
|
||||
// the web application, and they are *always* loaded via
|
||||
// system classloader.
|
||||
public final static String[] __dftSystemClasses =
|
||||
{
|
||||
public final static ClasspathPattern __dftSystemClasses = new ClasspathPattern
|
||||
(
|
||||
"java.", // Java SE classes (per servlet spec v2.5 / SRV.9.7.2)
|
||||
"javax.", // Java SE classes (per servlet spec v2.5 / SRV.9.7.2)
|
||||
"org.xml.", // javax.xml
|
||||
"org.w3c.", // javax.xml
|
||||
} ;
|
||||
"org.w3c." // javax.xml
|
||||
) ;
|
||||
|
||||
// Server classes are classes that are hidden from being
|
||||
// loaded by the web application using system classloader,
|
||||
// so if web application needs to load any of such classes,
|
||||
// it has to include them in its distribution.
|
||||
public final static String[] __dftServerClasses =
|
||||
{
|
||||
public final static ClasspathPattern __dftServerClasses =new ClasspathPattern
|
||||
(
|
||||
"org.eclipse.jetty." // hide jetty classes
|
||||
} ;
|
||||
);
|
||||
|
||||
private final Configurations _configurations = new Configurations();
|
||||
private ClasspathPattern _systemClasses = null;
|
||||
private ClasspathPattern _serverClasses = null;
|
||||
private final ClasspathPattern _systemClasses = new ClasspathPattern(__dftSystemClasses);
|
||||
private final ClasspathPattern _serverClasses = new ClasspathPattern(__dftServerClasses);
|
||||
|
||||
private String _defaultsDescriptor=WEB_DEFAULTS_XML;
|
||||
private String _descriptor=null;
|
||||
|
@ -287,10 +287,12 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
*/
|
||||
public WebAppContext(HandlerContainer parent, String contextPath, SessionHandler sessionHandler, SecurityHandler securityHandler, ServletHandler servletHandler, ErrorHandler errorHandler,int options)
|
||||
{
|
||||
super(parent, contextPath,sessionHandler, securityHandler, servletHandler, errorHandler,options);
|
||||
super(null,contextPath,sessionHandler, securityHandler, servletHandler, errorHandler,options);
|
||||
_scontext = new Context();
|
||||
setErrorHandler(errorHandler != null ? errorHandler : new ErrorPageErrorHandler());
|
||||
setProtectedTargets(__dftProtectedTargets);
|
||||
if (parent!=null)
|
||||
setParent(parent);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -468,33 +470,18 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
* @throws Exception if unable to pre configure
|
||||
*/
|
||||
public void preConfigure() throws Exception
|
||||
{
|
||||
// Setup default system classes
|
||||
loadSystemClasses();
|
||||
|
||||
// Setup default server classes
|
||||
loadServerClasses();
|
||||
|
||||
// Add the known server class inclusions for all configurations
|
||||
{
|
||||
// Add the known server class inclusions for all known configurations
|
||||
for (Configuration configuration : Configurations.getKnown())
|
||||
{
|
||||
for (String pattern: configuration.getServerClasses())
|
||||
{
|
||||
if (!pattern.startsWith("-"))
|
||||
addServerClass(pattern);
|
||||
}
|
||||
}
|
||||
_serverClasses.addInclusions(configuration.getServerClasses());
|
||||
|
||||
// Setup Configuration classes for this webapp!
|
||||
loadConfigurations();
|
||||
_configurations.sort();
|
||||
for (Configuration configuration:_configurations)
|
||||
{
|
||||
for (String pattern: configuration.getSystemClasses())
|
||||
addSystemClass(pattern);
|
||||
for (String pattern: configuration.getServerClasses())
|
||||
if (pattern.startsWith("-"))
|
||||
addServerClass(pattern);
|
||||
_systemClasses.add(configuration.getSystemClasses());
|
||||
_serverClasses.addExclusions(configuration.getServerClasses());
|
||||
}
|
||||
|
||||
// Configure classloader
|
||||
|
@ -685,22 +672,76 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
@ManagedAttribute(value="classes and packages hidden by the context classloader", readonly=true)
|
||||
public String[] getServerClasses()
|
||||
{
|
||||
loadServerClasses();
|
||||
return _serverClasses.toArray();
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the server classes patterns.
|
||||
* <p>
|
||||
* Server classes/packages are classes used to implement the server and are hidden
|
||||
* from the context. If the context needs to load these classes, it must have its
|
||||
* own copy of them in WEB-INF/lib or WEB-INF/classes.
|
||||
* @param serverClasses
|
||||
*
|
||||
*/
|
||||
public void setServerClasspathPattern(ClasspathPattern serverClasses)
|
||||
{
|
||||
_serverClasses.clear();
|
||||
_serverClasses.add(serverClasses);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the system classes patterns.
|
||||
* <p>
|
||||
* System classes/packages are classes provided by the JVM and that
|
||||
* cannot be replaced by classes of the same name from WEB-INF,
|
||||
* regardless of the value of {@link #setParentLoaderPriority(boolean)}.
|
||||
* @param systemClasses
|
||||
*/
|
||||
public void setSystemClasspathPattern(ClasspathPattern systemClasses)
|
||||
{
|
||||
_systemClasses.clear();
|
||||
_systemClasses.add(systemClasses);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void addServerClasspathPattern(ClasspathPattern serverClasses)
|
||||
{
|
||||
_serverClasses.add(serverClasses);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public void addSystemClasspathPattern(ClasspathPattern systemClasses)
|
||||
{
|
||||
_serverClasses.add(systemClasses);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public ClasspathPattern getServerClasspathPattern()
|
||||
{
|
||||
return _serverClasses;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public ClasspathPattern getSystemClasspathPattern()
|
||||
{
|
||||
return _systemClasses;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/** Add to the list of Server classes.
|
||||
* @param classOrPackage A fully qualified class name (eg com.foo.MyClass)
|
||||
* or a qualified package name ending with '.' (eg com.foo.). If the class
|
||||
* or package has '-' it is excluded from the server classes. This argument
|
||||
* may also be a comma separated list of classOrPackage patterns.
|
||||
* @deprecated use {@link #addServerClasspathPattern(ClasspathPattern)}
|
||||
* @see #setServerClasses(String[])
|
||||
* @see <a href="http://www.eclipse.org/jetty/documentation/current/jetty-classloading.html">Jetty Documentation: Classloading</a>
|
||||
*/
|
||||
public void addServerClass(String classOrPackage)
|
||||
{
|
||||
loadServerClasses();
|
||||
_serverClasses.add(classOrPackage);
|
||||
}
|
||||
|
||||
|
@ -710,7 +751,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
* or a qualified package name ending with '.' (eg com.foo.). If the class
|
||||
* or package has '-' it is excluded from the server classes. This argument may also be a comma
|
||||
* separated list of classOrPackage patterns.
|
||||
* @deprecated Order is no longer significant so use {@link #addServerClass(String)} instead.
|
||||
* @deprecated use {@link #addServerClasspathPattern(ClasspathPattern)}
|
||||
* @see #setServerClasses(String[])
|
||||
* @see <a href="http://www.eclipse.org/jetty/documentation/current/jetty-classloading.html">Jetty Documentation: Classloading</a>
|
||||
*/
|
||||
|
@ -721,13 +762,13 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* @deprecated use {@link #getSystemClasspathPattern()}.
|
||||
* @see #setSystemClasses(String[])
|
||||
* @return Returns the systemClasses.
|
||||
*/
|
||||
@ManagedAttribute(value="classes and packages given priority by context classloader", readonly=true)
|
||||
public String[] getSystemClasses()
|
||||
{
|
||||
loadSystemClasses();
|
||||
return _systemClasses.toArray();
|
||||
}
|
||||
|
||||
|
@ -738,12 +779,12 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
* or package has '-' it is excluded from the system classes.
|
||||
* This argument may also be a comma
|
||||
* separated list of classOrPackage patterns.
|
||||
* @deprecated use {@link #addSystemClasspathPattern(ClasspathPattern)}
|
||||
* @see #setSystemClasses(String[])
|
||||
* @see <a href="http://www.eclipse.org/jetty/documentation/current/jetty-classloading.html">Jetty Documentation: Classloading</a>
|
||||
*/
|
||||
public void addSystemClass(String classOrPackage)
|
||||
{
|
||||
loadSystemClasses();
|
||||
_systemClasses.add(classOrPackage);
|
||||
}
|
||||
|
||||
|
@ -754,13 +795,12 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
* or package has '-' it is excluded from the system classes.
|
||||
* This argument may also be a comma
|
||||
* separated list of classOrPackage patterns.
|
||||
* @deprecated Order is no longer significant so use {@link #addSystemClass(String)} instead.
|
||||
* @deprecated use {@link #addSystemClasspathPattern(ClasspathPattern)}
|
||||
* @see #setSystemClasses(String[])
|
||||
* @see <a href="http://www.eclipse.org/jetty/documentation/current/jetty-classloading.html">Jetty Documentation: Classloading</a>
|
||||
*/
|
||||
public void prependSystemClass(String classOrPackage)
|
||||
{
|
||||
loadSystemClasses();
|
||||
_systemClasses.add(classOrPackage);
|
||||
}
|
||||
|
||||
|
@ -768,7 +808,6 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
@Override
|
||||
public boolean isServerClass(String name)
|
||||
{
|
||||
loadServerClasses();
|
||||
return _serverClasses.match(name);
|
||||
}
|
||||
|
||||
|
@ -776,53 +815,34 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
@Override
|
||||
public boolean isSystemClass(String name)
|
||||
{
|
||||
loadSystemClasses();
|
||||
return _systemClasses.match(name);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void loadSystemClasses()
|
||||
{
|
||||
if (_systemClasses != null)
|
||||
return;
|
||||
|
||||
//look for a Server attribute with the list of System classes
|
||||
//to apply to every web application. If not present, use our defaults.
|
||||
Server server = getServer();
|
||||
if (server != null)
|
||||
{
|
||||
Object systemClasses = server.getAttribute(SERVER_SYS_CLASSES);
|
||||
if (systemClasses != null && systemClasses instanceof String[])
|
||||
_systemClasses = new ClasspathPattern((String[])systemClasses);
|
||||
}
|
||||
|
||||
if (_systemClasses == null)
|
||||
_systemClasses = new ClasspathPattern(__dftSystemClasses);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
protected void loadServerClasses()
|
||||
@Override
|
||||
public void setServer(Server server)
|
||||
{
|
||||
if (_serverClasses != null)
|
||||
{
|
||||
return;
|
||||
}
|
||||
|
||||
// look for a Server attribute with the list of Server classes
|
||||
// to apply to every web application. If not present, use our defaults.
|
||||
Server server = getServer();
|
||||
super.setServer(server);
|
||||
if (server != null)
|
||||
{
|
||||
Object serverClasses = server.getAttribute(SERVER_SRV_CLASSES);
|
||||
if (serverClasses != null && serverClasses instanceof String[])
|
||||
if (_systemClasses.isEmpty())
|
||||
{
|
||||
_serverClasses = new ClasspathPattern((String[])serverClasses);
|
||||
Object systemClasses = server.getAttribute(SERVER_SYS_CLASSES);
|
||||
if (systemClasses instanceof String[])
|
||||
systemClasses = new ClasspathPattern((String[])systemClasses);
|
||||
if (systemClasses instanceof ClasspathPattern)
|
||||
_systemClasses.add((ClasspathPattern)systemClasses);
|
||||
}
|
||||
}
|
||||
|
||||
if (_serverClasses == null)
|
||||
{
|
||||
_serverClasses = new ClasspathPattern(__dftServerClasses);
|
||||
if (_serverClasses.isEmpty())
|
||||
{
|
||||
Object serverClasses = server.getAttribute(SERVER_SRV_CLASSES);
|
||||
if (serverClasses instanceof String[])
|
||||
serverClasses = new ClasspathPattern((String[])serverClasses);
|
||||
if (serverClasses instanceof ClasspathPattern)
|
||||
_systemClasses.add((ClasspathPattern)serverClasses);
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
@ -936,8 +956,8 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
{
|
||||
dumpBeans(out,indent,
|
||||
Collections.singletonList(new ClassLoaderDump(getClassLoader())),
|
||||
Collections.singletonList(new DumpableCollection("Systemclasses "+this,_systemClasses.getPatterns())),
|
||||
Collections.singletonList(new DumpableCollection("Serverclasses "+this,_serverClasses.getPatterns())),
|
||||
Collections.singletonList(new DumpableCollection("Systemclasses "+this,_systemClasses==null?Collections.emptyList():_systemClasses.getPatterns())),
|
||||
Collections.singletonList(new DumpableCollection("Serverclasses "+this,_serverClasses==null?Collections.emptyList():_serverClasses.getPatterns())),
|
||||
Collections.singletonList(new DumpableCollection("Configurations "+this,_configurations.getConfigurations())),
|
||||
Collections.singletonList(new DumpableCollection("Handler attributes "+this,((AttributesMap)getAttributes()).getAttributeEntrySet())),
|
||||
Collections.singletonList(new DumpableCollection("Context attributes "+this,((Context)getServletContext()).getAttributeEntrySet())),
|
||||
|
@ -1159,6 +1179,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
_permissions = permissions;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
/**
|
||||
* Set the context white list
|
||||
*
|
||||
|
@ -1182,11 +1203,12 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
* from the context. If the context needs to load these classes, it must have its
|
||||
* own copy of them in WEB-INF/lib or WEB-INF/classes.
|
||||
* A {@link ClasspathPattern} is used to match the server classes.
|
||||
* @deprecated use {@link #setServerClasspathPattern(ClasspathPattern)} or {@link Configuration}s
|
||||
* @param serverClasses The serverClasses to set.
|
||||
*/
|
||||
public void setServerClasses(String... serverClasses)
|
||||
{
|
||||
_serverClasses = new ClasspathPattern(serverClasses);
|
||||
setServerClasspathPattern(new ClasspathPattern(serverClasses));
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
|
@ -1197,11 +1219,12 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
* cannot be replaced by classes of the same name from WEB-INF,
|
||||
* regardless of the value of {@link #setParentLoaderPriority(boolean)}.
|
||||
* A {@link ClasspathPattern} is used to match the system classes.
|
||||
* @deprecated use {@link #setSystemClasspathPattern(ClasspathPattern)} or {@link Configuration}s
|
||||
* @param systemClasses The systemClasses to set.
|
||||
*/
|
||||
public void setSystemClasses(String... systemClasses)
|
||||
{
|
||||
_systemClasses = new ClasspathPattern(systemClasses);
|
||||
setSystemClasspathPattern(new ClasspathPattern(systemClasses));
|
||||
}
|
||||
|
||||
|
||||
|
@ -1303,13 +1326,6 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
|
|||
this._logUrlOnStart = logOnStart;
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
@Override
|
||||
public void setServer(Server server)
|
||||
{
|
||||
super.setServer(server);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------ */
|
||||
public boolean isAllowDuplicateFragmentNames()
|
||||
{
|
||||
|
|
|
@ -34,14 +34,9 @@ public class WebSocketConfiguration extends AbstractConfiguration
|
|||
{
|
||||
public WebSocketConfiguration()
|
||||
{
|
||||
super(true,
|
||||
new String[]{WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),WebInfConfiguration.class.getName(),FragmentConfiguration.class.getName()},
|
||||
new String[]{"org.eclipse.jetty.annotations.AnnotationConfiguration",WebAppConfiguration.class.getName()},
|
||||
new String[]{
|
||||
"org.eclipse.jetty.websocket."
|
||||
},
|
||||
new String[]{
|
||||
"-org.eclipse.jetty.websocket.",
|
||||
});
|
||||
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.");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -39,7 +39,7 @@ public class WebXmlConfiguration extends AbstractConfiguration
|
|||
/* ------------------------------------------------------------------------------- */
|
||||
public WebXmlConfiguration()
|
||||
{
|
||||
super(new String[]{WebInfConfiguration.class.getName()},null);
|
||||
beforeThis(WebInfConfiguration.class);
|
||||
}
|
||||
|
||||
/* ------------------------------------------------------------------------------- */
|
||||
|
|
|
@ -180,8 +180,9 @@ public class WebAppClassLoaderTest
|
|||
assertCanLoadClass("org.acme.webapp.ClassInJarA");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testExposedClass() throws Exception
|
||||
public void testExposedClassDeprecated() throws Exception
|
||||
{
|
||||
String[] oldSC=_context.getServerClasses();
|
||||
String[] newSC=new String[oldSC.length+1];
|
||||
|
@ -198,20 +199,34 @@ public class WebAppClassLoaderTest
|
|||
}
|
||||
|
||||
@Test
|
||||
public void testSystemServerClass() throws Exception
|
||||
public void testExposedClass() throws Exception
|
||||
{
|
||||
_context.getServerClasspathPattern().exclude("org.eclipse.jetty.webapp.Configuration");
|
||||
|
||||
assertCanLoadClass("org.acme.webapp.ClassInJarA");
|
||||
assertCanLoadClass("org.acme.webapp.ClassInJarB");
|
||||
assertCanLoadClass("org.acme.other.ClassInClassesC");
|
||||
|
||||
assertCanLoadClass("org.eclipse.jetty.webapp.Configuration");
|
||||
assertCantLoadClass("org.eclipse.jetty.webapp.JarScanner");
|
||||
}
|
||||
|
||||
@SuppressWarnings("deprecation")
|
||||
@Test
|
||||
public void testSystemServerClassDeprecated() throws Exception
|
||||
{
|
||||
String[] oldServC=_context.getServerClasses();
|
||||
String[] newServC=new String[oldServC.length+1];
|
||||
newServC[0]="org.eclipse.jetty.webapp.Configuration";
|
||||
System.arraycopy(oldServC,0,newServC,1,oldServC.length);
|
||||
_context.setServerClasses(newServC);
|
||||
|
||||
|
||||
String[] oldSysC=_context.getSystemClasses();
|
||||
String[] newSysC=new String[oldSysC.length+1];
|
||||
newSysC[0]="org.eclipse.jetty.webapp.";
|
||||
System.arraycopy(oldSysC,0,newSysC,1,oldSysC.length);
|
||||
_context.setSystemClasses(newSysC);
|
||||
|
||||
|
||||
assertCanLoadClass("org.acme.webapp.ClassInJarA");
|
||||
assertCanLoadClass("org.acme.webapp.ClassInJarB");
|
||||
assertCanLoadClass("org.acme.other.ClassInClassesC");
|
||||
|
@ -234,6 +249,26 @@ public class WebAppClassLoaderTest
|
|||
_context.setServerClasses(newServC);
|
||||
assertCanLoadResource("org/acme/webapp/ClassInJarA.class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testSystemServerClass() throws Exception
|
||||
{
|
||||
_context.getServerClasspathPattern().add("org.eclipse.jetty.webapp.Configuration");
|
||||
_context.getSystemClasspathPattern().add("org.eclipse.jetty.webapp.");
|
||||
|
||||
assertCanLoadClass("org.acme.webapp.ClassInJarA");
|
||||
assertCanLoadClass("org.acme.webapp.ClassInJarB");
|
||||
assertCanLoadClass("org.acme.other.ClassInClassesC");
|
||||
assertCantLoadClass("org.eclipse.jetty.webapp.Configuration");
|
||||
assertCantLoadClass("org.eclipse.jetty.webapp.JarScanner");
|
||||
|
||||
_context.getSystemClasspathPattern().add("org.acme.webapp.ClassInJarA");
|
||||
assertCanLoadResource("org/acme/webapp/ClassInJarA.class");
|
||||
_context.getSystemClasspathPattern().remove("org.acme.webapp.ClassInJarA");
|
||||
|
||||
_context.getServerClasspathPattern().add("org.acme.webapp.ClassInJarA");
|
||||
assertCanLoadResource("org/acme/webapp/ClassInJarA.class");
|
||||
}
|
||||
|
||||
@Test
|
||||
public void testResources() throws Exception
|
||||
|
|
|
@ -37,7 +37,6 @@ import java.util.concurrent.atomic.AtomicInteger;
|
|||
import org.eclipse.jetty.io.EndPoint;
|
||||
import org.eclipse.jetty.io.EofException;
|
||||
import org.eclipse.jetty.io.ManagedSelector;
|
||||
import org.eclipse.jetty.io.SelectChannelEndPoint;
|
||||
import org.eclipse.jetty.io.SocketChannelEndPoint;
|
||||
import org.eclipse.jetty.toolchain.test.EventQueue;
|
||||
import org.eclipse.jetty.toolchain.test.TestTracker;
|
||||
|
|
Loading…
Reference in New Issue