|
7 | 7 | import com.marklogic.client.impl.*; |
8 | 8 | import com.marklogic.client.io.marker.ContentHandle; |
9 | 9 | import com.marklogic.client.io.marker.ContentHandleFactory; |
10 | | -import okhttp3.OkHttpClient; |
11 | 10 |
|
12 | 11 | import javax.naming.InvalidNameException; |
13 | 12 | import javax.naming.ldap.LdapName; |
|
31 | 30 | */ |
32 | 31 | public class DatabaseClientFactory { |
33 | 32 |
|
34 | | - static private List<ClientConfigurator<?>> clientConfigurators = Collections.synchronizedList(new ArrayList<>()); |
| 33 | + static private List<OkHttpClientConfigurator> clientConfigurators = Collections.synchronizedList(new ArrayList<>()); |
35 | 34 |
|
36 | 35 | static private HandleFactoryRegistry handleRegistry = |
37 | 36 | HandleFactoryRegistryImpl.newDefault(); |
@@ -1329,33 +1328,17 @@ static public DatabaseClient newClient(String host, int port, String database, |
1329 | 1328 | static public DatabaseClient newClient(String host, int port, String basePath, String database, |
1330 | 1329 | SecurityContext securityContext, |
1331 | 1330 | DatabaseClient.ConnectionType connectionType) { |
1332 | | - RESTServices services = new OkHttpServices(); |
1333 | 1331 | // As of 6.1.0, the following optimization is made as it's guaranteed that if the user is connecting to a |
1334 | 1332 | // Progress Data Cloud instance, then port 443 will be used. Every path for constructing a DatabaseClient goes through |
1335 | 1333 | // this method, ensuring that this optimization will always be applied, and thus freeing the user from having to |
1336 | 1334 | // worry about what port to configure when using Progress Data Cloud. |
1337 | 1335 | if (securityContext instanceof MarkLogicCloudAuthContext || securityContext instanceof ProgressDataCloudAuthContext) { |
1338 | 1336 | port = 443; |
1339 | 1337 | } |
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 | | - } |
1355 | 1338 |
|
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); |
1359 | 1342 | client.setHandleRegistry(getHandleRegistry().copy()); |
1360 | 1343 | return client; |
1361 | 1344 | } |
@@ -1397,13 +1380,13 @@ static public void registerDefaultHandles() { |
1397 | 1380 | * @param configurator the listener for configuring the communication library |
1398 | 1381 | */ |
1399 | 1382 | 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 | + } |
1405 | 1388 |
|
1406 | | - clientConfigurators.add(configurator); |
| 1389 | + clientConfigurators.add((OkHttpClientConfigurator) configurator); |
1407 | 1390 | } |
1408 | 1391 |
|
1409 | 1392 | /** |
|
0 commit comments