Merge branch `jetty-9.4.x` into `jetty-10.0.x`

Signed-off-by: Joakim Erdfelt <joakim.erdfelt@gmail.com>

# Conflicts:
#	examples/embedded/src/main/java/org/eclipse/jetty/embedded/OneWebApp.java
#	jetty-osgi/test-jetty-osgi/pom.xml
#	jetty-server/src/main/java/org/eclipse/jetty/server/Server.java
#	jetty-websocket/websocket-server/src/main/java/org/eclipse/jetty/websocket/server/WebSocketServerFactory.java
This commit is contained in:
Joakim Erdfelt 2019-03-15 16:00:59 -05:00
commit 95a6b76851
38 changed files with 503 additions and 267 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;
@ -65,7 +64,7 @@ public class OneWebApp
Configurations.setServerDefault(server);
// Start things up!
// Start things up!
server.start();
server.dumpStdErr();

View File

@ -18,12 +18,10 @@
package org.eclipse.jetty.alpn.conscrypt.client;
import java.lang.reflect.Method;
import java.nio.charset.StandardCharsets;
import java.security.Security;
import javax.net.ssl.SSLEngine;
import org.conscrypt.Conscrypt;
import org.conscrypt.OpenSSLProvider;
import org.eclipse.jetty.alpn.client.ALPNClientConnection;
import org.eclipse.jetty.io.Connection;
@ -40,7 +38,7 @@ public class ConscryptClientALPNProcessor implements ALPNProcessor.Client
@Override
public void init()
{
if (Security.getProvider("Conscrypt")==null)
if (Security.getProvider("Conscrypt") == null)
{
Security.addProvider(new OpenSSLProvider());
if (LOG.isDebugEnabled())
@ -59,11 +57,9 @@ public class ConscryptClientALPNProcessor implements ALPNProcessor.Client
{
try
{
Method setAlpnProtocols = sslEngine.getClass().getDeclaredMethod("setApplicationProtocols", String[].class);
setAlpnProtocols.setAccessible(true);
ALPNClientConnection alpn = (ALPNClientConnection)connection;
String[] protocols = alpn.getProtocols().toArray(new String[0]);
setAlpnProtocols.invoke(sslEngine, (Object)protocols);
Conscrypt.setApplicationProtocols(sslEngine, protocols);
((SslConnection.DecryptedEndPoint)connection.getEndPoint()).getSslConnection()
.addHandshakeListener(new ALPNListener(alpn));
}
@ -92,9 +88,9 @@ public class ConscryptClientALPNProcessor implements ALPNProcessor.Client
try
{
SSLEngine sslEngine = alpnConnection.getSSLEngine();
Method method = sslEngine.getClass().getDeclaredMethod("getApplicationProtocol");
method.setAccessible(true);
String protocol = (String)method.invoke(sslEngine);
String protocol = Conscrypt.getApplicationProtocol(sslEngine);
if (LOG.isDebugEnabled())
LOG.debug("Selected {} for {}", protocol, alpnConnection);
alpnConnection.selected(protocol);
}
catch (Throwable e)

View File

@ -38,6 +38,31 @@
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-alpn-conscrypt-client</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-client</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-client</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.http2</groupId>
<artifactId>http2-http-client-transport</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
<build>
<plugins>

View File

@ -18,13 +18,13 @@
package org.eclipse.jetty.alpn.conscrypt.server;
import java.lang.reflect.Method;
import java.security.Security;
import java.util.List;
import java.util.function.BiFunction;
import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSocket;
import org.conscrypt.ApplicationProtocolSelector;
import org.conscrypt.Conscrypt;
import org.conscrypt.OpenSSLProvider;
import org.eclipse.jetty.alpn.server.ALPNServerConnection;
import org.eclipse.jetty.io.Connection;
@ -41,7 +41,7 @@ public class ConscryptServerALPNProcessor implements ALPNProcessor.Server
@Override
public void init()
{
if (Security.getProvider("Conscrypt")==null)
if (Security.getProvider("Conscrypt") == null)
{
Security.addProvider(new OpenSSLProvider());
if (LOG.isDebugEnabled())
@ -56,13 +56,11 @@ public class ConscryptServerALPNProcessor implements ALPNProcessor.Server
}
@Override
public void configure(SSLEngine sslEngine,Connection connection)
public void configure(SSLEngine sslEngine, Connection connection)
{
try
{
Method method = sslEngine.getClass().getMethod("setHandshakeApplicationProtocolSelector", BiFunction.class);
method.setAccessible(true);
method.invoke(sslEngine,new ALPNCallback((ALPNServerConnection)connection));
Conscrypt.setApplicationProtocolSelector(sslEngine, new ALPNCallback((ALPNServerConnection)connection));
}
catch (RuntimeException x)
{
@ -74,23 +72,31 @@ public class ConscryptServerALPNProcessor implements ALPNProcessor.Server
}
}
private final class ALPNCallback implements BiFunction<SSLEngine,List<String>,String>, SslHandshakeListener
private final class ALPNCallback extends ApplicationProtocolSelector implements SslHandshakeListener
{
private final ALPNServerConnection alpnConnection;
private ALPNCallback(ALPNServerConnection connection)
{
alpnConnection = connection;
alpnConnection = connection;
((DecryptedEndPoint)alpnConnection.getEndPoint()).getSslConnection().addHandshakeListener(this);
}
@Override
public String apply(SSLEngine engine, List<String> protocols)
public String selectApplicationProtocol(SSLEngine engine, List<String> protocols)
{
if (LOG.isDebugEnabled())
LOG.debug("apply {} {}", alpnConnection, protocols);
alpnConnection.select(protocols);
return alpnConnection.getProtocol();
String protocol = alpnConnection.getProtocol();
if (LOG.isDebugEnabled())
LOG.debug("Selected {} among {} for {}", protocol, protocols, alpnConnection);
return protocol;
}
@Override
public String selectApplicationProtocol(SSLSocket socket, List<String> protocols)
{
throw new UnsupportedOperationException();
}
@Override
@ -99,7 +105,7 @@ public class ConscryptServerALPNProcessor implements ALPNProcessor.Server
String protocol = alpnConnection.getProtocol();
if (LOG.isDebugEnabled())
LOG.debug("TLS handshake succeeded, protocol={} for {}", protocol, alpnConnection);
if (protocol ==null)
if (protocol == null)
alpnConnection.unsupported();
}

View File

@ -1,72 +0,0 @@
//
// ========================================================================
// 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.alpn.conscrypt.server;
import java.security.Security;
import org.conscrypt.OpenSSLProvider;
import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory;
import org.eclipse.jetty.http2.HTTP2Cipher;
import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.util.ssl.SslContextFactory;
/**
* Test server that verifies that the Conscrypt ALPN mechanism works.
*/
public class ConscryptHTTP2Server
{
public static void main(String[] args) throws Exception
{
Security.addProvider(new OpenSSLProvider());
Server server = new Server();
HttpConfiguration httpsConfig = new HttpConfiguration();
httpsConfig.setSecureScheme("https");
httpsConfig.setSecurePort(8443);
httpsConfig.setSendXPoweredBy(true);
httpsConfig.setSendServerVersion(true);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setProvider("Conscrypt");
sslContextFactory.setKeyStorePath("src/test/resources/keystore.jks");
sslContextFactory.setKeyStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setKeyManagerPassword("OBF:1u2u1wml1z7s1z7a1wnl1u2g");
sslContextFactory.setCipherComparator(HTTP2Cipher.COMPARATOR);
HttpConnectionFactory http = new HttpConnectionFactory(httpsConfig);
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpsConfig);
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(http.getProtocol());
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, http);
http2Connector.setPort(8443);
server.addConnector(http2Connector);
server.start();
}
}

View File

@ -0,0 +1,140 @@
//
// ========================================================================
// 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.alpn.conscrypt.server;
import java.io.File;
import java.nio.file.Path;
import java.nio.file.Paths;
import java.security.Security;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.conscrypt.OpenSSLProvider;
import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http2.client.HTTP2Client;
import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2;
import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Request;
import org.eclipse.jetty.server.SecureRequestCustomizer;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.util.JavaVersion;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.junit.jupiter.api.Assertions.assertEquals;
/**
* Test server that verifies that the Conscrypt ALPN mechanism works for both server and client side
*/
public class ConscryptHTTP2ServerTest
{
static
{
Security.addProvider(new OpenSSLProvider());
}
private Server server = new Server();
private SslContextFactory newSslContextFactory()
{
Path path = Paths.get("src", "test", "resources");
File keys = path.resolve("keystore").toFile();
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyManagerPassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setTrustStorePath(keys.getAbsolutePath());
sslContextFactory.setKeyStorePath(keys.getAbsolutePath());
sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setProvider("Conscrypt");
sslContextFactory.setEndpointIdentificationAlgorithm(null);
if (JavaVersion.VERSION.getPlatform() < 9)
{
// Conscrypt enables TLSv1.3 by default but it's not supported in Java 8.
sslContextFactory.addExcludeProtocols("TLSv1.3");
}
return sslContextFactory;
}
@BeforeEach
public void startServer() throws Exception
{
HttpConfiguration httpsConfig = new HttpConfiguration();
httpsConfig.setSecureScheme("https");
httpsConfig.setSendXPoweredBy(true);
httpsConfig.setSendServerVersion(true);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
HttpConnectionFactory http = new HttpConnectionFactory(httpsConfig);
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpsConfig);
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(http.getProtocol());
SslConnectionFactory ssl = new SslConnectionFactory(newSslContextFactory(), alpn.getProtocol());
ServerConnector http2Connector = new ServerConnector(server, ssl, alpn, h2, http);
http2Connector.setPort(0);
server.addConnector(http2Connector);
server.setHandler(new AbstractHandler()
{
@Override
public void handle(String target, Request baseRequest, HttpServletRequest request, HttpServletResponse response)
{
response.setStatus(200);
baseRequest.setHandled(true);
}
});
server.start();
}
@AfterEach
public void stopServer() throws Exception
{
if (server != null)
server.stop();
}
@Test
public void testSimpleRequest() throws Exception
{
HTTP2Client h2Client = new HTTP2Client();
HttpClient client = new HttpClient(new HttpClientTransportOverHTTP2(h2Client), newSslContextFactory());
client.start();
try
{
int port = ((ServerConnector)server.getConnectors()[0]).getLocalPort();
ContentResponse contentResponse = client.GET("https://localhost:" + port);
assertEquals(200, contentResponse.getStatus());
}
finally
{
client.stop();
}
}
}

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

@ -36,8 +36,7 @@ public interface AppProvider extends LifeCycle
* if the provider {@link #isRunning()}.
*/
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);
@ -181,7 +179,7 @@ public class DeploymentManager extends ContainerLifeCycle
if (isRunning())
throw new IllegalStateException();
_providers.add(provider);
addBean(provider);
addBean(provider);
}
public void setLifeCycleBindings(Collection<AppLifeCycle.Binding> bindings)
@ -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

@ -203,7 +203,6 @@ public class Graph
Path path = breadthFirst(from,to,new CopyOnWriteArrayList<Path>(),new HashSet<Edge>());
return path;
}
private Path breadthFirst(Node from, Node destination, CopyOnWriteArrayList<Path> paths, Set<Edge> seen)
{
@ -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,26 +78,22 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
}
};
/* ------------------------------------------------------------ */
protected ScanningAppProvider()
{
}
/* ------------------------------------------------------------ */
protected ScanningAppProvider(FilenameFilter filter)
{
_filenameFilter = filter;
}
/* ------------------------------------------------------------ */
protected void setFilenameFilter(FilenameFilter filter)
{
if (isRunning())
throw new IllegalStateException();
_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
{
@ -161,14 +155,12 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_scanner = null;
}
}
/* ------------------------------------------------------------ */
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())
@ -198,8 +189,7 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_deploymentManager.addApp(app);
}
}
/* ------------------------------------------------------------ */
protected void fileRemoved(String filename) throws Exception
{
if (LOG.isDebugEnabled())
@ -208,8 +198,7 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
if (app != null)
_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
@ -309,16 +286,24 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
throw new IllegalArgumentException(e);
}
}
/* ------------------------------------------------------------ */
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
*/
@ -169,8 +164,7 @@ 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
*/
@ -203,8 +194,7 @@ public class WebAppProvider extends ScanningAppProvider
{
_configurationManager = configurationManager;
}
/* ------------------------------------------------------------ */
/**
* @param configurations The configuration class names.
*/
@ -212,8 +202,7 @@ public class WebAppProvider extends ScanningAppProvider
{
_configurationClasses = configurations==null?null:(String[])configurations.clone();
}
/* ------------------------------------------------------------ */
@ManagedAttribute("configuration classes for webapps to be processed through")
public String[] getConfigurationClasses()
{
@ -231,8 +220,7 @@ 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)
@ -265,8 +252,7 @@ public class WebAppProvider extends ScanningAppProvider
webapp.setAttribute(WebAppContext.BASETEMPDIR, _tempDirectory);
}
}
/* ------------------------------------------------------------ */
@Override
public ContextHandler createContextHandler(final App app) throws Exception
{
@ -349,8 +335,7 @@ 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.jmx.ObjectMBean;
import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject;
@ManagedObject("WebAppProvider mbean wrapper")
public class WebAppProviderMBean extends ObjectMBean
{
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

@ -147,7 +147,7 @@ We'll start by specifying which modules we want to use (this will create a start
[source, screen, subs="{sub-order}"]
....
C:\opt\myappbase>java -jar ..\jetty\start.jar --add-to-start=deploy,http,logging
C:\opt\myappbase>java -jar ..\jetty\start.jar --add-to-start=deploy,http,console-capture
WARNING: deploy initialised in ${jetty.base}\start.ini (appended)
WARNING: deploy enabled in ${jetty.base}\start.ini
@ -260,7 +260,7 @@ set PR_STOPPARAMS=--stop;STOP.KEY="%STOPKEY%";STOP.PORT=%STOPPORT%;STOP.WAIT=10
--JvmMs="%PR_JVMMS%" ^
--JvmMx="%PR_JVMMX%" ^
--JvmSs="%PR_JVMSS%" ^
--JvmOptions="%PR_JVMOPTIONS%" ^
--JvmOptions=%PR_JVMOPTIONS% ^
--Classpath="%PR_CLASSPATH%" ^
--StartMode="%PR_STARTMODE%" ^
--StartClass="%JETTY_START_CLASS%" ^

View File

@ -739,6 +739,9 @@ sslContextFactory.setProvider("Conscrypt");
If you are using the Jetty Distribution, please see the section on enabling the link:#jetty-conscrypt-distribution[Conscrypt SSL module.]
If you are using Conscrypt with Java 8, you must exclude `TLSv1.3` protocol as it is now enabled per default with Conscrypt 2.0.0 but not supported by Java 8.
==== Configuring SNI
From Java 8, the JVM contains support for the http://en.wikipedia.org/wiki/Server_Name_Indication[Server Name Indicator (SNI)] extension, which allows a SSL connection handshake to indicate one or more DNS names that it applies to.

View File

@ -29,6 +29,6 @@ Conscrypt is distributed under the Apache Licence 2.0
https://github.com/google/conscrypt/blob/master/LICENSE
[ini]
conscrypt.version?=1.1.4
conscrypt.version?=2.0.0
jetty.sslContext.provider?=Conscrypt

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;
@ -73,7 +72,7 @@ public class PreEncodedHttpField extends HttpField
else
LOG.warn("multiple PreEncoders for "+e.getHttpVersion());
}
// Always support HTTP1
if (__encoders[0]==null)
__encoders[0] = new Http1FieldPreEncoder();

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

@ -21,6 +21,13 @@
<Get class="org.eclipse.jetty.http2.HTTP2Cipher" name="COMPARATOR"/>
</Set>
<Set name="useCipherSuitesOrder">true</Set>
<Call name="addExcludeProtocols">
<Arg>
<Array type="java.lang.String">
<Item>TLSv1.3</Item>
</Array>
</Arg>
</Call>
</Ref>
</Configure>

View File

@ -24,13 +24,13 @@ import java.nio.file.Paths;
import java.util.ArrayList;
import java.util.List;
import java.util.concurrent.Executor;
import javax.inject.Inject;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http2.client.HTTP2Client;
import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2;
import org.eclipse.jetty.util.JavaVersion;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.Test;
@ -66,12 +66,12 @@ public class TestJettyOSGiBootHTTP2Conscrypt
{
ArrayList<Option> options = new ArrayList<>();
options.add(CoreOptions.junitBundles());
options.addAll(TestOSGiUtil.configureJettyHomeAndPort(true,"jetty-http2.xml"));
options.addAll(TestOSGiUtil.configureJettyHomeAndPort(true, "jetty-http2.xml"));
options.add(CoreOptions.bootDelegationPackages("org.xml.sax", "org.xml.*", "org.w3c.*", "javax.xml.*", "javax.activation.*"));
options.add(CoreOptions.systemPackages("com.sun.org.apache.xalan.internal.res","com.sun.org.apache.xml.internal.utils",
"com.sun.org.apache.xml.internal.utils", "com.sun.org.apache.xpath.internal",
"com.sun.org.apache.xpath.internal.jaxp", "com.sun.org.apache.xpath.internal.objects",
"sun.security", "sun.security.x509","sun.security.ssl"));
options.add(CoreOptions.systemPackages("com.sun.org.apache.xalan.internal.res", "com.sun.org.apache.xml.internal.utils",
"com.sun.org.apache.xml.internal.utils", "com.sun.org.apache.xpath.internal",
"com.sun.org.apache.xpath.internal.jaxp", "com.sun.org.apache.xpath.internal.objects",
"sun.security", "sun.security.x509", "sun.security.ssl"));
options.addAll(http2JettyDependencies());
options.addAll(TestOSGiUtil.coreJettyDependencies());
@ -94,10 +94,10 @@ public class TestJettyOSGiBootHTTP2Conscrypt
List<Option> res = new ArrayList<>();
res.add(CoreOptions.systemProperty("jetty.alpn.protocols").value("h2,http/1.1"));
res.add(CoreOptions.systemProperty("jetty.sslContext.provider").value("Conscrypt"));
res.add(wrappedBundle(mavenBundle().groupId("org.conscrypt").artifactId("conscrypt-openjdk-uber").versionAsInProject())
.imports("javax.net.ssl,*")
.exports("org.conscrypt;version="+System.getProperty("conscrypt-version"))
.exports("org.conscrypt;version=" + System.getProperty("conscrypt-version"))
.instructions("Bundle-NativeCode=META-INF/native/libconscrypt_openjdk_jni-linux-x86_64.so")
.start());
res.add(mavenBundle().groupId("org.eclipse.jetty.osgi").artifactId("jetty-osgi-alpn").versionAsInProject().noStart());
@ -129,14 +129,14 @@ public class TestJettyOSGiBootHTTP2Conscrypt
assertAllBundlesActiveOrResolved();
HTTP2Client client = new HTTP2Client();
try
try
{
String port = System.getProperty("boot.https.port");
assertNotNull(port);
Path path = Paths.get("src", "test", "config");
Path path = Paths.get("src", "test", "config");
File keys = path.resolve("etc").resolve("keystore").toFile();
HTTP2Client http2Client = new HTTP2Client();
SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyManagerPassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
@ -145,16 +145,20 @@ public class TestJettyOSGiBootHTTP2Conscrypt
sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setProvider("Conscrypt");
sslContextFactory.setEndpointIdentificationAlgorithm(null);
if (JavaVersion.VERSION.getPlatform() < 9)
{
// Conscrypt enables TLSv1.3 by default but it's not supported in Java 8.
sslContextFactory.addExcludeProtocols("TLSv1.3");
}
HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), sslContextFactory);
Executor executor = new QueuedThreadPool();
httpClient.setExecutor(executor);
httpClient.start();
ContentResponse response = httpClient.GET("https://localhost:"+port+"/jsp/jstl.jsp");
ContentResponse response = httpClient.GET("https://localhost:" + port + "/jsp/jstl.jsp");
assertEquals(200, response.getStatus());
assertTrue(response.getContentAsString().contains("JSTL Example"));
}
finally
{

View File

@ -30,7 +30,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor;
import javax.servlet.AsyncContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -55,7 +54,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 +103,7 @@ public class ConnectHandler extends HandlerWrapper
public void setScheduler(Scheduler scheduler)
{
updateBean(this.scheduler,scheduler);
this.scheduler = scheduler;
}
@ -115,6 +114,7 @@ public class ConnectHandler extends HandlerWrapper
public void setByteBufferPool(ByteBufferPool bufferPool)
{
updateBean(this.bufferPool, bufferPool);
this.bufferPool = bufferPool;
}
@ -167,10 +167,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

@ -28,7 +28,6 @@ import java.util.Enumeration;
import java.util.List;
import java.util.concurrent.CopyOnWriteArrayList;
import java.util.concurrent.Future;
import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
@ -400,18 +399,21 @@ public class Server extends HandlerWrapper implements Attributes
// #start(LifeCycle) is overridden so that connectors are not started
super.doStart();
// start connectors
// start connectors last
if (mex.size()==0)
{
for (Connector connector : _connectors)
{
try
{
connector.start();
}
catch(Throwable e)
catch (Throwable e)
{
mex.add(e);
}
}
}
mex.ifExceptionThrow();
LOG.info(String.format("Started @%dms",Uptime.getUptime()));

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;
@ -44,7 +32,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
@ -54,18 +41,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
{
/**
@ -657,6 +658,60 @@ public class GracefulStopTest
assertThat(response,Matchers.not(Matchers.containsString("Connection: close")));
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
{

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

@ -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;
case AUTO:
if (l.isRunning())
unmanage(b);
else
{
manage(b);
start(l);
}
break;
default:
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;
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;
}
}
/**

View File

@ -30,7 +30,7 @@
<infinispan.version>9.4.8.Final</infinispan.version>
<!-- default values are unsupported, but required to be defined for reactor sanity reasons -->
<alpn.version>undefined</alpn.version>
<conscrypt.version>1.4.1</conscrypt.version>
<conscrypt.version>2.0.0</conscrypt.version>
<asm.version>7.0</asm.version>
<jmh.version>1.21</jmh.version>
<jmhjar.name>benchmarks</jmhjar.name>