Merge remote-tracking branch 'origin/jetty-9.3.x' into jetty-9.4.x

This commit is contained in:
Greg Wilkins 2017-03-23 09:31:19 +11:00
commit 12dc169b5b
4 changed files with 227 additions and 10 deletions

View File

@ -58,6 +58,7 @@ public class ManyServletContexts
other.addServlet(new ServletHolder(new HelloServlet("YO!")), "*.yo");
server.start();
server.dumpStdErr();
server.join();
}
}

View File

@ -22,7 +22,6 @@ import java.io.File;
import java.lang.management.ManagementFactory;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.security.HashLoginService;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
import org.eclipse.jetty.webapp.WebAppContext;
@ -62,6 +61,8 @@ public class OneWebApp
// Start things up!
server.start();
server.dumpStdErr();
// The use of server.join() the will make the current thread join and
// wait until the server is done executing.
// See http://docs.oracle.com/javase/7/docs/api/java/lang/Thread.html#join()

View File

@ -46,18 +46,33 @@ public class ClassLoaderDump implements Dumpable
{
if (_loader==null)
out.append("No ClassLoader\n");
else if (_loader instanceof Dumpable)
{
ContainerLifeCycle.dump(out,indent,Collections.singleton(_loader));
}
else if (_loader instanceof URLClassLoader)
{
out.append(String.valueOf(_loader)).append("\n");
ClassLoader parent = _loader.getParent();
if (parent==null)
ContainerLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs()));
else if (parent == Server.class.getClassLoader())
ContainerLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs()),Collections.singleton(parent.toString()));
else if (parent instanceof Dumpable)
ContainerLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs()),Collections.singleton(parent));
else
ContainerLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs()),Collections.singleton(new ClassLoaderDump(parent)));
}
else
{
out.append(String.valueOf(_loader)).append("\n");
Object parent = _loader.getParent();
if (parent != null)
{
if (_loader instanceof URLClassLoader)
ContainerLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs()),Collections.singleton(parent.toString()));
else
ContainerLifeCycle.dump(out,indent,Collections.singleton(parent.toString()));
}
ClassLoader parent = _loader.getParent();
if (parent==Server.class.getClassLoader())
ContainerLifeCycle.dump(out,indent,Collections.singleton(parent.toString()));
else if (parent instanceof Dumpable)
ContainerLifeCycle.dump(out,indent,Collections.singleton(parent));
else if (parent!=null)
ContainerLifeCycle.dump(out,indent,Collections.singleton(new ClassLoaderDump(parent)));
}
}
}

View File

@ -0,0 +1,200 @@
//
// ========================================================================
// Copyright (c) 1995-2017 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.server;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.not;
import static org.junit.Assert.assertThat;
import java.io.IOException;
import java.net.URL;
import java.net.URLClassLoader;
import org.eclipse.jetty.util.component.Dumpable;
import org.hamcrest.Matchers;
import org.junit.Assert;
import org.junit.Test;
public class ClassLoaderDumptTest
{
@Test
public void testSimple() throws Exception
{
Server server = new Server();
ClassLoader loader = new ClassLoader()
{
public String toString()
{
return "SimpleLoader";
}
};
server.addBean(new ClassLoaderDump(loader));
StringBuilder out = new StringBuilder();
server.dump(out);
String dump = out.toString();
assertThat(dump,containsString("+- SimpleLoader"));
assertThat(dump,containsString("+> "+Server.class.getClassLoader()));
}
@Test
public void testParent() throws Exception
{
Server server = new Server();
ClassLoader loader = new ClassLoader(Server.class.getClassLoader())
{
public String toString()
{
return "ParentedLoader";
}
};
server.addBean(new ClassLoaderDump(loader));
StringBuilder out = new StringBuilder();
server.dump(out);
String dump = out.toString();
assertThat(dump,containsString("+- ParentedLoader"));
assertThat(dump,containsString("| +- "+Server.class.getClassLoader()));
assertThat(dump,containsString("+> "+Server.class.getClassLoader()));
}
@Test
public void testNested() throws Exception
{
Server server = new Server();
ClassLoader middleLoader = new ClassLoader(Server.class.getClassLoader())
{
public String toString()
{
return "MiddleLoader";
}
};
ClassLoader loader = new ClassLoader(middleLoader)
{
public String toString()
{
return "TopLoader";
}
};
server.addBean(new ClassLoaderDump(loader));
StringBuilder out = new StringBuilder();
server.dump(out);
String dump = out.toString();
assertThat(dump,containsString("+- TopLoader"));
assertThat(dump,containsString("| +- MiddleLoader"));
assertThat(dump,containsString("| +- "+Server.class.getClassLoader()));
assertThat(dump,containsString("+> "+Server.class.getClassLoader()));
}
@Test
public void testDumpable() throws Exception
{
Server server = new Server();
ClassLoader middleLoader = new DumpableClassLoader(Server.class.getClassLoader());
ClassLoader loader = new ClassLoader(middleLoader)
{
public String toString()
{
return "TopLoader";
}
};
server.addBean(new ClassLoaderDump(loader));
StringBuilder out = new StringBuilder();
server.dump(out);
String dump = out.toString();
assertThat(dump,containsString("+- TopLoader"));
assertThat(dump,containsString("| +- DumpableClassLoader"));
assertThat(dump,not(containsString("| +- "+Server.class.getClassLoader())));
assertThat(dump,containsString("+> "+Server.class.getClassLoader()));
}
public static class DumpableClassLoader extends ClassLoader implements Dumpable
{
public DumpableClassLoader(ClassLoader parent)
{
super(parent);
}
@Override
public String dump()
{
return "DumpableClassLoader";
}
@Override
public void dump(Appendable out, String indent) throws IOException
{
out.append(dump()).append('\n');
}
public String toString()
{
return "DumpableClassLoader";
}
}
@Test
public void testUrlClassLoaders() throws Exception
{
Server server = new Server();
ClassLoader middleLoader = new URLClassLoader(new URL[]
{new URL("file:/one"),new URL("file:/two"),new URL("file:/three"),},
Server.class.getClassLoader())
{
public String toString()
{
return "MiddleLoader";
}
};
ClassLoader loader = new URLClassLoader(new URL[]
{new URL("file:/ONE"),new URL("file:/TWO"),new URL("file:/THREE"),},
middleLoader)
{
public String toString()
{
return "TopLoader";
}
};
server.addBean(new ClassLoaderDump(loader));
StringBuilder out = new StringBuilder();
server.dump(out);
String dump = out.toString();
System.err.println(dump);
assertThat(dump,containsString("+- TopLoader"));
assertThat(dump,containsString("| +- file:/ONE"));
assertThat(dump,containsString("| +- file:/TWO"));
assertThat(dump,containsString("| +- file:/THREE"));
assertThat(dump,containsString("| +- MiddleLoader"));
assertThat(dump,containsString("| +- file:/one"));
assertThat(dump,containsString("| +- file:/two"));
assertThat(dump,containsString("| +- file:/three"));
assertThat(dump,containsString("| +- "+Server.class.getClassLoader()));
assertThat(dump,containsString("+> "+Server.class.getClassLoader()));
}
}