From 39e3adb24a7f5a94110ee784e6a8531041a549b9 Mon Sep 17 00:00:00 2001 From: Mark Paluch Date: Tue, 24 Apr 2018 18:26:48 +0200 Subject: [PATCH] Extend netty availability discovery. We now check additionally for presence of io.netty.handler.ssl.SslContext and io.netty.handler.codec.http.HttpClientCodec classes to prevent netty usage by presence of partial API components. Closes gh-249. --- .../ClientHttpRequestFactoryFactory.java | 32 +++++++++++++------ 1 file changed, 23 insertions(+), 9 deletions(-) diff --git a/spring-vault-core/src/main/java/org/springframework/vault/config/ClientHttpRequestFactoryFactory.java b/spring-vault-core/src/main/java/org/springframework/vault/config/ClientHttpRequestFactoryFactory.java index e6cebfb0..51610d4b 100644 --- a/spring-vault-core/src/main/java/org/springframework/vault/config/ClientHttpRequestFactoryFactory.java +++ b/spring-vault-core/src/main/java/org/springframework/vault/config/ClientHttpRequestFactoryFactory.java @@ -67,18 +67,32 @@ public class ClientHttpRequestFactoryFactory { private static final Log logger = LogFactory .getLog(ClientHttpRequestFactoryFactory.class); - private static final boolean HTTP_COMPONENTS_PRESENT = ClassUtils.isPresent( - "org.apache.http.client.HttpClient", - ClientHttpRequestFactoryFactory.class.getClassLoader()); + private static final boolean HTTP_COMPONENTS_PRESENT = isPresent("org.apache.http.client.HttpClient"); - private static final boolean OKHTTP3_PRESENT = ClassUtils.isPresent( - "okhttp3.OkHttpClient", - ClientHttpRequestFactoryFactory.class.getClassLoader()); + private static final boolean OKHTTP3_PRESENT = isPresent("okhttp3.OkHttpClient"); - private static final boolean NETTY_PRESENT = ClassUtils.isPresent( - "io.netty.channel.nio.NioEventLoopGroup", - ClientHttpRequestFactoryFactory.class.getClassLoader()); + private static final boolean NETTY_PRESENT = isPresent( + "io.netty.channel.nio.NioEventLoopGroup", "io.netty.handler.ssl.SslContext", + "io.netty.handler.codec.http.HttpClientCodec"); + /** + * Checks for presence of all {@code classNames} using this class' classloader. + * + * @param classNames + * @return {@literal true} if all classes are present; {@literal false} if at least + * one class cannot be found. + */ + private static boolean isPresent(String... classNames) { + + for (String className : classNames) { + if (!ClassUtils.isPresent(className, + ClientHttpRequestFactoryFactory.class.getClassLoader())) { + return false; + } + } + + return true; + } /** * Create a {@link ClientHttpRequestFactory} for the given {@link ClientOptions} and * {@link SslConfiguration}.