From 5b5a2e845b51f380951ceff399c7976a8fd725b2 Mon Sep 17 00:00:00 2001 From: Joakim Erdfelt Date: Wed, 23 Nov 2016 06:05:35 -0700 Subject: [PATCH 1/3] Removing commented out debug code --- .../jetty/server/ThreadStarvationTest.java | 26 ------------------- 1 file changed, 26 deletions(-) diff --git a/jetty-server/src/test/java/org/eclipse/jetty/server/ThreadStarvationTest.java b/jetty-server/src/test/java/org/eclipse/jetty/server/ThreadStarvationTest.java index d51241e7167..7d19f56f2f8 100644 --- a/jetty-server/src/test/java/org/eclipse/jetty/server/ThreadStarvationTest.java +++ b/jetty-server/src/test/java/org/eclipse/jetty/server/ThreadStarvationTest.java @@ -27,7 +27,6 @@ import java.io.IOException; import java.io.InputStream; import java.io.OutputStream; import java.net.Socket; -import java.nio.channels.SelectionKey; import java.nio.charset.StandardCharsets; import java.nio.file.Path; import java.util.ArrayList; @@ -50,7 +49,6 @@ import javax.servlet.http.HttpServletResponse; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.LeakTrackingByteBufferPool; -import org.eclipse.jetty.io.ManagedSelector; import org.eclipse.jetty.io.MappedByteBufferPool; import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.toolchain.test.MavenTestingUtils; @@ -245,30 +243,6 @@ public class ThreadStarvationTest }); } -// new Thread(()->{ -// try -// { -// TimeUnit.SECONDS.sleep(10); -// -// ServerConnector conn = _server.getBean(ServerConnector.class); -// ManagedSelector ms = conn.getSelectorManager().getBean(ManagedSelector.class); -// -// Selector sel = ms.getSelector(); -// sel.keys().stream().map((key)->key.attachment()).forEach( -// (attach) -> { -// System.out.println(attach); -// SocketChannelEndPoint endp = (SocketChannelEndPoint) attach; -// SslConnection sslconn = (SslConnection) endp.getConnection(); -// sslconn.dumpBuffers(); -// }); -// -// _server.dump(System.out, ""); -// } -// catch (Throwable ignore) -// { -// } -// }).start(); - try { List> responses = clientExecutors.invokeAll(clientTasks, 60, TimeUnit.SECONDS); From deac849325beda375277dff6942d48bf747c2aee Mon Sep 17 00:00:00 2001 From: Greg Wilkins Date: Thu, 24 Nov 2016 10:18:06 +1100 Subject: [PATCH 2/3] Fixes #1127 Fixes #1127 by updating #1074 solution. Spurious calls to HttpInput.run can be ignored. Hide some more test stacks --- .../proxy/AsyncMiddleManServletTest.java | 137 +++++++++--------- .../org/eclipse/jetty/server/HttpInput.java | 2 +- .../jetty/util/log/StacklessLogging.java | 4 +- 3 files changed, 75 insertions(+), 68 deletions(-) diff --git a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java index a40071dd3e3..6ad94fdbce9 100644 --- a/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java +++ b/jetty-proxy/src/test/java/org/eclipse/jetty/proxy/AsyncMiddleManServletTest.java @@ -63,6 +63,7 @@ import org.eclipse.jetty.http.HttpHeader; import org.eclipse.jetty.http.HttpHeaderValue; import org.eclipse.jetty.http.HttpStatus; import org.eclipse.jetty.io.RuntimeIOException; +import org.eclipse.jetty.server.HttpChannel; import org.eclipse.jetty.server.HttpConfiguration; import org.eclipse.jetty.server.HttpConnectionFactory; import org.eclipse.jetty.server.Server; @@ -518,49 +519,52 @@ public class AsyncMiddleManServletTest @Test public void testUpstreamTransformationThrowsAfterCommittingProxyRequest() throws Exception { - startServer(new EchoHttpServlet()); - startProxy(new AsyncMiddleManServlet() + try (StacklessLogging scope = new StacklessLogging(HttpChannel.class)) { - @Override - protected ContentTransformer newClientRequestContentTransformer(HttpServletRequest clientRequest, Request proxyRequest) + startServer(new EchoHttpServlet()); + startProxy(new AsyncMiddleManServlet() { - return new ContentTransformer() + @Override + protected ContentTransformer newClientRequestContentTransformer(HttpServletRequest clientRequest, Request proxyRequest) { - private int count; - - @Override - public void transform(ByteBuffer input, boolean finished, List output) throws IOException + return new ContentTransformer() { - if (++count < 2) - output.add(input); - else - throw new NullPointerException("explicitly_thrown_by_test"); - } - }; - } - }); - startClient(); + private int count; - final CountDownLatch latch = new CountDownLatch(1); - DeferredContentProvider content = new DeferredContentProvider(); - client.newRequest("localhost", serverConnector.getLocalPort()) - .content(content) - .send(new Response.CompleteListener() + @Override + public void transform(ByteBuffer input, boolean finished, List output) throws IOException + { + if (++count < 2) + output.add(input); + else + throw new NullPointerException("explicitly_thrown_by_test"); + } + }; + } + }); + startClient(); + + final CountDownLatch latch = new CountDownLatch(1); + DeferredContentProvider content = new DeferredContentProvider(); + client.newRequest("localhost", serverConnector.getLocalPort()) + .content(content) + .send(new Response.CompleteListener() + { + @Override + public void onComplete(Result result) { - @Override - public void onComplete(Result result) - { - if (result.isSucceeded() && result.getResponse().getStatus() == 502) - latch.countDown(); - } - }); + if (result.isSucceeded() && result.getResponse().getStatus() == 502) + latch.countDown(); + } + }); - content.offer(ByteBuffer.allocate(512)); - sleep(1000); - content.offer(ByteBuffer.allocate(512)); - content.close(); + content.offer(ByteBuffer.allocate(512)); + sleep(1000); + content.offer(ByteBuffer.allocate(512)); + content.close(); - Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); + Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); + } } @Test @@ -791,41 +795,44 @@ public class AsyncMiddleManServletTest @Test public void testClientRequestReadFailsOnSecondRead() throws Exception { - startServer(new EchoHttpServlet()); - startProxy(new AsyncMiddleManServlet() + try (StacklessLogging scope = new StacklessLogging(HttpChannel.class)) { - private int count; - - @Override - protected int readClientRequestContent(ServletInputStream input, byte[] buffer) throws IOException + startServer(new EchoHttpServlet()); + startProxy(new AsyncMiddleManServlet() { - if (++count < 2) - return super.readClientRequestContent(input, buffer); - else - throw new IOException("explicitly_thrown_by_test"); - } - }); - startClient(); + private int count; - final CountDownLatch latch = new CountDownLatch(1); - DeferredContentProvider content = new DeferredContentProvider(); - client.newRequest("localhost", serverConnector.getLocalPort()) - .content(content) - .send(new Response.CompleteListener() + @Override + protected int readClientRequestContent(ServletInputStream input, byte[] buffer) throws IOException { - @Override - public void onComplete(Result result) - { - if (result.getResponse().getStatus() == 502) - latch.countDown(); - } - }); - content.offer(ByteBuffer.allocate(512)); - sleep(1000); - content.offer(ByteBuffer.allocate(512)); - content.close(); + if (++count < 2) + return super.readClientRequestContent(input, buffer); + else + throw new IOException("explicitly_thrown_by_test"); + } + }); + startClient(); - Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); + final CountDownLatch latch = new CountDownLatch(1); + DeferredContentProvider content = new DeferredContentProvider(); + client.newRequest("localhost", serverConnector.getLocalPort()) + .content(content) + .send(new Response.CompleteListener() + { + @Override + public void onComplete(Result result) + { + if (result.getResponse().getStatus() == 502) + latch.countDown(); + } + }); + content.offer(ByteBuffer.allocate(512)); + sleep(1000); + content.offer(ByteBuffer.allocate(512)); + content.close(); + + Assert.assertTrue(latch.await(5, TimeUnit.SECONDS)); + } } @Test diff --git a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java index f524e237cba..e581f9f83f1 100644 --- a/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java +++ b/jetty-server/src/main/java/org/eclipse/jetty/server/HttpInput.java @@ -842,7 +842,7 @@ public class HttpInput extends ServletInputStream implements Runnable } } else if (content==null) - throw new IllegalStateException(); + return; } } diff --git a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StacklessLogging.java b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StacklessLogging.java index 6fbf0b6faf4..5e07861790f 100644 --- a/jetty-util/src/main/java/org/eclipse/jetty/util/log/StacklessLogging.java +++ b/jetty-util/src/main/java/org/eclipse/jetty/util/log/StacklessLogging.java @@ -46,7 +46,7 @@ public class StacklessLogging implements AutoCloseable { Logger log = Log.getLogger(clazz); // only operate on loggers that are of type StdErrLog - if (log instanceof StdErrLog) + if (log instanceof StdErrLog && !log.isDebugEnabled()) { StdErrLog stdErrLog=((StdErrLog)log); if (!stdErrLog.isHideStacks()) @@ -63,7 +63,7 @@ public class StacklessLogging implements AutoCloseable for (Logger log : logs) { // only operate on loggers that are of type StdErrLog - if (log instanceof StdErrLog) + if (log instanceof StdErrLog && !log.isDebugEnabled()) { StdErrLog stdErrLog=((StdErrLog)log); if (!stdErrLog.isHideStacks()) From 40d9e56d92de06a73af5e197204192ddea993907 Mon Sep 17 00:00:00 2001 From: Jan Bartel Date: Thu, 24 Nov 2016 14:04:37 +1100 Subject: [PATCH 3/3] Issue #1117 --- .../maven/plugin/JettyEffectiveWebXml.java | 5 +-- .../maven/plugin/JettyWebAppContext.java | 36 ++++++++++++++++++- .../QuickStartDescriptorGenerator.java | 14 ++++++-- .../jetty/quickstart/QuickStartWebApp.java | 34 +++++++++++++++++- .../org/eclipse/jetty/webapp/MetaData.java | 2 +- 5 files changed, 83 insertions(+), 8 deletions(-) diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java index b5bb983d2df..e28200cc7e2 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyEffectiveWebXml.java @@ -49,13 +49,14 @@ public class JettyEffectiveWebXml extends JettyRunMojo protected File target; /** - * The target directory + * The name of the file to generate into * * @parameter */ protected File effectiveWebXml; + protected boolean deleteOnExit = true; @@ -91,12 +92,12 @@ public class JettyEffectiveWebXml extends JettyRunMojo //ensure config of the webapp based on settings in plugin configureWebApplication(); - //set the webapp up to do very little other than generate the quickstart-web.xml webApp.setCopyWebDir(false); webApp.setCopyWebInf(false); webApp.setGenerateQuickStart(true); + //if the user didn't nominate a file to generate into, pick the name and //make sure that it is deleted on exit if (webApp.getQuickStartWebDescriptor() == null) diff --git a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java index 20529c513ba..f353374f7e5 100644 --- a/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java +++ b/jetty-maven-plugin/src/main/java/org/eclipse/jetty/maven/plugin/JettyWebAppContext.java @@ -102,6 +102,8 @@ public class JettyWebAppContext extends WebAppContext private String _jettyEnvXml; private List _overlays; private Resource _quickStartWebXml; + private String _originAttribute; + private boolean _generateOrigin; @@ -227,6 +229,38 @@ public class JettyWebAppContext extends WebAppContext _overlays = overlays; } + /** + * @return the originAttribute + */ + public String getOriginAttribute() + { + return _originAttribute; + } + + /** + * @param originAttribute the originAttribute to set + */ + public void setOriginAttribute(String originAttribute) + { + _originAttribute = originAttribute; + } + + /** + * @return the generateOrigin + */ + public boolean isGenerateOrigin() + { + return _generateOrigin; + } + + /** + * @param generateOrigin the generateOrigin to set + */ + public void setGenerateOrigin(boolean generateOrigin) + { + _generateOrigin = generateOrigin; + } + /* ------------------------------------------------------------ */ public List getOverlays() { @@ -311,7 +345,7 @@ public class JettyWebAppContext extends WebAppContext if (getQuickStartWebDescriptor() == null) throw new IllegalStateException ("No location to generate quickstart descriptor"); - QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, _preconfigProcessor.getXML()); + QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, _preconfigProcessor.getXML(), _originAttribute, _generateOrigin); try (FileOutputStream fos = new FileOutputStream(getQuickStartWebDescriptor().getFile())) { generator.generateQuickStartWebXml(fos); diff --git a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartDescriptorGenerator.java b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartDescriptorGenerator.java index 0c95a184401..e1d6e473803 100644 --- a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartDescriptorGenerator.java +++ b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartDescriptorGenerator.java @@ -56,6 +56,7 @@ import org.eclipse.jetty.servlet.ServletHandler; import org.eclipse.jetty.servlet.ServletHolder; import org.eclipse.jetty.servlet.ServletMapping; import org.eclipse.jetty.util.QuotedStringTokenizer; +import org.eclipse.jetty.util.StringUtil; import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.resource.Resource; @@ -77,9 +78,13 @@ public class QuickStartDescriptorGenerator private static final Logger LOG = Log.getLogger(QuickStartDescriptorGenerator.class); public static final String DEFAULT_QUICKSTART_DESCRIPTOR_NAME = "quickstart-web.xml"; + public static final String DEFAULT_ORIGIN_ATTRIBUTE_NAME = "origin"; protected WebAppContext _webApp; protected String _extraXML; + protected String _originAttribute; + protected boolean _generateOrigin; + protected int _count; @@ -87,10 +92,13 @@ public class QuickStartDescriptorGenerator * @param w the source WebAppContext * @param extraXML any extra xml snippet to append */ - public QuickStartDescriptorGenerator (WebAppContext w, String extraXML) + public QuickStartDescriptorGenerator (WebAppContext w, String extraXML, String originAttribute, boolean generateOrigin) { _webApp = w; _extraXML = extraXML; + _originAttribute = (StringUtil.isBlank(originAttribute)?DEFAULT_ORIGIN_ATTRIBUTE_NAME:originAttribute); + _generateOrigin = generateOrigin || LOG.isDebugEnabled(); + _count = 0; } @@ -694,7 +702,7 @@ public class QuickStartDescriptorGenerator */ public Map origin(MetaData md, String name) { - if (!LOG.isDebugEnabled()) + if (!_generateOrigin) return Collections.emptyMap(); if (name == null) return Collections.emptyMap(); @@ -702,7 +710,7 @@ public class QuickStartDescriptorGenerator if (LOG.isDebugEnabled()) LOG.debug("origin of "+name+" is "+origin); if (origin == null) return Collections.emptyMap(); - return Collections.singletonMap("origin",origin.toString()); + return Collections.singletonMap(_originAttribute,origin.toString()+":"+(_count++)); } } diff --git a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java index fc089092acc..0ee62478f0e 100644 --- a/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java +++ b/jetty-quickstart/src/main/java/org/eclipse/jetty/quickstart/QuickStartWebApp.java @@ -46,6 +46,9 @@ public class QuickStartWebApp extends WebAppContext private boolean _autoPreconfigure=false; private boolean _startWebapp=false; private PreconfigureDescriptorProcessor _preconfigProcessor; + private String _originAttribute; + private boolean _generateOrigin; + public static final String[] __preconfigurationClasses = new String[] { @@ -89,6 +92,35 @@ public class QuickStartWebApp extends WebAppContext _autoPreconfigure = autoPrecompile; } + public void setOriginAttribute (String name) + { + _originAttribute = name; + } + + /** + * @return the originAttribute + */ + public String getOriginAttribute() + { + return _originAttribute; + } + + /** + * @return the generateOrigin + */ + public boolean getGenerateOrigin() + { + return _generateOrigin; + } + + /** + * @param generateOrigin the generateOrigin to set + */ + public void setGenerateOrigin(boolean generateOrigin) + { + _generateOrigin = generateOrigin; + } + @Override protected void startWebapp() throws Exception { @@ -174,7 +206,7 @@ public class QuickStartWebApp extends WebAppContext Resource descriptor = getWebInf().addPath(QuickStartDescriptorGenerator.DEFAULT_QUICKSTART_DESCRIPTOR_NAME); if (!descriptor.exists()) descriptor.getFile().createNewFile(); - QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, extraXML); + QuickStartDescriptorGenerator generator = new QuickStartDescriptorGenerator(this, extraXML, _originAttribute, _generateOrigin); try (FileOutputStream fos = new FileOutputStream(descriptor.getFile())) { generator.generateQuickStartWebXml(fos); diff --git a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java index 522cf36e709..77127a5b2c3 100644 --- a/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java +++ b/jetty-webapp/src/main/java/org/eclipse/jetty/webapp/MetaData.java @@ -125,7 +125,7 @@ public class MetaData if (descriptor!=null) return descriptor.toString(); if (annotation!=null) - return "@"+annotation.annotationType().getSimpleName()+" on "+annotated.getName(); + return "@"+annotation.annotationType().getSimpleName()+"("+annotated.getName()+")"; return origin.toString(); } }