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

This commit is contained in:
Joakim Erdfelt 2020-09-28 17:55:41 -05:00
commit 3c7cd43148
No known key found for this signature in database
GPG Key ID: 2D0E1FB8FE4B68B4
10 changed files with 226 additions and 150 deletions

View File

@ -52,13 +52,14 @@
</dependency>
<dependency>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<artifactId>jetty-client</artifactId>
<version>${project.version}</version>
<scope>test</scope>
<scope>provided</scope>
</dependency>
<dependency>
<groupId>org.eclipse.jetty.toolchain</groupId>
<artifactId>jetty-test-helper</artifactId>
<groupId>org.eclipse.jetty</groupId>
<artifactId>jetty-jmx</artifactId>
<version>${project.version}</version>
<scope>test</scope>
</dependency>
<dependency>

View File

@ -12,10 +12,12 @@
<servlet-name>JavadocTransparentProxy</servlet-name>
<servlet-class>org.eclipse.jetty.proxy.ProxyServlet$Transparent</servlet-class>
<init-param>
<param-name>proxyTo</param-name><param-value>http://www.eclipse.org/jetty/javadoc/</param-value>
<param-name>proxyTo</param-name>
<param-value>https://www.eclipse.org/jetty/javadoc/</param-value>
</init-param>
<init-param>
<param-name>hostHeader</param-name><param-value>eclipse.org</param-value>
<param-name>hostHeader</param-name>
<param-value>www.eclipse.org</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
<async-supported>true</async-supported>

View File

@ -1,122 +0,0 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
//
// This program and the accompanying materials are made available under
// the terms of the Eclipse Public License 2.0 which is available at
// https://www.eclipse.org/legal/epl-2.0
//
// This Source Code may also be made available under the following
// Secondary Licenses when the conditions for such availability set
// forth in the Eclipse Public License, v. 2.0 are satisfied:
// the Apache License v2.0 which is available at
// https://www.apache.org/licenses/LICENSE-2.0
//
// SPDX-License-Identifier: EPL-2.0 OR Apache-2.0
// ========================================================================
//
package org.eclipse.jetty;
import java.lang.management.ManagementFactory;
import org.eclipse.jetty.alpn.server.ALPNServerConnectionFactory;
import org.eclipse.jetty.http2.HTTP2Cipher;
import org.eclipse.jetty.http2.server.HTTP2ServerConnectionFactory;
import org.eclipse.jetty.jmx.MBeanContainer;
import org.eclipse.jetty.server.ForwardedRequestCustomizer;
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.server.handler.ContextHandlerCollection;
import org.eclipse.jetty.server.handler.DefaultHandler;
import org.eclipse.jetty.server.handler.HandlerList;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.jupiter.api.Disabled;
@Disabled("Not a test case")
public class TestTransparentProxyServer
{
public static void main(String[] args) throws Exception
{
String jettyRoot = "../../..";
// Setup Threadpool
QueuedThreadPool threadPool = new QueuedThreadPool();
threadPool.setMaxThreads(100);
// Setup server
Server server = new Server(threadPool);
server.manage(threadPool);
// Setup JMX
MBeanContainer mbContainer = new MBeanContainer(ManagementFactory.getPlatformMBeanServer());
server.addBean(mbContainer);
// Common HTTP configuration
HttpConfiguration httpConfig = new HttpConfiguration();
httpConfig.setSecurePort(8443);
httpConfig.addCustomizer(new ForwardedRequestCustomizer());
httpConfig.setSendDateHeader(true);
httpConfig.setSendServerVersion(true);
// Http Connector
HttpConnectionFactory http = new HttpConnectionFactory(httpConfig);
ServerConnector httpConnector = new ServerConnector(server, http);
httpConnector.setPort(8080);
httpConnector.setIdleTimeout(30000);
server.addConnector(httpConnector);
// SSL configurations
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
sslContextFactory.setKeyStorePath(jettyRoot + "/jetty-server/src/main/config/modules/test-keystore/test-keystore.p12");
sslContextFactory.setKeyStorePassword("storepwd");
sslContextFactory.setExcludeCipherSuites(
"SSL_RSA_WITH_DES_CBC_SHA",
"SSL_DHE_RSA_WITH_DES_CBC_SHA",
"SSL_DHE_DSS_WITH_DES_CBC_SHA",
"SSL_RSA_EXPORT_WITH_RC4_40_MD5",
"SSL_RSA_EXPORT_WITH_DES40_CBC_SHA",
"SSL_DHE_RSA_EXPORT_WITH_DES40_CBC_SHA",
"SSL_DHE_DSS_EXPORT_WITH_DES40_CBC_SHA");
sslContextFactory.setCipherComparator(new HTTP2Cipher.CipherComparator());
// HTTPS Configuration
HttpConfiguration httpsConfig = new HttpConfiguration(httpConfig);
httpsConfig.addCustomizer(new SecureRequestCustomizer());
// HTTP2 factory
HTTP2ServerConnectionFactory h2 = new HTTP2ServerConnectionFactory(httpsConfig);
ALPNServerConnectionFactory alpn = new ALPNServerConnectionFactory();
alpn.setDefaultProtocol(h2.getProtocol());
// SSL Factory
SslConnectionFactory ssl = new SslConnectionFactory(sslContextFactory, alpn.getProtocol());
// HTTP2 Connector
ServerConnector http2Connector =
new ServerConnector(server, ssl, alpn, h2, new HttpConnectionFactory(httpsConfig));
http2Connector.setPort(8443);
http2Connector.setIdleTimeout(15000);
server.addConnector(http2Connector);
// Handlers
ContextHandlerCollection contexts = new ContextHandlerCollection();
server.setHandler(new HandlerList(contexts, new DefaultHandler()));
// Setup proxy webapp
WebAppContext webapp = new WebAppContext();
webapp.setResourceBase("src/main/webapp");
contexts.addHandler(webapp);
// start server
server.setStopAtShutdown(true);
server.start();
server.join();
}
}

View File

@ -54,6 +54,7 @@ import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.io.ClientConnector;
import org.eclipse.jetty.util.HttpCookieStore;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
@ -370,7 +371,9 @@ public abstract class AbstractProxyServlet extends HttpServlet
protected ClientConnector newClientConnector()
{
return new ClientConnector();
ClientConnector clientConnector = new ClientConnector();
clientConnector.setSslContextFactory(new SslContextFactory.Client());
return clientConnector;
}
protected HttpClient getHttpClient()

View File

@ -78,17 +78,21 @@ import org.eclipse.jetty.client.util.InputStreamResponseListener;
import org.eclipse.jetty.http.HttpHeader;
import org.eclipse.jetty.http.HttpHeaderValue;
import org.eclipse.jetty.http.HttpMethod;
import org.eclipse.jetty.http.HttpScheme;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.http.HttpVersion;
import org.eclipse.jetty.server.HttpConfiguration;
import org.eclipse.jetty.server.HttpConnectionFactory;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.server.SslConnectionFactory;
import org.eclipse.jetty.servlet.FilterHolder;
import org.eclipse.jetty.servlet.ServletContextHandler;
import org.eclipse.jetty.servlet.ServletHolder;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.IO;
import org.eclipse.jetty.util.StringUtil;
import org.eclipse.jetty.util.ssl.SslContextFactory;
import org.eclipse.jetty.util.thread.QueuedThreadPool;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.Test;
@ -129,6 +133,7 @@ public class ProxyServletTest
private AbstractProxyServlet proxyServlet;
private Server server;
private ServerConnector serverConnector;
private ServerConnector tlsServerConnector;
private void startServer(HttpServlet servlet) throws Exception
{
@ -138,6 +143,16 @@ public class ProxyServletTest
serverConnector = new ServerConnector(server);
server.addConnector(serverConnector);
SslContextFactory.Server sslContextFactory = new SslContextFactory.Server();
String keyStorePath = MavenTestingUtils.getTestResourceFile("server_keystore.p12").getAbsolutePath();
sslContextFactory.setKeyStorePath(keyStorePath);
sslContextFactory.setKeyStorePassword("storepwd");
tlsServerConnector = new ServerConnector(server, new SslConnectionFactory(
sslContextFactory,
HttpVersion.HTTP_1_1.asString()),
new HttpConnectionFactory());
server.addConnector(tlsServerConnector);
ServletContextHandler appCtx = new ServletContextHandler(server, "/", true, false);
ServletHolder appServletHolder = new ServletHolder(servlet);
appCtx.addServlet(appServletHolder, "/*");
@ -738,27 +753,80 @@ public class ProxyServletTest
public static Stream<Arguments> transparentImpls()
{
return Stream.of(
ProxyServlet.Transparent.class,
AsyncProxyServlet.Transparent.class,
AsyncMiddleManServlet.Transparent.class
new ProxyServlet.Transparent()
{
@Override
protected HttpClient newHttpClient()
{
return newTrustAllClient(super.newHttpClient());
}
@Override
public String toString()
{
return ProxyServlet.Transparent.class.getName();
}
},
new AsyncProxyServlet.Transparent()
{
@Override
protected HttpClient newHttpClient()
{
return newTrustAllClient(super.newHttpClient());
}
@Override
public String toString()
{
return AsyncProxyServlet.Transparent.class.getName();
}
},
new AsyncMiddleManServlet.Transparent()
{
@Override
protected HttpClient newHttpClient()
{
return newTrustAllClient(super.newHttpClient());
}
@Override
public String toString()
{
return AsyncMiddleManServlet.Transparent.class.getName();
}
}
).map(Arguments::of);
}
@ParameterizedTest
@MethodSource("transparentImpls")
public void testTransparentProxy(Class<? extends ProxyServlet> proxyServletClass) throws Exception
private static HttpClient newTrustAllClient(HttpClient client)
{
testTransparentProxyWithPrefix(proxyServletClass, "/proxy");
SslContextFactory.Client sslContextFactory = client.getSslContextFactory();
sslContextFactory.setTrustAll(true);
return client;
}
@ParameterizedTest
@MethodSource("transparentImpls")
public void testTransparentProxyWithRootContext(Class<? extends ProxyServlet> proxyServletClass) throws Exception
public void testTransparentProxy(AbstractProxyServlet proxyServletClass) throws Exception
{
testTransparentProxyWithPrefix(proxyServletClass, "/");
testTransparentProxyWithPrefix(proxyServletClass, "http", "/proxy");
}
private void testTransparentProxyWithPrefix(Class<? extends ProxyServlet> proxyServletClass, String prefix) throws Exception
@ParameterizedTest
@MethodSource("transparentImpls")
public void testTransparentProxyTls(AbstractProxyServlet proxyServletClass) throws Exception
{
testTransparentProxyWithPrefix(proxyServletClass, "https", "/proxy");
}
@ParameterizedTest
@MethodSource("transparentImpls")
public void testTransparentProxyWithRootContext(AbstractProxyServlet proxyServletClass) throws Exception
{
testTransparentProxyWithPrefix(proxyServletClass, "http", "/");
}
private void testTransparentProxyWithPrefix(AbstractProxyServlet proxyServletClass, String scheme, String prefix) throws Exception
{
final String target = "/test";
startServer(new HttpServlet()
@ -771,7 +839,10 @@ public class ProxyServletTest
resp.setStatus(target.equals(req.getRequestURI()) ? 200 : 404);
}
});
String proxyTo = "http://localhost:" + serverConnector.getLocalPort();
int serverPort = serverConnector.getLocalPort();
if (HttpScheme.HTTPS.is(scheme))
serverPort = tlsServerConnector.getLocalPort();
String proxyTo = scheme + "://localhost:" + serverPort;
Map<String, String> params = new HashMap<>();
params.put("proxyTo", proxyTo);
params.put("prefix", prefix);
@ -789,33 +860,33 @@ public class ProxyServletTest
@ParameterizedTest
@MethodSource("transparentImpls")
public void testTransparentProxyWithQuery(Class<? extends ProxyServlet> proxyServletClass) throws Exception
public void testTransparentProxyWithQuery(AbstractProxyServlet proxyServletClass) throws Exception
{
testTransparentProxyWithQuery(proxyServletClass, "/foo", "/proxy", "/test");
}
@ParameterizedTest
@MethodSource("transparentImpls")
public void testTransparentProxyEmptyContextWithQuery(Class<? extends ProxyServlet> proxyServletClass) throws Exception
public void testTransparentProxyEmptyContextWithQuery(AbstractProxyServlet proxyServletClass) throws Exception
{
testTransparentProxyWithQuery(proxyServletClass, "", "/proxy", "/test");
}
@ParameterizedTest
@MethodSource("transparentImpls")
public void testTransparentProxyEmptyTargetWithQuery(Class<? extends ProxyServlet> proxyServletClass) throws Exception
public void testTransparentProxyEmptyTargetWithQuery(AbstractProxyServlet proxyServletClass) throws Exception
{
testTransparentProxyWithQuery(proxyServletClass, "/bar", "/proxy", "");
}
@ParameterizedTest
@MethodSource("transparentImpls")
public void testTransparentProxyEmptyContextEmptyTargetWithQuery(Class<? extends ProxyServlet> proxyServletClass) throws Exception
public void testTransparentProxyEmptyContextEmptyTargetWithQuery(AbstractProxyServlet proxyServletClass) throws Exception
{
testTransparentProxyWithQuery(proxyServletClass, "", "/proxy", "");
}
private void testTransparentProxyWithQuery(Class<? extends ProxyServlet> proxyServletClass, String proxyToContext, String prefix, String target) throws Exception
private void testTransparentProxyWithQuery(AbstractProxyServlet proxyServletClass, String proxyToContext, String prefix, String target) throws Exception
{
final String query = "a=1&b=2";
startServer(new HttpServlet()
@ -859,7 +930,7 @@ public class ProxyServletTest
@ParameterizedTest
@MethodSource("transparentImpls")
public void testTransparentProxyWithQueryWithSpaces(Class<? extends ProxyServlet> proxyServletClass) throws Exception
public void testTransparentProxyWithQueryWithSpaces(AbstractProxyServlet proxyServletClass) throws Exception
{
final String target = "/test";
final String query = "a=1&b=2&c=1234%205678&d=hello+world";
@ -901,7 +972,7 @@ public class ProxyServletTest
@ParameterizedTest
@MethodSource("transparentImpls")
public void testTransparentProxyWithoutPrefix(Class<? extends ProxyServlet> proxyServletClass) throws Exception
public void testTransparentProxyWithoutPrefix(AbstractProxyServlet proxyServletClass) throws Exception
{
final String target = "/test";
startServer(new HttpServlet()

View File

@ -34,7 +34,7 @@
<jmh.version>1.25.2</jmh.version>
<jmhjar.name>benchmarks</jmhjar.name>
<tycho-version>2.0.0</tycho-version>
<junit.version>5.6.2</junit.version>
<junit.version>5.7.0</junit.version>
<maven.version>3.6.0</maven.version>
<maven.resolver.version>1.3.1</maven.resolver.version>
<weld.version>3.1.3.Final</weld.version>
@ -58,7 +58,7 @@
<!-- testing -->
<it.debug>false</it.debug>
<jetty.test.version>5.4</jetty.test.version>
<jetty.test.version>5.5</jetty.test.version>
<!-- springboot is only used for jetty-maven-plugin it test
otherwise depending on Spring Boot might be chicken and egg issue :) -->
<springboot.version>2.1.1.RELEASE</springboot.version>

View File

@ -10,7 +10,22 @@
<name>Jetty Tests :: Sessions :: Parent</name>
<url>http://www.eclipse.org/jetty</url>
<packaging>pom</packaging>
<build></build>
<dependencyManagement>
<dependencies>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<version>${junit.version}</version>
<scope>test</scope>
</dependency>
</dependencies>
</dependencyManagement>
<modules>
<module>test-sessions-common</module>
<module>test-file-sessions</module>

View File

@ -48,5 +48,10 @@
<artifactId>junit-jupiter</artifactId>
<scope>compile</scope>
</dependency>
<dependency>
<groupId>org.junit.jupiter</groupId>
<artifactId>junit-jupiter-api</artifactId>
<scope>compile</scope>
</dependency>
</dependencies>
</project>

View File

@ -0,0 +1,96 @@
//
// ========================================================================
// Copyright (c) 1995-2020 Mort Bay Consulting Pty Ltd and others.
// ------------------------------------------------------------------------
// 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;
import java.util.concurrent.ExecutionException;
import java.util.concurrent.TimeoutException;
import org.eclipse.jetty.client.HttpClient;
import org.eclipse.jetty.client.api.ContentResponse;
import org.eclipse.jetty.http.HttpStatus;
import org.eclipse.jetty.server.Server;
import org.eclipse.jetty.server.ServerConnector;
import org.eclipse.jetty.toolchain.test.MavenTestingUtils;
import org.eclipse.jetty.util.component.LifeCycle;
import org.eclipse.jetty.webapp.WebAppContext;
import org.junit.jupiter.api.AfterEach;
import org.junit.jupiter.api.BeforeEach;
import org.junit.jupiter.api.Tag;
import org.junit.jupiter.api.Test;
import static org.hamcrest.MatcherAssert.assertThat;
import static org.hamcrest.Matchers.containsString;
import static org.hamcrest.Matchers.is;
/**
* Test the configuration found in WEB-INF/web.xml for purposes of the demo-base
*/
public class ProxyWebAppTest
{
private Server server;
private HttpClient client;
@BeforeEach
public void setup() throws Exception
{
server = new Server();
ServerConnector connector = new ServerConnector(server);
connector.setPort(0);
server.addConnector(connector);
WebAppContext webapp = new WebAppContext();
// This is a pieced together WebApp.
// We don't have a valid WEB-INF/lib to rely on at this point.
// So, open up server classes here, for purposes of this testcase.
webapp.getServerClasspathPattern().add("-org.eclipse.jetty.proxy.");
webapp.setWar(MavenTestingUtils.getProjectDirPath("src/main/webapp").toString());
webapp.setExtraClasspath(MavenTestingUtils.getTargetPath().resolve("classes").toString());
server.setHandler(webapp);
server.start();
client = new HttpClient();
client.start();
}
@AfterEach
public void teardown()
{
LifeCycle.stop(client);
LifeCycle.stop(server);
}
@Test
@Tag("external")
public void testProxyRequest() throws InterruptedException, ExecutionException, TimeoutException
{
ContentResponse response = client.newRequest(server.getURI().resolve("/proxy/current/"))
.followRedirects(false)
.send();
// Expecting a 200 OK (not a 302 redirect or other error)
// If we got an error here, that means our configuration in web.xml is bad / out of date.
// Such as the redirect from the eclipse website, we want all of the requests to go through
// this proxy configuration, not redirected to the actual website.
assertThat("response status", response.getStatus(), is(HttpStatus.OK_200));
// Expecting a Javadoc / APIDoc response - look for something unique for APIdoc.
assertThat("response", response.getContentAsString(), containsString("All&nbsp;Classes"));
}
}

View File

@ -0,0 +1,5 @@
org.eclipse.jetty.util.log.class=org.eclipse.jetty.util.log.StdErrLog
#org.eclipse.jetty.LEVEL=WARN
#org.eclipse.jetty.client.LEVEL=DEBUG
#org.eclipse.jetty.http.LEVEL=DEBUG
#org.eclipse.jetty.proxy.LEVEL=DEBUG