From d6a4d05ee36eff67bcf17fcefe9e8ca6f5b9c8b9 Mon Sep 17 00:00:00 2001 From: Dmytro Lazarenko Date: Fri, 15 Jul 2022 13:40:15 +0200 Subject: [PATCH] Fix HttpConnection --- src/main/java/com/c8db/C8DB.java | 4 ++-- .../c8db/internal/http/HttpConnection.java | 2 +- .../internal/http/HttpConnectionFactory.java | 19 ++++--------------- 3 files changed, 7 insertions(+), 18 deletions(-) diff --git a/src/main/java/com/c8db/C8DB.java b/src/main/java/com/c8db/C8DB.java index 70ed3102..74a1c37b 100644 --- a/src/main/java/com/c8db/C8DB.java +++ b/src/main/java/com/c8db/C8DB.java @@ -642,8 +642,8 @@ public synchronized C8DB build() { if (protocol == null || Protocol.VST == protocol) { connectionFactory = new VstConnectionFactorySync(host, timeout, connectionTtl, useSsl, sslContext); } else { - connectionFactory = new HttpConnectionFactory(timeout, user, password, secretProvider, email, jwtAuth, useSsl, - sslContext, custom, protocol, connectionTtl, httpCookieSpec, apiKey, auxHost); + connectionFactory = new HttpConnectionFactory(timeout, user, password, email, secretProvider, jwtAuth, useSsl, + sslContext, custom, protocol, connectionTtl, httpCookieSpec, jwtToken, apiKey, auxHost); } final Map> hostsMatrix = createHostMatrix(max, connectionFactory); final HostResolver hostResolver = createHostResolver(hostsMatrix, max, connectionFactory); diff --git a/src/main/java/com/c8db/internal/http/HttpConnection.java b/src/main/java/com/c8db/internal/http/HttpConnection.java index 428e4712..88dc6b28 100644 --- a/src/main/java/com/c8db/internal/http/HttpConnection.java +++ b/src/main/java/com/c8db/internal/http/HttpConnection.java @@ -139,7 +139,7 @@ public long getKeepAliveDuration(final HttpResponse response, final HttpContext client = builder.build(); SecretProviderContext secCtx = new SecretProviderContext.Builder().email(email).username(user). - password(password.toCharArray()).client(client).host(auxHost).serialization(util).build(); + password(password != null ? password.toCharArray() : null).client(client).host(auxHost).serialization(util).build(); this.secretProvider = secretProvider == null ? new C8RemoteSecretProvider(useSsl, contentType) : secretProvider; this.secretProvider.init(secCtx); diff --git a/src/main/java/com/c8db/internal/http/HttpConnectionFactory.java b/src/main/java/com/c8db/internal/http/HttpConnectionFactory.java index cddd8cb3..1203fc8b 100644 --- a/src/main/java/com/c8db/internal/http/HttpConnectionFactory.java +++ b/src/main/java/com/c8db/internal/http/HttpConnectionFactory.java @@ -33,25 +33,14 @@ public class HttpConnectionFactory implements ConnectionFactory { private final HttpConnection.Builder builder; public HttpConnectionFactory(final Integer timeout, final String user, final String password, final String email, - final Boolean jwtAuth, final Boolean useSsl, final SSLContext sslContext, final C8Serialization util, - final Protocol protocol, final Long connectionTtl, String httpCookieSpec, final String jwtToken, final String apiKey, - final HostDescription auxiliaryHost) { + final SecretProvider secretProvider, final Boolean jwtAuth, final Boolean useSsl, final SSLContext sslContext, + final C8Serialization util, final Protocol protocol, final Long connectionTtl, String httpCookieSpec, + final String jwtToken, final String apiKey, final HostDescription auxiliaryHost) { super(); builder = new HttpConnection.Builder().timeout(timeout).user(user).password(password).email(email) .jwtAuthEnabled(jwtAuth).useSsl(useSsl).sslContext(sslContext).serializationUtil(util) .contentType(protocol).ttl(connectionTtl).httpCookieSpec(httpCookieSpec).jwt(jwtToken) - .apiKey(apiKey).auxHost(auxiliaryHost); - } - - public HttpConnectionFactory(final Integer timeout, final String user, final String password, - SecretProvider secretProvider, final String email, final Boolean jwtAuth, final Boolean useSsl, - final SSLContext sslContext, final C8Serialization util, final Protocol protocol, final Long connectionTtl, - String httpCookieSpec, final String apiKey, final HostDescription auxiliaryHost) { - super(); - builder = new HttpConnection.Builder().timeout(timeout).secretProvider(secretProvider).email(email) - .jwtAuthEnabled(jwtAuth).useSsl(useSsl).sslContext(sslContext).serializationUtil(util) - .contentType(protocol).ttl(connectionTtl).httpCookieSpec(httpCookieSpec) - .apiKey(apiKey).auxHost(auxiliaryHost).user(user).password(password); + .apiKey(apiKey).auxHost(auxiliaryHost).secretProvider(secretProvider); } @Override