work in progress

This commit is contained in:
Greg Wilkins 2016-03-15 17:57:23 +11:00
parent 725be8c051
commit cfe9c83691
14 changed files with 111 additions and 94 deletions

View File

@ -157,9 +157,9 @@ public class LikeJettyXml
// === jetty-deploy.xml ===
DeploymentManager deployer = new DeploymentManager();
DebugListener debug = new DebugListener(System.out,true,true,true);
server.addBean(debug);
deployer.addLifeCycleBinding(new DebugListenerBinding(debug));
//DebugListener debug = new DebugListener(System.out,true,true,true);
// server.addBean(debug);
// deployer.addLifeCycleBinding(new DebugListenerBinding(debug));
deployer.setContexts(contexts);
deployer.setContextAttribute(
"org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern",
@ -218,6 +218,7 @@ public class LikeJettyXml
// Start the server
server.start();
server.dumpStdErr();
server.join();
}
}

View File

@ -1,19 +0,0 @@
<?xml version="1.0"?>
<!DOCTYPE Configure PUBLIC "-//Jetty//Configure//EN" "http://www.eclipse.org/jetty/configure_9_3.dtd">
<Configure id="Server" class="org.eclipse.jetty.server.Server">
<!-- =========================================================== -->
<!-- Add annotation Configuring classes to all webapps for this Server -->
<!-- =========================================================== -->
<Call class="org.eclipse.jetty.webapp.Configurations" name="setServerDefault">
<Arg><Ref refid="Server" /></Arg>
<Call name="add">
<Arg>
<Array type="String">
<Item>org.eclipse.jetty.annotations.AnnotationConfiguration</Item>
</Array>
</Arg>
</Call>
</Call>
</Configure>

View File

@ -7,7 +7,3 @@ plus
[lib]
lib/jetty-annotations-${jetty.version}.jar
lib/annotations/*.jar
[xml]
# Enable annotation scanning webapp configurations
etc/jetty-annotations.xml

View File

@ -31,6 +31,7 @@ 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;
@ -93,12 +94,11 @@ public class AnnotationConfiguration extends AbstractConfiguration
protected CounterStatistic _webInfLibStats;
protected CounterStatistic _webInfClassesStats;
protected Pattern _sciExcludePattern;
protected ServiceLoader<ServletContainerInitializer> _loadedInitializers = null;
protected List<ServletContainerInitializer> _initializers;
public AnnotationConfiguration()
{
super(false,
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."},
@ -430,8 +430,8 @@ public class AnnotationConfiguration extends AbstractConfiguration
context.removeAttribute(CONTAINER_INITIALIZER_STARTER);
}
if (_loadedInitializers != null)
_loadedInitializers.reload();
if (_initializers != null)
_initializers.clear();
}
/**
@ -454,7 +454,7 @@ public class AnnotationConfiguration extends AbstractConfiguration
_discoverableAnnotationHandlers.add(new WebListenerAnnotationHandler(context));
}
}
//Regardless of metadata, if there are any ServletContainerInitializers with @HandlesTypes, then we need to scan all the
//classes so we can call their onStartup() methods correctly
createServletContainerInitializerAnnotationHandlers(context, getNonExcludedInitializers(context));
@ -857,32 +857,32 @@ public class AnnotationConfiguration extends AbstractConfiguration
//We use the ServiceLoader mechanism to find the ServletContainerInitializer classes to inspect
long start = 0;
ClassLoader old = Thread.currentThread().getContextClassLoader();
try
{
if (LOG.isDebugEnabled())
start = System.nanoTime();
Thread.currentThread().setContextClassLoader(context.getClassLoader());
_loadedInitializers = ServiceLoader.load(ServletContainerInitializer.class);
}
finally
{
Thread.currentThread().setContextClassLoader(old);
}
if (LOG.isDebugEnabled())
start = System.nanoTime();
ServiceLoader<ServletContainerInitializer> loader = ServiceLoader.load(ServletContainerInitializer.class);
if (LOG.isDebugEnabled())
LOG.debug("Service loaders found in {}ms", (TimeUnit.MILLISECONDS.convert((System.nanoTime()-start), TimeUnit.NANOSECONDS)));
Map<ServletContainerInitializer,Resource> sciResourceMap = new HashMap<ServletContainerInitializer,Resource>();
ServletContainerInitializerOrdering initializerOrdering = getInitializerOrdering(context);
//Get initial set of SCIs that aren't from excluded jars or excluded by the containerExclusionPattern, or excluded
//because containerInitializerOrdering omits it
for (ServletContainerInitializer sci:_loadedInitializers)
Iterator<ServletContainerInitializer> iter = loader.iterator();
while(iter.hasNext())
{
ServletContainerInitializer sci;
try
{
sci=iter.next();
}
catch(Error e)
{
// Probably a SCI discovered on the system classpath that is hidden by the context classloader
LOG.info("Error: "+e.getMessage()+" for "+context);
LOG.debug(e);
continue;
}
if (matchesExclusionPattern(sci))
{

View File

@ -0,0 +1,44 @@
//
// ========================================================================
// 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.cdi.websocket;
import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.WebSocketConfiguration;
/**
* <p>Websocket CDI Configuration</p>
* <p>This configuration configures the WebAppContext server/system classes to
* be able to see {@link WebSocketCdiInitializer}
* </p>
*/
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.",
});
}
}

View File

@ -0,0 +1 @@
org.eclipse.jetty.cdi.websocket.WebSocketCdiConfiguration

View File

@ -71,7 +71,6 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
context.getMetaData().setWebXml(quickStartWebXml);
}
@Override
public boolean configure(WebAppContext context) throws Exception
{
@ -89,20 +88,7 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
//Set up the quickstart environment for the context
boolean configured = super.configure(context);
// knock out environmental maven and plexus classes from webAppContext
String[] existingServerClasses = context.getServerClasses();
String[] newServerClasses = new String[2+(existingServerClasses==null?0:existingServerClasses.length)];
newServerClasses[0] = "org.apache.maven.";
newServerClasses[1] = "org.codehaus.plexus.";
System.arraycopy( existingServerClasses, 0, newServerClasses, 2, existingServerClasses.length );
if (LOG.isDebugEnabled())
{
LOG.debug("Server classes:");
for (int i=0;i<newServerClasses.length;i++)
LOG.debug(newServerClasses[i]);
}
context.setServerClasses( newServerClasses );
return configured;
}

View File

@ -40,7 +40,6 @@ import org.eclipse.jetty.plus.jndi.NamingEntryUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.webapp.AbstractConfiguration;
import org.eclipse.jetty.webapp.Configuration;
import org.eclipse.jetty.webapp.FragmentConfiguration;
import org.eclipse.jetty.webapp.JettyWebXmlConfiguration;
import org.eclipse.jetty.webapp.MetaInfConfiguration;
@ -98,7 +97,7 @@ public class EnvConfiguration extends AbstractConfiguration
org.eclipse.jetty.util.resource.Resource jettyEnv = web_inf.addPath("jetty-env.xml");
if(jettyEnv.exists())
{
jettyEnvXmlUrl = jettyEnv.getURL();
jettyEnvXmlUrl = jettyEnv.getURI().toURL();
}
}
}

View File

@ -153,7 +153,7 @@ public interface Configuration
if (afterClass.equals(c.getClass().getName()) || afterClass.equals(c.replaces().getName()))
{
for (String cc: configClass)
iter.add(getConfiguration(cc));
iter.add(newConfiguration(cc));
return;
}
}
@ -175,7 +175,7 @@ public interface Configuration
{
iter.previous();
for (String cc: configClass)
iter.add(getConfiguration(cc));
iter.add(newConfiguration(cc));
return;
}
}

View File

@ -24,11 +24,13 @@ import java.util.Arrays;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Iterator;
import java.util.List;
import java.util.ListIterator;
import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jetty.server.Server;
@ -43,13 +45,15 @@ public class Configurations extends AbstractList<Configuration>
private static final Logger LOG = Log.getLogger(Configurations.class);
private static final List<Configuration> __known = new ArrayList<>();
private static final Map<String,Configuration> __knownByClassName = new HashMap<>();
private static final Set<String> __knownByClassName = new HashSet<>();
static
{
ServiceLoader<Configuration> configs = ServiceLoader.load(Configuration.class);
for (Configuration configuration : configs)
__knownByClassName.put(configuration.getClass().getName(),configuration);
__known.addAll(__knownByClassName.values());
{
__known.add(configuration);
__knownByClassName.add(configuration.getClass().getName());
}
sort(__known);
if (LOG.isDebugEnabled())
{
@ -57,7 +61,7 @@ public class Configurations extends AbstractList<Configuration>
LOG.debug("known {}",c);
}
LOG.debug("Known Configurations {}",__knownByClassName.keySet());
LOG.debug("Known Configurations {}",__knownByClassName);
}
public static List<Configuration> getKnown()
@ -80,12 +84,19 @@ public class Configurations extends AbstractList<Configuration>
Configurations configurations=server.getBean(Configurations.class);
if (configurations!=null)
return configurations;
configurations=serverDefault(server);
configurations=getServerDefault(server);
server.addBean(configurations);
server.setAttribute(Configuration.ATTR,null);
return configurations;
}
/* ------------------------------------------------------------ */
@Deprecated
public static Configurations serverDefault(Server server)
{
return getServerDefault(server);
}
/* ------------------------------------------------------------ */
/** Get/Create the server default Configuration ClassList.
* <p>Get the class list from: a Server bean; or the attribute (which can
@ -94,7 +105,7 @@ public class Configurations extends AbstractList<Configuration>
* @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 Configurations serverDefault(Server server)
public static Configurations getServerDefault(Server server)
{
Configurations configurations=null;
if (server!=null)
@ -136,25 +147,21 @@ public class Configurations extends AbstractList<Configuration>
{
}
protected static Configuration getConfiguration(String classname)
protected static Configuration newConfiguration(String classname)
{
Configuration configuration = __knownByClassName.get(classname);
if (configuration==null)
if (!__knownByClassName.contains(classname))
LOG.warn("Unknown configuration {}. Not declared for ServiceLoader!",classname);
try
{
try
{
@SuppressWarnings("unchecked")
Class<Configuration> clazz = Loader.loadClass(classname);
configuration = clazz.newInstance();
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException e)
{
throw new RuntimeException(e);
}
LOG.info("Unknown configuration {}",classname);
@SuppressWarnings("unchecked")
Class<Configuration> clazz = Loader.loadClass(classname);
return clazz.newInstance();
}
catch (ClassNotFoundException | InstantiationException | IllegalAccessException e)
{
throw new RuntimeException(e);
}
return configuration;
}
public Configurations(String... classes)
@ -183,7 +190,7 @@ public class Configurations extends AbstractList<Configuration>
public void add(@Name("configClass")String... configClass)
{
for (String name : configClass)
addConfiguration(getConfiguration(name));
addConfiguration(newConfiguration(name));
}
public void clear()
@ -293,7 +300,7 @@ public class Configurations extends AbstractList<Configuration>
{
String name=configuration.getClass().getName();
// Is this configuration known?
if (!__knownByClassName.containsKey(name))
if (!__knownByClassName.contains(name))
LOG.warn("Unknown configuration {}. Not declared for ServiceLoader!",name);
// Do we need to replace any existing configuration?

View File

@ -31,7 +31,7 @@ public class WebAppConfiguration extends AbstractConfiguration
{
super(true,
new String[]{WebXmlConfiguration.class.getName(),MetaInfConfiguration.class.getName(),WebInfConfiguration.class.getName()},
null,
new String[]{JettyWebXmlConfiguration.class.getName()},
new String[]{
"org.eclipse.jetty.util.log.",
"org.eclipse.jetty.servlet.DefaultServlet",

View File

@ -913,7 +913,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
if (_configurations.size()>0)
return;
_configurations.add(Configurations.serverDefault(getServer()).toArray());
_configurations.add(Configurations.getServerDefault(getServer()).toArray());
}
/* ------------------------------------------------------------ */

View File

@ -79,6 +79,7 @@ public class WebAppContextTest
{
WebAppContext wac = new WebAppContext();
wac.setServer(new Server());
System.err.println(Arrays.asList(wac.getConfigurations()));
Assert.assertThat(Arrays.asList(wac.getConfigurations()).stream().map(c->c.getClass().getName()).collect(Collectors.toList()),
Matchers.contains(
"org.eclipse.jetty.webapp.JmxConfiguration",

View File

@ -18,6 +18,7 @@
package org.eclipse.jetty.test.rfcs;
import org.eclipse.jetty.cdi.websocket.WebSocketCdiInitializer;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.test.support.TestableJettyServer;
import org.eclipse.jetty.test.support.rawhttp.HttpSocket;