Merge remote-tracking branch 'eclipse/jetty-10.0.x' into jetty-10.0.x-3462-websocketclient-validation

Signed-off-by: Lachlan Roberts <lachlan@webtide.com>
This commit is contained in:
Lachlan Roberts 2019-03-19 11:33:19 +11:00
commit 403bdb70ea
60 changed files with 1477 additions and 546 deletions

View File

@ -99,7 +99,7 @@ public class LikeJettyXml
Server server = new Server(threadPool); Server server = new Server(threadPool);
// Scheduler // Scheduler
server.addBean(new ScheduledExecutorScheduler()); server.addBean(new ScheduledExecutorScheduler(null,false));
// HTTP Configuration // HTTP Configuration
HttpConfiguration http_config = new HttpConfiguration(); 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.jmx.MBeanContainer;
import org.eclipse.jetty.server.Server; import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.handler.AllowSymLinkAliasChecker;
import org.eclipse.jetty.webapp.Configurations; import org.eclipse.jetty.webapp.Configurations;
import org.eclipse.jetty.webapp.WebAppContext; import org.eclipse.jetty.webapp.WebAppContext;
@ -65,7 +64,7 @@ public class OneWebApp
Configurations.setServerDefault(server); Configurations.setServerDefault(server);
// Start things up! // Start things up!
server.start(); server.start();
server.dumpStdErr(); server.dumpStdErr();

View File

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

View File

@ -38,23 +38,57 @@
<version>${project.version}</version> <version>${project.version}</version>
<scope>test</scope> <scope>test</scope>
</dependency> </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> </dependencies>
<build> <build>
<plugins> <plugins>
<plugin> <plugin>
<groupId>org.apache.felix</groupId> <groupId>org.apache.felix</groupId>
<artifactId>maven-bundle-plugin</artifactId> <artifactId>maven-bundle-plugin</artifactId>
<extensions>true</extensions> <extensions>true</extensions>
<configuration> <configuration>
<instructions> <instructions>
<Bundle-Description>Conscrypt ALPN</Bundle-Description> <Bundle-Description>Conscrypt ALPN</Bundle-Description>
<Import-Package>org.conscrypt;version="${conscrypt.version}",*</Import-Package> <Import-Package>org.conscrypt;version="${conscrypt.version}",*</Import-Package>
<Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)";resolution:=optional</Require-Capability> <Require-Capability>osgi.extender; filter:="(osgi.extender=osgi.serviceloader.registrar)";resolution:=optional</Require-Capability>
<Provide-Capability>osgi.serviceloader;osgi.serviceloader=org.eclipse.jetty.io.ssl.ALPNProcessor$Server</Provide-Capability> <Provide-Capability>osgi.serviceloader;osgi.serviceloader=org.eclipse.jetty.io.ssl.ALPNProcessor$Server</Provide-Capability>
<_nouses>true</_nouses> <_nouses>true</_nouses>
</instructions> </instructions>
</configuration> </configuration>
</plugin> </plugin>
<plugin>
<artifactId>maven-surefire-plugin</artifactId>
<configuration>
<argLine>
@{argLine} ${jetty.surefire.argLine}
--add-reads org.eclipse.jetty.alpn.conscrypt.server=org.eclipse.jetty.server
</argLine>
</configuration>
</plugin>
</plugins> </plugins>
</build> </build>
</project> </project>

View File

@ -18,13 +18,13 @@
package org.eclipse.jetty.alpn.conscrypt.server; package org.eclipse.jetty.alpn.conscrypt.server;
import java.lang.reflect.Method;
import java.security.Security; import java.security.Security;
import java.util.List; import java.util.List;
import java.util.function.BiFunction;
import javax.net.ssl.SSLEngine; import javax.net.ssl.SSLEngine;
import javax.net.ssl.SSLSocket;
import org.conscrypt.ApplicationProtocolSelector;
import org.conscrypt.Conscrypt;
import org.conscrypt.OpenSSLProvider; import org.conscrypt.OpenSSLProvider;
import org.eclipse.jetty.alpn.server.ALPNServerConnection; import org.eclipse.jetty.alpn.server.ALPNServerConnection;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
@ -41,7 +41,7 @@ public class ConscryptServerALPNProcessor implements ALPNProcessor.Server
@Override @Override
public void init() public void init()
{ {
if (Security.getProvider("Conscrypt")==null) if (Security.getProvider("Conscrypt") == null)
{ {
Security.addProvider(new OpenSSLProvider()); Security.addProvider(new OpenSSLProvider());
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
@ -56,13 +56,11 @@ public class ConscryptServerALPNProcessor implements ALPNProcessor.Server
} }
@Override @Override
public void configure(SSLEngine sslEngine,Connection connection) public void configure(SSLEngine sslEngine, Connection connection)
{ {
try try
{ {
Method method = sslEngine.getClass().getMethod("setHandshakeApplicationProtocolSelector", BiFunction.class); Conscrypt.setApplicationProtocolSelector(sslEngine, new ALPNCallback((ALPNServerConnection)connection));
method.setAccessible(true);
method.invoke(sslEngine,new ALPNCallback((ALPNServerConnection)connection));
} }
catch (RuntimeException x) 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 final ALPNServerConnection alpnConnection;
private ALPNCallback(ALPNServerConnection connection) private ALPNCallback(ALPNServerConnection connection)
{ {
alpnConnection = connection; alpnConnection = connection;
((DecryptedEndPoint)alpnConnection.getEndPoint()).getSslConnection().addHandshakeListener(this); ((DecryptedEndPoint)alpnConnection.getEndPoint()).getSslConnection().addHandshakeListener(this);
} }
@Override @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); 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 @Override
@ -99,7 +105,7 @@ public class ConscryptServerALPNProcessor implements ALPNProcessor.Server
String protocol = alpnConnection.getProtocol(); String protocol = alpnConnection.getProtocol();
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
LOG.debug("TLS handshake succeeded, protocol={} for {}", protocol, alpnConnection); LOG.debug("TLS handshake succeeded, protocol={} for {}", protocol, alpnConnection);
if (protocol ==null) if (protocol == null)
alpnConnection.unsupported(); 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; _context = context;
} }
/* ------------------------------------------------------------ */
/** /**
* @return The deployment manager * @return The deployment manager
*/ */
@ -78,7 +77,6 @@ public class App
return _manager; return _manager;
} }
/* ------------------------------------------------------------ */
/** /**
* @return The AppProvider * @return The AppProvider
*/ */
@ -87,7 +85,6 @@ public class App
return _provider; return _provider;
} }
/* ------------------------------------------------------------ */
/** /**
* Get ContextHandler for the App. * Get ContextHandler for the App.
* *
@ -149,7 +146,6 @@ public class App
return this._context.getContextPath(); return this._context.getContextPath();
} }
/** /**
* The origin of this {@link App} as specified by the {@link AppProvider} * 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()}. * if the provider {@link #isRunning()}.
*/ */
void setDeploymentManager(DeploymentManager deploymentManager); void setDeploymentManager(DeploymentManager deploymentManager);
/* ------------------------------------------------------------ */
/** Create a ContextHandler for an App /** Create a ContextHandler for an App
* @param app The App * @param app The App
* @return A ContextHandler * @return A ContextHandler

View File

@ -152,7 +152,6 @@ public class DeploymentManager extends ContainerLifeCycle
} }
} }
/* ------------------------------------------------------------ */
/** Set the AppProviders. /** Set the AppProviders.
* The providers passed are added via {@link #addBean(Object)} so that * The providers passed are added via {@link #addBean(Object)} so that
* their lifecycles may be managed as a {@link ContainerLifeCycle}. * their lifecycles may be managed as a {@link ContainerLifeCycle}.
@ -170,7 +169,6 @@ public class DeploymentManager extends ContainerLifeCycle
addBean(provider); addBean(provider);
} }
@ManagedAttribute("Application Providers")
public Collection<AppProvider> getAppProviders() public Collection<AppProvider> getAppProviders()
{ {
return Collections.unmodifiableList(_providers); return Collections.unmodifiableList(_providers);
@ -181,7 +179,7 @@ public class DeploymentManager extends ContainerLifeCycle
if (isRunning()) if (isRunning())
throw new IllegalStateException(); throw new IllegalStateException();
_providers.add(provider); _providers.add(provider);
addBean(provider); addBean(provider);
} }
public void setLifeCycleBindings(Collection<AppLifeCycle.Binding> bindings) public void setLifeCycleBindings(Collection<AppLifeCycle.Binding> bindings)
@ -292,7 +290,6 @@ public class DeploymentManager extends ContainerLifeCycle
return Collections.unmodifiableCollection(_apps); return Collections.unmodifiableCollection(_apps);
} }
@ManagedAttribute("Deployed Apps")
public Collection<App> getApps() public Collection<App> getApps()
{ {
List<App> ret = new ArrayList< >(); 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.deploy.graph.Node;
import org.eclipse.jetty.server.DebugListener; import org.eclipse.jetty.server.DebugListener;
/** A Deployment binding that installs a DebugListener in all deployed contexts /** A Deployment binding that installs a DebugListener in all deployed contexts
*/ */
public class DebugListenerBinding extends DebugBinding public class DebugListenerBinding extends DebugBinding

View File

@ -18,8 +18,6 @@
package org.eclipse.jetty.deploy.bindings; package org.eclipse.jetty.deploy.bindings;
import java.io.File;
import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppLifeCycle; import org.eclipse.jetty.deploy.AppLifeCycle;
import org.eclipse.jetty.deploy.graph.Node; 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 static final Logger LOG = Log.getLogger(GlobalWebappConfigBinding.class);
private String _jettyXml; private String _jettyXml;
public String getJettyXml() public String getJettyXml()

View File

@ -203,7 +203,6 @@ public class Graph
Path path = breadthFirst(from,to,new CopyOnWriteArrayList<Path>(),new HashSet<Edge>()); Path path = breadthFirst(from,to,new CopyOnWriteArrayList<Path>(),new HashSet<Edge>());
return path; return path;
} }
private Path breadthFirst(Node from, Node destination, CopyOnWriteArrayList<Path> paths, Set<Edge> seen) private Path breadthFirst(Node from, Node destination, CopyOnWriteArrayList<Path> paths, Set<Edge> seen)
{ {
@ -246,7 +245,6 @@ public class Graph
return null; return null;
} }
public Set<Edge> getEdges() public Set<Edge> getEdges()
{ {
return _edges; return _edges;

View File

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

View File

@ -27,6 +27,7 @@ import java.util.HashMap;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.concurrent.CopyOnWriteArrayList; import java.util.concurrent.CopyOnWriteArrayList;
import java.util.stream.Collectors;
import org.eclipse.jetty.deploy.App; import org.eclipse.jetty.deploy.App;
import org.eclipse.jetty.deploy.AppProvider; 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.Scanner;
import org.eclipse.jetty.util.annotation.ManagedAttribute; import org.eclipse.jetty.util.annotation.ManagedAttribute;
import org.eclipse.jetty.util.annotation.ManagedObject; 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.component.AbstractLifeCycle;
import org.eclipse.jetty.util.log.Log; import org.eclipse.jetty.util.log.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
@ -55,7 +57,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
private int _scanInterval = 10; private int _scanInterval = 10;
private Scanner _scanner; private Scanner _scanner;
/* ------------------------------------------------------------ */
private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener() private final Scanner.DiscreteListener _scannerListener = new Scanner.DiscreteListener()
{ {
@Override @Override
@ -77,26 +78,22 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
} }
}; };
/* ------------------------------------------------------------ */
protected ScanningAppProvider() protected ScanningAppProvider()
{ {
} }
/* ------------------------------------------------------------ */
protected ScanningAppProvider(FilenameFilter filter) protected ScanningAppProvider(FilenameFilter filter)
{ {
_filenameFilter = filter; _filenameFilter = filter;
} }
/* ------------------------------------------------------------ */
protected void setFilenameFilter(FilenameFilter filter) protected void setFilenameFilter(FilenameFilter filter)
{ {
if (isRunning()) if (isRunning())
throw new IllegalStateException(); throw new IllegalStateException();
_filenameFilter = filter; _filenameFilter = filter;
} }
/* ------------------------------------------------------------ */
/** /**
* @return The index of currently deployed applications. * @return The index of currently deployed applications.
*/ */
@ -105,7 +102,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _appMap; return _appMap;
} }
/* ------------------------------------------------------------ */
/** /**
* Called by the Scanner.DiscreteListener to create a new App object. * 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 * 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); return new App(_deploymentManager,this,filename);
} }
/* ------------------------------------------------------------ */
@Override @Override
protected void doStart() throws Exception protected void doStart() throws Exception
{ {
@ -150,7 +145,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_scanner.start(); _scanner.start();
} }
/* ------------------------------------------------------------ */
@Override @Override
protected void doStop() throws Exception protected void doStop() throws Exception
{ {
@ -161,14 +155,12 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_scanner = null; _scanner = null;
} }
} }
/* ------------------------------------------------------------ */
protected boolean exists(String path) protected boolean exists(String path)
{ {
return _scanner.exists(path); return _scanner.exists(path);
} }
/* ------------------------------------------------------------ */
protected void fileAdded(String filename) throws Exception protected void fileAdded(String filename) throws Exception
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
@ -181,7 +173,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
} }
} }
/* ------------------------------------------------------------ */
protected void fileChanged(String filename) throws Exception protected void fileChanged(String filename) throws Exception
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
@ -198,8 +189,7 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
_deploymentManager.addApp(app); _deploymentManager.addApp(app);
} }
} }
/* ------------------------------------------------------------ */
protected void fileRemoved(String filename) throws Exception protected void fileRemoved(String filename) throws Exception
{ {
if (LOG.isDebugEnabled()) if (LOG.isDebugEnabled())
@ -208,8 +198,7 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
if (app != null) if (app != null)
_deploymentManager.removeApp(app); _deploymentManager.removeApp(app);
} }
/* ------------------------------------------------------------ */
/** /**
* Get the deploymentManager. * Get the deploymentManager.
* *
@ -220,8 +209,6 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _deploymentManager; return _deploymentManager;
} }
/* ------------------------------------------------------------ */
public Resource getMonitoredDirResource() public Resource getMonitoredDirResource()
{ {
if (_monitored.size()==0) if (_monitored.size()==0)
@ -231,60 +218,51 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
return _monitored.get(0); return _monitored.get(0);
} }
/* ------------------------------------------------------------ */
public String getMonitoredDirName() public String getMonitoredDirName()
{ {
Resource resource=getMonitoredDirResource(); Resource resource=getMonitoredDirResource();
return resource==null?null:resource.toString(); return resource==null?null:resource.toString();
} }
/* ------------------------------------------------------------ */
@ManagedAttribute("scanning interval to detect changes which need reloaded") @ManagedAttribute("scanning interval to detect changes which need reloaded")
public int getScanInterval() public int getScanInterval()
{ {
return _scanInterval; return _scanInterval;
} }
/* ------------------------------------------------------------ */
@ManagedAttribute("recursive scanning supported") @ManagedAttribute("recursive scanning supported")
public boolean isRecursive() public boolean isRecursive()
{ {
return _recursive; return _recursive;
} }
/* ------------------------------------------------------------ */
@Override @Override
public void setDeploymentManager(DeploymentManager deploymentManager) public void setDeploymentManager(DeploymentManager deploymentManager)
{ {
_deploymentManager = deploymentManager; _deploymentManager = deploymentManager;
} }
/* ------------------------------------------------------------ */
public void setMonitoredResources(List<Resource> resources) public void setMonitoredResources(List<Resource> resources)
{ {
_monitored.clear(); _monitored.clear();
_monitored.addAll(resources); _monitored.addAll(resources);
} }
/* ------------------------------------------------------------ */
public List<Resource> getMonitoredResources() public List<Resource> getMonitoredResources()
{ {
return Collections.unmodifiableList(_monitored); return Collections.unmodifiableList(_monitored);
} }
/* ------------------------------------------------------------ */
public void setMonitoredDirResource(Resource resource) public void setMonitoredDirResource(Resource resource)
{ {
setMonitoredResources(Collections.singletonList(resource)); setMonitoredResources(Collections.singletonList(resource));
} }
/* ------------------------------------------------------------ */
public void addScannerListener(Scanner.Listener listener) public void addScannerListener(Scanner.Listener listener)
{ {
_scanner.addListener(listener); _scanner.addListener(listener);
} }
/* ------------------------------------------------------------ */
/** /**
* @param dir * @param dir
* Directory to scan for context descriptors or war files * 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)); setMonitoredDirectories(Collections.singletonList(dir));
} }
/* ------------------------------------------------------------ */
public void setMonitoredDirectories(Collection<String> directories) public void setMonitoredDirectories(Collection<String> directories)
{ {
try try
@ -309,16 +286,24 @@ public abstract class ScanningAppProvider extends AbstractLifeCycle implements A
throw new IllegalArgumentException(e); throw new IllegalArgumentException(e);
} }
} }
/* ------------------------------------------------------------ */
protected void setRecursive(boolean recursive) protected void setRecursive(boolean recursive)
{ {
_recursive = recursive; _recursive = recursive;
} }
/* ------------------------------------------------------------ */
public void setScanInterval(int scanInterval) public void setScanInterval(int scanInterval)
{ {
_scanInterval = 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() public WebAppProvider()
{ {
super(); super();
@ -132,7 +131,6 @@ public class WebAppProvider extends ScanningAppProvider
setScanInterval(0); setScanInterval(0);
} }
/* ------------------------------------------------------------ */
/** Get the extractWars. /** Get the extractWars.
* @return the extractWars * @return the extractWars
*/ */
@ -142,7 +140,6 @@ public class WebAppProvider extends ScanningAppProvider
return _extractWars; return _extractWars;
} }
/* ------------------------------------------------------------ */
/** Set the extractWars. /** Set the extractWars.
* @param extractWars the extractWars to set * @param extractWars the extractWars to set
*/ */
@ -151,7 +148,6 @@ public class WebAppProvider extends ScanningAppProvider
_extractWars = extractWars; _extractWars = extractWars;
} }
/* ------------------------------------------------------------ */
/** Get the parentLoaderPriority. /** Get the parentLoaderPriority.
* @return the parentLoaderPriority * @return the parentLoaderPriority
*/ */
@ -161,7 +157,6 @@ public class WebAppProvider extends ScanningAppProvider
return _parentLoaderPriority; return _parentLoaderPriority;
} }
/* ------------------------------------------------------------ */
/** Set the parentLoaderPriority. /** Set the parentLoaderPriority.
* @param parentLoaderPriority the parentLoaderPriority to set * @param parentLoaderPriority the parentLoaderPriority to set
*/ */
@ -169,8 +164,7 @@ public class WebAppProvider extends ScanningAppProvider
{ {
_parentLoaderPriority = parentLoaderPriority; _parentLoaderPriority = parentLoaderPriority;
} }
/* ------------------------------------------------------------ */
/** Get the defaultsDescriptor. /** Get the defaultsDescriptor.
* @return the defaultsDescriptor * @return the defaultsDescriptor
*/ */
@ -180,7 +174,6 @@ public class WebAppProvider extends ScanningAppProvider
return _defaultsDescriptor; return _defaultsDescriptor;
} }
/* ------------------------------------------------------------ */
/** Set the defaultsDescriptor. /** Set the defaultsDescriptor.
* @param defaultsDescriptor the defaultsDescriptor to set * @param defaultsDescriptor the defaultsDescriptor to set
*/ */
@ -189,13 +182,11 @@ public class WebAppProvider extends ScanningAppProvider
_defaultsDescriptor = defaultsDescriptor; _defaultsDescriptor = defaultsDescriptor;
} }
/* ------------------------------------------------------------ */
public ConfigurationManager getConfigurationManager() public ConfigurationManager getConfigurationManager()
{ {
return _configurationManager; return _configurationManager;
} }
/* ------------------------------------------------------------ */
/** Set the configurationManager. /** Set the configurationManager.
* @param configurationManager the configurationManager to set * @param configurationManager the configurationManager to set
*/ */
@ -203,8 +194,7 @@ public class WebAppProvider extends ScanningAppProvider
{ {
_configurationManager = configurationManager; _configurationManager = configurationManager;
} }
/* ------------------------------------------------------------ */
/** /**
* @param configurations The configuration class names. * @param configurations The configuration class names.
*/ */
@ -212,8 +202,7 @@ public class WebAppProvider extends ScanningAppProvider
{ {
_configurationClasses = configurations==null?null:(String[])configurations.clone(); _configurationClasses = configurations==null?null:(String[])configurations.clone();
} }
/* ------------------------------------------------------------ */
@ManagedAttribute("configuration classes for webapps to be processed through") @ManagedAttribute("configuration classes for webapps to be processed through")
public String[] getConfigurationClasses() public String[] getConfigurationClasses()
{ {
@ -231,8 +220,7 @@ public class WebAppProvider extends ScanningAppProvider
{ {
_tempDirectory = directory; _tempDirectory = directory;
} }
/* ------------------------------------------------------------ */
/** /**
* Get the user supplied Work Directory. * Get the user supplied Work Directory.
* *
@ -244,7 +232,6 @@ public class WebAppProvider extends ScanningAppProvider
return _tempDirectory; return _tempDirectory;
} }
/* ------------------------------------------------------------ */
protected void initializeWebAppContextDefaults(WebAppContext webapp) protected void initializeWebAppContextDefaults(WebAppContext webapp)
{ {
if (_defaultsDescriptor != null) if (_defaultsDescriptor != null)
@ -265,8 +252,7 @@ public class WebAppProvider extends ScanningAppProvider
webapp.setAttribute(WebAppContext.BASETEMPDIR, _tempDirectory); webapp.setAttribute(WebAppContext.BASETEMPDIR, _tempDirectory);
} }
} }
/* ------------------------------------------------------------ */
@Override @Override
public ContextHandler createContextHandler(final App app) throws Exception public ContextHandler createContextHandler(final App app) throws Exception
{ {
@ -349,8 +335,7 @@ public class WebAppProvider extends ScanningAppProvider
return webAppContext; return webAppContext;
} }
/* ------------------------------------------------------------ */
@Override @Override
protected void fileChanged(String filename) throws Exception protected void fileChanged(String filename) throws Exception
{ {
@ -410,7 +395,6 @@ public class WebAppProvider extends ScanningAppProvider
super.fileChanged(filename); super.fileChanged(filename);
} }
/* ------------------------------------------------------------ */
@Override @Override
protected void fileAdded(String filename) throws Exception protected void fileAdded(String filename) throws Exception
{ {
@ -433,7 +417,6 @@ public class WebAppProvider extends ScanningAppProvider
return; return;
} }
//is the file that was added a .war file? //is the file that was added a .war file?
String lowname = file.getName().toLowerCase(Locale.ENGLISH); String lowname = file.getName().toLowerCase(Locale.ENGLISH);
if (lowname.endsWith(".war")) if (lowname.endsWith(".war"))
@ -453,8 +436,6 @@ public class WebAppProvider extends ScanningAppProvider
super.fileAdded(filename); super.fileAdded(filename);
} }
/* ------------------------------------------------------------ */
@Override @Override
protected void fileRemoved(String filename) throws Exception 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.io.IOException;
import java.lang.management.ManagementFactory; import java.lang.management.ManagementFactory;
import javax.management.MBeanServer; import javax.management.MBeanServer;
import javax.management.MBeanServerConnection; import javax.management.MBeanServerConnection;
import javax.management.remote.JMXConnector; import javax.management.remote.JMXConnector;
@ -74,7 +73,6 @@ public class JmxServiceConnection
return serviceUrl; return serviceUrl;
} }
/* ------------------------------------------------------------ */
/** /**
* Retrieve a connection to MBean server * 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}"] [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 initialised in ${jetty.base}\start.ini (appended)
WARNING: deploy enabled in ${jetty.base}\start.ini 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%" ^ --JvmMs="%PR_JVMMS%" ^
--JvmMx="%PR_JVMMX%" ^ --JvmMx="%PR_JVMMX%" ^
--JvmSs="%PR_JVMSS%" ^ --JvmSs="%PR_JVMSS%" ^
--JvmOptions="%PR_JVMOPTIONS%" ^ --JvmOptions=%PR_JVMOPTIONS% ^
--Classpath="%PR_CLASSPATH%" ^ --Classpath="%PR_CLASSPATH%" ^
--StartMode="%PR_STARTMODE%" ^ --StartMode="%PR_STARTMODE%" ^
--StartClass="%JETTY_START_CLASS%" ^ --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 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 ==== 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. 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 https://github.com/google/conscrypt/blob/master/LICENSE
[ini] [ini]
conscrypt.version?=1.1.4 conscrypt.version?=2.0.0
jetty.sslContext.provider?=Conscrypt jetty.sslContext.provider?=Conscrypt

View File

@ -19,10 +19,10 @@
package org.eclipse.jetty.http; package org.eclipse.jetty.http;
import static java.nio.charset.StandardCharsets.ISO_8859_1;
import java.util.Arrays; 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[] v=value.getBytes(ISO_8859_1);
byte[] bytes=Arrays.copyOf(n,n.length+2+v.length+2); byte[] bytes=Arrays.copyOf(n,n.length+2+v.length+2);
bytes[n.length]=(byte)':'; 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-2]=(byte)'\r';
bytes[bytes.length-1]=(byte)'\n'; bytes[bytes.length-1]=(byte)'\n';

View File

@ -21,7 +21,6 @@ package org.eclipse.jetty.http;
import java.nio.ByteBuffer; import java.nio.ByteBuffer;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Arrays;
import java.util.Iterator; import java.util.Iterator;
import java.util.List; import java.util.List;
import java.util.ServiceLoader; import java.util.ServiceLoader;
@ -73,7 +72,7 @@ public class PreEncodedHttpField extends HttpField
else else
LOG.warn("multiple PreEncoders for "+e.getHttpVersion()); LOG.warn("multiple PreEncoders for "+e.getHttpVersion());
} }
// Always support HTTP1 // Always support HTTP1
if (__encoders[0]==null) if (__encoders[0]==null)
__encoders[0] = new Http1FieldPreEncoder(); __encoders[0] = new Http1FieldPreEncoder();

View File

@ -18,15 +18,6 @@
package org.eclipse.jetty.http; 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.nio.ByteBuffer;
import java.util.Collections; import java.util.Collections;
import java.util.Enumeration; import java.util.Enumeration;
@ -40,6 +31,15 @@ import org.eclipse.jetty.util.BufferUtil;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.jupiter.api.Test; 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 public class HttpFieldsTest
{ {
@Test @Test
@ -299,6 +299,46 @@ public class HttpFieldsTest
assertEquals(false, e.hasMoreElements()); 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 @Test
public void testGetValues() throws Exception public void testGetValues() throws Exception
{ {

View File

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

View File

@ -24,13 +24,13 @@ import java.nio.file.Paths;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import javax.inject.Inject; import javax.inject.Inject;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse; import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http2.client.HTTP2Client; import org.eclipse.jetty.http2.client.HTTP2Client;
import org.eclipse.jetty.http2.client.http.HttpClientTransportOverHTTP2; 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.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.Test; import org.junit.Test;
@ -66,12 +66,12 @@ public class TestJettyOSGiBootHTTP2Conscrypt
{ {
ArrayList<Option> options = new ArrayList<>(); ArrayList<Option> options = new ArrayList<>();
options.add(CoreOptions.junitBundles()); 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.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", 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.xml.internal.utils", "com.sun.org.apache.xpath.internal",
"com.sun.org.apache.xpath.internal.jaxp", "com.sun.org.apache.xpath.internal.objects", "com.sun.org.apache.xpath.internal.jaxp", "com.sun.org.apache.xpath.internal.objects",
"sun.security", "sun.security.x509","sun.security.ssl")); "sun.security", "sun.security.x509", "sun.security.ssl"));
options.addAll(http2JettyDependencies()); options.addAll(http2JettyDependencies());
options.addAll(TestOSGiUtil.coreJettyDependencies()); options.addAll(TestOSGiUtil.coreJettyDependencies());
@ -94,10 +94,10 @@ public class TestJettyOSGiBootHTTP2Conscrypt
List<Option> res = new ArrayList<>(); List<Option> res = new ArrayList<>();
res.add(CoreOptions.systemProperty("jetty.alpn.protocols").value("h2,http/1.1")); res.add(CoreOptions.systemProperty("jetty.alpn.protocols").value("h2,http/1.1"));
res.add(CoreOptions.systemProperty("jetty.sslContext.provider").value("Conscrypt")); res.add(CoreOptions.systemProperty("jetty.sslContext.provider").value("Conscrypt"));
res.add(wrappedBundle(mavenBundle().groupId("org.conscrypt").artifactId("conscrypt-openjdk-uber").versionAsInProject()) res.add(wrappedBundle(mavenBundle().groupId("org.conscrypt").artifactId("conscrypt-openjdk-uber").versionAsInProject())
.imports("javax.net.ssl,*") .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") .instructions("Bundle-NativeCode=META-INF/native/libconscrypt_openjdk_jni-linux-x86_64.so")
.start()); .start());
res.add(mavenBundle().groupId("org.eclipse.jetty.osgi").artifactId("jetty-osgi-alpn").versionAsInProject().noStart()); res.add(mavenBundle().groupId("org.eclipse.jetty.osgi").artifactId("jetty-osgi-alpn").versionAsInProject().noStart());
@ -129,14 +129,14 @@ public class TestJettyOSGiBootHTTP2Conscrypt
assertAllBundlesActiveOrResolved(); assertAllBundlesActiveOrResolved();
HTTP2Client client = new HTTP2Client(); HTTP2Client client = new HTTP2Client();
try try
{ {
String port = System.getProperty("boot.https.port"); String port = System.getProperty("boot.https.port");
assertNotNull(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(); File keys = path.resolve("etc").resolve("keystore").toFile();
HTTP2Client http2Client = new HTTP2Client(); HTTP2Client http2Client = new HTTP2Client();
SslContextFactory sslContextFactory = new SslContextFactory(); SslContextFactory sslContextFactory = new SslContextFactory();
sslContextFactory.setKeyManagerPassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslContextFactory.setKeyManagerPassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
@ -145,16 +145,20 @@ public class TestJettyOSGiBootHTTP2Conscrypt
sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4"); sslContextFactory.setTrustStorePassword("OBF:1vny1zlo1x8e1vnw1vn61x8g1zlu1vn4");
sslContextFactory.setProvider("Conscrypt"); sslContextFactory.setProvider("Conscrypt");
sslContextFactory.setEndpointIdentificationAlgorithm(null); 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); HttpClient httpClient = new HttpClient(new HttpClientTransportOverHTTP2(http2Client), sslContextFactory);
Executor executor = new QueuedThreadPool(); Executor executor = new QueuedThreadPool();
httpClient.setExecutor(executor); httpClient.setExecutor(executor);
httpClient.start(); 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()); assertEquals(200, response.getStatus());
assertTrue(response.getContentAsString().contains("JSTL Example")); assertTrue(response.getContentAsString().contains("JSTL Example"));
} }
finally finally
{ {

View File

@ -30,7 +30,6 @@ import java.util.Set;
import java.util.concurrent.ConcurrentHashMap; import java.util.concurrent.ConcurrentHashMap;
import java.util.concurrent.ConcurrentMap; import java.util.concurrent.ConcurrentMap;
import java.util.concurrent.Executor; import java.util.concurrent.Executor;
import javax.servlet.AsyncContext; import javax.servlet.AsyncContext;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; 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.Callback;
import org.eclipse.jetty.util.HostPort; import org.eclipse.jetty.util.HostPort;
import org.eclipse.jetty.util.Promise; 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.Log;
import org.eclipse.jetty.util.log.Logger; import org.eclipse.jetty.util.log.Logger;
import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler; import org.eclipse.jetty.util.thread.ScheduledExecutorScheduler;
@ -105,6 +103,7 @@ public class ConnectHandler extends HandlerWrapper
public void setScheduler(Scheduler scheduler) public void setScheduler(Scheduler scheduler)
{ {
updateBean(this.scheduler,scheduler);
this.scheduler = scheduler; this.scheduler = scheduler;
} }
@ -115,6 +114,7 @@ public class ConnectHandler extends HandlerWrapper
public void setByteBufferPool(ByteBufferPool bufferPool) public void setByteBufferPool(ByteBufferPool bufferPool)
{ {
updateBean(this.bufferPool, bufferPool);
this.bufferPool = bufferPool; this.bufferPool = bufferPool;
} }
@ -167,10 +167,18 @@ public class ConnectHandler extends HandlerWrapper
executor = getServer().getThreadPool(); executor = getServer().getThreadPool();
if (scheduler == null) 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) if (bufferPool == null)
addBean(bufferPool = new MappedByteBufferPool()); {
bufferPool = new MappedByteBufferPool();
addBean(bufferPool);
}
addBean(selector = newSelectorManager()); addBean(selector = newSelectorManager());
selector.setConnectTimeout(getConnectTimeout()); selector.setConnectTimeout(getConnectTimeout());

View File

@ -183,7 +183,7 @@ public abstract class AbstractConnector extends ContainerLifeCycle implements Co
_executor=executor!=null?executor:_server.getThreadPool(); _executor=executor!=null?executor:_server.getThreadPool();
if (scheduler==null) if (scheduler==null)
scheduler=_server.getBean(Scheduler.class); 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) if (pool==null)
pool=_server.getBean(ByteBufferPool.class); pool=_server.getBean(ByteBufferPool.class);
_byteBufferPool = pool!=null?pool:new ArrayByteBufferPool(); _byteBufferPool = pool!=null?pool:new ArrayByteBufferPool();

View File

@ -369,14 +369,11 @@ public class Server extends HandlerWrapper implements Attributes
String gitHash = Jetty.GIT_HASH; String gitHash = Jetty.GIT_HASH;
String timestamp = Jetty.BUILD_TIMESTAMP; String timestamp = Jetty.BUILD_TIMESTAMP;
LOG.info("jetty-{}; built: {}; git: {}; jvm {}", getVersion(), timestamp, gitHash, System.getProperty("java.runtime.version",System.getProperty("java.version"))); LOG.info("jetty-{}; built: {}; git: {}; jvm {}", getVersion(), timestamp, gitHash, System.getProperty("java.runtime.version",System.getProperty("java.version")));
if (!Jetty.STABLE) if (!Jetty.STABLE)
{ LOG.warn("THIS IS NOT A STABLE RELEASE! DO NOT USE IN PRODUCTION!");
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(); MultiException mex=new MultiException();
@ -392,7 +389,7 @@ public class Server extends HandlerWrapper implements Attributes
mex.add(th); mex.add(th);
} }
}); });
// Throw now if verified start sequence and there was an open exception // Throw now if verified start sequence and there was an open exception
mex.ifExceptionThrow(); mex.ifExceptionThrow();
@ -410,29 +407,30 @@ public class Server extends HandlerWrapper implements Attributes
catch(Throwable e) catch(Throwable e)
{ {
mex.add(e); mex.add(e);
// stop any started connectors
_connectors.stream().filter(LifeCycle::isRunning).map(Object.class::cast).forEach(LifeCycle::stop);
} }
} }
mex.ifExceptionThrow(); mex.ifExceptionThrow();
LOG.info(String.format("Started @%dms",Uptime.getUptime())); LOG.info(String.format("Started @%dms",Uptime.getUptime()));
} }
catch(Throwable e1) catch(Throwable th)
{ {
try // Close any connectors that were opened
_connectors.stream().filter(NetworkConnector.class::isInstance).map(NetworkConnector.class::cast).forEach(nc->
{ {
// Stop any components already started! try
super.doStop(); {
} nc.close();
catch(Exception e2) }
{ catch(Throwable t2)
e1.addSuppressed(e2); {
} if (th!=t2)
finally th.addSuppressed(t2);
{ }
// Close any connectors that were opened });
_connectors.stream().filter(NetworkConnector.class::isInstance).map(NetworkConnector.class::cast).forEach(NetworkConnector::close); throw th;
}
throw e1;
} }
finally finally
{ {

View File

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

View File

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

View File

@ -18,18 +18,6 @@
package org.eclipse.jetty.server; 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.BufferedReader;
import java.io.IOException; import java.io.IOException;
import java.io.InputStream; import java.io.InputStream;
@ -44,7 +32,6 @@ import java.util.concurrent.TimeUnit;
import java.util.concurrent.TimeoutException; import java.util.concurrent.TimeoutException;
import java.util.concurrent.atomic.AtomicBoolean; import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference; import java.util.concurrent.atomic.AtomicReference;
import javax.servlet.ServletException; import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse; 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.LocalConnector.LocalEndPoint;
import org.eclipse.jetty.server.handler.AbstractHandler; import org.eclipse.jetty.server.handler.AbstractHandler;
import org.eclipse.jetty.server.handler.ContextHandler; 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.server.handler.StatisticsHandler;
import org.eclipse.jetty.util.BufferUtil; import org.eclipse.jetty.util.BufferUtil;
import org.eclipse.jetty.util.IO; 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.log.Log;
import org.eclipse.jetty.util.thread.QueuedThreadPool; import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.hamcrest.Matcher; import org.hamcrest.Matcher;
import org.hamcrest.Matchers; import org.hamcrest.Matchers;
import org.junit.jupiter.api.Disabled; import org.junit.jupiter.api.Disabled;
import org.junit.jupiter.api.Test; import org.junit.jupiter.api.Test;
import org.junit.jupiter.api.condition.DisabledOnOs; 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 public class GracefulStopTest
{ {
/** /**
@ -657,6 +658,60 @@ public class GracefulStopTest
assertThat(response,Matchers.not(Matchers.containsString("Connection: close"))); assertThat(response,Matchers.not(Matchers.containsString("Connection: close")));
assertTrue(latch.await(10,TimeUnit.SECONDS)); 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 static class NoopHandler extends AbstractHandler
{ {

View File

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

View File

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

View File

@ -96,35 +96,64 @@ public class ContainerLifeCycle extends AbstractLifeCycle implements Container,
_doStarted = true; _doStarted = true;
// start our managed and auto beans // 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; if (b._bean instanceof LifeCycle)
switch(b._managed)
{ {
case MANAGED: LifeCycle l = (LifeCycle)b._bean;
if (!l.isRunning()) switch (b._managed)
start(l); {
break; case MANAGED:
if (!l.isRunning())
case AUTO: start(l);
if (l.isRunning()) break;
unmanage(b);
else case AUTO:
{ if (l.isRunning())
manage(b); unmanage(b);
start(l); else
} {
break; manage(b);
start(l);
default: }
break; 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

@ -18,236 +18,50 @@
package org.eclipse.jetty.websocket.api.extensions; package org.eclipse.jetty.websocket.api.extensions;
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.HashMap;
import java.util.Iterator;
import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.ServiceLoader;
import java.util.Set; import java.util.Set;
/** /**
* Represents an Extension Configuration, as seen during the connection Handshake process. * Represents an Extension Configuration, as seen during the connection Handshake process.
*/ */
public class ExtensionConfig public interface ExtensionConfig
{ {
/** interface Parser
* Parse a single parameterized name.
*
* @param parameterizedName the parameterized name
* @return the ExtensionConfig
*/
public static ExtensionConfig parse(String parameterizedName)
{ {
return new ExtensionConfig(parameterizedName); ExtensionConfig parse(String parameterizedName);
} }
/** private static ExtensionConfig.Parser getParser()
* Parse enumeration of {@code Sec-WebSocket-Extensions} header values into a {@code ExtensionConfig} list
*
* @param valuesEnum the raw header values enum
* @return the list of extension configs
*/
public static List<ExtensionConfig> parseEnum(Enumeration<String> valuesEnum)
{ {
List<ExtensionConfig> configs = new ArrayList<>(); return ServiceLoader.load(ExtensionConfig.Parser.class).findFirst().get();
if (valuesEnum != null)
{
while (valuesEnum.hasMoreElements())
{
Iterator<String> extTokenIter = QuoteUtil.splitAt(valuesEnum.nextElement(), ",");
while (extTokenIter.hasNext())
{
String extToken = extTokenIter.next();
configs.add(ExtensionConfig.parse(extToken));
}
}
}
return configs;
} }
/** static ExtensionConfig parse(String parameterizedName)
* Parse 1 or more raw {@code Sec-WebSocket-Extensions} header values into a {@code ExtensionConfig} list
*
* @param rawSecWebSocketExtensions the raw header values
* @return the list of extension configs
*/
public static List<ExtensionConfig> parseList(String... rawSecWebSocketExtensions)
{ {
List<ExtensionConfig> configs = new ArrayList<>(); return getParser().parse(parameterizedName);
for (String rawValue : rawSecWebSocketExtensions)
{
Iterator<String> extTokenIter = QuoteUtil.splitAt(rawValue, ",");
while (extTokenIter.hasNext())
{
String extToken = extTokenIter.next();
configs.add(ExtensionConfig.parse(extToken));
}
}
return configs;
} }
/** String getName();
* Convert a list of {@code ExtensionConfig} to a header value
*
* @param configs the list of extension configs
* @return the header value (null if no configs present)
*/
public static String toHeaderValue(List<ExtensionConfig> configs)
{
if ((configs == null) || (configs.isEmpty()))
{
return null;
}
StringBuilder parameters = new StringBuilder();
boolean needsDelim = false;
for (ExtensionConfig ext : configs)
{
if (needsDelim)
{
parameters.append(", ");
}
parameters.append(ext.getParameterizedName());
needsDelim = true;
}
return parameters.toString();
}
private final String name; int getParameter(String key, int defValue);
private final Map<String, String> parameters;
/** String getParameter(String key, String defValue);
* Copy constructor
*
* @param copy the extension config to copy
*/
public ExtensionConfig(ExtensionConfig copy)
{
this.name = copy.name;
this.parameters = new HashMap<>();
this.parameters.putAll(copy.parameters);
}
public ExtensionConfig(String parameterizedName) String getParameterizedName();
{
Iterator<String> extListIter = QuoteUtil.splitAt(parameterizedName, ";");
this.name = extListIter.next();
this.parameters = new HashMap<>();
// now for parameters Set<String> getParameterKeys();
while (extListIter.hasNext())
{
String extParam = extListIter.next();
Iterator<String> extParamIter = QuoteUtil.splitAt(extParam, "=");
String key = extParamIter.next().trim();
String value = null;
if (extParamIter.hasNext())
{
value = extParamIter.next();
}
parameters.put(key, value);
}
}
public ExtensionConfig(String name, Map<String, String> parameters)
{
this.name = name;
this.parameters = parameters;
}
public String getName()
{
return name;
}
public final int getParameter(String key, int defValue)
{
String val = parameters.get(key);
if (val == null)
{
return defValue;
}
return Integer.parseInt(val);
}
public final String getParameter(String key, String defValue)
{
String val = parameters.get(key);
if (val == null)
{
return defValue;
}
return val;
}
public final String getParameterizedName()
{
StringBuilder str = new StringBuilder();
str.append(name);
for (String param : parameters.keySet())
{
str.append(';');
str.append(param);
String value = parameters.get(param);
if (value != null)
{
str.append('=');
QuoteUtil.quoteIfNeeded(str, value, ";=");
}
}
return str.toString();
}
public final Set<String> getParameterKeys()
{
return parameters.keySet();
}
/** /**
* Return parameters found in request URI. * Return parameters found in request URI.
* *
* @return the parameter map * @return the parameter map
*/ */
public final Map<String, String> getParameters() Map<String, String> getParameters();
{
return parameters;
}
/** void setParameter(String key);
* Initialize the parameters on this config from the other configuration.
*
* @param other the other configuration.
*/
public final void init(ExtensionConfig other)
{
this.parameters.clear();
this.parameters.putAll(other.parameters);
}
public final void setParameter(String key) void setParameter(String key, int value);
{
parameters.put(key, null);
}
public final void setParameter(String key, int value) void setParameter(String key, String value);
{
parameters.put(key, Integer.toString(value));
}
public final void setParameter(String key, String value)
{
parameters.put(key, value);
}
@Override
public String toString()
{
return getParameterizedName();
}
} }

View File

@ -0,0 +1,42 @@
//
// ========================================================================
// 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.websocket.client;
import org.eclipse.jetty.client.HttpRequest;
import org.eclipse.jetty.client.HttpResponse;
public interface JettyUpgradeListener
{
/**
* Event that triggers before the Handshake request is sent.
*
* @param request the request
*/
default void onHandshakeRequest(HttpRequest request)
{}
/**
* Event that triggers after the Handshake response has been received.
*
* @param request the request that was used
* @param response the response that was received
*/
default void onHandshakeResponse(HttpRequest request, HttpResponse response)
{}
}

View File

@ -32,6 +32,8 @@ import java.util.concurrent.ThreadLocalRandom;
import java.util.function.Consumer; import java.util.function.Consumer;
import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.HttpRequest;
import org.eclipse.jetty.client.HttpResponse;
import org.eclipse.jetty.io.ByteBufferPool; import org.eclipse.jetty.io.ByteBufferPool;
import org.eclipse.jetty.io.Connection; import org.eclipse.jetty.io.Connection;
import org.eclipse.jetty.util.DecoratedObjectFactory; import org.eclipse.jetty.util.DecoratedObjectFactory;
@ -124,15 +126,29 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketPoli
* @return the future for the session, available on success of connect * @return the future for the session, available on success of connect
* @throws IOException if unable to connect * @throws IOException if unable to connect
*/ */
public CompletableFuture<Session> connect(Object websocket, URI toUri, UpgradeRequest request, UpgradeListener upgradeListener) throws IOException public CompletableFuture<Session> connect(Object websocket, URI toUri, UpgradeRequest request, JettyUpgradeListener upgradeListener) throws IOException
{ {
for (Connection.Listener listener : getBeans(Connection.Listener.class)) for (Connection.Listener listener : getBeans(Connection.Listener.class))
coreClient.addBean(listener); coreClient.addBean(listener);
JettyClientUpgradeRequest upgradeRequest = new JettyClientUpgradeRequest(this, coreClient, request, toUri, websocket); JettyClientUpgradeRequest upgradeRequest = new JettyClientUpgradeRequest(this, coreClient, request, toUri, websocket);
if (upgradeListener != null) if (upgradeListener != null)
upgradeRequest.addListener(upgradeListener); {
upgradeRequest.addListener(new UpgradeListener()
{
@Override
public void onHandshakeRequest(HttpRequest request)
{
upgradeListener.onHandshakeRequest(request);
}
@Override
public void onHandshakeResponse(HttpRequest request, HttpResponse response)
{
upgradeListener.onHandshakeResponse(request, response);
}
});
}
coreClient.connect(upgradeRequest); coreClient.connect(upgradeRequest);
return upgradeRequest.getFutureSession(); return upgradeRequest.getFutureSession();
} }
@ -283,11 +299,6 @@ public class WebSocketClient extends ContainerLifeCycle implements WebSocketPoli
return getHttpClient().getExecutor(); return getHttpClient().getExecutor();
} }
public WebSocketExtensionRegistry getExtensionRegistry()
{
return extensionRegistry;
}
public HttpClient getHttpClient() public HttpClient getHttpClient()
{ {
return coreClient.getHttpClient(); return coreClient.getHttpClient();

View File

@ -22,6 +22,7 @@ import java.net.HttpCookie;
import java.net.URI; import java.net.URI;
import java.util.List; import java.util.List;
import java.util.concurrent.CompletableFuture; import java.util.concurrent.CompletableFuture;
import java.util.stream.Collectors;
import org.eclipse.jetty.client.HttpResponse; import org.eclipse.jetty.client.HttpResponse;
import org.eclipse.jetty.http.HttpFields; import org.eclipse.jetty.http.HttpFields;
@ -33,6 +34,7 @@ import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.UpgradeResponse; import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.client.WebSocketClient; import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler; import org.eclipse.jetty.websocket.common.JettyWebSocketFrameHandler;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.FrameHandler; import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest; import org.eclipse.jetty.websocket.core.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient; import org.eclipse.jetty.websocket.core.client.WebSocketCoreClient;
@ -74,9 +76,9 @@ public class JettyClientUpgradeRequest extends ClientUpgradeRequest
setSubProtocols(request.getSubProtocols()); setSubProtocols(request.getSubProtocols());
// Copy extensions // Copy extensions
/* TODO or not? setExtensions(request.getExtensions().stream()
setExtensions(request.getExtensions()); .map(c -> new ExtensionConfig(c.getName(), c.getParameters()))
*/ .collect(Collectors.toList()));
// Copy method from upgradeRequest object // Copy method from upgradeRequest object
if (request.getMethod() != null) if (request.getMethod() != null)

View File

@ -16,6 +16,9 @@
// ======================================================================== // ========================================================================
// //
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.common.ExtensionConfigParser;
module org.eclipse.jetty.websocket.jetty.common module org.eclipse.jetty.websocket.jetty.common
{ {
exports org.eclipse.jetty.websocket.common; exports org.eclipse.jetty.websocket.common;
@ -27,4 +30,6 @@ module org.eclipse.jetty.websocket.jetty.common
requires org.eclipse.jetty.util; requires org.eclipse.jetty.util;
requires org.eclipse.jetty.websocket.core; requires org.eclipse.jetty.websocket.core;
requires org.eclipse.jetty.websocket.jetty.api; requires org.eclipse.jetty.websocket.jetty.api;
provides ExtensionConfig.Parser with ExtensionConfigParser;
} }

View File

@ -0,0 +1,36 @@
//
// ========================================================================
// 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.websocket.common;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
public class ExtensionConfigParser implements org.eclipse.jetty.websocket.api.extensions.ExtensionConfig.Parser
{
/**
* Parse a single parameterized name.
*
* @param parameterizedName the parameterized name
* @return the ExtensionConfig
*/
@Override
public JettyExtensionConfig parse(String parameterizedName)
{
return new JettyExtensionConfig(ExtensionConfig.parse(parameterizedName));
}
}

View File

@ -0,0 +1,128 @@
//
// ========================================================================
// 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.websocket.common;
import java.util.Map;
import java.util.Set;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
/**
* Represents an Extension Configuration, as seen during the connection Handshake process.
*/
public class JettyExtensionConfig implements org.eclipse.jetty.websocket.api.extensions.ExtensionConfig
{
private final ExtensionConfig config;
/**
* Copy constructor
*
* @param copy the extension config to copy
*/
public JettyExtensionConfig(JettyExtensionConfig copy)
{
this(copy.config);
}
public JettyExtensionConfig(ExtensionConfig config)
{
this.config = config;
}
public JettyExtensionConfig(String parameterizedName)
{
this.config = new ExtensionConfig(parameterizedName);
}
public JettyExtensionConfig(String name, Map<String, String> parameters)
{
this.config = new ExtensionConfig(name, parameters);
}
public ExtensionConfig getCoreConfig()
{
return config;
}
@Override
public String getName()
{
return config.getName();
}
@Override
public final int getParameter(String key, int defValue)
{
return config.getParameter(key, defValue);
}
@Override
public final String getParameter(String key, String defValue)
{
return config.getParameter(key, defValue);
}
@Override
public final String getParameterizedName()
{
return config.getParameterizedName();
}
@Override
public final Set<String> getParameterKeys()
{
return config.getParameterKeys();
}
/**
* Return parameters found in request URI.
*
* @return the parameter map
*/
@Override
public final Map<String, String> getParameters()
{
return config.getParameters();
}
@Override
public final void setParameter(String key)
{
config.setParameter(key);
}
@Override
public final void setParameter(String key, int value)
{
config.setParameter(key, value);
}
@Override
public final void setParameter(String key, String value)
{
config.setParameter(key, value);
}
@Override
public String toString()
{
return config.toString();
}
}

View File

@ -0,0 +1 @@
org.eclipse.jetty.websocket.common.ExtensionConfigParser

View File

@ -0,0 +1,328 @@
//
// ========================================================================
// 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.websocket.server;
import java.net.HttpCookie;
import java.net.InetSocketAddress;
import java.net.SocketAddress;
import java.net.URI;
import java.security.Principal;
import java.security.cert.X509Certificate;
import java.util.Enumeration;
import java.util.List;
import java.util.Locale;
import java.util.Map;
import java.util.stream.Collectors;
import javax.servlet.ServletRequest;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.common.JettyExtensionConfig;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
public class JettyServerUpgradeRequest
{
private ServletUpgradeRequest upgradeRequest;
public JettyServerUpgradeRequest(ServletUpgradeRequest request)
{
upgradeRequest = request;
}
/**
* @return The {@link X509Certificate} instance at request attribute "javax.servlet.request.X509Certificate" or null.
*/
public X509Certificate[] getCertificates()
{
return upgradeRequest.getCertificates();
}
/**
* @see HttpServletRequest#getCookies()
* @return Request cookies
*/
public List<HttpCookie> getCookies()
{
return upgradeRequest.getCookies();
}
/**
* @return The extensions offered
* @see Negotiation#getOfferedExtensions()
*/
public List<ExtensionConfig> getExtensions()
{
return upgradeRequest.getExtensions().stream().map(JettyExtensionConfig::new).collect(Collectors.toList());
}
/**
* @param name Header name
* @return Header value or null
* @see HttpServletRequest#getHeader(String)
*/
public String getHeader(String name)
{
return upgradeRequest.getHeader(name);
}
/**
* @param name Header name
* @return Header value as integer or -1
* @see HttpServletRequest#getHeader(String)
*/
public int getHeaderInt(String name)
{
return upgradeRequest.getHeaderInt(name);
}
/**
* @return Map of headers
*/
public Map<String, List<String>> getHeadersMap()
{
return upgradeRequest.getHeadersMap();
}
/**
* @param name Header name
* @return List of header values or null
*/
public List<String> getHeaders(String name)
{
return upgradeRequest.getHeaders(name);
}
/**
* @return The requested host
* @see HttpServletRequest#getRequestURL()
*/
public String getHost()
{
return upgradeRequest.getHost();
}
/**
* @return Immutable version of {@link HttpServletRequest}
*/
public HttpServletRequest getHttpServletRequest()
{
return upgradeRequest.getHttpServletRequest();
}
/**
* @return The HTTP protocol version
* @see HttpServletRequest#getProtocol()
*/
public String getHttpVersion()
{
return upgradeRequest.getHttpVersion();
}
/**
* @return The requested Locale
* @see HttpServletRequest#getLocale()
*/
public Locale getLocale()
{
return upgradeRequest.getLocale();
}
/**
* @return The requested Locales
* @see HttpServletRequest#getLocales()
*/
public Enumeration<Locale> getLocales()
{
return upgradeRequest.getLocales();
}
/**
* @return The local requested address, which is typically an {@link InetSocketAddress}, but may be another derivation of {@link SocketAddress}
* @see ServletRequest#getLocalAddr()
* @see ServletRequest#getLocalPort()
*/
public SocketAddress getLocalSocketAddress()
{
return upgradeRequest.getLocalSocketAddress();
}
/**
* @return The requested method
* @see HttpServletRequest#getMethod()
*/
public String getMethod()
{
return upgradeRequest.getMethod();
}
/**
* @return The origin header value
*/
public String getOrigin()
{
return upgradeRequest.getOrigin();
}
/**
* @return The request parameter map
* @see ServletRequest#getParameterMap()
*/
public Map<String, List<String>> getParameterMap()
{
return upgradeRequest.getParameterMap();
}
/**
* @return WebSocket protocol version from "Sec-WebSocket-Version" header
*/
public String getProtocolVersion()
{
return upgradeRequest.getProtocolVersion();
}
/**
* @return The request query string
* @see HttpServletRequest#getQueryString()
*/
public String getQueryString()
{
return upgradeRequest.getQueryString();
}
/**
* @return The remote request address, which is typically an {@link InetSocketAddress}, but may be another derivation of {@link SocketAddress}
* @see ServletRequest#getRemoteAddr()
* @see ServletRequest#getRemotePort()
*/
public SocketAddress getRemoteSocketAddress()
{
return upgradeRequest.getRemoteSocketAddress();
}
/**
* @return The request URI path within the context
*/
public String getRequestPath()
{
return upgradeRequest.getRequestPath();
}
/**
* @return The request URI
* @see HttpServletRequest#getRequestURL()
*/
public URI getRequestURI()
{
return upgradeRequest.getRequestURI();
}
/**
* @param name Attribute name
* @return Attribute value or null
* @see ServletRequest#getAttribute(String)
*/
public Object getServletAttribute(String name)
{
return upgradeRequest.getServletAttribute(name);
}
/**
* @return Request attribute map
*/
public Map<String, Object> getServletAttributes()
{
return upgradeRequest.getServletAttributes();
}
/**
* @return Request parameters
* @see ServletRequest#getParameterMap()
*/
public Map<String, List<String>> getServletParameters()
{
return upgradeRequest.getServletParameters();
}
/**
* @return The HttpSession, which may be null or invalidated
* @see HttpServletRequest#getSession(boolean)
*/
public HttpSession getSession()
{
return upgradeRequest.getSession();
}
/**
* @return Get WebSocket negotiation offered sub protocols
*/
public List<String> getSubProtocols()
{
return upgradeRequest.getSubProtocols();
}
/**
* @return The User's {@link Principal} or null
* @see HttpServletRequest#getUserPrincipal()
*/
public Principal getUserPrincipal()
{
return upgradeRequest.getUserPrincipal();
}
/**
* @param subprotocol A sub protocol name
* @return True if the sub protocol was offered
*/
public boolean hasSubProtocol(String subprotocol)
{
return upgradeRequest.hasSubProtocol(subprotocol);
}
/**
* @return True if the request is secure
* @see ServletRequest#isSecure()
*/
public boolean isSecure()
{
return upgradeRequest.isSecure();
}
/**
* @param role The user role
* @return True if the requests user has the role
* @see HttpServletRequest#isUserInRole(String)
*/
public boolean isUserInRole(String role)
{
return upgradeRequest.isUserInRole(role);
}
/**
* @param name Attribute name
* @param value Attribute value to set
* @see ServletRequest#setAttribute(String, Object)
*/
public void setServletAttribute(String name, Object value)
{
upgradeRequest.setServletAttribute(name, value);
}
}

View File

@ -0,0 +1,121 @@
//
// ========================================================================
// 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.websocket.server;
import java.io.IOException;
import java.util.List;
import java.util.Map;
import java.util.Set;
import java.util.stream.Collectors;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.common.JettyExtensionConfig;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
public class JettyServerUpgradeResponse
{
private ServletUpgradeResponse upgradeResponse;
public JettyServerUpgradeResponse(ServletUpgradeResponse response)
{
upgradeResponse = response;
}
public void addHeader(String name, String value)
{
upgradeResponse.addHeader(name, value);
}
public void setHeader(String name, String value)
{
upgradeResponse.setHeader(name, value);
}
public void setHeader(String name, List<String> values)
{
upgradeResponse.setHeader(name, values);
}
public String getAcceptedSubProtocol()
{
return upgradeResponse.getAcceptedSubProtocol();
}
public List<ExtensionConfig> getExtensions()
{
return upgradeResponse.getExtensions().stream().map(JettyExtensionConfig::new).collect(Collectors.toList());
}
public String getHeader(String name)
{
return upgradeResponse.getHeader(name);
}
public Set<String> getHeaderNames()
{
return upgradeResponse.getHeaderNames();
}
public Map<String, List<String>> getHeadersMap()
{
return upgradeResponse.getHeadersMap();
}
public List<String> getHeaders(String name)
{
return upgradeResponse.getHeaders(name);
}
public int getStatusCode()
{
return upgradeResponse.getStatusCode();
}
public boolean isCommitted()
{
return upgradeResponse.isCommitted();
}
public void sendError(int statusCode, String message) throws IOException
{
upgradeResponse.sendError(statusCode, message);
}
public void sendForbidden(String message) throws IOException
{
upgradeResponse.sendForbidden(message);
}
public void setAcceptedSubProtocol(String protocol)
{
upgradeResponse.setAcceptedSubProtocol(protocol);
}
public void setExtensions(List<ExtensionConfig> configs)
{
upgradeResponse.setExtensions(configs.stream()
.map(c->new org.eclipse.jetty.websocket.core.ExtensionConfig(c.getName(), c.getParameters()))
.collect(Collectors.toList()));
}
public void setStatusCode(int statusCode)
{
upgradeResponse.setStatusCode(statusCode);
}
}

View File

@ -0,0 +1,39 @@
//
// ========================================================================
// 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.websocket.server;
/**
* Abstract WebSocket creator interface.
* <p>
* Should you desire filtering of the WebSocket object creation due to criteria such as origin or sub-protocol, then you will be required to implement a custom
* WebSocketCreator implementation.
* </p>
*/
public interface JettyWebSocketCreator
{
/**
* Create a websocket from the incoming request.
*
* @param req the request details
* @param resp the response details
* @return a websocket object to use, or null if no websocket should be created from this request.
*/
Object createWebSocket(JettyServerUpgradeRequest req, JettyServerUpgradeResponse resp);
}

View File

@ -28,7 +28,6 @@ import java.util.function.Consumer;
import javax.servlet.ServletContext; import javax.servlet.ServletContext;
import org.eclipse.jetty.http.pathmap.PathSpec; import org.eclipse.jetty.http.pathmap.PathSpec;
import org.eclipse.jetty.server.handler.ContextHandler;
import org.eclipse.jetty.servlet.ServletContextHandler; import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.util.component.ContainerLifeCycle; import org.eclipse.jetty.util.component.ContainerLifeCycle;
import org.eclipse.jetty.util.component.LifeCycle; import org.eclipse.jetty.util.component.LifeCycle;
@ -44,7 +43,6 @@ import org.eclipse.jetty.websocket.core.FrameHandler;
import org.eclipse.jetty.websocket.core.WebSocketComponents; import org.eclipse.jetty.websocket.core.WebSocketComponents;
import org.eclipse.jetty.websocket.core.WebSocketException; import org.eclipse.jetty.websocket.core.WebSocketException;
import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory; import org.eclipse.jetty.websocket.servlet.FrameHandlerFactory;
import org.eclipse.jetty.websocket.servlet.WebSocketCreator;
import org.eclipse.jetty.websocket.servlet.WebSocketMapping; import org.eclipse.jetty.websocket.servlet.WebSocketMapping;
public class JettyWebSocketServerContainer extends ContainerLifeCycle implements WebSocketContainer, WebSocketPolicy, LifeCycle.Listener public class JettyWebSocketServerContainer extends ContainerLifeCycle implements WebSocketContainer, WebSocketPolicy, LifeCycle.Listener
@ -114,13 +112,15 @@ public class JettyWebSocketServerContainer extends ContainerLifeCycle implements
addSessionListener(sessionTracker); addSessionListener(sessionTracker);
} }
public void addMapping(String pathSpec, WebSocketCreator creator) public void addMapping(String pathSpec, JettyWebSocketCreator creator)
{ {
PathSpec ps = WebSocketMapping.parsePathSpec(pathSpec); PathSpec ps = WebSocketMapping.parsePathSpec(pathSpec);
if (webSocketMapping.getMapping(ps) != null) if (webSocketMapping.getMapping(ps) != null)
throw new WebSocketException("Duplicate WebSocket Mapping for PathSpec"); throw new WebSocketException("Duplicate WebSocket Mapping for PathSpec");
webSocketMapping.addMapping(ps, creator, frameHandlerFactory, customizer); webSocketMapping.addMapping(ps,
(req, resp)-> creator.createWebSocket(new JettyServerUpgradeRequest(req), new JettyServerUpgradeResponse(resp)),
frameHandlerFactory, customizer);
} }
@Override @Override

View File

@ -27,6 +27,7 @@ import java.util.stream.Collectors;
import org.eclipse.jetty.websocket.api.UpgradeRequest; import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig; import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.common.JettyExtensionConfig;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest; import org.eclipse.jetty.websocket.servlet.ServletUpgradeRequest;
public class DelegatedJettyServletUpgradeRequest implements UpgradeRequest public class DelegatedJettyServletUpgradeRequest implements UpgradeRequest
@ -60,7 +61,7 @@ public class DelegatedJettyServletUpgradeRequest implements UpgradeRequest
public List<ExtensionConfig> getExtensions() public List<ExtensionConfig> getExtensions()
{ {
return this.servletRequest.getExtensions().stream() return this.servletRequest.getExtensions().stream()
.map((ext) -> new org.eclipse.jetty.websocket.api.extensions.ExtensionConfig(ext.getName(), ext.getParameters())) .map((ext) -> new JettyExtensionConfig(ext.getName(), ext.getParameters()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View File

@ -18,16 +18,17 @@
package org.eclipse.jetty.websocket.server.internal; package org.eclipse.jetty.websocket.server.internal;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
import java.io.IOException; import java.io.IOException;
import java.util.List; import java.util.List;
import java.util.Map; import java.util.Map;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import org.eclipse.jetty.websocket.api.UpgradeResponse;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.common.JettyExtensionConfig;
import org.eclipse.jetty.websocket.servlet.ServletUpgradeResponse;
public class UpgradeResponseAdapter implements UpgradeResponse public class UpgradeResponseAdapter implements UpgradeResponse
{ {
private final ServletUpgradeResponse servletResponse; private final ServletUpgradeResponse servletResponse;
@ -53,7 +54,7 @@ public class UpgradeResponseAdapter implements UpgradeResponse
public List<ExtensionConfig> getExtensions() public List<ExtensionConfig> getExtensions()
{ {
return this.servletResponse.getExtensions().stream() return this.servletResponse.getExtensions().stream()
.map((ext) -> new org.eclipse.jetty.websocket.api.extensions.ExtensionConfig(ext.getName(), ext.getParameters())) .map((ext) -> new JettyExtensionConfig(ext.getName(), ext.getParameters()))
.collect(Collectors.toList()); .collect(Collectors.toList());
} }

View File

@ -0,0 +1,136 @@
//
// ========================================================================
// 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.websocket.tests;
import java.net.URI;
import java.util.List;
import java.util.concurrent.CompletableFuture;
import java.util.concurrent.CountDownLatch;
import java.util.concurrent.TimeUnit;
import org.eclipse.jetty.client.HttpRequest;
import org.eclipse.jetty.client.HttpResponse;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.websocket.api.Session;
import org.eclipse.jetty.websocket.api.UpgradeRequest;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.eclipse.jetty.websocket.client.ClientUpgradeRequest;
import org.eclipse.jetty.websocket.client.JettyUpgradeListener;
import org.eclipse.jetty.websocket.client.WebSocketClient;
import org.eclipse.jetty.websocket.server.JettyWebSocketServerContainer;
import org.eclipse.jetty.websocket.server.JettyWebSocketServletContainerInitializer;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertEquals;
import static org.junit.jupiter.api.Assertions.assertNotNull;
import static org.junit.jupiter.api.Assertions.assertThrows;
import static org.junit.jupiter.api.Assertions.assertTrue;
public class JettyWebSocketExtensionConfigTest
{
Server server;
WebSocketClient client;
@BeforeEach
public void start() throws Exception
{
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(8080);
server.addConnector(connector);
ServletContextHandler contextHandler = new ServletContextHandler(ServletContextHandler.SESSIONS);
contextHandler.setContextPath("/");
server.setHandler(contextHandler);
JettyWebSocketServerContainer container = JettyWebSocketServletContainerInitializer.configureContext(contextHandler);
container.addMapping("/", (req, resp)->
{
assertEquals(req.getExtensions().stream().filter(e -> e.getName().equals("permessage-deflate")).count(), 1);
assertEquals(resp.getExtensions().stream().filter(e -> e.getName().equals("permessage-deflate")).count(), 1);
ExtensionConfig nonRequestedExtension = ExtensionConfig.parse("identity");
assertNotNull(nonRequestedExtension);
assertThrows(IllegalArgumentException.class,
()->resp.setExtensions(List.of(nonRequestedExtension)),
"should not allow extensions not requested");
// Check identity extension was not added because it was not requested
assertEquals(resp.getExtensions().stream().filter(config -> config.getName().equals("identity")).count(), 0);
assertEquals(resp.getExtensions().stream().filter(e -> e.getName().equals("permessage-deflate")).count(), 1);
return new EchoSocket();
});
server.start();
client = new WebSocketClient();
client.start();
}
@AfterEach
public void stop() throws Exception
{
client.stop();
server.stop();
}
@Test
public void testJettyExtensionConfig() throws Exception
{
URI uri = URI.create("ws://localhost:8080/filterPath");
EventSocket socket = new EventSocket();
UpgradeRequest request = new ClientUpgradeRequest();
request.addExtensions(ExtensionConfig.parse("permessage-deflate"));
CountDownLatch correctResponseExtensions = new CountDownLatch(1);
JettyUpgradeListener listener = new JettyUpgradeListener()
{
@Override
public void onHandshakeResponse(HttpRequest request, HttpResponse response)
{
String extensions = response.getHeaders().get(HttpHeader.SEC_WEBSOCKET_EXTENSIONS);
if("permessage-deflate".equals(extensions))
correctResponseExtensions.countDown();
else
throw new IllegalStateException("Unexpected Negotiated Extensions: " + extensions);
}
};
CompletableFuture<Session> connect = client.connect(socket, uri, request, listener);
try(Session session = connect.get(5, TimeUnit.SECONDS))
{
session.getRemote().sendString("hello world");
}
assertTrue(socket.closed.await(5, TimeUnit.SECONDS));
assertTrue(correctResponseExtensions.await(5, TimeUnit.SECONDS));
String msg = socket.receivedMessages.poll();
assertThat(msg, is("hello world"));
}
}

View File

@ -16,13 +16,14 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.api.extensions; package org.eclipse.jetty.websocket.tests.extensions;
import org.junit.jupiter.api.Test;
import java.util.HashMap; import java.util.HashMap;
import java.util.Map; import java.util.Map;
import org.eclipse.jetty.websocket.api.extensions.ExtensionConfig;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.hamcrest.Matchers.notNullValue; import static org.hamcrest.Matchers.notNullValue;

View File

@ -16,13 +16,14 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.api.util; package org.eclipse.jetty.websocket.tests.util;
import org.junit.jupiter.api.Test;
import java.util.Iterator; import java.util.Iterator;
import java.util.NoSuchElementException; import java.util.NoSuchElementException;
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;
import static org.junit.jupiter.api.Assertions.assertThrows; import static org.junit.jupiter.api.Assertions.assertThrows;

View File

@ -16,16 +16,17 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.api.util; package org.eclipse.jetty.websocket.tests.util;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.List; import java.util.List;
import java.util.stream.Stream; import java.util.stream.Stream;
import org.eclipse.jetty.websocket.api.util.QuoteUtil;
import org.junit.jupiter.params.ParameterizedTest;
import org.junit.jupiter.params.provider.Arguments;
import org.junit.jupiter.params.provider.MethodSource;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;

View File

@ -16,13 +16,14 @@
// ======================================================================== // ========================================================================
// //
package org.eclipse.jetty.websocket.api.util; package org.eclipse.jetty.websocket.tests.util;
import org.junit.jupiter.api.Test;
import java.net.URI; import java.net.URI;
import java.net.URISyntaxException; import java.net.URISyntaxException;
import org.eclipse.jetty.websocket.api.util.WSURI;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat; import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.is; import static org.hamcrest.Matchers.is;

View File

@ -28,7 +28,8 @@ public interface UpgradeListener
* *
* @param request the request * @param request the request
*/ */
void onHandshakeRequest(HttpRequest request); default void onHandshakeRequest(HttpRequest request)
{}
/** /**
* Event that triggers after the Handshake response has been received. * Event that triggers after the Handshake response has been received.
@ -36,5 +37,6 @@ public interface UpgradeListener
* @param request the request that was used * @param request the request that was used
* @param response the response that was received * @param response the response that was received
*/ */
void onHandshakeResponse(HttpRequest request, HttpResponse response); default void onHandshakeResponse(HttpRequest request, HttpResponse response)
{}
} }

View File

@ -18,11 +18,6 @@
package org.eclipse.jetty.websocket.servlet; package org.eclipse.jetty.websocket.servlet;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.server.Negotiation;
import javax.servlet.http.HttpServletResponse;
import java.io.IOException; import java.io.IOException;
import java.util.ArrayList; import java.util.ArrayList;
import java.util.Collections; import java.util.Collections;
@ -33,6 +28,12 @@ import java.util.Objects;
import java.util.Set; import java.util.Set;
import java.util.stream.Collectors; import java.util.stream.Collectors;
import javax.servlet.http.HttpServletResponse;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.websocket.core.ExtensionConfig;
import org.eclipse.jetty.websocket.core.server.Negotiation;
/** /**
* Servlet Specific UpgradeResponse implementation. * Servlet Specific UpgradeResponse implementation.
*/ */
@ -166,6 +167,23 @@ public class ServletUpgradeResponse
public void setExtensions(List<ExtensionConfig> configs) public void setExtensions(List<ExtensionConfig> configs)
{ {
// This validation is also done later in RFC6455Handshaker but it is better to fail earlier
for (ExtensionConfig config : configs)
{
int matches = (int)negotiation.getOfferedExtensions().stream()
.filter(e -> e.getName().equals(config.getName())).count();
switch (matches)
{
case 0:
throw new IllegalArgumentException("Extension not a requested extension");
case 1:
continue;
default:
throw new IllegalArgumentException("Multiple extensions of the same name");
}
}
negotiation.setNegotiatedExtensions(configs); negotiation.setNegotiatedExtensions(configs);
} }

View File

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