docs: private void init() throws Exception {
          this.useCertAuth = (((Boolean) props.get(USE_CERTIFICATE_AUTHENTICATION)) == null) ? false : (Boolean) props.get(USE_CERTIFICATE_AUTHENTICATION);
  
          ClassLoader loader = libraryRef.getServiceWithException().getClassLoader();
  
          // Lazy initialization for version 2.x of the Mongo Java driver.
  
          boolean sslEnabled = (((Boolean) props.get(SSL_ENABLED)) == null) ? false : (Boolean) props.get(SSL_ENABLED);
  
          assertLibrary(loader, sslEnabled);
          assertValidSSLConfig();
  
          // Initialize List<ServerAddress>
          List<Object> serverAddresses = new LinkedList<Object>();
          Constructor<?> ServerAddress_constructor = loader.loadClass("com.mongodb.ServerAddress").getConstructor(String.class, int.class);
          String[] hosts = (String[]) props.get(HOST_NAMES);
          int[] ports = (int[]) props.get(PORTS);
          int numServerAddresses = hosts.length;
          if (hosts.length != ports.length) {
              IllegalArgumentException failure = ignoreWarnOrFail(null, IllegalArgumentException.class, "CWKKD0011.hosts.ports.mismatch",
                                                                  MONGO, id, hosts.length, ports.length);
              if (failure == null) // tolerate the error and keep going
                  numServerAddresses = hosts.length < ports.length ? hosts.length : ports.length;
              else
                  throw failure;
          }
  
          //Initialise URI. Only used when constructing mongo with the default SSL turned on.
          StringBuilder uriBuilder = new StringBuilder();
          uriBuilder.append("mongodb://");
          for (int i = 0; i < numServerAddresses; i++) {
              serverAddresses.add(ServerAddress_constructor.newInstance(hosts[i], ports[i]));
              //Add server addresses to URI
              uriBuilder.append(hosts[i] + ":" + ports[i]);
              if (i != numServerAddresses - 1) {
                  uriBuilder.append(",");
              }
          }
  
          // Initialize MongoOptions
          Class<?> MongoClientOptions = loader.loadClass("com.mongodb.MongoClientOptions");
          Class<?> MongoClientOptions_Builder = loader.loadClass("com.mongodb.MongoClientOptions$Builder");
  
          Object optionsBuilder = MongoClientOptions_Builder.newInstance();
          for (Map.Entry<String, Object> prop : props.entrySet()) {
              String name = prop.getKey();
              Object value = prop.getValue();
              if (value != null && name.indexOf('.') < 0 && !NOT_MONGO_CLIENT_OPTIONS.contains(name))
                  set(MongoClientOptions_Builder, optionsBuilder, name, value);
          }
  
          String value = (String) props.get(READ_PREFERENCE);
          if (value != null) {
              setReadPreference(MongoClientOptions_Builder, optionsBuilder, value);
          }
          value = (String) props.get(WRITE_CONCERN);
          if (value != null) {
              setWriteConcern(MongoClientOptions_Builder, optionsBuilder, value);
          }
  
          //SSL setup
          boolean sslRefExists = props.containsKey(SSL_REF);
          Properties sslProperties = null;
          if (sslEnabled) {
              Map<String, Object> connectionInfo = getConnectionInfo();
              setSocketFactory(MongoClientOptions_Builder, optionsBuilder, connectionInfo);
              sslProperties = sslHelper.getSSLProperties(sslConfigurationRef.getService(), connectionInfo, this);
          }
          // Initialize the Mongo instance
          Class<?> MongoClient = loader.loadClass(com_mongodb_MongoClient);
          Class<?> MongoClientURI = loader.loadClass("com.mongodb.MongoClientURI");
          if (sslEnabled && !sslRefExists && !useCertAuth) {
              // TODO check if this is still needed as we are setting the socket factory above
              uriBuilder.append("/?ssl=true");
              String uri = uriBuilder.toString();
              Constructor<?> MongoClientURI_constructor = MongoClientURI.getConstructor(String.class, MongoClientOptions_Builder);
              Object uriObject = MongoClientURI_constructor.newInstance(uri, optionsBuilder);
              Constructor<?> MongoClient_constructor = MongoClient.getConstructor(MongoClientURI);
              mongoClient = MongoClient_constructor.newInstance(uriObject);
  
          } else if (sslEnabled && useCertAuth) {
              // get the name from the certificate and handle exceptions / null
              String certificateDN = getCerticateSubject(keyStoreServiceRef, sslProperties);
  
              // Create an x509 credential calling the MongoCredential class reflectively passing the DN
              Class<?> MongoCredential = loader.loadClass("com.mongodb.MongoCredential");
              Method MongoCredential_createCertificate = MongoCredential.getMethod("createMongoX509Credential", String.class);
              Object credential = MongoCredential_createCertificate.invoke(null, certificateDN);
  
              // create a client authenticated using this credential
              Constructor<?> MongoClient_constructor = MongoClient.getConstructor(List.class, List.class, MongoClientOptions);
              Object mongoClientOptions = MongoClientOptions_Builder.getMethod("build").invoke(optionsBuilder);
              mongoClient = MongoClient_constructor.newInstance(serverAddresses, Arrays.asList(credential), mongoClientOptions);
          } else {
              Constructor<?> MongoClient_constructor = MongoClient.getConstructor(List.class, MongoClientOptions);
              Object mongoClientOptions = MongoClientOptions_Builder.getMethod("build").invoke(optionsBuilder);
              mongoClient = MongoClient_constructor.newInstance(serverAddresses, mongoClientOptions);
          }
  
          // Methods that we need each each time a DB instance is created
          MongoClient_getDB = MongoClient.getMethod("getDB", String.class);
          Class<?> DB = loader.loadClass("com.mongodb.DB");
          DB_authenticate = DB.getMethod("authenticate", String.class, char[].class);
          DB_isAuthenticated = DB.getMethod("isAuthenticated");
      }