From cd7138131e4f9825c3951059011c337cd95e5a8b Mon Sep 17 00:00:00 2001 From: Yanming Zhou Date: Wed, 12 Sep 2018 10:50:32 +0800 Subject: [PATCH 01/16] Fix outdated bundle vendor Signed-off-by: Yanming Zhou --- .../src/main/java/org/eclipse/jetty/start/StartArgs.java | 2 +- jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java | 2 +- pom.xml | 4 ++-- 3 files changed, 4 insertions(+), 4 deletions(-) diff --git a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java index 89eeebf0a79..5bf6c404d89 100644 --- a/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java +++ b/jetty-start/src/main/java/org/eclipse/jetty/start/StartArgs.java @@ -60,7 +60,7 @@ public class StartArgs if (ver == null) { Package pkg = StartArgs.class.getPackage(); - if ((pkg != null) && "Eclipse.org - Jetty".equals(pkg.getImplementationVendor()) && (pkg.getImplementationVersion() != null)) + if ((pkg != null) && "Eclipse Jetty Project".equals(pkg.getImplementationVendor()) && (pkg.getImplementationVersion() != null)) { ver = pkg.getImplementationVersion(); if (tag == null) diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java b/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java index 56a4d4e28ef..d9636250e44 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/Jetty.java @@ -66,7 +66,7 @@ public class Jetty Package pkg = Jetty.class.getPackage(); if (pkg != null && - "Eclipse.org - Jetty".equals(pkg.getImplementationVendor()) && + "Eclipse Jetty Project".equals(pkg.getImplementationVendor()) && pkg.getImplementationVersion() != null) VERSION = pkg.getImplementationVersion(); else diff --git a/pom.xml b/pom.xml index ef3fcf75261..377b426c387 100644 --- a/pom.xml +++ b/pom.xml @@ -307,7 +307,7 @@ 2 ${project.name} ${bundle-symbolic-name}.source - Eclipse.org - Jetty + Eclipse Jetty Project ${parsedVersion.osgiVersion} ${bundle-symbolic-name};version="${parsedVersion.osgiVersion}";roots:="." @@ -494,7 +494,7 @@ ${project.build.outputDirectory}/META-INF/MANIFEST.MF ${project.version} - Eclipse.org - Jetty + Eclipse Jetty Project ${jetty.url} From 37a85152eb1a6a1aabbee226a660b07c700576aa Mon Sep 17 00:00:00 2001 From: Magnus Reftel Date: Sat, 13 Oct 2018 08:39:15 +0200 Subject: [PATCH 02/16] Improve error message when binding to in-use port Signed-off-by: Magnus Reftel --- .../eclipse/jetty/server/ServerConnector.java | 7 +++- .../jetty/server/ServerConnectorTest.java | 34 +++++++++++++++---- 2 files changed, 34 insertions(+), 7 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java index 3210ed8deb9..f8e9ee1d69c 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java @@ -20,6 +20,7 @@ package org.eclipse.jetty.server; import java.io.Closeable; import java.io.IOException; +import java.net.BindException; import java.net.InetSocketAddress; import java.net.ServerSocket; import java.net.Socket; @@ -336,7 +337,11 @@ public class ServerConnector extends AbstractNetworkConnector InetSocketAddress bindAddress = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort()); serverChannel.socket().setReuseAddress(getReuseAddress()); - serverChannel.socket().bind(bindAddress, getAcceptQueueSize()); + try { + serverChannel.socket().bind(bindAddress, getAcceptQueueSize()); + } catch (BindException e) { + throw new IOException("Failed to bind to " + bindAddress, e); + } } return serverChannel; diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java index 3ae014fb538..19cd1de2ef8 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java @@ -33,8 +33,10 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Field; +import java.net.BindException; import java.net.HttpURLConnection; import java.net.InetSocketAddress; +import java.net.ServerSocket; import java.net.Socket; import java.net.URI; import java.net.URISyntaxException; @@ -55,6 +57,7 @@ import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; +import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class ServerConnectorTest @@ -296,11 +299,30 @@ public class ServerConnectorTest server.stop(); assertThat(connector.getTransport(),Matchers.nullValue()); - - - - - - + } + + @Test + public void testBindToAddressWhichIsInUse() throws Exception { + try (ServerSocket socket = new ServerSocket(0)) { + final int port = socket.getLocalPort(); + + Server server = new Server(); + ServerConnector connector = new ServerConnector(server); + connector.setPort(port); + server.addConnector(connector); + + HandlerList handlers = new HandlerList(); + handlers.addHandler(new DefaultHandler()); + + server.setHandler(handlers); + + try { + server.start(); + Assertions.fail("No exception thrown"); + } catch (IOException e) { + assertThat(e.getCause(), Matchers.instanceOf(BindException.class)); + assertThat(e.getMessage(), Matchers.containsString("0.0.0.0:" + port)); + } + } } } From a10c84c40a8d89e69a2576d148d6cb93014ece99 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 19 Oct 2018 10:20:10 -0500 Subject: [PATCH 03/16] Issue #3001 - making test more resilient to environments without UTF-8 filesystem support --- .../util/resource/FileSystemResourceTest.java | 19 ++++++++++++++++--- 1 file changed, 16 insertions(+), 3 deletions(-) diff --git a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java index e764594f39b..abff1f5fe1b 100644 --- a/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java +++ b/jetty-util/src/test/java/org/eclipse/jetty/util/resource/FileSystemResourceTest.java @@ -1457,9 +1457,22 @@ public class FileSystemResourceTest public void testUtf8Dir(Class resourceClass) throws Exception { Path dir = workDir.getEmptyPathDir(); - Path utf8Dir = dir.resolve("bãm"); - Files.createDirectories(utf8Dir); - + Path utf8Dir; + + try + { + utf8Dir = dir.resolve("bãm"); + Files.createDirectories(utf8Dir); + } + catch (InvalidPathException e) + { + // if unable to create file, no point testing the rest. + // this is the path that occurs if you have a system that doesn't support UTF-8 + // directory names (or you simply don't have a Locale set properly) + assumeTrue(true, "Not supported on this OS"); + return; + } + Path file = utf8Dir.resolve("file.txt"); Files.createFile(file); From 35ea653f73dfb2ed260451d237dcd92264a35b17 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 19 Oct 2018 10:36:26 -0500 Subject: [PATCH 04/16] Fixing PR #3003 - formatting and junit5 syntax Signed-off-by: Joakim Erdfelt --- .../eclipse/jetty/server/ServerConnector.java | 7 +++++-- .../jetty/server/ServerConnectorTest.java | 20 ++++++++----------- 2 files changed, 13 insertions(+), 14 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java b/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java index f8e9ee1d69c..d18b3a08e1a 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/ServerConnector.java @@ -337,9 +337,12 @@ public class ServerConnector extends AbstractNetworkConnector InetSocketAddress bindAddress = getHost() == null ? new InetSocketAddress(getPort()) : new InetSocketAddress(getHost(), getPort()); serverChannel.socket().setReuseAddress(getReuseAddress()); - try { + try + { serverChannel.socket().bind(bindAddress, getAcceptQueueSize()); - } catch (BindException e) { + } + catch (BindException e) + { throw new IOException("Failed to bind to " + bindAddress, e); } } diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java index 19cd1de2ef8..46621475643 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.server; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.anyOf; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.greaterThan; @@ -26,14 +27,13 @@ import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.notNullValue; import static org.junit.jupiter.api.Assertions.assertEquals; import static org.junit.jupiter.api.Assertions.assertSame; -import static org.hamcrest.MatcherAssert.assertThat; +import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Field; -import java.net.BindException; import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.ServerSocket; @@ -57,7 +57,6 @@ import org.eclipse.jetty.server.handler.HandlerList; import org.eclipse.jetty.util.IO; import org.eclipse.jetty.util.log.StacklessLogging; import org.hamcrest.Matchers; -import org.junit.jupiter.api.Assertions; import org.junit.jupiter.api.Test; public class ServerConnectorTest @@ -302,8 +301,10 @@ public class ServerConnectorTest } @Test - public void testBindToAddressWhichIsInUse() throws Exception { - try (ServerSocket socket = new ServerSocket(0)) { + public void testBindToAddressWhichIsInUse() throws Exception + { + try (ServerSocket socket = new ServerSocket(0)) + { final int port = socket.getLocalPort(); Server server = new Server(); @@ -316,13 +317,8 @@ public class ServerConnectorTest server.setHandler(handlers); - try { - server.start(); - Assertions.fail("No exception thrown"); - } catch (IOException e) { - assertThat(e.getCause(), Matchers.instanceOf(BindException.class)); - assertThat(e.getMessage(), Matchers.containsString("0.0.0.0:" + port)); - } + IOException x = assertThrows(IOException.class, () -> server.start()); + assertThat(x.getMessage(), containsString("0.0.0.0:" + port)); } } } From 9e84c1ee930c953265df643c3fd6b22eb8bf50b8 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Fri, 19 Oct 2018 10:38:09 -0500 Subject: [PATCH 05/16] Testing for BindException cause as well Signed-off-by: Joakim Erdfelt --- .../test/java/org/eclipse/jetty/server/ServerConnectorTest.java | 2 ++ 1 file changed, 2 insertions(+) diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java index 46621475643..6642057d8ab 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ServerConnectorTest.java @@ -34,6 +34,7 @@ import java.io.IOException; import java.io.InputStream; import java.io.PrintWriter; import java.lang.reflect.Field; +import java.net.BindException; import java.net.HttpURLConnection; import java.net.InetSocketAddress; import java.net.ServerSocket; @@ -318,6 +319,7 @@ public class ServerConnectorTest server.setHandler(handlers); IOException x = assertThrows(IOException.class, () -> server.start()); + assertThat(x.getCause(), instanceOf(BindException.class)); assertThat(x.getMessage(), containsString("0.0.0.0:" + port)); } } From efdf3c2473eb191d19169bd30742e22ece6365c0 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Sat, 20 Oct 2018 10:15:05 +1100 Subject: [PATCH 06/16] Issue #2970 ensure onComplete is called (#2971) * Issue #2970 ensure onComplete is called * Cleanup after review - single try Signed-off-by: Greg Wilkins --- .../org/eclipse/jetty/server/HttpChannel.java | 45 ++++++++++--------- 1 file changed, 25 insertions(+), 20 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java index 8b490299d21..43ab02dc183 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpChannel.java @@ -481,33 +481,38 @@ public class HttpChannel implements Runnable, HttpOutput.Interceptor case COMPLETE: { - if (!_response.isCommitted() && !_request.isHandled()) + try { - _response.sendError(HttpStatus.NOT_FOUND_404); - } - else - { - // RFC 7230, section 3.3. - int status = _response.getStatus(); - boolean hasContent = !(_request.isHead() || + if (!_response.isCommitted() && !_request.isHandled()) + { + _response.sendError(HttpStatus.NOT_FOUND_404); + } + else + { + // RFC 7230, section 3.3. + int status = _response.getStatus(); + boolean hasContent = !(_request.isHead() || HttpMethod.CONNECT.is(_request.getMethod()) && status == HttpStatus.OK_200 || HttpStatus.isInformational(status) || status == HttpStatus.NO_CONTENT_204 || status == HttpStatus.NOT_MODIFIED_304); - if (hasContent && !_response.isContentComplete(_response.getHttpOutput().getWritten())) - { - if (isCommitted()) - abort(new IOException("insufficient content written")); - else - _response.sendError(HttpStatus.INTERNAL_SERVER_ERROR_500,"insufficient content written"); + if (hasContent && !_response.isContentComplete(_response.getHttpOutput().getWritten())) + { + if (isCommitted()) + abort(new IOException("insufficient content written")); + else + _response.sendError(HttpStatus.INTERNAL_SERVER_ERROR_500, "insufficient content written"); + } } + _response.closeOutput(); + + } + finally + { + _request.setHandled(true); + _state.onComplete(); + onCompleted(); } - _response.closeOutput(); - _request.setHandled(true); - - _state.onComplete(); - - onCompleted(); break loop; } From 15e1c73f9c89905da851344b55ff83e0b7af2584 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Mon, 22 Oct 2018 11:53:59 +1100 Subject: [PATCH 07/16] 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(); } From 0236f4064a01500e4106fe0d70c193cb8364ca99 Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Mon, 22 Oct 2018 22:47:54 +0200 Subject: [PATCH 08/16] Issue #2998 - Cleanup the dump implementation. Fixed dump() in HTTP2Session. Signed-off-by: Simone Bordet --- .../src/main/java/org/eclipse/jetty/http2/HTTP2Session.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) 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 da4f3ad5b69..18a59f95b2d 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,7 +62,6 @@ 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; @@ -1206,7 +1205,7 @@ public abstract class HTTP2Session extends ContainerLifeCycle implements ISessio @Override public void dump(Appendable out, String indent) throws IOException { - Dumpable.dumpObjects(out, indent, this, new DumpableCollection("streams", streams.values())); + dumpBeans(out, indent, new DumpableCollection("streams", streams.values())); } @Override From 8eb21f84a37e08af70c985b56275cec4d19b9bd0 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Tue, 23 Oct 2018 17:18:12 +1100 Subject: [PATCH 09/16] Issue #2998 Add key to DebugListener dump; ensure LoginService dumped only once. --- .../org/eclipse/jetty/security/AbstractLoginService.java | 2 +- .../eclipse/jetty/security/ConstraintSecurityHandler.java | 4 ---- .../main/java/org/eclipse/jetty/server/DebugListener.java | 5 +++++ 3 files changed, 6 insertions(+), 5 deletions(-) diff --git a/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java b/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java index 7e8ea64a9e0..7202a964439 100644 --- a/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java +++ b/jetty-security/src/main/java/org/eclipse/jetty/security/AbstractLoginService.java @@ -153,7 +153,7 @@ public abstract class AbstractLoginService extends AbstractLifeCycle implements @Override public String toString() { - return this.getClass().getSimpleName()+"["+_name+"]"; + return String.format("%s@%x[%s]", this.getClass().getSimpleName(), hashCode(), _name); } 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 6825ecde4d1..4b3b1cbad27 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 @@ -766,11 +766,7 @@ public class ConstraintSecurityHandler extends SecurityHandler implements Constr @Override public void dump(Appendable out,String indent) throws IOException { - // TODO these should all be beans dumpBeans(out,indent, - getLoginService(), - getIdentityService(), - getAuthenticator(), DumpableCollection.from("roles",_roles), DumpableCollection.from("constraints",_constraintMap.entrySet())); } diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/DebugListener.java b/jetty-server/src/main/java/org/eclipse/jetty/server/DebugListener.java index 7df261f9918..8b11dde9228 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/DebugListener.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/DebugListener.java @@ -42,6 +42,7 @@ 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.AbstractLifeCycle; +import org.eclipse.jetty.util.component.Dumpable; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; @@ -127,12 +128,16 @@ public class DebugListener extends AbstractLifeCycle implements ServletContextLi if (_dumpContext) { if (_out==null) + { handler.dumpStdErr(); + System.err.println(Dumpable.KEY); + } else { try { handler.dump(_out); + _out.println(Dumpable.KEY); } catch(Exception e) { From 4ababf9888e46593f788535a6ece11414f866ed6 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Tue, 23 Oct 2018 17:29:54 +1100 Subject: [PATCH 10/16] Issue #294 Initial enter scope for DebugListener (#3021) Signed-off-by: Jan Bartel --- .../java/org/eclipse/jetty/server/handler/ContextHandler.java | 4 ++++ 1 file changed, 4 insertions(+) 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 ae7003247f2..503147a9963 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 @@ -678,7 +678,11 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu _durableListeners.add(listener); if (listener instanceof ContextScopeListener) + { _contextListeners.add((ContextScopeListener)listener); + if (__context.get()!=null) + ((ContextScopeListener)listener).enterScope(__context.get(),null,"Listener registered"); + } if (listener instanceof ServletContextListener) _servletContextListeners.add((ServletContextListener)listener); From a0cefea29fd012a66ac2f31a501076400e76caa4 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Tue, 23 Oct 2018 17:59:24 +1100 Subject: [PATCH 11/16] Issue #2903 Fix ListenerHolder.setListner (#3019) Signed-off-by: Jan Bartel --- .../src/main/java/org/eclipse/jetty/servlet/ListenerHolder.java | 1 - 1 file changed, 1 deletion(-) diff --git a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ListenerHolder.java b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ListenerHolder.java index b3aa0e4c845..c8ab56b5ffc 100644 --- a/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ListenerHolder.java +++ b/jetty-servlet/src/main/java/org/eclipse/jetty/servlet/ListenerHolder.java @@ -71,7 +71,6 @@ public class ListenerHolder extends BaseHolder _listener = listener; _extInstance=true; setHeldClass(_listener.getClass()); - setClassName(_listener.getClass().getName()); } From 66d6ea67995e6889b13a5f0fb2f2b4a097af442f Mon Sep 17 00:00:00 2001 From: Simone Bordet Date: Tue, 23 Oct 2018 12:05:32 +0200 Subject: [PATCH 12/16] Issue #2998 - Cleanup the dump implementation. Fixed dump() in QueuedThreadPool. When the dump was not detailed, it was printing jobs=0 even if there were jobs in the queue. Given that it was adding no information (actually misleading information) and that the queue size is already reported by QueuedThreadPool.toString() the jobs are not dumped if the dump is not detailed. Signed-off-by: Simone Bordet --- .../eclipse/jetty/util/thread/QueuedThreadPool.java | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) 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 a35adc3c41d..57f1986cc57 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.Collections; import java.util.List; import java.util.Set; import java.util.concurrent.BlockingQueue; @@ -625,11 +624,15 @@ public class QueuedThreadPool extends ContainerLifeCycle implements SizedThreadP } } - List jobs = Collections.emptyList(); if (isDetailedDump()) - jobs = new ArrayList<>(getQueue()); - - dumpBeans(out, indent, new DumpableCollection("threads",threads), new DumpableCollection("jobs", jobs)); + { + List jobs = new ArrayList<>(getQueue()); + dumpBeans(out, indent, new DumpableCollection("threads", threads), new DumpableCollection("jobs", jobs)); + } + else + { + dumpBeans(out, indent, new DumpableCollection("threads", threads)); + } } @Override From 8500e806ecffb699546cf530725b30e4651f4d55 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Wed, 24 Oct 2018 19:02:31 +1000 Subject: [PATCH 13/16] align used algorithm to detect java bin to use (#3025) add javaPath for JettyRunDistro mojo to force a java executable to use Signed-off-by: olivier lamy --- .../development/maven/jetty-maven-plugin.adoc | 6 +++ .../jetty-simple-webapp/pom.xml | 1 + .../jetty/maven/plugin/JettyRunDistro.java | 15 ++++-- .../maven/plugin/JettyRunForkedMojo.java | 54 +++++-------------- .../jetty/maven/plugin/JettyRunMojo.java | 40 ++++++++++++++ 5 files changed, 71 insertions(+), 45 deletions(-) diff --git a/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc b/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc index 93e404d0258..a0fd6bacc42 100644 --- a/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc +++ b/jetty-documentation/src/main/asciidoc/development/maven/jetty-maven-plugin.adoc @@ -624,6 +624,9 @@ Only relevant if `waitForChild` is `false`. forkWebXml:: Default is `target/fork-web.xml`. This is the name of the file into which jetty generates the effective web.xml for use by the child process. +javaPath:: +Default will be your `${java.home}/bin/java` +This the java executable used to start the child process The following `jetty:run` parameters are NOT applicable: @@ -715,6 +718,9 @@ maxChildCheckInterval:: Default value 100. This is the interval in milliseconds between checks to see if the child started correctly. Only applicable if `waitForChild` is `false`. +javaPath:: +Default will be your `${java.home}/bin/java` +This the java executable used to start the child process ____ [NOTE] diff --git a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml index a1d4c8c1ea1..5237db3ddcb 100644 --- a/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml +++ b/jetty-maven-plugin/src/it/jetty-run-distro-mojo-it/jetty-simple-webapp/pom.xml @@ -93,6 +93,7 @@ ${basedir}/src/base + ${java.home}/bin/java jetty.server.dumpAfterStart=true jetty.port.file=${jetty.port.file} diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java index 1a1fc463be4..d5a502e5f50 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunDistro.java @@ -198,8 +198,10 @@ public class JettyRunDistro extends JettyRunMojo private Random random; private Path tokenFile; - - + + @Parameter(property = "jetty.javaPath") + private String javaPath; + /** * @see org.eclipse.jetty.maven.plugin.JettyRunMojo#execute() */ @@ -492,7 +494,14 @@ public class JettyRunDistro extends JettyRunMojo public ProcessBuilder configureCommand() { List cmd = new ArrayList<>(); - cmd.add("java"); + if(StringUtil.isNotBlank( javaPath )) + { + cmd.add( javaPath ); + } + else + { + cmd.add( getJavaBin() ); + } cmd.add("-jar"); cmd.add(new File(jettyHome, "start.jar").getAbsolutePath()); diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java index e0df458fdf9..5ff79475c8a 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunForkedMojo.java @@ -44,6 +44,7 @@ import org.apache.maven.plugins.annotations.Parameter; import org.apache.maven.plugins.annotations.ResolutionScope; import org.eclipse.jetty.annotations.AnnotationConfiguration; import org.eclipse.jetty.server.Server; +import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.resource.Resource; import org.eclipse.jetty.util.thread.QueuedThreadPool; @@ -151,7 +152,9 @@ public class JettyRunForkedMojo extends JettyRunMojo * pom has an explicit dependency on it. */ private boolean hasSlf4jDeps; - + + @Parameter(property = "jetty.javaPath") + private String javaPath; /** * ShutdownThread @@ -271,7 +274,14 @@ public class JettyRunForkedMojo extends JettyRunMojo tpool.stop(); List cmd = new ArrayList<>(); - cmd.add(getJavaBin()); + if( StringUtil.isNotBlank( javaPath )) + { + cmd.add( javaPath ); + } + else + { + cmd.add( getJavaBin() ); + } if (jvmArgs != null) { @@ -307,7 +317,6 @@ public class JettyRunForkedMojo extends JettyRunMojo cmd.add("--props"); cmd.add(props.getAbsolutePath()); - String token = createToken(); Path tokenFile = target.toPath().resolve(createToken()+".txt"); cmd.add("--token"); cmd.add(tokenFile.toAbsolutePath().toString()); @@ -508,46 +517,7 @@ public class JettyRunForkedMojo extends JettyRunMojo return classPath.toString(); } - - - /** - * @return - */ - private String getJavaBin() - { - String javaexes[] = new String[] - { "java", "java.exe" }; - - File javaHomeDir = new File(System.getProperty("java.home")); - for (String javaexe : javaexes) - { - File javabin = new File(javaHomeDir,fileSeparators("bin/" + javaexe)); - if (javabin.exists() && javabin.isFile()) - { - return javabin.getAbsolutePath(); - } - } - - return "java"; - } - - public static String fileSeparators(String path) - { - StringBuilder ret = new StringBuilder(); - for (char c : path.toCharArray()) - { - if ((c == '/') || (c == '\\')) - { - ret.append(File.separatorChar); - } - else - { - ret.append(c); - } - } - return ret.toString(); - } public static String pathSeparators(String path) { diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java index a29d5beb2fb..038e3a83a82 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyRunMojo.java @@ -738,4 +738,44 @@ public class JettyRunMojo extends AbstractJettyMojo return null; } + + + + /** + * @return + */ + protected String getJavaBin() + { + String javaexes[] = new String[] + { "java", "java.exe" }; + + File javaHomeDir = new File(System.getProperty("java.home")); + for (String javaexe : javaexes) + { + File javabin = new File(javaHomeDir,fileSeparators("bin/" + javaexe)); + if (javabin.exists() && javabin.isFile()) + { + return javabin.getAbsolutePath(); + } + } + + return "java"; + } + + public static String fileSeparators(String path) + { + StringBuilder ret = new StringBuilder(); + for (char c : path.toCharArray()) + { + if ((c == '/') || (c == '\\')) + { + ret.append(File.separatorChar); + } + else + { + ret.append(c); + } + } + return ret.toString(); + } } From 898560bec57d94e90c595d4f44d1744ab2cf13b9 Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Fri, 26 Oct 2018 06:44:40 +1100 Subject: [PATCH 14/16] Issue #3030 Enforce Content-Encoding check only on parameter extraction. (#3031) --- .../org/eclipse/jetty/server/Request.java | 11 +++--- .../org/eclipse/jetty/server/RequestTest.java | 34 +++++++++++++++++-- 2 files changed, 36 insertions(+), 9 deletions(-) diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java index 32c3b446b05..ac5198063a5 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/Request.java @@ -455,23 +455,21 @@ public class Request implements HttpServletRequest /* ------------------------------------------------------------ */ private void extractContentParameters() { - // Content cannot be encoded - if (_metaData!=null && getHttpFields().contains(HttpHeader.CONTENT_ENCODING)) - throw new BadMessageException(HttpStatus.NOT_IMPLEMENTED_501,"Unsupported Content-Encoding"); - String contentType = getContentType(); if (contentType == null || contentType.isEmpty()) _contentParameters=NO_PARAMS; else { _contentParameters=new MultiMap<>(); - contentType = HttpFields.valueParameters(contentType, null); int contentLength = getContentLength(); if (contentLength != 0 && _inputState == __NONE) { + contentType = HttpFields.valueParameters(contentType, null); if (MimeTypes.Type.FORM_ENCODED.is(contentType) && _channel.getHttpConfiguration().isFormEncodedMethod(getMethod())) { + if (_metaData!=null && getHttpFields().contains(HttpHeader.CONTENT_ENCODING)) + throw new BadMessageException(HttpStatus.NOT_IMPLEMENTED_501,"Unsupported Content-Encoding"); extractFormParameters(_contentParameters); } else if (MimeTypes.Type.MULTIPART_FORM_DATA.is(contentType) && @@ -480,6 +478,8 @@ public class Request implements HttpServletRequest { try { + if (_metaData!=null && getHttpFields().contains(HttpHeader.CONTENT_ENCODING)) + throw new BadMessageException(HttpStatus.NOT_IMPLEMENTED_501,"Unsupported Content-Encoding"); getParts(_contentParameters); } catch (IOException | ServletException e) @@ -490,7 +490,6 @@ public class Request implements HttpServletRequest } } } - } /* ------------------------------------------------------------ */ diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java index b7add70fecf..802e7b10a28 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/RequestTest.java @@ -18,6 +18,7 @@ package org.eclipse.jetty.server; +import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.Matchers.containsString; import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.not; @@ -28,7 +29,6 @@ import static org.junit.jupiter.api.Assertions.assertNotNull; import static org.junit.jupiter.api.Assertions.assertNotSame; import static org.junit.jupiter.api.Assertions.assertNull; import static org.junit.jupiter.api.Assertions.assertSame; -import static org.hamcrest.MatcherAssert.assertThat; import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertTrue; import static org.junit.jupiter.api.Assertions.fail; @@ -634,7 +634,7 @@ public class RequestTest }; //Send a request with encoded form content - String request="GET / HTTP/1.1\r\n"+ + String request="POST / HTTP/1.1\r\n"+ "Host: whatever\r\n"+ "Content-Type: application/x-www-form-urlencoded; charset=utf-8\n"+ "Content-Length: 10\n"+ @@ -647,6 +647,34 @@ public class RequestTest assertThat(responses,startsWith("HTTP/1.1 200")); } + + @Test + public void testEncodedNotParams() throws Exception + { + _handler._checker = new RequestTester() + { + @Override + public boolean check(HttpServletRequest request,HttpServletResponse response) + { + return request.getParameter("param")==null; + } + }; + + //Send a request with encoded form content + String request="POST / HTTP/1.1\r\n"+ + "Host: whatever\r\n"+ + "Content-Type: application/octet-stream\n"+ + "Content-Length: 10\n"+ + "Content-Encoding: gzip\n"+ + "Connection: close\n"+ + "\n"+ + "0123456789\n"; + + String responses=_connector.getResponse(request); + assertThat(responses,startsWith("HTTP/1.1 200")); + } + + @Test public void testInvalidHostHeader() throws Exception { @@ -1815,7 +1843,7 @@ public class RequestTest ((Request)request).setHandled(true); if (request.getContentLength()>0 - && !MimeTypes.Type.FORM_ENCODED.asString().equals(request.getContentType()) + && !request.getContentType().startsWith(MimeTypes.Type.FORM_ENCODED.asString()) && !request.getContentType().startsWith("multipart/form-data")) _content=IO.toString(request.getInputStream()); From b19d9b27abceb6536b879b8e6caf7a1761b18f6a Mon Sep 17 00:00:00 2001 From: olivier lamy Date: Fri, 26 Oct 2018 12:38:11 +1000 Subject: [PATCH 15/16] use maven pmd plugin 3.11.0 Signed-off-by: olivier lamy --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index c25b37051f4..18221c13ddc 100644 --- a/pom.xml +++ b/pom.xml @@ -529,7 +529,7 @@ org.apache.maven.plugins maven-pmd-plugin - 3.10.0 + 3.11.0 org.apache.maven.plugins From 542872cd758164a51e93eb52aa07f76f34cee662 Mon Sep 17 00:00:00 2001 From: Olivier Lamy Date: Mon, 29 Oct 2018 18:18:02 +1000 Subject: [PATCH 16/16] fix duplicate dependency javax.transaction-api --- examples/embedded/pom.xml | 4 ---- 1 file changed, 4 deletions(-) diff --git a/examples/embedded/pom.xml b/examples/embedded/pom.xml index 1fcade91b31..ea373830aea 100644 --- a/examples/embedded/pom.xml +++ b/examples/embedded/pom.xml @@ -95,10 +95,6 @@ test-mock-resources ${project.version} - - javax.transaction - javax.transaction-api - org.eclipse.jetty jetty-proxy