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

Signed-off-by: Greg Wilkins <gregw@webtide.com>
This commit is contained in:
Greg Wilkins 2019-03-14 18:22:29 +11:00
commit 59b026efce
26 changed files with 291 additions and 173 deletions

View File

@ -99,7 +99,7 @@ public class LikeJettyXml
Server server = new Server(threadPool);
// Scheduler
server.addBean(new ScheduledExecutorScheduler());
server.addBean(new ScheduledExecutorScheduler(null,false));
// HTTP Configuration
HttpConfiguration http_config = new HttpConfiguration();

View File

@ -23,7 +23,6 @@ import java.lang.management.ManagementFactory;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
import org.eclipse.jetty.webapp.Configurations;
import org.eclipse.jetty.webapp.WebAppContext;

View File

@ -69,7 +69,6 @@ public class App
_context = context;
}
/* ------------------------------------------------------------ */
/**
* @return The deployment manager
*/
@ -78,7 +77,6 @@ public class App
return _manager;
}
/* ------------------------------------------------------------ */
/**
* @return The AppProvider
*/
@ -87,7 +85,6 @@ public class App
return _provider;
}
/* ------------------------------------------------------------ */
/**
* Get ContextHandler for the App.
*
@ -149,7 +146,6 @@ public class App
return this._context.getContextPath();
}
/**
* The origin of this {@link App} as specified by the {@link AppProvider}
*

View File

@ -37,7 +37,6 @@ public interface AppProvider extends LifeCycle
*/
void setDeploymentManager(DeploymentManager deploymentManager);
/* ------------------------------------------------------------ */
/** Create a ContextHandler for an App
* @param app The App
* @return A ContextHandler

View File

@ -152,7 +152,6 @@ public class DeploymentManager extends ContainerLifeCycle
}
}
/* ------------------------------------------------------------ */
/** Set the AppProviders.
* The providers passed are added via {@link #addBean(Object)} so that
* their lifecycles may be managed as a {@link ContainerLifeCycle}.
@ -170,7 +169,6 @@ public class DeploymentManager extends ContainerLifeCycle
addBean(provider);
}
@ManagedAttribute("Application Providers")
public Collection<AppProvider> getAppProviders()
{
return Collections.unmodifiableList(_providers);
@ -292,7 +290,6 @@ public class DeploymentManager extends ContainerLifeCycle
return Collections.unmodifiableCollection(_apps);
}
@ManagedAttribute("Deployed Apps")
public Collection<App> getApps()
{
List<App> ret = new ArrayList< >();

View File

@ -22,7 +22,6 @@ import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.server.DebugListener;
/** A Deployment binding that installs a DebugListener in all deployed contexts
*/
public class DebugListenerBinding extends DebugBinding

View File

@ -18,8 +18,6 @@
package org.eclipse.jetty.deploy.bindings;
import java.io.File;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.graph.Node;
@ -49,7 +47,6 @@ public class GlobalWebappConfigBinding implements AppLifeCycle.Binding
{
private static final Logger LOG = Log.getLogger(GlobalWebappConfigBinding.class);
private String _jettyXml;
public String getJettyXml()

View File

@ -204,7 +204,6 @@ public class Graph
return path;
}
private Path breadthFirst(Node from, Node destination, CopyOnWriteArrayList<Path> paths, Set<Edge> seen)
{
// Add next unseen segments to paths.
@ -246,7 +245,6 @@ public class Graph
return null;
}
public Set<Edge> getEdges()
{
return _edges;

View File

@ -24,11 +24,11 @@ import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppProvider;
import org.eclipse.jetty.deploy.DeploymentManager;
import org.eclipse.jetty.deploy.graph.Node;
import org.eclipse.jetty.jmx.ObjectMBean;
import org.eclipse.jetty.server.handler.ContextHandler;
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.annotation.Name;
@ -45,7 +45,7 @@ public class DeploymentManagerMBean extends ObjectMBean
_manager = (DeploymentManager) managedObject;
}
@ManagedOperation(value = "list apps being tracked", impact = "INFO")
@ManagedAttribute(value = "list apps being tracked")
public Collection<String> getApps()
{
List<String> ret = new ArrayList<>();
@ -95,9 +95,10 @@ public class DeploymentManagerMBean extends ObjectMBean
return apps;
}
public Collection<AppProvider> getAppProviders()
@ManagedAttribute("Registered AppProviders")
public List<String> getAppProviders()
{
return _manager.getAppProviders();
return _manager.getAppProviders().stream().map(String::valueOf).collect(Collectors.toList());
}
public void requestAppGoal(String appId, String nodeName)

View File

@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppProvider;
@ -34,6 +35,7 @@ import org.eclipse.jetty.deploy.DeploymentManager;
import org.eclipse.jetty.util.Scanner;
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.log.Log;
import org.eclipse.jetty.util.log.Logger;
@ -55,7 +57,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
private int _scanInterval = 10;
private Scanner _scanner;
/* ------------------------------------------------------------ */
private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener()
{
@Override
@ -77,18 +78,15 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
}
};
/* ------------------------------------------------------------ */
protected ScanningAppProvider()
{
}
/* ------------------------------------------------------------ */
protected ScanningAppProvider(FilenameFilter filter)
{
_filenameFilter = filter;
}
/* ------------------------------------------------------------ */
protected void setFilenameFilter(FilenameFilter filter)
{
if (isRunning())
@ -96,7 +94,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_filenameFilter = filter;
}
/* ------------------------------------------------------------ */
/**
* @return The index of currently deployed applications.
*/
@ -105,7 +102,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _appMap;
}
/* ------------------------------------------------------------ */
/**
* Called by the Scanner.DiscreteListener to create a new App object.
* Isolated in a method so that it is possible to override the default App
@ -121,7 +117,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return new App(_deploymentManager,this,filename);
}
/* ------------------------------------------------------------ */
@Override
protected void doStart() throws Exception
{
@ -150,7 +145,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_scanner.start();
}
/* ------------------------------------------------------------ */
@Override
protected void doStop() throws Exception
{
@ -162,13 +156,11 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
}
}
/* ------------------------------------------------------------ */
protected boolean exists(String path)
{
return _scanner.exists(path);
}
/* ------------------------------------------------------------ */
protected void fileAdded(String filename) throws Exception
{
if (LOG.isDebugEnabled())
@ -181,7 +173,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
}
}
/* ------------------------------------------------------------ */
protected void fileChanged(String filename) throws Exception
{
if (LOG.isDebugEnabled())
@ -199,7 +190,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
}
}
/* ------------------------------------------------------------ */
protected void fileRemoved(String filename) throws Exception
{
if (LOG.isDebugEnabled())
@ -209,7 +199,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_deploymentManager.removeApp(app);
}
/* ------------------------------------------------------------ */
/**
* Get the deploymentManager.
*
@ -220,8 +209,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _deploymentManager;
}
/* ------------------------------------------------------------ */
public Resource getMonitoredDirResource()
{
if (_monitored.size()==0)
@ -231,60 +218,51 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _monitored.get(0);
}
/* ------------------------------------------------------------ */
public String getMonitoredDirName()
{
Resource resource=getMonitoredDirResource();
return resource==null?null:resource.toString();
}
/* ------------------------------------------------------------ */
@ManagedAttribute("scanning interval to detect changes which need reloaded")
public int getScanInterval()
{
return _scanInterval;
}
/* ------------------------------------------------------------ */
@ManagedAttribute("recursive scanning supported")
public boolean isRecursive()
{
return _recursive;
}
/* ------------------------------------------------------------ */
@Override
public void setDeploymentManager(DeploymentManager deploymentManager)
{
_deploymentManager = deploymentManager;
}
/* ------------------------------------------------------------ */
public void setMonitoredResources(List<Resource> resources)
{
_monitored.clear();
_monitored.addAll(resources);
}
/* ------------------------------------------------------------ */
public List<Resource> getMonitoredResources()
{
return Collections.unmodifiableList(_monitored);
}
/* ------------------------------------------------------------ */
public void setMonitoredDirResource(Resource resource)
{
setMonitoredResources(Collections.singletonList(resource));
}
/* ------------------------------------------------------------ */
public void addScannerListener(Scanner.Listener listener)
{
_scanner.addListener(listener);
}
/* ------------------------------------------------------------ */
/**
* @param dir
* Directory to scan for context descriptors or war files
@ -294,7 +272,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
setMonitoredDirectories(Collections.singletonList(dir));
}
/* ------------------------------------------------------------ */
public void setMonitoredDirectories(Collection<String> directories)
{
try
@ -310,15 +287,23 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
}
}
/* ------------------------------------------------------------ */
protected void setRecursive(boolean recursive)
{
_recursive = recursive;
}
/* ------------------------------------------------------------ */
public void setScanInterval(int scanInterval)
{
_scanInterval = scanInterval;
}
@ManagedOperation(value = "Scan the monitored directories", impact = "ACTION")
public void scan()
{
LOG.info("Performing scan of monitored directories: {}",
getMonitoredResources().stream().map((r) -> r.getURI().toASCIIString())
.collect(Collectors.joining(", ", "[", "]"))
);
_scanner.scan();
}
}

View File

@ -124,7 +124,6 @@ public class WebAppProvider extends ScanningAppProvider
}
}
/* ------------------------------------------------------------ */
public WebAppProvider()
{
super();
@ -132,7 +131,6 @@ public class WebAppProvider extends ScanningAppProvider
setScanInterval(0);
}
/* ------------------------------------------------------------ */
/** Get the extractWars.
* @return the extractWars
*/
@ -142,7 +140,6 @@ public class WebAppProvider extends ScanningAppProvider
return _extractWars;
}
/* ------------------------------------------------------------ */
/** Set the extractWars.
* @param extractWars the extractWars to set
*/
@ -151,7 +148,6 @@ public class WebAppProvider extends ScanningAppProvider
_extractWars = extractWars;
}
/* ------------------------------------------------------------ */
/** Get the parentLoaderPriority.
* @return the parentLoaderPriority
*/
@ -161,7 +157,6 @@ public class WebAppProvider extends ScanningAppProvider
return _parentLoaderPriority;
}
/* ------------------------------------------------------------ */
/** Set the parentLoaderPriority.
* @param parentLoaderPriority the parentLoaderPriority to set
*/
@ -170,7 +165,6 @@ public class WebAppProvider extends ScanningAppProvider
_parentLoaderPriority = parentLoaderPriority;
}
/* ------------------------------------------------------------ */
/** Get the defaultsDescriptor.
* @return the defaultsDescriptor
*/
@ -180,7 +174,6 @@ public class WebAppProvider extends ScanningAppProvider
return _defaultsDescriptor;
}
/* ------------------------------------------------------------ */
/** Set the defaultsDescriptor.
* @param defaultsDescriptor the defaultsDescriptor to set
*/
@ -189,13 +182,11 @@ public class WebAppProvider extends ScanningAppProvider
_defaultsDescriptor = defaultsDescriptor;
}
/* ------------------------------------------------------------ */
public ConfigurationManager getConfigurationManager()
{
return _configurationManager;
}
/* ------------------------------------------------------------ */
/** Set the configurationManager.
* @param configurationManager the configurationManager to set
*/
@ -204,7 +195,6 @@ public class WebAppProvider extends ScanningAppProvider
_configurationManager = configurationManager;
}
/* ------------------------------------------------------------ */
/**
* @param configurations The configuration class names.
*/
@ -213,7 +203,6 @@ public class WebAppProvider extends ScanningAppProvider
_configurationClasses = configurations==null?null:(String[])configurations.clone();
}
/* ------------------------------------------------------------ */
@ManagedAttribute("configuration classes for webapps to be processed through")
public String[] getConfigurationClasses()
{
@ -232,7 +221,6 @@ public class WebAppProvider extends ScanningAppProvider
_tempDirectory = directory;
}
/* ------------------------------------------------------------ */
/**
* Get the user supplied Work Directory.
*
@ -244,7 +232,6 @@ public class WebAppProvider extends ScanningAppProvider
return _tempDirectory;
}
/* ------------------------------------------------------------ */
protected void initializeWebAppContextDefaults(WebAppContext webapp)
{
if (_defaultsDescriptor != null)
@ -266,7 +253,6 @@ public class WebAppProvider extends ScanningAppProvider
}
}
/* ------------------------------------------------------------ */
@Override
public ContextHandler createContextHandler(final App app) throws Exception
{
@ -350,7 +336,6 @@ public class WebAppProvider extends ScanningAppProvider
return webAppContext;
}
/* ------------------------------------------------------------ */
@Override
protected void fileChanged(String filename) throws Exception
{
@ -410,7 +395,6 @@ public class WebAppProvider extends ScanningAppProvider
super.fileChanged(filename);
}
/* ------------------------------------------------------------ */
@Override
protected void fileAdded(String filename) throws Exception
{
@ -433,7 +417,6 @@ public class WebAppProvider extends ScanningAppProvider
return;
}
//is the file that was added a .war file?
String lowname = file.getName().toLowerCase(Locale.ENGLISH);
if (lowname.endsWith(".war"))
@ -453,8 +436,6 @@ public class WebAppProvider extends ScanningAppProvider
super.fileAdded(filename);
}
/* ------------------------------------------------------------ */
@Override
protected void fileRemoved(String filename) throws Exception
{

View File

@ -0,0 +1,44 @@
//
// ========================================================================
// Copyright (c) 1995-2019 Mort Bay Consulting Pty. Ltd.
// ------------------------------------------------------------------------
// All rights reserved. This program and the accompanying materials
// are made available under the terms of the Eclipse Public License v1.0
// and Apache License v2.0 which accompanies this distribution.
//
// The Eclipse Public License is available at
// http://www.eclipse.org/legal/epl-v10.html
//
// The Apache License v2.0 is available at
// http://www.opensource.org/licenses/apache2.0.php
//
// You may elect to redistribute this code under either of these licenses.
// ========================================================================
//
package org.eclipse.jetty.deploy.providers.jmx;
import java.util.List;
import java.util.stream.Collectors;
import org.eclipse.jetty.deploy.providers.WebAppProvider;
import org.eclipse.jetty.server.handler.jmx.AbstractHandlerMBean;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
@ManagedObject("WebAppProvider mbean wrapper")
public class WebAppProviderMBean extends AbstractHandlerMBean
{
public WebAppProviderMBean(Object managedObject)
{
super(managedObject);
}
@ManagedAttribute("List of monitored resources")
public List<String> getMonitoredResources()
{
return ((WebAppProvider) _managed).getMonitoredResources().stream()
.map((r) -> r.getURI().toASCIIString())
.collect(Collectors.toList());
}
}

View File

@ -20,7 +20,6 @@ package org.eclipse.jetty.deploy;
import java.io.IOException;
import java.lang.management.ManagementFactory;
import javax.management.MBeanServer;
import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector;
@ -74,7 +73,6 @@ public class JmxServiceConnection
return serviceUrl;
}
/* ------------------------------------------------------------ */
/**
* Retrieve a connection to MBean server
*

View File

@ -19,10 +19,10 @@
package org.eclipse.jetty.http;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import java.util.Arrays;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
/* ------------------------------------------------------------ */
/**
@ -60,7 +60,8 @@ public class Http1FieldPreEncoder implements HttpFieldPreEncoder
byte[] v=value.getBytes(ISO_8859_1);
byte[] bytes=Arrays.copyOf(n,n.length+2+v.length+2);
bytes[n.length]=(byte)':';
bytes[n.length]=(byte)' ';
bytes[n.length+1]=(byte)' ';
System.arraycopy(v, 0, bytes, n.length+2, v.length);
bytes[bytes.length-2]=(byte)'\r';
bytes[bytes.length-1]=(byte)'\n';

View File

@ -21,7 +21,6 @@ package org.eclipse.jetty.http;
import java.nio.ByteBuffer;
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator;
import java.util.List;
import java.util.ServiceLoader;

View File

@ -18,15 +18,6 @@
package org.eclipse.jetty.http;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import java.nio.ByteBuffer;
import java.util.Collections;
import java.util.Enumeration;
@ -40,6 +31,15 @@ import org.eclipse.jetty.util.BufferUtil;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class HttpFieldsTest
{
@Test
@ -299,6 +299,46 @@ public class HttpFieldsTest
assertEquals(false, e.hasMoreElements());
}
@Test
public void testPreEncodedField()
{
ByteBuffer buffer = BufferUtil.allocate(1024);
PreEncodedHttpField known = new PreEncodedHttpField(HttpHeader.CONNECTION, HttpHeaderValue.CLOSE.asString());
BufferUtil.clearToFill(buffer);
known.putTo(buffer,HttpVersion.HTTP_1_1);
BufferUtil.flipToFlush(buffer,0);
assertThat(BufferUtil.toString(buffer),is("Connection: close\r\n"));
PreEncodedHttpField unknown = new PreEncodedHttpField(null, "Header", "Value");
BufferUtil.clearToFill(buffer);
unknown.putTo(buffer,HttpVersion.HTTP_1_1);
BufferUtil.flipToFlush(buffer,0);
assertThat(BufferUtil.toString(buffer),is("Header: Value\r\n"));
}
@Test
public void testAddPreEncodedField()
{
final PreEncodedHttpField X_XSS_PROTECTION_FIELD = new PreEncodedHttpField("X-XSS-Protection", "1; mode=block");
HttpFields fields = new HttpFields();
fields.add(X_XSS_PROTECTION_FIELD);
assertThat("Fields output", fields.toString(), containsString("X-XSS-Protection: 1; mode=block"));
}
@Test
public void testAddFinalHttpField()
{
final HttpField X_XSS_PROTECTION_FIELD = new HttpField("X-XSS-Protection", "1; mode=block");
HttpFields fields = new HttpFields();
fields.add(X_XSS_PROTECTION_FIELD);
assertThat("Fields output", fields.toString(), containsString("X-XSS-Protection: 1; mode=block"));
}
@Test
public void testGetValues() throws Exception
{

View File

@ -55,7 +55,6 @@ import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.Callback;
import org.eclipse.jetty.util.HostPort;
import org.eclipse.jetty.util.Promise;
import org.eclipse.jetty.util.TypeUtil;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
@ -105,6 +104,7 @@ public class ConnectHandler extends HandlerWrapper
public void setScheduler(Scheduler scheduler)
{
updateBean(this.scheduler,scheduler);
this.scheduler = scheduler;
}
@ -115,6 +115,7 @@ public class ConnectHandler extends HandlerWrapper
public void setByteBufferPool(ByteBufferPool bufferPool)
{
updateBean(this.bufferPool, bufferPool);
this.bufferPool = bufferPool;
}
@ -167,10 +168,18 @@ public class ConnectHandler extends HandlerWrapper
executor = getServer().getThreadPool();
if (scheduler == null)
addBean(scheduler = new ScheduledExecutorScheduler());
{
scheduler = getServer().getBean(Scheduler.class);
if (scheduler == null)
scheduler = new ScheduledExecutorScheduler(String.format("Proxy-Scheduler-%x", hashCode()), false);
addBean(scheduler);
}
if (bufferPool == null)
addBean(bufferPool = new MappedByteBufferPool());
{
bufferPool = new MappedByteBufferPool();
addBean(bufferPool);
}
addBean(selector = newSelectorManager());
selector.setConnectTimeout(getConnectTimeout());

View File

@ -183,7 +183,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
_executor=executor!=null?executor:_server.getThreadPool();
if (scheduler==null)
scheduler=_server.getBean(Scheduler.class);
_scheduler=scheduler!=null?scheduler:new ScheduledExecutorScheduler();
_scheduler=scheduler!=null?scheduler:new ScheduledExecutorScheduler(String.format("Connector-Scheduler-%x",hashCode()),false);
if (pool==null)
pool=_server.getBean(ByteBufferPool.class);
_byteBufferPool = pool!=null?pool:new ArrayByteBufferPool();

View File

@ -369,14 +369,14 @@ public class Server extends HandlerWrapper implements Attributes
String gitHash = Jetty.GIT_HASH;
String timestamp = Jetty.BUILD_TIMESTAMP;
LOG.info("jetty-{}; built: {}; git: {}; jvm {}", getVersion(), timestamp, gitHash, System.getProperty("java.runtime.version",System.getProperty("java.version")));
if (!Jetty.STABLE)
{
LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!");
LOG.warn("Download a stable release from http://download.eclipse.org/jetty/");
}
LOG.info("jetty-{}; built: {}; git: {}; jvm {}", getVersion(), timestamp, gitHash, System.getProperty("java.runtime.version",System.getProperty("java.version")));
if (!Jetty.STABLE)
{
LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!");
LOG.warn("Download a stable release from http://download.eclipse.org/jetty/");
}
HttpGenerator.setJettyVersion(HttpConfiguration.SERVER_VERSION);
HttpGenerator.setJettyVersion(HttpConfiguration.SERVER_VERSION);
MultiException mex=new MultiException();
@ -410,29 +410,19 @@ public class Server extends HandlerWrapper implements Attributes
catch(Throwable e)
{
mex.add(e);
// stop any started connectors
_connectors.stream().filter(LifeCycle::isRunning).map(Object.class::cast).forEach(LifeCycle::stop);
}
}
mex.ifExceptionThrow();
LOG.info(String.format("Started @%dms",Uptime.getUptime()));
}
catch(Throwable e1)
catch(Throwable th)
{
try
{
// Stop any components already started!
super.doStop();
}
catch(Exception e2)
{
e1.addSuppressed(e2);
}
finally
{
// Close any connectors that were opened
_connectors.stream().filter(NetworkConnector.class::isInstance).map(NetworkConnector.class::cast).forEach(NetworkConnector::close);
}
throw e1;
// Close any connectors that were opened
_connectors.stream().filter(NetworkConnector.class::isInstance).map(NetworkConnector.class::cast).forEach(NetworkConnector::close);
throw th;
}
finally
{

View File

@ -1143,7 +1143,7 @@ public class ContextHandler extends ScopedHandler implements Attributes, Gracefu
case UNAVAILABLE:
baseRequest.setHandled(true);
response.sendError(HttpServletResponse.SC_SERVICE_UNAVAILABLE);
return false;
return true;
default:
if ((DispatcherType.REQUEST.equals(dispatch) && baseRequest.isHandled()))
return false;

View File

@ -121,7 +121,7 @@ public class HouseKeeper extends AbstractLifeCycle
if (_scheduler == null)
{
_scheduler = new ScheduledExecutorScheduler();
_scheduler = new ScheduledExecutorScheduler(String.format("Session-HouseKeeper-%x",hashCode()),false);
_ownScheduler = true;
_scheduler.start();
if (LOG.isDebugEnabled()) LOG.debug("Using own scheduler for scavenging");

View File

@ -516,10 +516,9 @@ public class SessionHandler extends ScopedHandler
_scheduler = server.getBean(Scheduler.class);
if (_scheduler == null)
{
_scheduler = new ScheduledExecutorScheduler();
_scheduler = new ScheduledExecutorScheduler(String.format("Session-Scheduler-%x",hashCode()), false);
_ownScheduler = true;
_scheduler.start();
}
}

View File

@ -18,18 +18,6 @@
package org.eclipse.jetty.server;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.condition.OS.WINDOWS;
import java.io.BufferedReader;
import java.io.IOException;
import java.io.InputStream;
@ -54,18 +42,32 @@ import org.eclipse.jetty.io.EndPoint;
import org.eclipse.jetty.server.LocalConnector.LocalEndPoint;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.StatisticsHandler;
import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.hamcrest.Matcher;
import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.greaterThan;
import static org.hamcrest.Matchers.instanceOf;
import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.lessThan;
import static org.hamcrest.Matchers.notNullValue;
import static org.junit.jupiter.api.Assertions.assertFalse;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
import static org.junit.jupiter.api.Assertions.fail;
import static org.junit.jupiter.api.condition.OS.WINDOWS;
public class GracefulStopTest
{
/**
@ -658,6 +660,60 @@ public class GracefulStopTest
assertTrue(latch.await(10,TimeUnit.SECONDS));
}
@Test
public void testFailedStart()
{
Server server= new Server();
LocalConnector connector = new LocalConnector(server);
server.addConnector(connector);
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(contexts);
AtomicBoolean context0Started = new AtomicBoolean(false);
ContextHandler context0 = new ContextHandler("/zero")
{
@Override
protected void doStart() throws Exception
{
context0Started.set(true);
}
};
ContextHandler context1 = new ContextHandler("/one")
{
@Override
protected void doStart() throws Exception
{
throw new Exception("Test start failure");
}
};
AtomicBoolean context2Started = new AtomicBoolean(false);
ContextHandler context2 = new ContextHandler("/two")
{
@Override
protected void doStart() throws Exception
{
context2Started.set(true);
}
};
contexts.setHandlers(new Handler[]{context0, context1, context2});
try
{
server.start();
fail();
}
catch(Exception e)
{
assertThat(e.getMessage(),is("Test start failure"));
}
assertTrue(server.getContainedBeans(LifeCycle.class).stream().noneMatch(LifeCycle::isRunning));
assertTrue(server.getContainedBeans(LifeCycle.class).stream().anyMatch(LifeCycle::isFailed));
assertTrue(context0Started.get());
assertFalse(context2Started.get());
}
static class NoopHandler extends AbstractHandler
{
final CountDownLatch latch = new CountDownLatch(1);

View File

@ -280,7 +280,7 @@ public class DoSFilter implements Filter
{
try
{
Scheduler result = new ScheduledExecutorScheduler();
Scheduler result = new ScheduledExecutorScheduler(String.format("DoS-Scheduler-%x",hashCode()),false);
result.start();
return result;
}

View File

@ -220,4 +220,5 @@ public class MultiException extends Exception
return str.toString();
}
}

View File

@ -96,35 +96,64 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
_doStarted = true;
// start our managed and auto beans
for (Bean b : _beans)
try
{
if (b._bean instanceof LifeCycle)
for (Bean b : _beans)
{
LifeCycle l = (LifeCycle)b._bean;
switch(b._managed)
if (b._bean instanceof LifeCycle)
{
case MANAGED:
if (!l.isRunning())
start(l);
break;
LifeCycle l = (LifeCycle)b._bean;
switch (b._managed)
{
case MANAGED:
if (!l.isRunning())
start(l);
break;
case AUTO:
if (l.isRunning())
unmanage(b);
else
{
manage(b);
start(l);
}
break;
case AUTO:
if (l.isRunning())
unmanage(b);
else
{
manage(b);
start(l);
}
break;
default:
break;
default:
break;
}
}
}
}
super.doStart();
super.doStart();
}
catch (Throwable t)
{
// on failure, stop any managed components that have been started
List<Bean> reverse = new ArrayList<>(_beans);
Collections.reverse(reverse);
for (Bean b : reverse)
{
if (b._bean instanceof LifeCycle && b._managed == Managed.MANAGED)
{
LifeCycle l = (LifeCycle)b._bean;
if (l.isRunning())
{
try
{
l.stop();
}
catch(Throwable t2)
{
if (t2!=t)
t.addSuppressed(t2);
}
}
}
}
throw t;
}
}
/**