From 43ab14454aa7c4520bcb500669f7fadcb12ebb6f Mon Sep 17 00:00:00 2001
From: Greg Wilkins
Date: Wed, 17 Oct 2018 17:14:26 +1100
Subject: [PATCH] Some dump cleanups
Signed-off-by: Greg Wilkins
---
.../eclipse/jetty/servlet/FilterHolder.java | 12 ++++---
.../util/component/ContainerLifeCycle.java | 1 +
.../jetty/webapp/AbstractConfiguration.java | 1 -
.../eclipse/jetty/webapp/Configurations.java | 26 ++++++++++++--
.../java/org/eclipse/jetty/TestServer.java | 36 ++++++++++++-------
5 files changed, 55 insertions(+), 21 deletions(-)
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..a4ca11b2068 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
@@ -22,6 +22,7 @@ import java.io.IOException;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collection;
+import java.util.Collections;
import java.util.EnumSet;
import java.util.List;
@@ -33,7 +34,10 @@ import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import org.eclipse.jetty.util.TypeUtil;
+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.component.DumpableCollection;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@@ -206,10 +210,10 @@ public class FilterHolder extends Holder
@Override
public void dump(Appendable out, String indent) throws IOException
{
- super.dump(out, indent);
- if(_filter instanceof Dumpable) {
- ((Dumpable) _filter).dump(out, indent);
- }
+ out.append(toString()).append(" - ").append(AbstractLifeCycle.getState(this)).append('\n');
+ ContainerLifeCycle.dump(out,indent,
+ Collections.singletonList(_filter),
+ Collections.singletonList(new DumpableCollection("initParams", _initParams.entrySet())));
}
/* ------------------------------------------------------------ */
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 bdf5a4385eb..cc46c3548dd 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
@@ -20,6 +20,7 @@ package org.eclipse.jetty.util.component;
import java.io.IOException;
import java.util.ArrayList;
+import java.util.Arrays;
import java.util.Collection;
import java.util.Collections;
import java.util.HashSet;
diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/AbstractConfiguration.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/AbstractConfiguration.java
index ec7b793edec..19500931aba 100644
--- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/AbstractConfiguration.java
+++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/AbstractConfiguration.java
@@ -26,7 +26,6 @@ import java.util.stream.Collectors;
public class AbstractConfiguration implements Configuration
{
- protected static final boolean ENABLE_BY_DEFAULT = true;
private final boolean _disabledByDefault;
private final List _after=new ArrayList<>();
private final List _beforeThis=new ArrayList<>();
diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java
index d392436d4d7..e81be2949b4 100644
--- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java
+++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/Configurations.java
@@ -18,10 +18,12 @@
package org.eclipse.jetty.webapp;
+import java.io.IOException;
import java.lang.reflect.InvocationTargetException;
import java.util.AbstractList;
import java.util.ArrayList;
import java.util.Arrays;
+import java.util.Collection;
import java.util.Collections;
import java.util.ConcurrentModificationException;
import java.util.HashMap;
@@ -38,6 +40,9 @@ import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.util.Loader;
import org.eclipse.jetty.util.TopologicalSort;
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.DumpableCollection;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
@@ -60,7 +65,7 @@ import org.eclipse.jetty.util.log.Logger;
* type.
*
*/
-public class Configurations extends AbstractList
+public class Configurations extends AbstractList implements Dumpable
{
private static final Logger LOG = Log.getLogger(Configurations.class);
@@ -440,7 +445,7 @@ public class Configurations extends AbstractList
@Override
public String toString()
{
- return getConfigurations().toString();
+ return String.format("%s@%x",this.getClass(),this.hashCode());
}
public void preConfigure(WebAppContext webapp) throws Exception
@@ -487,5 +492,20 @@ public class Configurations extends AbstractList
configuration.postConfigure(webapp);
}
}
-
+
+ @Override
+ public String dump()
+ {
+ return ContainerLifeCycle.dump(this);
+ }
+
+ @Override
+ public void dump(Appendable out, String indent) throws IOException
+ {
+ ContainerLifeCycle.dumpObject(out, this);
+ ContainerLifeCycle.dump(out,indent,
+ Collections.singletonList(new DumpableCollection("Known",Configurations.getKnown())),
+ Collections.singletonList(new DumpableCollection("Configurations",this)));
+
+ }
}
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..7183e54d71c 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,15 +36,26 @@ 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;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
+import org.eclipse.jetty.webapp.Configurations;
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 +65,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();
@@ -70,6 +78,7 @@ public class TestServer
// Setup server
Server server = new Server(threadPool);
+ Configurations.setServerDefault(server);
server.manage(threadPool);
// Setup JMX
@@ -112,7 +121,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 +134,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 +150,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();
}