Skip to content

Commit cc94b53

Browse files
committed
MLE-24405 Cleaned up RESTServices API
This internal API had several unused methods. In addition, application of the client configurators happens in OkHttpServices now. That removes as much OkHttp stuff as possible from DatabaseClientFactory. This will greatly simplify shifting to the JDK HTTP client some time in the future.
1 parent 9e70443 commit cc94b53

File tree

6 files changed

+81
-199
lines changed

6 files changed

+81
-199
lines changed

marklogic-client-api/src/main/java/com/marklogic/client/DatabaseClientFactory.java

Lines changed: 10 additions & 27 deletions
Original file line numberDiff line numberDiff line change
@@ -7,7 +7,6 @@
77
import com.marklogic.client.impl.*;
88
import com.marklogic.client.io.marker.ContentHandle;
99
import com.marklogic.client.io.marker.ContentHandleFactory;
10-
import okhttp3.OkHttpClient;
1110

1211
import javax.naming.InvalidNameException;
1312
import javax.naming.ldap.LdapName;
@@ -31,7 +30,7 @@
3130
*/
3231
public class DatabaseClientFactory {
3332

34-
static private List<ClientConfigurator<?>> clientConfigurators = Collections.synchronizedList(new ArrayList<>());
33+
static private List<OkHttpClientConfigurator> clientConfigurators = Collections.synchronizedList(new ArrayList<>());
3534

3635
static private HandleFactoryRegistry handleRegistry =
3736
HandleFactoryRegistryImpl.newDefault();
@@ -1329,33 +1328,17 @@ static public DatabaseClient newClient(String host, int port, String database,
13291328
static public DatabaseClient newClient(String host, int port, String basePath, String database,
13301329
SecurityContext securityContext,
13311330
DatabaseClient.ConnectionType connectionType) {
1332-
RESTServices services = new OkHttpServices();
13331331
// As of 6.1.0, the following optimization is made as it's guaranteed that if the user is connecting to a
13341332
// Progress Data Cloud instance, then port 443 will be used. Every path for constructing a DatabaseClient goes through
13351333
// this method, ensuring that this optimization will always be applied, and thus freeing the user from having to
13361334
// worry about what port to configure when using Progress Data Cloud.
13371335
if (securityContext instanceof MarkLogicCloudAuthContext || securityContext instanceof ProgressDataCloudAuthContext) {
13381336
port = 443;
13391337
}
1340-
services.connect(host, port, basePath, database, securityContext);
1341-
1342-
if (clientConfigurators != null) {
1343-
clientConfigurators.forEach(configurator -> {
1344-
if (configurator instanceof OkHttpClientConfigurator) {
1345-
OkHttpClient okHttpClient = (OkHttpClient) services.getClientImplementation();
1346-
Objects.requireNonNull(okHttpClient);
1347-
OkHttpClient.Builder clientBuilder = okHttpClient.newBuilder();
1348-
((OkHttpClientConfigurator) configurator).configure(clientBuilder);
1349-
((OkHttpServices) services).setClientImplementation(clientBuilder.build());
1350-
} else {
1351-
throw new IllegalArgumentException("A ClientConfigurator must implement OkHttpClientConfigurator");
1352-
}
1353-
});
1354-
}
13551338

1356-
DatabaseClientImpl client = new DatabaseClientImpl(
1357-
services, host, port, basePath, database, securityContext, connectionType
1358-
);
1339+
OkHttpServices.ConnectionConfig config = new OkHttpServices.ConnectionConfig(host, port, basePath, database, securityContext, clientConfigurators);
1340+
RESTServices services = new OkHttpServices(config);
1341+
DatabaseClientImpl client = new DatabaseClientImpl(services, host, port, basePath, database, securityContext, connectionType);
13591342
client.setHandleRegistry(getHandleRegistry().copy());
13601343
return client;
13611344
}
@@ -1397,13 +1380,13 @@ static public void registerDefaultHandles() {
13971380
* @param configurator the listener for configuring the communication library
13981381
*/
13991382
static public void addConfigurator(ClientConfigurator<?> configurator) {
1400-
if (!OkHttpClientConfigurator.class.isInstance(configurator)) {
1401-
throw new IllegalArgumentException(
1402-
"Configurator must implement OkHttpClientConfigurator"
1403-
);
1404-
}
1383+
if (!OkHttpClientConfigurator.class.isInstance(configurator)) {
1384+
throw new IllegalArgumentException(
1385+
"Configurator must implement OkHttpClientConfigurator"
1386+
);
1387+
}
14051388

1406-
clientConfigurators.add(configurator);
1389+
clientConfigurators.add((OkHttpClientConfigurator) configurator);
14071390
}
14081391

14091392
/**

marklogic-client-api/src/main/java/com/marklogic/client/extra/okhttpclient/OkHttpClientBuilderFactory.java

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -7,6 +7,8 @@
77
import com.marklogic.client.impl.okhttp.OkHttpUtil;
88
import okhttp3.OkHttpClient;
99

10+
import java.util.ArrayList;
11+
1012
/**
1113
* Exposes the mechanism for constructing an {@code OkHttpClient.Builder} in the same fashion as when a
1214
* {@code DatabaseClient} is constructed. Primarily intended for reuse in the ml-app-deployer library. If the
@@ -17,6 +19,6 @@
1719
public interface OkHttpClientBuilderFactory {
1820

1921
static OkHttpClient.Builder newOkHttpClientBuilder(String host, DatabaseClientFactory.SecurityContext securityContext) {
20-
return OkHttpUtil.newOkHttpClientBuilder(host, securityContext);
22+
return OkHttpUtil.newOkHttpClientBuilder(host, securityContext, new ArrayList<>());
2123
}
2224
}

marklogic-client-api/src/main/java/com/marklogic/client/impl/DatabaseClientImpl.java

Lines changed: 0 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -60,8 +60,6 @@ public DatabaseClientImpl(RESTServices services, String host, int port, String b
6060
this.database = database;
6161
this.securityContext = securityContext;
6262
this.connectionType = connectionType;
63-
64-
services.setDatabaseClient(this);
6563
}
6664

6765
public long getServerVersion() {

0 commit comments

Comments
 (0)