<commit_before>package net.explorviz.security.persistence.mongo;

import com.mongodb.MongoClient;
import java.net.UnknownHostException;
import javax.ws.rs.InternalServerErrorException;
import net.explorviz.shared.annotations.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Handles the access to the {@link MongoClient} instance. Only one instance of {@link MongoClient}
 * should exist in the application for performance reasons (pooling).
 *
 */
public final class MongoClientHelper {

  private final Logger LOGGER = LoggerFactory.getLogger(this.getClass().getSimpleName());


  private static final String DEFAUL_ADDRESS = "192.168.99.100";
  private static final String DEFAULT_PORT = "27017";



  @Config("mongo.ip")
  private String host;

  @Config("mongo.port")
  private String port;



  private MongoClient client = null;

  /**
   * Retrieves the connection to the database (i.e. the {@link MongoClient}). If the client is
   * closed, all connections are lost and the mongoDB instance cannot longer be used. Use
   * {@link MongoClientHelper#reset()} to obtain a new client.
   *
   * @return the client
   */
  public MongoClient getMongoClient() {
    if (this.client == null) {
      this.LOGGER.info("Connecting to " + this.host + ":" + this.port);

      try {
        this.client = new MongoClient(this.host + ":" + this.port);
        this.LOGGER.info("Connected to " + this.host + ":" + this.port);
      } catch (final UnknownHostException e) {
        this.LOGGER.error("Target not reachable: " + this.host + ":" + this.port);
        throw new InternalServerErrorException();
      }
    }

    return this.client;
  }

}<commit_msg>Return 500 if the database is not reachable<commit_after>package net.explorviz.security.persistence.mongo;

import com.mongodb.MongoClient;
import com.mongodb.MongoTimeoutException;
import java.net.UnknownHostException;
import javax.ws.rs.InternalServerErrorException;
import net.explorviz.shared.annotations.Config;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

/**
 * Handles the access to the {@link MongoClient} instance. Only one instance of {@link MongoClient}
 * should exist in the application for performance reasons (pooling).
 *
 */
public final class MongoClientHelper {

  private final Logger LOGGER = LoggerFactory.getLogger(this.getClass().getSimpleName());


  private static final String DEFAUL_ADDRESS = "192.168.99.100";
  private static final String DEFAULT_PORT = "27017";



  @Config("mongo.ip")
  private String host;

  @Config("mongo.port")
  private String port;



  private MongoClient client = null;

  /**
   * Retrieves the connection to the database (i.e. the {@link MongoClient}). If the client is
   * closed, all connections are lost and the mongoDB instance cannot longer be used. Use
   * {@link MongoClientHelper#reset()} to obtain a new client.
   *
   * @return the client
   */
  public MongoClient getMongoClient() {
    if (this.client == null) {
      try {
        this.client = new MongoClient(this.host + ":" + this.port);
        this.client.getDatabaseNames();
        this.LOGGER.info("Connected to " + this.host + ":" + this.port);
      } catch (final UnknownHostException | MongoTimeoutException e) {
        this.LOGGER.error("Target not reachable: " + this.host + ":" + this.port);
        throw new InternalServerErrorException();
      }
    }

    return this.client;
  }

}
{'fraction_non_alphanumeric': 0.11198600174978128, 'fraction_numerical': 0.011373578302712161, 'mean_word_length': 3.6164199192462987, 'pattern_counts': {'":': 7, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 2, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5111598', 'n_tokens_mistral': 1062, 'n_tokens_neox': 1003, 'n_words': 291}