Пример #1
0
  // exposed for testing
  static PersistedConfigurationAdapter load(final String configurationFile) throws IOException {
    final URL configurationUrl =
        Thread.currentThread().getContextClassLoader().getResource(configurationFile);
    Validate.notNull(
        configurationUrl, "Impossible to find " + configurationFile + " on the classpath");

    final InputStream is = configurationUrl.openStream();
    final String json = IOUtils.toString(is);
    IOUtils.closeQuietly(is);

    final PersistedConfiguration pc = Util.fromJson(json, PersistedConfiguration.class);
    final PersistedConfigurationAdapter pca =
        new PersistedConfigurationAdapter(configurationUrl, pc);
    return pca;
  }
Пример #2
0
  /**
   * Extracts an UriBuilder for the current request, taking into account the possibility of
   * header-based URI override.
   *
   * @param uriInfo
   * @param httpHeaders
   * @return
   * @throws URISyntaxException
   */
  public static UriBuilder getUriBuilder(final UriInfo uriInfo, final HttpHeaders httpHeaders)
      throws URISyntaxException {
    final UriBuilder uriBuilder = uriInfo.getBaseUriBuilder();

    final List<String> hosts = httpHeaders.getRequestHeader(HttpHeaders.HOST);
    if ((hosts != null) && (!hosts.isEmpty())) {
      final String host = hosts.get(0);
      uriBuilder.host(StringUtils.substringBefore(host, ":"));

      final String port = StringUtils.substringAfter(host, ":");
      if (StringUtils.isNotBlank(port)) {
        uriBuilder.port(Integer.valueOf(port));
      }
    }

    final String protocol =
        Util.getSingleHeader(httpHeaders, Constants.FORWARDED_PROTOCOL_HTTP_HEADER);
    if (StringUtils.isNotBlank(protocol)) {
      uriBuilder.scheme(protocol);
    }

    return uriBuilder;
  }
Пример #3
0
  static Set<String> validate(final PersistedConfigurationAdapter pca) throws IOException {
    final Set<String> validationErrors = new HashSet<String>();

    LOGGER.info("Validating configuration: " + pca.getConfigurationUrl());
    validateNotNull(pca.getActiveMqWorkDirectory(), "activeMqWorkDirectory", validationErrors);
    validateNotNull(pca.getResultsDirectory(), "rsbResultsDirectory", validationErrors);
    validateNotNull(pca.getDefaultRserviPoolUri(), "defaultRserviPoolUri", validationErrors);
    validateNotNull(pca.getSmtpConfiguration(), "smtpConfiguration", validationErrors);

    if (StringUtils.isNotEmpty(pca.getAdministratorEmail())) {
      validateIsTrue(
          EmailValidator.getInstance().isValid(pca.getAdministratorEmail()),
          "if present, the administrator email must be valid",
          validationErrors);
    }

    if (pca.getDepositRootDirectories() != null) {

      for (final DepositDirectoryConfiguration depositRootDirectoryConfig :
          pca.getDepositRootDirectories()) {
        final String depositApplicationName = depositRootDirectoryConfig.getApplicationName();
        validateIsTrue(
            Util.isValidApplicationName(depositApplicationName),
            "invalid deposit directory application name: " + depositApplicationName,
            validationErrors);
      }
    }

    if (pca.getDepositEmailAccounts() != null) {
      for (final DepositEmailConfiguration depositEmailAccount : pca.getDepositEmailAccounts()) {
        validateIsTrue(
            Util.isValidApplicationName(depositEmailAccount.getApplicationName()),
            "invalid deposit email application name: " + depositEmailAccount.getApplicationName(),
            validationErrors);

        if (depositEmailAccount.getResponseFileName() != null) {
          final File responseFile =
              new File(
                  pca.getEmailRepliesCatalogDirectory(), depositEmailAccount.getResponseFileName());
          validateIsTrue(
              responseFile.exists(), "missing response file: " + responseFile, validationErrors);
        }

        if (depositEmailAccount.getJobConfigurationFileName() != null) {
          final File jobConfigurationFile =
              new File(
                  pca.getJobConfigurationCatalogDirectory(),
                  depositEmailAccount.getJobConfigurationFileName());
          validateIsTrue(
              jobConfigurationFile.exists(),
              "missing job configuration file: " + jobConfigurationFile,
              validationErrors);
        }
      }
    }

    if (pca.getDataDirectories() != null) {
      for (final File dataDirectoryRoot : pca.getDataDirectories()) {
        validateIsTrue(
            dataDirectoryRoot.isDirectory(),
            "invalid data directory: " + dataDirectoryRoot,
            validationErrors);
      }
    }

    return validationErrors;
  }