From 15e1c73f9c89905da851344b55ff83e0b7af2584 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 22 Oct 2018 11:53:59 +1100 Subject: [PATCH] Cleanup the dump implementation (#2998) * Cleanup the dump implementation * improved the clarity of utility methods for dump and updated most dump methods * fixed upgrade filter dump * Improved dump after review * Moved dumpObjects to Dumpable * implemented dumpBeans with dumpObjects * less verbose dump * Dump streams * fixed dump test Signed-off-by: Greg Wilkins Signed-off-by: Simone Bordet --- examples/embedded/pom.xml | 7 +- .../eclipse/jetty/embedded/LikeJettyXml.java | 2 +- .../jetty/embedded/ManyConnectors.java | 2 +- .../eclipse/jetty/embedded/ManyContexts.java | 1 + .../OneServletContextWithSession.java | 1 + .../jetty/embedded/ServerWithAnnotations.java | 5 +- .../jetty/client/AbstractConnectionPool.java | 3 +- .../jetty/client/DuplexConnectionPool.java | 17 +- .../eclipse/jetty/client/HttpDestination.java | 3 +- .../jetty/client/MultiplexConnectionPool.java | 16 +- .../client/RoundRobinConnectionPool.java | 5 +- .../client/ValidatingConnectionPool.java | 9 +- .../jetty/http/pathmap/PathMappings.java | 6 +- .../http2/AbstractFlowControlStrategy.java | 3 +- .../org/eclipse/jetty/http2/HTTP2Flusher.java | 3 +- .../org/eclipse/jetty/http2/HTTP2Session.java | 4 +- .../org/eclipse/jetty/http2/HTTP2Stream.java | 3 +- .../AbstractHTTP2ServerConnectionFactory.java | 6 +- .../jetty/io/ConnectionStatistics.java | 17 +- .../org/eclipse/jetty/io/ManagedSelector.java | 11 +- .../org/eclipse/jetty/jmx/MBeanContainer.java | 5 +- .../eclipse/jetty/proxy/ConnectHandler.java | 7 - .../security/ConstraintSecurityHandler.java | 11 +- .../eclipse/jetty/server/ClassLoaderDump.java | 29 +-- .../jetty/server/ConnectorStatistics.java | 11 +- .../java/org/eclipse/jetty/server/Server.java | 3 +- .../jetty/server/handler/ContextHandler.java | 11 +- .../handler/ContextHandlerCollection.java | 2 +- .../server/handler/HandlerCollection.java | 8 - .../server/handler/InetAccessHandler.java | 5 +- .../jetty/server/ClassLoaderDumptTest.java | 46 ++--- .../org/eclipse/jetty/servlet/BaseHolder.java | 6 +- .../eclipse/jetty/servlet/FilterHolder.java | 32 +-- .../eclipse/jetty/servlet/FilterMapping.java | 3 +- .../org/eclipse/jetty/servlet/Holder.java | 12 +- .../eclipse/jetty/servlet/ServletHandler.java | 10 +- .../eclipse/jetty/servlet/ServletHolder.java | 16 +- .../org/eclipse/jetty/util/AttributesMap.java | 17 +- .../util/component/ContainerLifeCycle.java | 158 ++++++-------- .../jetty/util/component/Dumpable.java | 192 +++++++++++++++++- .../util/component/DumpableCollection.java | 16 +- .../jetty/util/ssl/SslContextFactory.java | 19 +- .../jetty/util/ssl/SslSelectionDump.java | 16 +- .../jetty/util/thread/ExecutorThreadPool.java | 17 +- .../jetty/util/thread/QueuedThreadPool.java | 13 +- .../thread/ScheduledExecutorScheduler.java | 15 +- .../jetty/util/URIUtilCanonicalPathTest.java | 2 +- .../component/ContainerLifeCycleTest.java | 117 ++++++----- .../eclipse/jetty/webapp/WebAppContext.java | 14 +- .../websocket/client/WebSocketClient.java | 7 - .../websocket/common/WebSocketSession.java | 25 +-- .../common/extensions/AbstractExtension.java | 3 +- .../io/AbstractWebSocketConnection.java | 3 +- .../server/WebSocketUpgradeFilter.java | 6 +- .../java/org/eclipse/jetty/TestServer.java | 34 ++-- 55 files changed, 584 insertions(+), 431 deletions(-) diff --git a/examples/embedded/pom.xml b/examples/embedded/pom.xml index 7280aaf5dac..1fcade91b31 100644 --- a/examples/embedded/pom.xml +++ b/examples/embedded/pom.xml @@ -128,7 +128,12 @@ org.eclipse.jetty.orbit javax.mail.glassfish - + + javax.transaction + javax.transaction-api + compile + + org.eclipse.jetty.toolchain jetty-test-helper diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java index f592d061f30..356a9181978 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/LikeJettyXml.java @@ -60,7 +60,7 @@ public class LikeJettyXml public static void main( String[] args ) throws Exception { // Path to as-built jetty-distribution directory - String jettyHomeBuild = "../../jetty-distribution/target/distribution"; + String jettyHomeBuild = "jetty-distribution/target/distribution"; // Find jetty home and base directories String homePath = System.getProperty("jetty.home", jettyHomeBuild); diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java index ef62bcbc2df..72285a31ee3 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyConnectors.java @@ -137,7 +137,7 @@ public class ManyConnectors // Start the server server.start(); - + server.dumpStdErr(); server.join(); } } diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyContexts.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyContexts.java index 87c39c0727b..1b7ad9bc8db 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyContexts.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ManyContexts.java @@ -50,6 +50,7 @@ public class ManyContexts server.setHandler(contexts); server.start(); + server.dumpStdErr(); server.join(); } } diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneServletContextWithSession.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneServletContextWithSession.java index d098589d0bc..023f169794b 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneServletContextWithSession.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneServletContextWithSession.java @@ -58,6 +58,7 @@ public class OneServletContextWithSession context.addServlet(HelloSessionServlet.class, "/"); server.start(); + server.dumpStdErr(); server.join(); } } diff --git a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java index d67880eef52..ca7ba901a84 100644 --- a/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java +++ b/examples/embedded/src/main/java/org/eclipse/jetty/embedded/ServerWithAnnotations.java @@ -52,7 +52,7 @@ public class ServerWithAnnotations WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/"); File warFile = new File( - "../../jetty-distribution/target/distribution/demo-base/webapps/test.war"); + "jetty-distribution/target/distribution/demo-base/webapps/test.war"); webapp.setWar(warFile.getAbsolutePath()); webapp.setAttribute( "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern", @@ -72,10 +72,11 @@ public class ServerWithAnnotations // Configure a LoginService HashLoginService loginService = new HashLoginService(); loginService.setName("Test Realm"); - loginService.setConfig("src/test/resources/realm.properties"); + loginService.setConfig("examples/embedded/src/test/resources/realm.properties"); server.addBean(loginService); server.start(); + server.dumpStdErr(); server.join(); } diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectionPool.java b/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectionPool.java index 29d85e8fd79..19d0d1f073c 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectionPool.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/AbstractConnectionPool.java @@ -28,7 +28,6 @@ import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Promise; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -212,6 +211,6 @@ public abstract class AbstractConnectionPool implements ConnectionPool, Dumpable @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } } diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/DuplexConnectionPool.java b/jetty-client/src/main/java/org/eclipse/jetty/client/DuplexConnectionPool.java index 5261751a62f..92bbd49311c 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/DuplexConnectionPool.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/DuplexConnectionPool.java @@ -35,7 +35,8 @@ import org.eclipse.jetty.client.api.Destination; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; -import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.component.Dumpable; +import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.Sweeper; @@ -239,20 +240,24 @@ public class DuplexConnectionPool extends AbstractConnectionPool implements Swee @Override public void dump(Appendable out, String indent) throws IOException { - List connections = new ArrayList<>(); + DumpableCollection active; + DumpableCollection idle; lock(); try { - connections.addAll(activeConnections); - connections.addAll(idleConnections); + active = new DumpableCollection("active",new ArrayList<>(activeConnections)); + idle = new DumpableCollection("idle",new ArrayList<>(idleConnections)); } finally { unlock(); } + dump(out, indent, active, idle); + } - ContainerLifeCycle.dumpObject(out, this); - ContainerLifeCycle.dump(out, indent, connections); + protected void dump(Appendable out, String indent, Object... items) throws IOException + { + Dumpable.dumpObjects(out, indent, this, items); } @Override diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java index a19613ee3b9..7b7ebc432c2 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/HttpDestination.java @@ -472,8 +472,7 @@ public abstract class HttpDestination extends ContainerLifeCycle implements Dest @Override public void dump(Appendable out, String indent) throws IOException { - super.dump(out, indent); - ContainerLifeCycle.dump(out, indent, Collections.singleton(new DumpableCollection("exchanges", exchanges))); + dumpBeans(out, indent, new DumpableCollection("exchanges", exchanges)); } public String asString() diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/MultiplexConnectionPool.java b/jetty-client/src/main/java/org/eclipse/jetty/client/MultiplexConnectionPool.java index 179d66e9ca3..8e3bdf31195 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/MultiplexConnectionPool.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/MultiplexConnectionPool.java @@ -31,7 +31,8 @@ import java.util.stream.Collectors; import org.eclipse.jetty.client.api.Connection; import org.eclipse.jetty.util.Callback; -import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.component.Dumpable; +import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.Sweeper; @@ -310,21 +311,22 @@ public class MultiplexConnectionPool extends AbstractConnectionPool implements C @Override public void dump(Appendable out, String indent) throws IOException { - List connections = new ArrayList<>(); + DumpableCollection busy; + DumpableCollection muxed; + DumpableCollection idle; lock(); try { - connections.addAll(busyConnections.values()); - connections.addAll(muxedConnections.values()); - connections.addAll(idleConnections); + busy = new DumpableCollection("busy", new ArrayList<>(busyConnections.values())); + muxed = new DumpableCollection("muxed", new ArrayList<>(muxedConnections.values())); + idle = new DumpableCollection("idle", new ArrayList<>(idleConnections)); } finally { unlock(); } - ContainerLifeCycle.dumpObject(out, this); - ContainerLifeCycle.dump(out, indent, connections); + Dumpable.dumpObjects(out, indent, this, busy, muxed, idle); } @Override diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/RoundRobinConnectionPool.java b/jetty-client/src/main/java/org/eclipse/jetty/client/RoundRobinConnectionPool.java index f69cbf63eea..2986d1a3189 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/RoundRobinConnectionPool.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/RoundRobinConnectionPool.java @@ -26,7 +26,7 @@ import org.eclipse.jetty.client.api.Connection; import org.eclipse.jetty.client.api.Destination; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.annotation.ManagedObject; -import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.component.Dumpable; @ManagedObject public class RoundRobinConnectionPool extends AbstractConnectionPool implements ConnectionPool.Multiplexable @@ -192,8 +192,7 @@ public class RoundRobinConnectionPool extends AbstractConnectionPool implements { connections = new ArrayList<>(entries); } - ContainerLifeCycle.dumpObject(out, this); - ContainerLifeCycle.dump(out, indent, connections); + Dumpable.dumpObjects(out, indent, out, connections); } @Override diff --git a/jetty-client/src/main/java/org/eclipse/jetty/client/ValidatingConnectionPool.java b/jetty-client/src/main/java/org/eclipse/jetty/client/ValidatingConnectionPool.java index 5d539284ee3..bc1aa22ac56 100644 --- a/jetty-client/src/main/java/org/eclipse/jetty/client/ValidatingConnectionPool.java +++ b/jetty-client/src/main/java/org/eclipse/jetty/client/ValidatingConnectionPool.java @@ -23,12 +23,13 @@ import java.util.HashMap; import java.util.Map; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicBoolean; +import java.util.stream.Stream; import org.eclipse.jetty.client.api.Connection; import org.eclipse.jetty.client.api.Destination; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.annotation.ManagedAttribute; -import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.Scheduler; @@ -129,10 +130,10 @@ public class ValidatingConnectionPool extends DuplexConnectionPool } @Override - public void dump(Appendable out, String indent) throws IOException + protected void dump(Appendable out, String indent, Object... items) throws IOException { - super.dump(out, indent); - ContainerLifeCycle.dump(out, indent, quarantine.values()); + DumpableCollection toDump = new DumpableCollection("quarantine", quarantine.values()); + super.dump(out, indent, Stream.concat(Stream.of(items), Stream.of(toDump))); } @Override diff --git a/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/PathMappings.java b/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/PathMappings.java index 6bd3d6b7217..1954da4228c 100644 --- a/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/PathMappings.java +++ b/jetty-http/src/main/java/org/eclipse/jetty/http/pathmap/PathMappings.java @@ -31,7 +31,6 @@ import org.eclipse.jetty.util.ArrayTernaryTrie; import org.eclipse.jetty.util.Trie; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -56,14 +55,13 @@ public class PathMappings implements Iterable>, Dumpable @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override public void dump(Appendable out, String indent) throws IOException { - out.append("PathMappings[size=").append(Integer.toString(_mappings.size())).append("]\n"); - ContainerLifeCycle.dump(out, indent, _mappings); + Dumpable.dumpObjects(out, indent, toString(), _mappings); } @ManagedAttribute(value = "mappings", readonly = true) diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/AbstractFlowControlStrategy.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/AbstractFlowControlStrategy.java index 16a0068a8e6..fe8deaaa6a0 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/AbstractFlowControlStrategy.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/AbstractFlowControlStrategy.java @@ -29,7 +29,6 @@ import org.eclipse.jetty.http2.frames.WindowUpdateFrame; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedOperation; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -243,7 +242,7 @@ public abstract class AbstractFlowControlStrategy implements FlowControlStrategy @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Flusher.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Flusher.java index 61b9c69acad..219c36e8d48 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Flusher.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Flusher.java @@ -34,7 +34,6 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.EofException; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.IteratingCallback; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -353,7 +352,7 @@ public class HTTP2Flusher extends IteratingCallback implements Dumpable @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java index fe2b90e6526..da4f3ad5b69 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Session.java @@ -62,6 +62,7 @@ import org.eclipse.jetty.util.Retainable; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -1205,8 +1206,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio @Override public void dump(Appendable out, String indent) throws IOException { - super.dump(out, indent); - dump(out, indent, Collections.singleton(new DumpableCollection("streams", streams.values()))); + Dumpable.dumpObjects(out, indent, this, new DumpableCollection("streams", streams.values())); } @Override diff --git a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java index 3cc9d531ce0..14002387880 100644 --- a/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java +++ b/jetty-http2/http2-common/src/main/java/org/eclipse/jetty/http2/HTTP2Stream.java @@ -42,7 +42,6 @@ import org.eclipse.jetty.http2.frames.WindowUpdateFrame; import org.eclipse.jetty.io.IdleTimeout; import org.eclipse.jetty.util.Callback; import org.eclipse.jetty.util.Promise; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -616,7 +615,7 @@ public class HTTP2Stream extends IdleTimeout implements IStream, Callback, Dumpa @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override diff --git a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java index 46d3e46960e..da37a88d485 100644 --- a/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java +++ b/jetty-http2/http2-server/src/main/java/org/eclipse/jetty/http2/server/AbstractHTTP2ServerConnectionFactory.java @@ -43,7 +43,6 @@ import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.Name; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.component.LifeCycle; @@ -288,14 +287,13 @@ public abstract class AbstractHTTP2ServerConnectionFactory extends AbstractConne @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override public void dump(Appendable out, String indent) throws IOException { - ContainerLifeCycle.dumpObject(out, this); - ContainerLifeCycle.dump(out, indent, sessions); + Dumpable.dumpObjects(out,indent,this, sessions); } @Override diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ConnectionStatistics.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ConnectionStatistics.java index 871d57c6353..f13877f430e 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ConnectionStatistics.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ConnectionStatistics.java @@ -19,8 +19,6 @@ package org.eclipse.jetty.io; import java.io.IOException; -import java.util.ArrayList; -import java.util.List; import java.util.concurrent.TimeUnit; import java.util.concurrent.atomic.AtomicLong; import java.util.concurrent.atomic.LongAdder; @@ -29,7 +27,6 @@ import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedOperation; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.statistic.CounterStatistic; import org.eclipse.jetty.util.statistic.SampleStatistic; @@ -210,19 +207,17 @@ public class ConnectionStatistics extends AbstractLifeCycle implements Connectio @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override public void dump(Appendable out, String indent) throws IOException { - ContainerLifeCycle.dumpObject(out, this); - List children = new ArrayList<>(); - children.add(String.format("connections=%s", _connections)); - children.add(String.format("durations=%s", _connectionsDuration)); - children.add(String.format("bytes in/out=%s/%s", getReceivedBytes(), getSentBytes())); - children.add(String.format("messages in/out=%s/%s", getReceivedMessages(), getSentMessages())); - ContainerLifeCycle.dump(out, indent, children); + Dumpable.dumpObjects(out,indent,this, + String.format("connections=%s", _connections), + String.format("durations=%s", _connectionsDuration), + String.format("bytes in/out=%s/%s", getReceivedBytes(), getSentBytes()), + String.format("messages in/out=%s/%s", getReceivedMessages(), getSentMessages())); } @Override diff --git a/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java b/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java index d476885b1e0..3197f2ad1f8 100644 --- a/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java +++ b/jetty-io/src/main/java/org/eclipse/jetty/io/ManagedSelector.java @@ -296,8 +296,10 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable String keysAt = DateTimeFormatter.ISO_OFFSET_DATE_TIME.format(ZonedDateTime.now()); if (keys==null) keys = Collections.singletonList("No dump keys retrieved"); - dumpBeans(out, indent, Arrays.asList(new DumpableCollection("updates @ "+updatesAt, updates), - new DumpableCollection("keys @ "+keysAt, keys))); + + dumpBeans(out, indent, + new DumpableCollection("updates @ "+updatesAt, updates), + new DumpableCollection("keys @ "+keysAt, keys)); } else { @@ -543,7 +545,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable */ public interface SelectorUpdate { - public void update(Selector selector); + void update(Selector selector); } private class Start implements SelectorUpdate @@ -567,8 +569,7 @@ public class ManagedSelector extends ContainerLifeCycle implements Dumpable public void update(Selector selector) { Set selector_keys = selector.keys(); - List list = new ArrayList<>(selector_keys.size()+1); - list.add(selector + " keys=" + selector_keys.size()); + List list = new ArrayList<>(selector_keys.size()); for (SelectionKey key : selector_keys) { if (key==null) diff --git a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java index 17ef201b4e7..c63b9446d4c 100644 --- a/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java +++ b/jetty-jmx/src/main/java/org/eclipse/jetty/jmx/MBeanContainer.java @@ -398,14 +398,13 @@ public class MBeanContainer implements Container.InheritedListener, Dumpable, De @Override public void dump(Appendable out, String indent) throws IOException { - ContainerLifeCycle.dumpObject(out, this); - ContainerLifeCycle.dump(out, indent, _mbeans.entrySet()); + Dumpable.dumpObjects(out, indent, this, _mbeans.entrySet()); } @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override diff --git a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java index a6120df2191..34826102b05 100644 --- a/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java +++ b/jetty-proxy/src/main/java/org/eclipse/jetty/proxy/ConnectHandler.java @@ -486,13 +486,6 @@ public class ConnectHandler extends HandlerWrapper return true; } - @Override - public void dump(Appendable out, String indent) throws IOException - { - dumpThis(out); - dump(out, indent, getBeans(), TypeUtil.asList(getHandlers())); - } - protected class ConnectManager extends SelectorManager { protected ConnectManager(Executor executor, Scheduler scheduler, int selectors) diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/ConstraintSecurityHandler.java b/jetty-security/src/main/java/org/eclipse/jetty/security/ConstraintSecurityHandler.java index 8540bfb53bf..6825ecde4d1 100644 --- a/jetty-security/src/main/java/org/eclipse/jetty/security/ConstraintSecurityHandler.java +++ b/jetty-security/src/main/java/org/eclipse/jetty/security/ConstraintSecurityHandler.java @@ -46,6 +46,7 @@ import org.eclipse.jetty.server.Response; import org.eclipse.jetty.server.UserIdentity; import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.URIUtil; +import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.security.Constraint; @@ -767,11 +768,11 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr { // TODO these should all be beans dumpBeans(out,indent, - Collections.singleton(getLoginService()), - Collections.singleton(getIdentityService()), - Collections.singleton(getAuthenticator()), - Collections.singleton(_roles), - _constraintMap.entrySet()); + getLoginService(), + getIdentityService(), + getAuthenticator(), + DumpableCollection.from("roles",_roles), + DumpableCollection.from("constraints",_constraintMap.entrySet())); } /* ------------------------------------------------------------ */ diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ClassLoaderDump.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ClassLoaderDump.java index 3ca4321424d..44072e42b65 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ClassLoaderDump.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ClassLoaderDump.java @@ -20,11 +20,9 @@ package org.eclipse.jetty.server; import java.io.IOException; import java.net.URLClassLoader; -import java.util.Collections; -import org.eclipse.jetty.util.TypeUtil; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; +import org.eclipse.jetty.util.component.DumpableCollection; public class ClassLoaderDump implements Dumpable { @@ -38,7 +36,7 @@ public class ClassLoaderDump implements Dumpable @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override @@ -48,31 +46,34 @@ public class ClassLoaderDump implements Dumpable out.append("No ClassLoader\n"); else if (_loader instanceof Dumpable) { - ContainerLifeCycle.dump(out,indent,Collections.singleton(_loader)); + ((Dumpable)_loader).dump(out,indent); } else if (_loader instanceof URLClassLoader) { - out.append(String.valueOf(_loader)).append("\n"); + String loader = _loader.toString(); + DumpableCollection urls = DumpableCollection.fromArray("URLs", ((URLClassLoader)_loader).getURLs()); ClassLoader parent = _loader.getParent(); if (parent==null) - ContainerLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs())); + Dumpable.dumpObjects(out,indent,loader,urls); else if (parent == Server.class.getClassLoader()) - ContainerLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs()),Collections.singleton(parent.toString())); + Dumpable.dumpObjects(out,indent,loader,urls,parent.toString()); else if (parent instanceof Dumpable) - ContainerLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs()),Collections.singleton(parent)); + Dumpable.dumpObjects(out,indent,loader,urls,parent); else - ContainerLifeCycle.dump(out,indent,TypeUtil.asList(((URLClassLoader)_loader).getURLs()),Collections.singleton(new ClassLoaderDump(parent))); + Dumpable.dumpObjects(out,indent,loader,urls,new ClassLoaderDump(parent)); } else { - out.append(String.valueOf(_loader)).append("\n"); + String loader = _loader.toString(); ClassLoader parent = _loader.getParent(); + if (parent==null) + Dumpable.dumpObject(out,loader); if (parent==Server.class.getClassLoader()) - ContainerLifeCycle.dump(out,indent,Collections.singleton(parent.toString())); + Dumpable.dumpObjects(out,indent,loader,parent.toString()); else if (parent instanceof Dumpable) - ContainerLifeCycle.dump(out,indent,Collections.singleton(parent)); + Dumpable.dumpObjects(out,indent,loader,parent); else if (parent!=null) - ContainerLifeCycle.dump(out,indent,Collections.singleton(new ClassLoaderDump(parent))); + Dumpable.dumpObjects(out,indent,loader,new ClassLoaderDump(parent)); } } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ConnectorStatistics.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ConnectorStatistics.java index 519f71e7561..ae42690537c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ConnectorStatistics.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ConnectorStatistics.java @@ -19,7 +19,6 @@ package org.eclipse.jetty.server; import java.io.IOException; -import java.util.Arrays; import java.util.Map; import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; @@ -33,7 +32,6 @@ import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedOperation; import org.eclipse.jetty.util.component.AbstractLifeCycle; import org.eclipse.jetty.util.component.Container; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.statistic.CounterStatistic; import org.eclipse.jetty.util.statistic.SampleStatistic; @@ -240,14 +238,17 @@ public class ConnectorStatistics extends AbstractLifeCycle implements Dumpable, @ManagedOperation("dump thread state") public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override public void dump(Appendable out, String indent) throws IOException { - ContainerLifeCycle.dumpObject(out,this); - ContainerLifeCycle.dump(out,indent,Arrays.asList(new String[]{"connections="+_connectionStats,"duration="+_connectionDurationStats,"in="+_messagesIn,"out="+_messagesOut})); + Dumpable.dumpObjects(out,indent,this, + "connections="+_connectionStats, + "duration="+_connectionDurationStats, + "in="+_messagesIn, + "out="+_messagesOut); } public static void addToAllConnectors(Server server) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java index 97838eff969..cc7f6312a98 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Server.java @@ -628,6 +628,7 @@ public class Server extends HandlerWrapper implements Attributes @Override public void setAttribute(String name, Object attribute) { + // TODO this is a crude way to get attribute values managed by JMX. Object old=_attributes.getAttribute(name); updateBean(old,attribute); _attributes.setAttribute(name, attribute); @@ -690,7 +691,7 @@ public class Server extends HandlerWrapper implements Attributes @Override public void dump(Appendable out,String indent) throws IOException { - dumpBeans(out,indent,Collections.singleton(new ClassLoaderDump(this.getClass().getClassLoader()))); + dumpBeans(out,indent,new ClassLoaderDump(this.getClass().getClassLoader()),_attributes); } /* ------------------------------------------------------------ */ diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java index e9560d603b2..ae7003247f2 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandler.java @@ -256,11 +256,12 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu @Override public void dump(Appendable out, String indent) throws IOException { - dumpBeans(out,indent,Collections.singletonList(new ClassLoaderDump(getClassLoader())), - Collections.singletonList(new DumpableCollection("eventListeners "+this,_eventListeners)), - 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()))); + dumpBeans(out, indent, + new ClassLoaderDump(getClassLoader()), + new DumpableCollection("eventListeners " + this, _eventListeners), + new DumpableCollection("handler attributes " + this, ((AttributesMap)getAttributes()).getAttributeEntrySet()), + new DumpableCollection("context attributes " + this, ((Context)getServletContext()).getAttributeEntrySet()), + new DumpableCollection("initparams " + this,getInitParams().entrySet())); } /* ------------------------------------------------------------ */ diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java index 25f62ae8002..4b264af1949 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/ContextHandlerCollection.java @@ -335,7 +335,7 @@ public class ContextHandlerCollection extends HandlerCollection { return _handler; } - + @Override public String toString() { diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java index 2c28806fae9..0018d17ed7c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/HandlerCollection.java @@ -202,12 +202,4 @@ public class HandlerCollection extends AbstractHandlerContainer child.destroy(); super.destroy(); } - - /* ------------------------------------------------------------ */ - @Override - public String toString() - { - Handler[] handlers=getHandlers(); - return super.toString()+(handlers==null?"[]":Arrays.asList(handlers).toString()); - } } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/InetAccessHandler.java b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/InetAccessHandler.java index 0aed271810d..4529f3fa7a8 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/handler/InetAccessHandler.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/handler/InetAccessHandler.java @@ -32,6 +32,7 @@ import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.Request; import org.eclipse.jetty.util.IncludeExcludeSet; import org.eclipse.jetty.util.InetAddressSet; +import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -137,6 +138,8 @@ public class InetAccessHandler extends HandlerWrapper @Override public void dump(Appendable out, String indent) throws IOException { - dumpBeans(out, indent, _set.getIncluded(), _set.getExcluded()); + dumpBeans(out, indent, + DumpableCollection.from("included",_set.getIncluded()), + DumpableCollection.from("excluded",_set.getExcluded())); } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ClassLoaderDumptTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ClassLoaderDumptTest.java index b69e4652f41..3354d9511a6 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ClassLoaderDumptTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ClassLoaderDumptTest.java @@ -48,8 +48,8 @@ public class ClassLoaderDumptTest StringBuilder out = new StringBuilder(); server.dump(out); String dump = out.toString(); - assertThat(dump,containsString("+- SimpleLoader")); - assertThat(dump,containsString("+> "+Server.class.getClassLoader())); + assertThat(dump,containsString("+-SimpleLoader")); + assertThat(dump,containsString("+>"+Server.class.getClassLoader())); } @Test @@ -69,9 +69,9 @@ public class ClassLoaderDumptTest 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())); + assertThat(dump,containsString("+-ParentedLoader")); + assertThat(dump,containsString("| +>"+Server.class.getClassLoader())); + assertThat(dump,containsString("+>"+Server.class.getClassLoader())); } @Test @@ -98,10 +98,10 @@ public class ClassLoaderDumptTest 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())); + assertThat(dump,containsString("+-TopLoader")); + assertThat(dump,containsString("| +>MiddleLoader")); + assertThat(dump,containsString("| +>"+Server.class.getClassLoader())); + assertThat(dump,containsString("+>"+Server.class.getClassLoader())); } @Test @@ -122,10 +122,10 @@ public class ClassLoaderDumptTest 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())); + 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 @@ -184,15 +184,15 @@ public class ClassLoaderDumptTest 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())); + 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())); } } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/BaseHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/BaseHolder.java index ef4ab0e8616..3b244704249 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/BaseHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/BaseHolder.java @@ -27,7 +27,6 @@ import org.eclipse.jetty.server.handler.ContextHandler; import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -194,14 +193,13 @@ public abstract class BaseHolder extends AbstractLifeCycle implements Dumpabl @Override public void dump(Appendable out, String indent) throws IOException { - out.append(toString()) - .append(" - ").append(AbstractLifeCycle.getState(this)).append("\n"); + Dumpable.dumpObject(out, this); } /* ------------------------------------------------------------ */ @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java index 9e214dd7045..b4e03591156 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterHolder.java @@ -34,10 +34,11 @@ import javax.servlet.ServletException; import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.component.Dumpable; +import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; -public class FilterHolder extends Holder +public class FilterHolder extends Holder { private static final Logger LOG = Log.getLogger(FilterHolder.class); @@ -100,10 +101,6 @@ public class FilterHolder extends Holder } } - - - - /* ------------------------------------------------------------ */ @Override @@ -195,21 +192,24 @@ public class FilterHolder extends Holder return _filter; } - /* ------------------------------------------------------------ */ - @Override - public String toString() - { - return getName(); - } - /* ------------------------------------------------------------ */ @Override public void dump(Appendable out, String indent) throws IOException { - super.dump(out, indent); - if(_filter instanceof Dumpable) { - ((Dumpable) _filter).dump(out, indent); - } + if (_initParams.isEmpty()) + Dumpable.dumpObjects(out, indent, this, + _filter == null?getHeldClass():_filter); + else + Dumpable.dumpObjects(out, indent, this, + _filter == null?getHeldClass():_filter, + new DumpableCollection("initParams", _initParams.entrySet())); + } + + /* ------------------------------------------------------------ */ + @Override + public String toString() + { + return String.format("%s@%x==%s,inst=%b,async=%b",_name,hashCode(),_className,_filter!=null,isAsyncSupported()); } /* ------------------------------------------------------------ */ diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java index 50a1f6bf94e..5b66fea8b1d 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/FilterMapping.java @@ -29,7 +29,6 @@ import org.eclipse.jetty.http.PathMap; import org.eclipse.jetty.util.TypeUtil; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; @ManagedObject("Filter Mappings") @@ -334,6 +333,6 @@ public class FilterMapping implements Dumpable @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } } diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java index a2e9924207d..66a16d6f552 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/Holder.java @@ -32,6 +32,7 @@ import javax.servlet.ServletContext; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.ContainerLifeCycle; +import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -45,7 +46,7 @@ import org.eclipse.jetty.util.log.Logger; * @param the type of holder */ @ManagedObject("Holder - a container for servlets and the like") -public class Holder extends BaseHolder +public abstract class Holder extends BaseHolder { private static final Logger LOG = Log.getLogger(Holder.class); @@ -188,15 +189,6 @@ public class Holder extends BaseHolder return _asyncSupported; } - - /* ------------------------------------------------------------ */ - @Override - public void dump(Appendable out, String indent) throws IOException - { - super.dump(out,indent); - ContainerLifeCycle.dump(out,indent,_initParams.entrySet()); - } - /* ------------------------------------------------------------ */ @Override public String dump() diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java index 34adff4bf68..d64b86c98f7 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHandler.java @@ -138,11 +138,11 @@ public class ServletHandler extends ScopedHandler public void dump(Appendable out, String indent) throws IOException { dumpBeans(out,indent, - Collections.singletonList(new DumpableCollection("listeners "+this,_listeners)), - Collections.singletonList(new DumpableCollection("filters "+this,_filters)), - Collections.singletonList(new DumpableCollection("filterMappings "+this,_filterMappings)), - Collections.singletonList(new DumpableCollection("servlets "+this,_servlets)), - Collections.singletonList(new DumpableCollection("servletMappings "+this,_servletMappings))); + DumpableCollection.fromArray("listeners "+this,_listeners), + DumpableCollection.fromArray("filters "+this,_filters), + DumpableCollection.fromArray("filterMappings "+this,_filterMappings), + DumpableCollection.fromArray("servlets "+this,_servlets), + DumpableCollection.fromArray("servletMappings "+this,_servletMappings)); } /* ----------------------------------------------------------------- */ diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java index e4681ab1a52..4ddec3bb15b 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ServletHolder.java @@ -55,6 +55,8 @@ import org.eclipse.jetty.util.Loader; import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; +import org.eclipse.jetty.util.component.Dumpable; +import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -1312,11 +1314,23 @@ public class ServletHolder extends Holder implements UserIdentity.Scope } } + /* ------------------------------------------------------------ */ + @Override + public void dump(Appendable out, String indent) throws IOException + { + if (_initParams.isEmpty()) + Dumpable.dumpObjects(out, indent, this, + _servlet == null?getHeldClass():_servlet); + else + Dumpable.dumpObjects(out, indent, this, + _servlet == null?getHeldClass():_servlet, + new DumpableCollection("initParams", _initParams.entrySet())); + } /* ------------------------------------------------------------ */ @Override public String toString() { - return String.format("%s@%x==%s,jsp=%s,order=%d,inst=%b",_name,hashCode(),_className,_forcedPath,_initOrder,_servlet!=null); + return String.format("%s@%x==%s,jsp=%s,order=%d,inst=%b,async=%b",_name,hashCode(),_className,_forcedPath,_initOrder,_servlet!=null,isAsyncSupported()); } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/AttributesMap.java b/jetty-util/src/main/java/org/eclipse/jetty/util/AttributesMap.java index b086228589a..4ff033d6673 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/AttributesMap.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/AttributesMap.java @@ -18,6 +18,9 @@ package org.eclipse.jetty.util; +import org.eclipse.jetty.util.component.Dumpable; + +import java.io.IOException; import java.util.ArrayList; import java.util.Collections; import java.util.Enumeration; @@ -28,7 +31,7 @@ import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentMap; import java.util.concurrent.atomic.AtomicReference; -public class AttributesMap implements Attributes +public class AttributesMap implements Attributes, Dumpable { private final AtomicReference> _map = new AtomicReference<>(); @@ -148,4 +151,16 @@ public class AttributesMap implements Attributes setAttribute(name, attributes.getAttribute(name)); } } + + @Override + public String dump() + { + return Dumpable.dump(this); + } + + @Override + public void dump(Appendable out, String indent) throws IOException + { + Dumpable.dumpObjects(out,indent,String.format("%s@%x",this.getClass().getSimpleName(),hashCode()),map()); + } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java index 4b6d963969e..fd1f70447cc 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/ContainerLifeCycle.java @@ -230,6 +230,30 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container, return false; } + /** + * @param bean the bean to test + * @return whether this aggregate contains the bean in auto state + */ + public boolean isAuto(Object bean) + { + for (Bean b : _beans) + if (b._bean == bean) + return b._managed==Managed.AUTO; + return false; + } + + /** + * @param bean the bean to test + * @return whether this aggregate contains the bean in auto state + */ + public boolean isUnmanaged(Object bean) + { + for (Bean b : _beans) + if (b._bean == bean) + return b._managed==Managed.UNMANAGED; + return false; + } + /** * Adds the given bean, detecting whether to manage it or not. * If the bean is a {@link LifeCycle}, then it will be managed if it is not @@ -616,6 +640,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container, try { dump(System.err, ""); + System.err.println(Dumpable.KEY); } catch (IOException e) { @@ -627,46 +652,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container, @ManagedOperation("Dump the object to a string") public String dump() { - return dump(this); - } - - public static String dump(Dumpable dumpable) - { - StringBuilder b = new StringBuilder(); - try - { - dumpable.dump(b, ""); - } - catch (IOException e) - { - LOG.warn(e); - } - return b.toString(); - } - - public void dump(Appendable out) throws IOException - { - dump(out, ""); - } - - protected void dumpThis(Appendable out) throws IOException - { - out.append(String.valueOf(this)).append(" - ").append(getState()).append("\n"); - } - - public static void dumpObject(Appendable out, Object o) throws IOException - { - try - { - if (o instanceof LifeCycle) - out.append(String.valueOf(o)).append(" - ").append((AbstractLifeCycle.getState((LifeCycle)o))).append("\n"); - else - out.append(String.valueOf(o)).append("\n"); - } - catch (Throwable th) - { - out.append(" => ").append(th.toString()).append('\n'); - } + return Dumpable.dump(this); } @Override @@ -675,63 +661,41 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container, dumpBeans(out,indent); } - protected void dumpBeans(Appendable out, String indent, Collection... collections) throws IOException + /** + * Dump this object to an Appendable with no indent. + * @param out The appendable to dump to. + * @throws IOException May be thrown by the Appendable + */ + public void dump(Appendable out) throws IOException { - dumpThis(out); - int size = _beans.size(); - for (Collection c : collections) - size += c.size(); - int i = 0; - for (Bean b : _beans) - { - ++i; - switch(b._managed) - { - case POJO: - out.append(indent).append(" +- "); - if (b._bean instanceof Dumpable) - ((Dumpable)b._bean).dump(out, indent + (i == size ? " " : " | ")); - else - dumpObject(out, b._bean); - break; - - case MANAGED: - out.append(indent).append(" += "); - if (b._bean instanceof Dumpable) - ((Dumpable)b._bean).dump(out, indent + (i == size ? " " : " | ")); - else - dumpObject(out, b._bean); - break; - - case UNMANAGED: - out.append(indent).append(" +~ "); - dumpObject(out, b._bean); - break; - - case AUTO: - out.append(indent).append(" +? "); - if (b._bean instanceof Dumpable) - ((Dumpable)b._bean).dump(out, indent + (i == size ? " " : " | ")); - else - dumpObject(out, b._bean); - break; - } - } - - for (Collection c : collections) - { - for (Object o : c) - { - i++; - out.append(indent).append(" +> "); - if (o instanceof Dumpable) - ((Dumpable)o).dump(out, indent + (i == size ? " " : " | ")); - else - dumpObject(out, o); - } - } + dump(out, ""); } + /** + * Dump just this object, but not it's children. Typically used to + * implement {@link #dump(Appendable, String)} + * @param out The appendable to dump to + * @throws IOException May be thrown by the Appendable + */ + @Deprecated + protected void dumpThis(Appendable out) throws IOException + { + out.append(String.valueOf(this)).append(" - ").append(getState()).append("\n"); + } + + + /** Dump this object, it's contained beans and additional items to an Appendable + * @param out The appendable to dump to + * @param indent The indent to apply after any new lines + * @param items Additional items to be dumped as contained. + * @throws IOException May be thrown by the Appendable + */ + protected void dumpBeans(Appendable out, String indent, Object... items) throws IOException + { + Dumpable.dumpObjects(out,indent,this, items); + } + + @Deprecated public static void dump(Appendable out, String indent, Collection... collections) throws IOException { if (collections.length == 0) @@ -749,11 +713,7 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container, { i++; out.append(indent).append(" +- "); - - if (o instanceof Dumpable) - ((Dumpable)o).dump(out, indent + (i == size ? " " : " | ")); - else - dumpObject(out, o); + Dumpable.dumpObjects(out,indent + (i)o).size()); + else + s = String.valueOf(o).replace("\r\n","|").replace("\n","|"); + + if (o instanceof LifeCycle) + out.append(s).append(" - ").append((AbstractLifeCycle.getState((LifeCycle)o))).append("\n"); + else + out.append(s).append("\n"); + } + catch (Throwable th) + { + out.append("=>").append(th.toString()).append("\n"); + } + } + + /** + * Dump an Object, it's contained items and additional items to an {@link Appendable}. + * If the object in an {@link Iterable} or an {@link Array}, then its contained items + * are also dumped. + * @param out the Appendable to dump to + * @param indent The indent to apply after any new lines + * @param object The object to dump. If the object is an instance + * of {@link Container}, {@link Stream}, {@link Iterable}, {@link Array} or {@link Map}, + * then children of the object a recursively dumped. + * @param extraChildren Items to be dumped as children of the object, in addition to any discovered children of object + * @throws IOException May be thrown by the Appendable + */ + static void dumpObjects(Appendable out, String indent, Object object, Object... extraChildren) throws IOException + { + dumpObject(out,object); + + int size = extraChildren==null?0:extraChildren.length; + + if (object instanceof Stream) + object = ((Stream)object).toArray(); + if (object instanceof Array) + object = Arrays.asList((Object[])object); + + if (object instanceof Container) + { + Container container = (Container)object; + ContainerLifeCycle containerLifeCycle = container instanceof ContainerLifeCycle ? (ContainerLifeCycle)container : null; + for (Iterator i = container.getBeans().iterator(); i.hasNext();) + { + Object bean = i.next(); + String nextIndent = indent + ((i.hasNext() || size>0) ? "| " : " "); + if (bean instanceof LifeCycle) + { + if (container.isManaged(bean)) + { + out.append(indent).append("+="); + if (bean instanceof Dumpable) + ((Dumpable)bean).dump(out,nextIndent); + else + dumpObjects(out, nextIndent, bean); + } + else if (containerLifeCycle != null && containerLifeCycle.isAuto(bean)) + { + out.append(indent).append("+?"); + if (bean instanceof Dumpable) + ((Dumpable)bean).dump(out,nextIndent); + else + dumpObjects(out, nextIndent, bean); + } + else + { + out.append(indent).append("+~"); + dumpObject(out, bean); + } + } + else if (containerLifeCycle != null && containerLifeCycle.isUnmanaged(bean)) + { + out.append(indent).append("+~"); + dumpObject(out, bean); + } + else + { + out.append(indent).append("+-"); + if (bean instanceof Dumpable) + ((Dumpable)bean).dump(out,nextIndent); + else + dumpObjects(out, nextIndent, bean); + } + } + } + if (object instanceof Iterable) + { + for (Iterator i = ((Iterable)object).iterator(); i.hasNext();) + { + Object item = i.next(); + String nextIndent = indent + ((i.hasNext() || size>0) ? "| " : " "); + out.append(indent).append("+:"); + if (item instanceof Dumpable) + ((Dumpable)item).dump(out,nextIndent); + else + dumpObjects(out,nextIndent, item); + } + } + else if (object instanceof Map) + { + for (Iterator> i = ((Map)object).entrySet().iterator(); i.hasNext();) + { + Map.Entry entry = i.next(); + String nextIndent = indent + ((i.hasNext() || size>0) ? "| " : " "); + out.append(indent).append("+@").append(String.valueOf(entry.getKey())).append('='); + Object item = entry.getValue(); + if (item instanceof Dumpable) + ((Dumpable)item).dump(out,nextIndent); + else + dumpObjects(out,nextIndent, item); + } + } + + if (size==0) + return; + + int i = 0; + for (Object item : extraChildren) + { + i++; + String nextIndent = indent + (i"); + if (item instanceof Dumpable) + ((Dumpable)item).dump(out,nextIndent); + else + dumpObjects(out, nextIndent, item); + } + } + } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/component/DumpableCollection.java b/jetty-util/src/main/java/org/eclipse/jetty/util/component/DumpableCollection.java index 0fb4c13f139..7e7e4190740 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/component/DumpableCollection.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/component/DumpableCollection.java @@ -34,22 +34,26 @@ public class DumpableCollection implements Dumpable _collection=collection; } - public DumpableCollection(String name,Object... items) + public static DumpableCollection fromArray(String name, Object[] array) { - this(name, items==null?Collections.emptyList():Arrays.asList(items)); + return new DumpableCollection(name,array==null?Collections.emptyList():Arrays.asList(array)); + } + + public static DumpableCollection from(String name, Object... items) + { + return new DumpableCollection(name,items==null?Collections.emptyList():Arrays.asList(items)); } @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override public void dump(Appendable out, String indent) throws IOException { - out.append(_name).append(System.lineSeparator()); - if (_collection!=null) - ContainerLifeCycle.dump(out,indent,_collection); + Object[] array = _collection.toArray(); + Dumpable.dumpObjects(out,indent,_name + " size="+array.length, array); } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java index b86a10f98e6..de50dd90667 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslContextFactory.java @@ -76,7 +76,6 @@ import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -355,18 +354,26 @@ public class SslContextFactory extends AbstractLifeCycle implements Dumpable @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override public void dump(Appendable out, String indent) throws IOException { - out.append(String.valueOf(this)).append(" trustAll=").append(Boolean.toString(_trustAll)).append(System.lineSeparator()); - try { - List selections = selectionDump(); - ContainerLifeCycle.dump(out, indent, selections); + SSLEngine sslEngine = SSLContext.getDefault().createSSLEngine(); + Dumpable.dumpObjects(out, indent, this, "trustAll=" + _trustAll, + new SslSelectionDump("Protocol", + sslEngine.getSupportedProtocols(), + sslEngine.getEnabledProtocols(), + getExcludeProtocols(), + getIncludeProtocols()), + new SslSelectionDump("Cipher Suite", + sslEngine.getSupportedCipherSuites(), + sslEngine.getEnabledCipherSuites(), + getExcludeCipherSuites(), + getIncludeCipherSuites())); } catch (NoSuchAlgorithmException ignore) { diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslSelectionDump.java b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslSelectionDump.java index 0b1069d3797..c30dd82a671 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslSelectionDump.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/ssl/SslSelectionDump.java @@ -35,25 +35,23 @@ class SslSelectionDump extends ContainerLifeCycle implements Dumpable static class CaptionedList extends ArrayList implements Dumpable { private final String caption; - + public CaptionedList(String caption) { this.caption = caption; } - + @Override public String dump() { - return ContainerLifeCycle.dump(SslSelectionDump.CaptionedList.this); + return Dumpable.dump(SslSelectionDump.CaptionedList.this); } - + @Override public void dump(Appendable out, String indent) throws IOException { - out.append(caption); - out.append(" (size=").append(Integer.toString(size())).append(")"); - out.append(System.lineSeparator()); - ContainerLifeCycle.dump(out, indent, this); + Object[] array = toArray(); + Dumpable.dumpObjects(out, indent, caption + " size="+array.length, array); } } @@ -161,7 +159,7 @@ class SslSelectionDump extends ContainerLifeCycle implements Dumpable @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutorThreadPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutorThreadPool.java index 0f6a4c98d89..328a93d8e7f 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutorThreadPool.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ExecutorThreadPool.java @@ -20,7 +20,6 @@ package org.eclipse.jetty.util.thread; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.concurrent.LinkedBlockingQueue; @@ -353,23 +352,27 @@ public class ExecutorThreadPool extends ContainerLifeCycle implements ThreadPool @Override public void dump(Appendable out, String indent) throws IOException { - out.append(String.valueOf(thread.getId())) + StringBuilder b = new StringBuilder(); + b.append(String.valueOf(thread.getId())) .append(" ") .append(thread.getName()) .append(" p=").append(String.valueOf(thread.getPriority())) .append(" ") .append(known) .append(thread.getState().toString()); + + if (isDetailedDump()) { - out.append(System.lineSeparator()); if (known.isEmpty()) - ContainerLifeCycle.dump(out, indent, Arrays.asList(frames)); + Dumpable.dumpObjects(out, indent, b.toString(), (Object[])frames); + else + Dumpable.dumpObject(out, b.toString()); } else { - out.append(" @ ").append(frames.length > 0 ? String.valueOf(frames[0]) : "") - .append(System.lineSeparator()); + b.append(" @ ").append(frames.length > 0 ? String.valueOf(frames[0]) : ""); + Dumpable.dumpObject(out, b.toString()); } } @@ -385,7 +388,7 @@ public class ExecutorThreadPool extends ContainerLifeCycle implements ThreadPool List jobs = Collections.emptyList(); if (isDetailedDump()) jobs = new ArrayList<>(_executor.getQueue()); - dumpBeans(out, indent, threads, Collections.singletonList(new DumpableCollection("jobs - size=" + jobs.size(), jobs))); + dumpBeans(out, indent, threads, new DumpableCollection("jobs", jobs)); } @Override diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java index 72c8e51012b..a35adc3c41d 100755 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/QueuedThreadPool.java @@ -20,7 +20,6 @@ package org.eclipse.jetty.util.thread; import java.io.IOException; import java.util.ArrayList; -import java.util.Arrays; import java.util.Collections; import java.util.List; import java.util.Set; @@ -32,7 +31,6 @@ import java.util.concurrent.atomic.AtomicInteger; import java.util.concurrent.atomic.AtomicLong; import org.eclipse.jetty.util.BlockingArrayQueue; -import org.eclipse.jetty.util.ProcessorUtils; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.annotation.ManagedOperation; @@ -606,12 +604,11 @@ public class QueuedThreadPool extends ContainerLifeCycle implements SizedThreadP @Override public void dump(Appendable out, String indent) throws IOException { - out.append(String.valueOf(thread.getId())).append(' ').append(thread.getName()).append(' ').append(known).append(thread.getState().toString()); - if (thread.getPriority()!=Thread.NORM_PRIORITY) - out.append(" prio=").append(String.valueOf(thread.getPriority())); - out.append(System.lineSeparator()); + String s = thread.getId()+" "+thread.getName()+" "+thread.getState()+" "+thread.getPriority(); if (known.length()==0) - ContainerLifeCycle.dump(out, indent, Arrays.asList(trace)); + Dumpable.dumpObjects(out, indent, s, (Object[])trace); + else + Dumpable.dumpObjects(out, indent, s); } @Override @@ -632,7 +629,7 @@ public class QueuedThreadPool extends ContainerLifeCycle implements SizedThreadP if (isDetailedDump()) jobs = new ArrayList<>(getQueue()); - dumpBeans(out, indent, threads, Collections.singletonList(new DumpableCollection("jobs - size=" + jobs.size(), jobs))); + dumpBeans(out, indent, new DumpableCollection("threads",threads), new DumpableCollection("jobs", jobs)); } @Override diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java index 7925ad43af5..8740dc78326 100755 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/thread/ScheduledExecutorScheduler.java @@ -19,15 +19,12 @@ package org.eclipse.jetty.util.thread; import java.io.IOException; -import java.util.Arrays; -import java.util.List; import java.util.concurrent.ScheduledFuture; import java.util.concurrent.ScheduledThreadPoolExecutor; import java.util.concurrent.ThreadFactory; import java.util.concurrent.TimeUnit; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; /** @@ -109,19 +106,17 @@ public class ScheduledExecutorScheduler extends AbstractLifeCycle implements Sch @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override public void dump(Appendable out, String indent) throws IOException { - ContainerLifeCycle.dumpObject(out, this); Thread thread = this.thread; - if (thread != null) - { - List frames = Arrays.asList(thread.getStackTrace()); - ContainerLifeCycle.dump(out, indent, frames); - } + if (thread == null) + Dumpable.dumpObject(out, this); + else + Dumpable.dumpObjects(out,indent,this, (Object[])thread.getStackTrace()); } private static class ScheduledFutureTask implements Task diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilCanonicalPathTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilCanonicalPathTest.java index cffd41caa0e..fa9fd4288cd 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilCanonicalPathTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/URIUtilCanonicalPathTest.java @@ -119,7 +119,7 @@ public class URIUtilCanonicalPathTest ArrayList ret = new ArrayList<>(); for(String[] args: canonical) { - ret.add(Arguments.of(args)); + ret.add(Arguments.of((Object[])args)); } return ret.stream(); } diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/component/ContainerLifeCycleTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/component/ContainerLifeCycleTest.java index fedc1708db6..1ad73ec321f 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/component/ContainerLifeCycleTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/component/ContainerLifeCycleTest.java @@ -215,59 +215,59 @@ public class ContainerLifeCycleTest a0.addBean(aa0); dump = trim(a0.dump()); dump = check(dump, "ContainerLifeCycl"); - dump = check(dump, " +? ContainerLife"); + dump = check(dump, "+?ContainerLife"); ContainerLifeCycle aa1 = new ContainerLifeCycle(); a0.addBean(aa1); dump = trim(a0.dump()); dump = check(dump, "ContainerLifeCycl"); - dump = check(dump, " +? ContainerLife"); - dump = check(dump, " +? ContainerLife"); + dump = check(dump, "+?ContainerLife"); + dump = check(dump, "+?ContainerLife"); dump = check(dump, ""); ContainerLifeCycle aa2 = new ContainerLifeCycle(); a0.addBean(aa2, false); dump = trim(a0.dump()); dump = check(dump, "ContainerLifeCycl"); - dump = check(dump, " +? ContainerLife"); - dump = check(dump, " +? ContainerLife"); - dump = check(dump, " +~ ContainerLife"); + dump = check(dump, "+?ContainerLife"); + dump = check(dump, "+?ContainerLife"); + dump = check(dump, "+~ContainerLife"); dump = check(dump, ""); aa1.start(); a0.start(); dump = trim(a0.dump()); dump = check(dump, "ContainerLifeCycl"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " +~ ContainerLife"); - dump = check(dump, " +~ ContainerLife"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "+~ContainerLife"); + dump = check(dump, "+~ContainerLife"); dump = check(dump, ""); a0.manage(aa1); a0.removeBean(aa2); dump = trim(a0.dump()); dump = check(dump, "ContainerLifeCycl"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " += ContainerLife"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "+=ContainerLife"); dump = check(dump, ""); ContainerLifeCycle aaa0 = new ContainerLifeCycle(); aa0.addBean(aaa0); dump = trim(a0.dump()); dump = check(dump, "ContainerLifeCycl"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " | +~ Container"); - dump = check(dump, " += ContainerLife"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "| +~Container"); + dump = check(dump, "+=ContainerLife"); dump = check(dump, ""); ContainerLifeCycle aa10 = new ContainerLifeCycle(); aa1.addBean(aa10, true); dump = trim(a0.dump()); dump = check(dump, "ContainerLifeCycl"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " | +~ Container"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " += Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "| +~Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, " +=Container"); dump = check(dump, ""); final ContainerLifeCycle a1 = new ContainerLifeCycle(); @@ -280,63 +280,70 @@ public class ContainerLifeCycleTest @Override public void dump(Appendable out, String indent) throws IOException { - out.append(this.toString()).append("\n"); - dump(out, indent, TypeUtil.asList(new Object[]{a1, a2}), TypeUtil.asList(new Object[]{a3, a4})); + Dumpable.dumpObjects(out, indent, this.toString(), TypeUtil.asList(new Object[]{a1, a2}), TypeUtil.asList(new Object[]{a3, a4})); } }; a0.addBean(aa, true); + + dump = trim(a0.dump()); dump = check(dump, "ContainerLifeCycl"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " | +~ Container"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " | += Container"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " +- Container"); - dump = check(dump, " +- Container"); - dump = check(dump, " +- Container"); - dump = check(dump, " +- Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "| +~Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "| +=Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, " +>java.util.Arrays$ArrayList"); + dump = check(dump, " | +:ContainerLifeCycle"); + dump = check(dump, " | +:ContainerLifeCycle"); + dump = check(dump, " +>java.util.Arrays$ArrayList"); + dump = check(dump, " +:ContainerLifeCycle"); + dump = check(dump, " +:ContainerLifeCycle"); dump = check(dump, ""); a2.addBean(aa0, true); dump = trim(a0.dump()); dump = check(dump, "ContainerLifeCycl"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " | +~ Container"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " | += Container"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " +- Container"); - dump = check(dump, " +- Container"); - dump = check(dump, " | += Conta"); - dump = check(dump, " | +~ C"); - dump = check(dump, " +- Container"); - dump = check(dump, " +- Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "| +~Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "| +=Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, " +>java.util.Arrays$ArrayList"); + dump = check(dump, " | +:ContainerLifeCycle"); + dump = check(dump, " | +:ContainerLifeCycle"); + dump = check(dump, " | +=Conta"); + dump = check(dump, " | +~C"); + dump = check(dump, " +>java.util.Arrays$ArrayList"); + dump = check(dump, " +:ContainerLifeCycle"); + dump = check(dump, " +:ContainerLifeCycle"); dump = check(dump, ""); a2.unmanage(aa0); dump = trim(a0.dump()); dump = check(dump, "ContainerLifeCycl"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " | +~ Container"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " | += Container"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " +- Container"); - dump = check(dump, " +- Container"); - dump = check(dump, " | +~ Conta"); - dump = check(dump, " +- Container"); - dump = check(dump, " +- Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "| +~Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "| +=Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, " +>java.util.Arrays$ArrayList"); + dump = check(dump, " | +:ContainerLifeCycle"); + dump = check(dump, " | +:ContainerLifeCycle"); + dump = check(dump, " | +~Conta"); + dump = check(dump, " +>java.util.Arrays$ArrayList"); + dump = check(dump, " +:ContainerLifeCycle"); + dump = check(dump, " +:ContainerLifeCycle"); dump = check(dump, ""); a0.unmanage(aa); dump = trim(a0.dump()); dump = check(dump, "ContainerLifeCycl"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " | +~ Container"); - dump = check(dump, " += ContainerLife"); - dump = check(dump, " | += Container"); - dump = check(dump, " +~ ContainerLife"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "| +~Container"); + dump = check(dump, "+=ContainerLife"); + dump = check(dump, "| +=Container"); + dump = check(dump, "+~ContainerLife"); dump = check(dump, ""); } diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java index c3594d29bf3..0f735e7933e 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/WebAppContext.java @@ -1068,13 +1068,13 @@ public class WebAppContext extends ServletContextHandler implements WebAppClassL } dumpBeans(out,indent, - Collections.singletonList(new ClassLoaderDump(getClassLoader())), - Collections.singletonList(new DumpableCollection("Systemclasses "+this,system_classes)), - Collections.singletonList(new DumpableCollection("Serverclasses "+this,server_classes)), - 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())) + new ClassLoaderDump(getClassLoader()), + new DumpableCollection("Systemclasses "+this,system_classes), + new DumpableCollection("Serverclasses "+this,server_classes), + new DumpableCollection("Configurations "+this,_configurations), + new DumpableCollection("Handler attributes "+this,((AttributesMap)getAttributes()).getAttributeEntrySet()), + new DumpableCollection("Context attributes "+this,((Context)getServletContext()).getAttributeEntrySet()), + new DumpableCollection("Initparams "+this,getInitParams().entrySet()) ); } diff --git a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java index f34b7ad077c..c732e779bd9 100644 --- a/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java +++ b/jetty-websocket/websocket-client/src/main/java/org/eclipse/jetty/websocket/client/WebSocketClient.java @@ -694,13 +694,6 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketCont getPolicy().setMaxTextMessageBufferSize(max); } - @Override - public void dump(Appendable out, String indent) throws IOException - { - dumpThis(out); - dump(out,indent,getOpenSessions()); - } - public HttpClient getHttpClient() { return this.httpClient; diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java index ee4c7f8b92e..78804518591 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/WebSocketSession.java @@ -21,6 +21,7 @@ package org.eclipse.jetty.websocket.common; import java.io.IOException; import java.net.InetSocketAddress; import java.net.URI; +import java.util.Collections; import java.util.HashMap; import java.util.Iterator; import java.util.List; @@ -38,6 +39,7 @@ import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; +import org.eclipse.jetty.util.component.DumpableCollection; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.thread.ThreadClassLoaderScope; @@ -279,26 +281,9 @@ public class WebSocketSession extends ContainerLifeCycle implements Session, Rem @Override public void dump(Appendable out, String indent) throws IOException { - dumpThis(out); - out.append(indent).append(" +- incomingHandler : "); - if (incomingHandler instanceof Dumpable) - { - ((Dumpable)incomingHandler).dump(out,indent + " "); - } - else - { - out.append(incomingHandler.toString()).append(System.lineSeparator()); - } - - out.append(indent).append(" +- outgoingHandler : "); - if (outgoingHandler instanceof Dumpable) - { - ((Dumpable)outgoingHandler).dump(out,indent + " "); - } - else - { - out.append(outgoingHandler.toString()).append(System.lineSeparator()); - } + dumpBeans(out,indent, + DumpableCollection.from("incoming", incomingHandler), + DumpableCollection.from("outgoing", outgoingHandler)); } @Override diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtension.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtension.java index bf7d1a10486..9cd3b91b304 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtension.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/extensions/AbstractExtension.java @@ -24,7 +24,6 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; import org.eclipse.jetty.util.component.AbstractLifeCycle; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -58,7 +57,7 @@ public abstract class AbstractExtension extends AbstractLifeCycle implements Dum @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override diff --git a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java index b6cd50b1e68..8f32399d2c6 100644 --- a/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java +++ b/jetty-websocket/websocket-common/src/main/java/org/eclipse/jetty/websocket/common/io/AbstractWebSocketConnection.java @@ -33,7 +33,6 @@ import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.EndPoint; import org.eclipse.jetty.util.BufferUtil; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -634,7 +633,7 @@ public abstract class AbstractWebSocketConnection extends AbstractConnection imp @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override diff --git a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java index 4322dc7dcfe..90487b4a129 100644 --- a/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java +++ b/jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketUpgradeFilter.java @@ -39,7 +39,6 @@ import org.eclipse.jetty.servlet.FilterHolder; import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedObject; -import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -275,14 +274,13 @@ public class WebSocketUpgradeFilter implements Filter, MappedWebSocketCreator, D @Override public String dump() { - return ContainerLifeCycle.dump(this); + return Dumpable.dump(this); } @Override public void dump(Appendable out, String indent) throws IOException { - out.append(indent).append(" +- configuration=").append(configuration.toString()).append("\n"); - configuration.dump(out, indent); + Dumpable.dumpObjects(out,indent,this,configuration); } public WebSocketServletFactory getFactory() diff --git a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java index 6d493f2029b..a078dac760e 100644 --- a/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java +++ b/tests/test-webapps/test-jetty-webapp/src/test/java/org/eclipse/jetty/TestServer.java @@ -18,14 +18,6 @@ package org.eclipse.jetty; -import java.io.File; -import java.io.IOException; -import java.lang.management.ManagementFactory; - -import javax.servlet.ServletException; -import javax.servlet.http.HttpServletRequest; -import javax.servlet.http.HttpServletResponse; - import org.eclipse.jetty.jmx.MBeanContainer; import org.eclipse.jetty.security.HashLoginService; import org.eclipse.jetty.server.ForwardedRequestCustomizer; @@ -44,8 +36,8 @@ import org.eclipse.jetty.server.handler.HandlerCollection; import org.eclipse.jetty.server.handler.HandlerWrapper; import org.eclipse.jetty.server.handler.RequestLogHandler; import org.eclipse.jetty.server.handler.ResourceHandler; -import org.eclipse.jetty.server.session.FileSessionDataStore; import org.eclipse.jetty.server.session.DefaultSessionCache; +import org.eclipse.jetty.server.session.FileSessionDataStore; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.StdErrLog; @@ -53,6 +45,16 @@ import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.webapp.WebAppContext; import org.junit.jupiter.api.Disabled; +import javax.servlet.ServletException; +import javax.servlet.http.HttpServletRequest; +import javax.servlet.http.HttpServletResponse; +import java.io.File; +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.nio.file.FileSystems; +import java.nio.file.Files; +import java.nio.file.Path; + @Disabled("Not a test case") public class TestServer { @@ -62,7 +64,12 @@ public class TestServer { ((StdErrLog)Log.getLog()).setSource(false); - String jetty_root = "../../.."; + // TODO don't depend on this file structure + Path jetty_root = FileSystems.getDefault().getPath(".").toAbsolutePath().normalize(); + if (!Files.exists(jetty_root.resolve("VERSION.txt"))) + jetty_root = FileSystems.getDefault().getPath("../../..").toAbsolutePath().normalize(); + if (!Files.exists(jetty_root.resolve("VERSION.txt"))) + throw new IllegalArgumentException(jetty_root.toString()); // Setup Threadpool QueuedThreadPool threadPool = new QueuedThreadPool(); @@ -112,7 +119,7 @@ public class TestServer // Setup context HashLoginService login = new HashLoginService(); login.setName("Test Realm"); - login.setConfig(jetty_root + "/tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/realm.properties"); + login.setConfig(jetty_root.resolve("tests/test-webapps/test-jetty-webapp/src/main/config/demo-base/etc/realm.properties").toString()); server.addBean(login); File log=File.createTempFile("jetty-yyyy_mm_dd", "log"); @@ -125,7 +132,7 @@ public class TestServer WebAppContext webapp = new WebAppContext(); webapp.setContextPath("/test"); webapp.setParentLoaderPriority(true); - webapp.setResourceBase("./src/main/webapp"); + webapp.setResourceBase(jetty_root.resolve("tests/test-webapps/test-jetty-webapp/src/main/webapp").toString()); webapp.setAttribute("testAttribute","testValue"); File sessiondir=File.createTempFile("sessions",null); if (sessiondir.exists()) @@ -141,12 +148,13 @@ public class TestServer contexts.addHandler(webapp); ContextHandler srcroot = new ContextHandler(); - srcroot.setResourceBase("."); + srcroot.setResourceBase(jetty_root.resolve("tests/test-webapps/test-jetty-webapp/src").toString()); srcroot.setHandler(new ResourceHandler()); srcroot.setContextPath("/src"); contexts.addHandler(srcroot); server.start(); + server.dumpStdErr(); server.join(); }