Merge remote-tracking branch 'origin/jetty-9.4.x'

This commit is contained in:
Jan Bartel 2016-11-24 15:51:06 +11:00
commit 79c364368d
11 changed files with 240 additions and 122 deletions

View File

@ -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)

View File

@ -82,7 +82,9 @@ public class JettyWebAppContext extends WebAppContext
private String _jettyEnvXml;
private List<Overlay> _overlays;
private Resource _quickStartWebXml;
private String _originAttribute;
private boolean _generateOrigin;
/**
* Set the "org.eclipse.jetty.server.webapp.ContainerIncludeJarPattern" with a pattern for matching jars on
* container classpath to scan. This is analogous to the WebAppContext.setAttribute() call.
@ -209,6 +211,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<Overlay> getOverlays()
{
@ -283,6 +317,7 @@ public class JettyWebAppContext extends WebAppContext
}
/* ------------------------------------------------------------ */
@Override
public void doStart () throws Exception
@ -290,16 +325,21 @@ public class JettyWebAppContext extends WebAppContext
//choose if this will be a quickstart or normal start
if (!isGenerateQuickStart() && getQuickStartWebDescriptor() != null)
{
QuickStartConfiguration quickStart = new MavenQuickStartConfiguration();
MavenQuickStartConfiguration quickStart = new MavenQuickStartConfiguration();
quickStart.setMode(Mode.QUCKSTART);
quickStart.setQuickStartWebXml(getQuickStartWebDescriptor());
addConfiguration(quickStart);
}
else
{
if (isGenerateQuickStart())
{
QuickStartConfiguration quickStart = new MavenQuickStartConfiguration();
MavenQuickStartConfiguration quickStart = new MavenQuickStartConfiguration();
quickStart.setMode(Mode.GENERATE);
quickStart.getGenerator().setGenerateOrigin(isGenerateOrigin());
quickStart.getGenerator().setOriginAttribute(getOriginAttribute());
quickStart.setQuickStartWebXml(getQuickStartWebDescriptor());
quickStart.getGenerator().setQuickStartWebXml(getQuickStartWebDescriptor());
addConfiguration(quickStart);
}
}
@ -362,8 +402,6 @@ public class JettyWebAppContext extends WebAppContext
{
if (c instanceof EnvConfiguration && getJettyEnvXml() != null)
((EnvConfiguration)c).setJettyEnvXml(Resource.toURL(new File(getJettyEnvXml())));
else if (c instanceof MavenQuickStartConfiguration && getQuickStartWebDescriptor() != null)
((MavenQuickStartConfiguration)c).setQuickStartWebXml(getQuickStartWebDescriptor());
}
}
catch(Exception e)

View File

@ -43,6 +43,8 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
private Resource _quickStartWebXml;
public void setQuickStartWebXml (Resource r)
{
_quickStartWebXml = r;
@ -58,7 +60,7 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
@Override
public void preConfigure(WebAppContext context) throws Exception
{
{
//check that webapp is suitable for quick start
if (context.getBaseResource() == null)
throw new IllegalStateException ("No location for webapp");
@ -66,9 +68,8 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
//look for quickstart-web.xml in WEB-INF of webapp
Resource quickStartWebXml = getQuickStartWebXml(context);
LOG.debug("quickStartWebXml={}",quickStartWebXml);
context.getMetaData().setWebXml(quickStartWebXml);
if (LOG.isDebugEnabled()) LOG.debug("quickStartWebXml={}",quickStartWebXml);
super.preConfigure(context);
}
@Override
@ -86,7 +87,7 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
}
//Set up the quickstart environment for the context
configure(context);
super.configure(context);
}
@Override
@ -111,6 +112,7 @@ public class MavenQuickStartConfiguration extends QuickStartConfiguration
}
}
}
super.deconfigure(context);
}
}

View File

@ -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<ByteBuffer> 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<ByteBuffer> 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

View File

@ -59,8 +59,10 @@ public class QuickStartConfiguration extends AbstractConfiguration implements Co
public enum Mode {DISABLED, GENERATE, AUTO, QUCKSTART};
private Mode _mode=Mode.AUTO;
private boolean _quickStart;
private QuickStartGeneratorConfiguration _generator = new QuickStartGeneratorConfiguration();
public QuickStartConfiguration()
{
beforeThis(WebInfConfiguration.class);
@ -77,7 +79,11 @@ public class QuickStartConfiguration extends AbstractConfiguration implements Co
return _mode;
}
public QuickStartGeneratorConfiguration getGenerator()
{
return _generator;
}
/**
* @see org.eclipse.jetty.webapp.AbstractConfiguration#preConfigure(org.eclipse.jetty.webapp.WebAppContext)
*/
@ -92,6 +98,7 @@ public class QuickStartConfiguration extends AbstractConfiguration implements Co
//look for quickstart-web.xml in WEB-INF of webapp
Resource quickStartWebXml = getQuickStartWebXml(context);
LOG.debug("quickStartWebXml={} exists={}",quickStartWebXml,quickStartWebXml.exists());
_quickStart=false;
switch(_mode)
{
@ -101,7 +108,9 @@ public class QuickStartConfiguration extends AbstractConfiguration implements Co
case GENERATE:
super.preConfigure(context);
context.addConfiguration(new QuickStartGeneratorConfiguration());
context.addConfiguration(_generator);
context.addConfiguration(new StopContextConfiguration());
break;

View File

@ -54,6 +54,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;
@ -75,12 +76,61 @@ import org.eclipse.jetty.xml.XmlAppendable;
public class QuickStartGeneratorConfiguration extends AbstractConfiguration implements Configuration.DisabledByDefault
{
private static final Logger LOG = Log.getLogger(QuickStartGeneratorConfiguration.class);
public static final String DEFAULT_ORIGIN_ATTRIBUTE_NAME = "origin";
protected String _originAttribute;
protected boolean _generateOrigin;
protected int _count;
protected Resource _quickStartWebXml;
public QuickStartGeneratorConfiguration()
{
_count = 0;
}
public void setOriginAttribute (String name)
{
_originAttribute = name;
}
/**
* @return the originAttribute
*/
public String getOriginAttribute()
{
return _originAttribute;
}
/**
* @return the generateOrigin
*/
public boolean isGenerateOrigin()
{
return _generateOrigin;
}
/**
* @param generateOrigin the generateOrigin to set
*/
public void setGenerateOrigin(boolean generateOrigin)
{
_generateOrigin = generateOrigin;
}
public Resource getQuickStartWebXml()
{
return _quickStartWebXml;
}
public void setQuickStartWebXml(Resource quickStartWebXml)
{
_quickStartWebXml = quickStartWebXml;
}
/**
* Perform the generation of the xml file
* @param stream the stream to generate the quickstart-web.xml to
@ -94,6 +144,8 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration impl
if (stream == null)
throw new IllegalStateException("No output for quickstart generation");
if (_originAttribute == null)
_originAttribute = DEFAULT_ORIGIN_ATTRIBUTE_NAME;
context.getMetaData().getOrigins();
if (context.getBaseResource()==null)
@ -681,7 +733,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration impl
*/
public Map<String, String> origin(MetaData md, String name)
{
if (!LOG.isDebugEnabled())
if (!(_generateOrigin || LOG.isDebugEnabled()))
return Collections.emptyMap();
if (name == null)
return Collections.emptyMap();
@ -689,7 +741,7 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration impl
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++));
}
@ -702,13 +754,17 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration impl
super.preConfigure(context);
}
@Override
public void configure(WebAppContext context) throws Exception
{
MetaData metadata = context.getMetaData();
metadata.resolve(context);
Resource quickStartWebXml = context.getBaseResource().addPath("/WEB-INF/quickstart-web.xml");
Resource quickStartWebXml = _quickStartWebXml;
if (_quickStartWebXml == null)
quickStartWebXml = context.getBaseResource().addPath("/WEB-INF/quickstart-web.xml");
if (!quickStartWebXml.exists())
quickStartWebXml.getFile().createNewFile();
try (FileOutputStream fos = new FileOutputStream(quickStartWebXml.getFile(),false))
@ -716,6 +772,4 @@ public class QuickStartGeneratorConfiguration extends AbstractConfiguration impl
generateQuickStartWebXml(context,fos);
}
}
}

View File

@ -29,16 +29,20 @@ import org.eclipse.jetty.webapp.WebAppContext;
*/
public class QuickStartWebApp extends WebAppContext
{
private final QuickStartConfiguration _quickStartConfiguration;
private String _originAttribute;
private boolean _generateOrigin;
public QuickStartWebApp()
{
super();
addConfiguration(
_quickStartConfiguration=new QuickStartConfiguration(),
new EnvConfiguration(),
new PlusConfiguration(),
new AnnotationConfiguration());
_quickStartConfiguration=new QuickStartConfiguration(),
new EnvConfiguration(),
new PlusConfiguration(),
new AnnotationConfiguration());
setExtractWAR(true);
setCopyWebDir(false);
setCopyWebInf(false);
@ -67,7 +71,36 @@ public class QuickStartWebApp extends WebAppContext
{
setAutoGenerate(autoPrecompile);
}
public void setOriginAttribute (String name)
{
_quickStartConfiguration.getGenerator().setOriginAttribute(name);
}
/**
* @return the originAttribute
*/
public String getOriginAttribute()
{
return _originAttribute;
}
/**
* @return the generateOrigin
*/
public boolean isGenerateOrigin()
{
return _generateOrigin;
}
/**
* @param generateOrigin the generateOrigin to set
*/
public void setGenerateOrigin(boolean generateOrigin)
{
_quickStartConfiguration.getGenerator().setGenerateOrigin(generateOrigin);
}
public boolean isGenerate()
{
return _quickStartConfiguration.getMode()==Mode.GENERATE;

View File

@ -842,7 +842,7 @@ public class HttpInput extends ServletInputStream implements Runnable
}
}
else if (content==null)
throw new IllegalStateException();
return;
}
}

View File

@ -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<Future<String>> responses = clientExecutors.invokeAll(clientTasks, 60, TimeUnit.SECONDS);

View File

@ -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())

View File

@ -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();
}
}