improved Dump

This commit is contained in:
Greg Wilkins 2015-06-18 15:46:56 +10:00
parent 1d1149440b
commit 1a572c3236
11 changed files with 268 additions and 152 deletions

View File

@ -217,6 +217,7 @@ public class LikeJettyXml
// Start the server // Start the server
server.start(); server.start();
server.dumpStdErr();
server.join(); server.join();
} }
} }

View File

@ -53,13 +53,10 @@ public class ClassLoaderDump implements Dumpable
Object parent = _loader.getParent(); Object parent = _loader.getParent();
if (parent != null) if (parent != null)
{ {
if (!(parent instanceof Dumpable))
parent = new ClassLoaderDump((ClassLoader)parent);
if (_loader instanceof URLClassLoader) if (_loader instanceof URLClassLoader)
ContainerLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs()),Collections.singleton(parent)); ContainerLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs()),Collections.singleton(parent.toString()));
else else
ContainerLifeCycle.dump(out,indent,Collections.singleton(parent)); ContainerLifeCycle.dump(out,indent,Collections.singleton(parent.toString()));
} }
} }
} }

View File

@ -81,6 +81,7 @@ import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.DumpableCollection;
import org.eclipse.jetty.util.component.Graceful; import org.eclipse.jetty.util.component.Graceful;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -231,10 +232,11 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
public void dump(Appendable out, String indent) throws IOException public void dump(Appendable out, String indent) throws IOException
{ {
dumpBeans(out,indent, dumpBeans(out,indent,
Collections.singletonList(new ClassLoaderDump(getClassLoader())), Collections.singletonList(new ClassLoaderDump(getClassLoader())),
_initParams.entrySet(), Collections.singletonList(new DumpableCollection("Handler attributes "+this,((AttributesMap)getAttributes()).getAttributeEntrySet())),
_attributes.getAttributeEntrySet(), Collections.singletonList(new DumpableCollection("Context attributes "+this,((Context)getServletContext()).getAttributeEntrySet())),
_scontext.getAttributeEntrySet()); Collections.singletonList(new DumpableCollection("Initparams "+this,getInitParams().entrySet()))
);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -1479,7 +1481,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
{ {
if (errorHandler != null) if (errorHandler != null)
errorHandler.setServer(getServer()); errorHandler.setServer(getServer());
updateBean(_errorHandler,errorHandler); updateBean(_errorHandler,errorHandler,true);
_errorHandler = errorHandler; _errorHandler = errorHandler;
} }

View File

@ -86,7 +86,7 @@ public class HandlerWrapper extends AbstractHandlerContainer
Handler old=_handler; Handler old=_handler;
_handler=handler; _handler=handler;
updateBean(old,_handler); updateBean(old,_handler,true);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */

View File

@ -77,7 +77,7 @@ public class HotSwapHandler extends AbstractHandlerContainer
throw new IllegalArgumentException("Parameter handler is null."); throw new IllegalArgumentException("Parameter handler is null.");
try try
{ {
updateBean(_handler,handler); updateBean(_handler,handler,true);
_handler=handler; _handler=handler;
Server server = getServer(); Server server = getServer();
handler.setServer(server); handler.setServer(server);

View File

@ -743,7 +743,7 @@ public class StringUtil
if (s.length()==2) if (s.length()==2)
return new String[]{}; return new String[]{};
return s.substring(1,s.length()-1).split(" *, *"); return s.substring(1,s.length()-1).split("\\s*,\\s*");
} }
public static String sanitizeXmlString(String html) public static String sanitizeXmlString(String html)

View File

@ -777,6 +777,17 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
addBean(newBean); addBean(newBean);
} }
} }
public void updateBean(Object oldBean, final Object newBean, boolean managed)
{
if (newBean!=oldBean)
{
if (oldBean!=null)
removeBean(oldBean);
if (newBean!=null)
addBean(newBean,managed);
}
}
public void updateBeans(Object[] oldBeans, final Object[] newBeans) public void updateBeans(Object[] oldBeans, final Object[] newBeans)
{ {

View File

@ -0,0 +1,51 @@
//
// ========================================================================
// Copyright (c) 1995-2015 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.util.component;
import java.io.IOException;
import java.util.Collection;
import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.Dumpable;
public class DumpableCollection implements Dumpable
{
private final String _name;
private final Collection<?> _collection;
public DumpableCollection(String name,Collection<?> collection)
{
_name=name;
_collection=collection;
}
@Override
public String dump()
{
return ContainerLifeCycle.dump(this);
}
@Override
public void dump(Appendable out, String indent) throws IOException
{
out.append(_name).append("\n");
if (_collection!=null)
ContainerLifeCycle.dump(out,indent,_collection);
}
}

View File

@ -19,14 +19,15 @@
package org.eclipse.jetty.webapp; package org.eclipse.jetty.webapp;
import java.util.AbstractList;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.List; import java.util.List;
import java.util.StringTokenizer; import java.util.ListIterator;
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* ClasspathPattern performs sequential pattern matching of a class name * Classpath classes list performs sequential pattern matching of a class name
* against an internal array of classpath pattern entries. * against an internal array of classpath pattern entries.
* *
* When an entry starts with '-' (minus), reverse matching is performed. * When an entry starts with '-' (minus), reverse matching is performed.
@ -36,16 +37,30 @@ import java.util.StringTokenizer;
* in this string should be separated by ':' (semicolon) or ',' (comma). * in this string should be separated by ':' (semicolon) or ',' (comma).
*/ */
public class ClasspathPattern public class ClasspathPattern extends AbstractList<String>
{ {
private static class Entry private static class Entry
{ {
public String classpath = null; public final String _pattern;
public boolean result = false; public final String _name;
public boolean partial = false; public final boolean _inclusive;
public final boolean _package;
Entry(String pattern)
{
_pattern=pattern;
_inclusive = !pattern.startsWith("-");
_package = pattern.endsWith(".");
_name = _inclusive ? pattern : pattern.substring(1).trim();
}
@Override
public String toString()
{
return _pattern;
}
} }
final private List<String> _patterns = new ArrayList<String>();
final private List<Entry> _entries = new ArrayList<Entry>(); final private List<Entry> _entries = new ArrayList<Entry>();
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -56,160 +71,140 @@ public class ClasspathPattern
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public ClasspathPattern(String[] patterns) public ClasspathPattern(String[] patterns)
{ {
setPatterns(patterns); setAll(patterns);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
public ClasspathPattern(String pattern) public ClasspathPattern(String pattern)
{ {
setPattern(pattern); add(pattern);
} }
/* ------------------------------------------------------------ */
@Override
public String get(int index)
{
return _entries.get(index)._pattern;
}
/* ------------------------------------------------------------ */
@Override
public String set(int index, String element)
{
Entry e = _entries.set(index,new Entry(element));
return e==null?null:e._pattern;
}
/* ------------------------------------------------------------ */
@Override
public void add(int index, String element)
{
_entries.add(index,new Entry(element));
}
/* ------------------------------------------------------------ */
@Deprecated
public void addPattern(String element)
{
add(element);
}
/* ------------------------------------------------------------ */
@Override
public String remove(int index)
{
Entry e = _entries.remove(index);
return e==null?null:e._pattern;
}
/* ------------------------------------------------------------ */
public boolean remove(String pattern)
{
for (int i=_entries.size();i-->0;)
{
if (pattern.equals(_entries.get(i)._pattern))
{
_entries.remove(i);
return true;
}
}
return false;
}
/* ------------------------------------------------------------ */
@Override
public int size()
{
return _entries.size();
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* Initialize the matcher by parsing each classpath pattern in an array * Initialize the matcher by parsing each classpath pattern in an array
* *
* @param patterns array of classpath patterns * @param classes array of classpath patterns
*/ */
private void setPatterns(String[] patterns) private void setAll(String[] classes)
{ {
_patterns.clear();
_entries.clear(); _entries.clear();
addPatterns(patterns); addAll(classes);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* @param patterns array of classpath patterns * @param classes array of classpath patterns
*/ */
private void addPatterns(String[] patterns) private void addAll(String[] classes)
{ {
if (patterns != null) if (classes!=null)
{ addAll(Arrays.asList(classes));
Entry entry = null;
for (String pattern : patterns)
{
entry = createEntry(pattern);
if (entry != null)
{
_patterns.add(pattern);
_entries.add(entry);
}
}
}
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* @param patterns array of classpath patterns * @param classes array of classpath patterns
*/ */
private void prependPatterns(String[] patterns) public void prepend(String[] classes)
{ {
if (patterns != null) if (classes != null)
{ {
Entry entry = null;
int i=0; int i=0;
for (String pattern : patterns) for (String c : classes)
{ {
entry = createEntry(pattern); add(i,c);
if (entry != null) i++;
{
_patterns.add(i,pattern);
_entries.add(i,entry);
i++;
}
} }
} }
} }
/* ------------------------------------------------------------ */
/**
* Create an entry object containing information about
* a single classpath pattern
*
* @param pattern single classpath pattern
* @return corresponding Entry object
*/
private Entry createEntry(String pattern)
{
Entry entry = null;
if (pattern != null)
{
String item = pattern.trim();
if (item.length() > 0)
{
entry = new Entry();
entry.result = !item.startsWith("-");
entry.partial = item.endsWith(".");
entry.classpath = entry.result ? item : item.substring(1).trim();
}
}
return entry;
}
/* ------------------------------------------------------------ */
/**
* Initialize the matcher by parsing a classpath pattern string
*
* @param pattern classpath pattern string
*/
public void setPattern(String pattern)
{
_patterns.clear();
_entries.clear();
addPattern(pattern);
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** public void prependPattern(String pattern)
* Parse a classpath pattern string and appending the result
* to the existing configuration.
*
* @param pattern classpath pattern string
*/
public void addPattern(String pattern)
{ {
ArrayList<String> patterns = new ArrayList<String>(); add(0,pattern);
StringTokenizer entries = new StringTokenizer(pattern, ":,");
while (entries.hasMoreTokens())
{
patterns.add(entries.nextToken());
}
addPatterns(patterns.toArray(new String[patterns.size()]));
}
/* ------------------------------------------------------------ */
public void prependPattern(String classOrPackage)
{
ArrayList<String> patterns = new ArrayList<String>();
StringTokenizer entries = new StringTokenizer(classOrPackage, ":,");
while (entries.hasMoreTokens())
{
patterns.add(entries.nextToken());
}
prependPatterns(patterns.toArray(new String[patterns.size()]));
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* @return array of classpath patterns * @return array of classpath patterns
*/ */
public String[] getPatterns() public String[] getPatterns()
{ {
String[] patterns = null; return toArray(new String[_entries.size()]);
}
if (_patterns!=null && _patterns.size() > 0)
/* ------------------------------------------------------------ */
/**
* @return List of classes excluded class exclusions and package patterns
*/
public List<String> getClasses()
{
List<String> list = new ArrayList<>();
for (Entry e:_entries)
{ {
patterns = _patterns.toArray(new String[_patterns.size()]); if (e._inclusive && !e._package)
list.add(e._name);
} }
return list;
return patterns;
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -241,21 +236,21 @@ public class ClasspathPattern
{ {
if (entry != null) if (entry != null)
{ {
if (entry.partial) if (entry._package)
{ {
if (name.regionMatches(startIndex, entry.classpath, 0, entry.classpath.length())) if (name.regionMatches(startIndex, entry._name, 0, entry._name.length()))
{ {
result = entry.result; result = entry._inclusive;
break; break;
} }
} }
else else
{ {
int regionLength = endIndex-startIndex; int regionLength = endIndex-startIndex;
if (regionLength == entry.classpath.length() if (regionLength == entry._name.length()
&& name.regionMatches(startIndex, entry.classpath, 0, regionLength)) && name.regionMatches(startIndex, entry._name, 0, regionLength))
{ {
result = entry.result; result = entry._inclusive;
break; break;
} }
} }
@ -265,4 +260,42 @@ public class ClasspathPattern
return result; return result;
} }
public void addAfter(String afterPattern,String... patterns)
{
if (patterns!=null && afterPattern!=null)
{
ListIterator<String> iter = listIterator();
while (iter.hasNext())
{
String cc=iter.next();
if (afterPattern.equals(cc))
{
for (int i=0;i<patterns.length;i++)
iter.add(patterns[i]);
return;
}
}
}
throw new IllegalArgumentException("after '"+afterPattern+"' not found in "+this);
}
public void addBefore(String beforePattern,String... patterns)
{
if (patterns!=null && beforePattern!=null)
{
ListIterator<String> iter = listIterator();
while (iter.hasNext())
{
String cc=iter.next();
if (beforePattern.equals(cc))
{
iter.previous();
for (int i=0;i<patterns.length;i++)
iter.add(patterns[i]);
return;
}
}
}
throw new IllegalArgumentException("before '"+beforePattern+"' not found in "+this);
}
} }

View File

@ -128,14 +128,18 @@ public interface Configuration
*/ */
public static ClassList serverDefault(Server server) public static ClassList serverDefault(Server server)
{ {
ClassList cl=server.getBean(ClassList.class); ClassList cl=null;
if (cl!=null) if (server!=null)
return new ClassList(cl); {
Object attr = server.getAttribute(ATTR); cl= server.getBean(ClassList.class);
if (attr instanceof ClassList) if (cl!=null)
return new ClassList((ClassList)attr); return new ClassList(cl);
if (attr instanceof String[]) Object attr = server.getAttribute(ATTR);
return new ClassList((String[])attr); if (attr instanceof ClassList)
return new ClassList((ClassList)attr);
if (attr instanceof String[])
return new ClassList((String[])attr);
}
return new ClassList(); return new ClassList();
} }

View File

@ -48,6 +48,7 @@ import org.eclipse.jetty.security.ConstraintAware;
import org.eclipse.jetty.security.ConstraintMapping; import org.eclipse.jetty.security.ConstraintMapping;
import org.eclipse.jetty.security.ConstraintSecurityHandler; import org.eclipse.jetty.security.ConstraintSecurityHandler;
import org.eclipse.jetty.security.SecurityHandler; import org.eclipse.jetty.security.SecurityHandler;
import org.eclipse.jetty.server.ClassLoaderDump;
import org.eclipse.jetty.server.Connector; import org.eclipse.jetty.server.Connector;
import org.eclipse.jetty.server.HandlerContainer; import org.eclipse.jetty.server.HandlerContainer;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
@ -57,11 +58,13 @@ import org.eclipse.jetty.server.session.SessionHandler;
import org.eclipse.jetty.servlet.ErrorPageErrorHandler; import org.eclipse.jetty.servlet.ErrorPageErrorHandler;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHandler;
import org.eclipse.jetty.util.AttributesMap;
import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.MultiException; import org.eclipse.jetty.util.MultiException;
import org.eclipse.jetty.util.URIUtil; import org.eclipse.jetty.util.URIUtil;
import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedObject;
import org.eclipse.jetty.util.component.DumpableCollection;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.resource.Resource;
@ -348,13 +351,12 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
{ {
super.setClassLoader(classLoader); super.setClassLoader(classLoader);
// if ( !(classLoader instanceof WebAppClassLoader) ) String name = getDisplayName();
// { if (name==null)
// LOG.info("NOTE: detected a classloader which is not an instance of WebAppClassLoader being set on WebAppContext, some typical class and resource locations may be missing on: " + toString() ); name=getContextPath();
// }
if (classLoader!=null && classLoader instanceof WebAppClassLoader && getDisplayName()!=null) if (classLoader!=null && classLoader instanceof WebAppClassLoader && getDisplayName()!=null)
((WebAppClassLoader)classLoader).setName(getDisplayName()); ((WebAppClassLoader)classLoader).setName(name);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -688,7 +690,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
if (_serverClasses == null) if (_serverClasses == null)
loadServerClasses(); loadServerClasses();
_serverClasses.addPattern(classOrPackage); _serverClasses.add(classOrPackage);
} }
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
@ -738,7 +740,7 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
if (_systemClasses == null) if (_systemClasses == null)
loadSystemClasses(); loadSystemClasses();
_systemClasses.addPattern(classOrPackage); _systemClasses.add(classOrPackage);
} }
@ -952,7 +954,22 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL
} }
return super.toString(); return super.toString();
} }
/* ------------------------------------------------------------ */
@Override
public void dump(Appendable out, String indent) throws IOException
{
dumpBeans(out,indent,
Collections.singletonList(new ClassLoaderDump(getClassLoader())),
Collections.singletonList(new DumpableCollection("Systemclasses "+this,_systemClasses)),
Collections.singletonList(new DumpableCollection("Serverclasses "+this,_serverClasses)),
Collections.singletonList(new DumpableCollection("Configurations "+this,_configurations)),
Collections.singletonList(new DumpableCollection("Handler attributes "+this,((AttributesMap)getAttributes()).getAttributeEntrySet())),
Collections.singletonList(new DumpableCollection("Context attributes "+this,((Context)getServletContext()).getAttributeEntrySet())),
Collections.singletonList(new DumpableCollection("Initparams "+this,getInitParams().entrySet()))
);
}
/* ------------------------------------------------------------ */ /* ------------------------------------------------------------ */
/** /**
* @param configurations The configuration class names. If setConfigurations is not called * @param configurations The configuration class names. If setConfigurations is not called