diff --git a/core/src/test/java/org/apache/druid/java/util/http/client/FriendlyServersTest.java b/core/src/test/java/org/apache/druid/java/util/http/client/FriendlyServersTest.java index c6c935067b1..c961dbc0d14 100644 --- a/core/src/test/java/org/apache/druid/java/util/http/client/FriendlyServersTest.java +++ b/core/src/test/java/org/apache/druid/java/util/http/client/FriendlyServersTest.java @@ -96,7 +96,10 @@ public class FriendlyServersTest final HttpClient client = HttpClientInit.createClient(config, lifecycle); final StatusResponseHolder response = client .go( - new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", serverSocket.getLocalPort()))), + new Request( + HttpMethod.GET, + new URL(StringUtils.format("http://localhost:%d/", serverSocket.getLocalPort())) + ), StatusResponseHandler.getInstance() ).get(); @@ -155,7 +158,10 @@ public class FriendlyServersTest final HttpClient client = HttpClientInit.createClient(config, lifecycle); final StatusResponseHolder response = client .go( - new Request(HttpMethod.GET, new URL(StringUtils.format("http://localhost:%d/", serverSocket.getLocalPort()))), + new Request( + HttpMethod.GET, + new URL(StringUtils.format("http://localhost:%d/", serverSocket.getLocalPort())) + ), StatusResponseHandler.getInstance() ).get(); @@ -180,7 +186,7 @@ public class FriendlyServersTest HttpConfiguration https = new HttpConfiguration(); https.addCustomizer(new SecureRequestCustomizer()); - SslContextFactory sslContextFactory = new SslContextFactory(); + SslContextFactory.Server sslContextFactory = new SslContextFactory.Server(); sslContextFactory.setKeyStorePath(keyStorePath); sslContextFactory.setKeyStorePassword("abc123"); sslContextFactory.setKeyManagerPassword("abc123"); diff --git a/licenses.yaml b/licenses.yaml index 709772cba34..6f7c748170c 100644 --- a/licenses.yaml +++ b/licenses.yaml @@ -1661,7 +1661,7 @@ name: Jetty license_category: binary module: java-core license_name: Apache License version 2.0 -version: 9.4.12.v20180830 +version: 9.4.30.v20200611 libraries: - org.eclipse.jetty: jetty-client - org.eclipse.jetty: jetty-continuation diff --git a/pom.xml b/pom.xml index fb7a9575e22..65b2e74c63f 100644 --- a/pom.xml +++ b/pom.xml @@ -91,7 +91,7 @@ 16.0.1 4.1.0 1.3 - 9.4.12.v20180830 + 9.4.30.v20200611 1.19.3 2.10.2 1.9.13 @@ -1268,7 +1268,10 @@ org/apache/druid/cli/Cli* org/apache/druid/cli/*JettyServerInitializer* - + org/apache/druid/server/initialization/*Module* + org/apache/druid/server/initialization/jetty/*Module* + org/apache/druid/guice/http/* + org/apache/druid/math/expr/antlr/Expr* org/apache/druid/**/generated/*Benchmark* diff --git a/server/src/main/java/org/apache/druid/guice/http/AbstractHttpClientProvider.java b/server/src/main/java/org/apache/druid/guice/http/AbstractHttpClientProvider.java index 532f4c99c20..2967f9faedc 100644 --- a/server/src/main/java/org/apache/druid/guice/http/AbstractHttpClientProvider.java +++ b/server/src/main/java/org/apache/druid/guice/http/AbstractHttpClientProvider.java @@ -19,6 +19,7 @@ package org.apache.druid.guice.http; +import com.google.common.base.Preconditions; import com.google.common.base.Supplier; import com.google.inject.Binding; import com.google.inject.Inject; @@ -32,6 +33,7 @@ import javax.net.ssl.SSLContext; import java.lang.annotation.Annotation; /** + * */ public abstract class AbstractHttpClientProvider implements Provider { @@ -40,28 +42,10 @@ public abstract class AbstractHttpClientProvider implements Prov private Injector injector; - public AbstractHttpClientProvider() - { - configKey = Key.get( - new TypeLiteral>() - { - } - ); - sslContextKey = Key.get(SSLContext.class); - } - - public AbstractHttpClientProvider(Annotation annotation) - { - configKey = Key.get( - new TypeLiteral>() - { - }, annotation - ); - sslContextKey = Key.get(SSLContext.class, annotation); - } - public AbstractHttpClientProvider(Class annotation) { + Preconditions.checkNotNull(annotation, "annotation"); + configKey = Key.get( new TypeLiteral>() { @@ -76,20 +60,11 @@ public abstract class AbstractHttpClientProvider implements Prov this.injector = injector; } - public Key> getConfigKey() - { - return configKey; - } - - public Key getSslContextKey() - { - return sslContextKey; - } - public Provider> getConfigProvider() { return injector.getProvider(configKey); } + public Provider getLifecycleProvider() { return injector.getProvider(Lifecycle.class); diff --git a/server/src/main/java/org/apache/druid/guice/http/HttpClientModule.java b/server/src/main/java/org/apache/druid/guice/http/HttpClientModule.java index ff3742fd27a..813b86d9fbd 100644 --- a/server/src/main/java/org/apache/druid/guice/http/HttpClientModule.java +++ b/server/src/main/java/org/apache/druid/guice/http/HttpClientModule.java @@ -19,8 +19,10 @@ package org.apache.druid.guice.http; +import com.google.common.base.Preconditions; import com.google.common.collect.ImmutableSet; import com.google.inject.Binder; +import com.google.inject.Binding; import com.google.inject.Inject; import com.google.inject.Module; import org.apache.druid.guice.JsonConfigProvider; @@ -34,10 +36,12 @@ import org.apache.druid.java.util.http.client.HttpClientConfig; import org.apache.druid.java.util.http.client.HttpClientInit; import org.apache.druid.server.security.Escalator; +import javax.net.ssl.SSLContext; import java.lang.annotation.Annotation; import java.util.Set; /** + * */ public class HttpClientModule implements Module { @@ -55,68 +59,32 @@ public class HttpClientModule implements Module ImmutableSet.of(EscalatedGlobal.class, EscalatedClient.class); private final String propertyPrefix; - private Annotation annotation = null; - private Class annotationClazz = null; - private boolean isEscalated = false; + private final Class annotationClazz; + private final boolean isEscalated; - public HttpClientModule(String propertyPrefix) + public HttpClientModule(String propertyPrefix, Class annotationClazz) { - this.propertyPrefix = propertyPrefix; - } + this.propertyPrefix = Preconditions.checkNotNull(propertyPrefix, "propertyPrefix"); + this.annotationClazz = Preconditions.checkNotNull(annotationClazz, "annotationClazz"); - public HttpClientModule(String propertyPrefix, Class annotation) - { - this.propertyPrefix = propertyPrefix; - this.annotationClazz = annotation; - - isEscalated = ESCALATING_ANNOTATIONS.contains(annotationClazz); - } - - public HttpClientModule(String propertyPrefix, Annotation annotation) - { - this.propertyPrefix = propertyPrefix; - this.annotation = annotation; + isEscalated = ESCALATING_ANNOTATIONS.contains(this.annotationClazz); } @Override public void configure(Binder binder) { - if (annotation != null) { - JsonConfigProvider.bind(binder, propertyPrefix, DruidHttpClientConfig.class, annotation); - binder.bind(HttpClient.class) - .annotatedWith(annotation) - .toProvider(new HttpClientProvider(annotation, isEscalated)) - .in(LazySingleton.class); - } else if (annotationClazz != null) { - JsonConfigProvider.bind(binder, propertyPrefix, DruidHttpClientConfig.class, annotationClazz); - binder.bind(HttpClient.class) - .annotatedWith(annotationClazz) - .toProvider(new HttpClientProvider(annotationClazz, isEscalated)) - .in(LazySingleton.class); - } else { - JsonConfigProvider.bind(binder, propertyPrefix, DruidHttpClientConfig.class); - binder.bind(HttpClient.class) - .toProvider(new HttpClientProvider(isEscalated)) - .in(LazySingleton.class); - } + JsonConfigProvider.bind(binder, propertyPrefix, DruidHttpClientConfig.class, annotationClazz); + binder.bind(HttpClient.class) + .annotatedWith(annotationClazz) + .toProvider(new HttpClientProvider(annotationClazz, isEscalated)) + .in(LazySingleton.class); } public static class HttpClientProvider extends AbstractHttpClientProvider { - private boolean isEscalated; + private final boolean isEscalated; private Escalator escalator; - public HttpClientProvider(boolean isEscalated) - { - this.isEscalated = isEscalated; - } - - public HttpClientProvider(Annotation annotation, boolean isEscalated) - { - super(annotation); - this.isEscalated = isEscalated; - } - public HttpClientProvider(Class annotationClazz, boolean isEscalated) { super(annotationClazz); @@ -144,8 +112,10 @@ public class HttpClientModule implements Module ) .withUnusedConnectionTimeoutDuration(config.getUnusedConnectionTimeout()); - if (getSslContextBinding() != null) { - builder.withSslContext(getSslContextBinding().getProvider().get()); + final Binding sslContextBinding = getSslContextBinding(); + + if (sslContextBinding != null) { + builder.withSslContext(sslContextBinding.getProvider().get()); } HttpClient client = HttpClientInit.createClient( diff --git a/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java b/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java index 22cbfcd937d..3c2ad854f23 100644 --- a/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java +++ b/server/src/main/java/org/apache/druid/guice/http/JettyHttpClientModule.java @@ -19,7 +19,9 @@ package org.apache.druid.guice.http; +import com.google.common.base.Preconditions; import com.google.inject.Binder; +import com.google.inject.Binding; import com.google.inject.Module; import org.apache.druid.guice.JsonConfigProvider; import org.apache.druid.guice.LazySingleton; @@ -29,10 +31,12 @@ import org.eclipse.jetty.client.HttpClient; import org.eclipse.jetty.util.ssl.SslContextFactory; import org.eclipse.jetty.util.thread.QueuedThreadPool; +import javax.net.ssl.SSLContext; import java.lang.annotation.Annotation; import java.util.concurrent.TimeUnit; /** + * */ public class JettyHttpClientModule implements Module { @@ -44,60 +48,26 @@ public class JettyHttpClientModule implements Module } private final String propertyPrefix; - private Annotation annotation = null; - private Class annotationClazz = null; + private final Class annotationClazz; - public JettyHttpClientModule(String propertyPrefix) + public JettyHttpClientModule(String propertyPrefix, Class annotationClazz) { - this.propertyPrefix = propertyPrefix; - } - - public JettyHttpClientModule(String propertyPrefix, Class annotation) - { - this.propertyPrefix = propertyPrefix; - this.annotationClazz = annotation; - } - - public JettyHttpClientModule(String propertyPrefix, Annotation annotation) - { - this.propertyPrefix = propertyPrefix; - this.annotation = annotation; + this.propertyPrefix = Preconditions.checkNotNull(propertyPrefix, "propertyPrefix"); + this.annotationClazz = Preconditions.checkNotNull(annotationClazz, "annotationClazz"); } @Override public void configure(Binder binder) { - if (annotation != null) { - JsonConfigProvider.bind(binder, propertyPrefix, DruidHttpClientConfig.class, annotation); - binder.bind(HttpClient.class) - .annotatedWith(annotation) - .toProvider(new HttpClientProvider(annotation)) - .in(LazySingleton.class); - } else if (annotationClazz != null) { - JsonConfigProvider.bind(binder, propertyPrefix, DruidHttpClientConfig.class, annotationClazz); - binder.bind(HttpClient.class) - .annotatedWith(annotationClazz) - .toProvider(new HttpClientProvider(annotationClazz)) - .in(LazySingleton.class); - } else { - JsonConfigProvider.bind(binder, propertyPrefix, DruidHttpClientConfig.class); - binder.bind(HttpClient.class) - .toProvider(new HttpClientProvider()) - .in(LazySingleton.class); - } + JsonConfigProvider.bind(binder, propertyPrefix, DruidHttpClientConfig.class, annotationClazz); + binder.bind(HttpClient.class) + .annotatedWith(annotationClazz) + .toProvider(new HttpClientProvider(annotationClazz)) + .in(LazySingleton.class); } public static class HttpClientProvider extends AbstractHttpClientProvider { - public HttpClientProvider() - { - } - - public HttpClientProvider(Annotation annotation) - { - super(annotation); - } - public HttpClientProvider(Class annotation) { super(annotation); @@ -109,9 +79,10 @@ public class JettyHttpClientModule implements Module final DruidHttpClientConfig config = getConfigProvider().get().get(); final HttpClient httpClient; - if (getSslContextBinding() != null) { - final SslContextFactory sslContextFactory = new SslContextFactory(); - sslContextFactory.setSslContext(getSslContextBinding().getProvider().get()); + final Binding sslContextBinding = getSslContextBinding(); + if (sslContextBinding != null) { + final SslContextFactory.Client sslContextFactory = new SslContextFactory.Client(); + sslContextFactory.setSslContext(sslContextBinding.getProvider().get()); httpClient = new HttpClient(sslContextFactory); } else { httpClient = new HttpClient(); diff --git a/server/src/main/java/org/apache/druid/server/initialization/jetty/ChatHandlerServerModule.java b/server/src/main/java/org/apache/druid/server/initialization/jetty/ChatHandlerServerModule.java index b1ff03331f8..aead7b86c71 100644 --- a/server/src/main/java/org/apache/druid/server/initialization/jetty/ChatHandlerServerModule.java +++ b/server/src/main/java/org/apache/druid/server/initialization/jetty/ChatHandlerServerModule.java @@ -106,7 +106,7 @@ public class ChatHandlerServerModule implements Module node, config, TLSServerConfig, - injector.getExistingBinding(Key.get(SslContextFactory.class)), + injector.getExistingBinding(Key.get(SslContextFactory.Server.class)), injector.getInstance(TLSCertificateChecker.class) ); } diff --git a/server/src/main/java/org/apache/druid/server/initialization/jetty/CliIndexerServerModule.java b/server/src/main/java/org/apache/druid/server/initialization/jetty/CliIndexerServerModule.java index fbf9c55680e..d8f6bd1dbae 100644 --- a/server/src/main/java/org/apache/druid/server/initialization/jetty/CliIndexerServerModule.java +++ b/server/src/main/java/org/apache/druid/server/initialization/jetty/CliIndexerServerModule.java @@ -132,7 +132,7 @@ public class CliIndexerServerModule implements Module node, makeAdjustedServerConfig(config), TLSServerConfig, - injector.getExistingBinding(Key.get(SslContextFactory.class)), + injector.getExistingBinding(Key.get(SslContextFactory.Server.class)), injector.getInstance(TLSCertificateChecker.class) ); } diff --git a/server/src/main/java/org/apache/druid/server/initialization/jetty/JettyServerModule.java b/server/src/main/java/org/apache/druid/server/initialization/jetty/JettyServerModule.java index fc6f93ed653..39ccf8cfe4a 100644 --- a/server/src/main/java/org/apache/druid/server/initialization/jetty/JettyServerModule.java +++ b/server/src/main/java/org/apache/druid/server/initialization/jetty/JettyServerModule.java @@ -94,6 +94,7 @@ import java.util.concurrent.LinkedBlockingQueue; import java.util.concurrent.atomic.AtomicInteger; /** + * */ public class JettyServerModule extends JerseyServletModule { @@ -168,7 +169,7 @@ public class JettyServerModule extends JerseyServletModule node, config, TLSServerConfig, - injector.getExistingBinding(Key.get(SslContextFactory.class)), + injector.getExistingBinding(Key.get(SslContextFactory.Server.class)), injector.getInstance(TLSCertificateChecker.class) ); } @@ -197,7 +198,7 @@ public class JettyServerModule extends JerseyServletModule DruidNode node, ServerConfig config, TLSServerConfig tlsServerConfig, - Binding sslContextFactoryBinding, + Binding sslContextFactoryBinding, TLSCertificateChecker certificateChecker ) { @@ -245,7 +246,8 @@ public class JettyServerModule extends JerseyServletModule serverConnectors.add(connector); } - final SslContextFactory sslContextFactory; + final SslContextFactory.Server sslContextFactory; + if (node.isEnableTlsPort()) { log.info("Creating https connector with port [%d]", node.getTlsPort()); if (sslContextFactoryBinding == null) { @@ -498,7 +500,7 @@ public class JettyServerModule extends JerseyServletModule } } - private static class IdentityCheckOverrideSslContextFactory extends SslContextFactory + private static class IdentityCheckOverrideSslContextFactory extends SslContextFactory.Server { private final TLSServerConfig tlsServerConfig; private final TLSCertificateChecker certificateChecker; @@ -508,7 +510,7 @@ public class JettyServerModule extends JerseyServletModule TLSCertificateChecker certificateChecker ) { - super(false); + super(); this.tlsServerConfig = tlsServerConfig; this.certificateChecker = certificateChecker; }