Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.marklogic.client.impl.*;
import com.marklogic.client.io.marker.ContentHandle;
import com.marklogic.client.io.marker.ContentHandleFactory;
import okhttp3.OkHttpClient;

import javax.naming.InvalidNameException;
import javax.naming.ldap.LdapName;
Expand All @@ -31,7 +30,7 @@
*/
public class DatabaseClientFactory {

static private List<ClientConfigurator<?>> clientConfigurators = Collections.synchronizedList(new ArrayList<>());
static private List<OkHttpClientConfigurator> clientConfigurators = Collections.synchronizedList(new ArrayList<>());

static private HandleFactoryRegistry handleRegistry =
HandleFactoryRegistryImpl.newDefault();
Expand Down Expand Up @@ -1329,33 +1328,17 @@ static public DatabaseClient newClient(String host, int port, String database,
static public DatabaseClient newClient(String host, int port, String basePath, String database,
SecurityContext securityContext,
DatabaseClient.ConnectionType connectionType) {
RESTServices services = new OkHttpServices();
// As of 6.1.0, the following optimization is made as it's guaranteed that if the user is connecting to a
// Progress Data Cloud instance, then port 443 will be used. Every path for constructing a DatabaseClient goes through
// this method, ensuring that this optimization will always be applied, and thus freeing the user from having to
// worry about what port to configure when using Progress Data Cloud.
if (securityContext instanceof MarkLogicCloudAuthContext || securityContext instanceof ProgressDataCloudAuthContext) {
port = 443;
}
services.connect(host, port, basePath, database, securityContext);

if (clientConfigurators != null) {
clientConfigurators.forEach(configurator -> {
if (configurator instanceof OkHttpClientConfigurator) {
OkHttpClient okHttpClient = (OkHttpClient) services.getClientImplementation();
Objects.requireNonNull(okHttpClient);
OkHttpClient.Builder clientBuilder = okHttpClient.newBuilder();
((OkHttpClientConfigurator) configurator).configure(clientBuilder);
((OkHttpServices) services).setClientImplementation(clientBuilder.build());
} else {
throw new IllegalArgumentException("A ClientConfigurator must implement OkHttpClientConfigurator");
}
});
}

DatabaseClientImpl client = new DatabaseClientImpl(
services, host, port, basePath, database, securityContext, connectionType
);
OkHttpServices.ConnectionConfig config = new OkHttpServices.ConnectionConfig(host, port, basePath, database, securityContext, clientConfigurators);
RESTServices services = new OkHttpServices(config);
DatabaseClientImpl client = new DatabaseClientImpl(services, host, port, basePath, database, securityContext, connectionType);
client.setHandleRegistry(getHandleRegistry().copy());
return client;
}
Expand Down Expand Up @@ -1397,13 +1380,13 @@ static public void registerDefaultHandles() {
* @param configurator the listener for configuring the communication library
*/
static public void addConfigurator(ClientConfigurator<?> configurator) {
if (!OkHttpClientConfigurator.class.isInstance(configurator)) {
throw new IllegalArgumentException(
"Configurator must implement OkHttpClientConfigurator"
);
}
if (!OkHttpClientConfigurator.class.isInstance(configurator)) {
throw new IllegalArgumentException(
"Configurator must implement OkHttpClientConfigurator"
);
}

clientConfigurators.add(configurator);
clientConfigurators.add((OkHttpClientConfigurator) configurator);
}

/**
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,6 +7,8 @@
import com.marklogic.client.impl.okhttp.OkHttpUtil;
import okhttp3.OkHttpClient;

import java.util.ArrayList;

/**
* Exposes the mechanism for constructing an {@code OkHttpClient.Builder} in the same fashion as when a
* {@code DatabaseClient} is constructed. Primarily intended for reuse in the ml-app-deployer library. If the
Expand All @@ -17,6 +19,6 @@
public interface OkHttpClientBuilderFactory {

static OkHttpClient.Builder newOkHttpClientBuilder(String host, DatabaseClientFactory.SecurityContext securityContext) {
return OkHttpUtil.newOkHttpClientBuilder(host, securityContext);
return OkHttpUtil.newOkHttpClientBuilder(host, securityContext, new ArrayList<>());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -60,8 +60,6 @@ public DatabaseClientImpl(RESTServices services, String host, int port, String b
this.database = database;
this.securityContext = securityContext;
this.connectionType = connectionType;

services.setDatabaseClient(this);
}

public long getServerVersion() {
Expand Down
Loading