Java Code Examples for org.apache.kafka.common.config.ConfigException#initCause()

The following examples show how to use org.apache.kafka.common.config.ConfigException#initCause() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HeaderToFieldConfig.java    From kafka-connect-transform-common with Apache License 2.0 6 votes vote down vote up
public HeaderToFieldConfig(Map<?, ?> originals) {
  super(config(), originals);

  List<HeaderToFieldMapping> mappings = new ArrayList<>();
  List<String> rawMappings = getList(HEADER_MAPPINGS_CONF);

  for (String rawMapping : rawMappings) {
    try {
      HeaderToFieldMapping mapping = HeaderToFieldMapping.parse(rawMapping);
      mappings.add(mapping);
    } catch (Exception ex) {
      ConfigException configException = new ConfigException(HEADER_MAPPINGS_CONF, rawMapping);
      configException.initCause(ex);
      throw configException;
    }
  }

  this.mappings = ImmutableList.copyOf(mappings);
}
 
Example 2
Source File: ConfigUtils.java    From connect-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Method is used to return a charset(s) for a list key.
 *
 * @param config Config to read from.
 * @param key    Key to read from
 * @return
 */
public static List<Charset> charsets(AbstractConfig config, String key) {
  final List<String> charsetNames = config.getList(key);
  final List<Charset> result = new ArrayList<>(charsetNames.size());

  for (String charsetName : charsetNames) {
    try {
      Charset charset = Charset.forName(charsetName);
      result.add(charset);
    } catch (final UnsupportedCharsetException ex) {
      ConfigException exception = new ConfigException(key, charsetName, "Invalid charset.");
      exception.initCause(ex);
      throw exception;
    }

  }
  return result;
}
 
Example 3
Source File: ValidURI.java    From connect-utils with Apache License 2.0 6 votes vote down vote up
void validate(String config, String value) {
  try {
    final URI uri = new URI(value);

    if (!validSchemes.isEmpty() && !validSchemes.contains(uri.getScheme())) {
      throw new ConfigException(
          config,
          value,
          String.format(
              "Scheme must be one of the following. '%s'",
              Joiner.on("', '").join(this.validSchemes)
          )
      );
    }


  } catch (URISyntaxException e) {
    ConfigException configException = new ConfigException(
        config, value, "Could not parse to URL."
    );
    configException.initCause(e);

    throw configException;
  }
}
 
Example 4
Source File: Validators.java    From connect-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Validator is used to ensure that the KeyStore type specified is valid.
 * @return
 */
public static Validator validKeyStoreType() {
  return (s, o) -> {
    if (!(o instanceof String)) {
      throw new ConfigException(s, o, "Must be a string.");
    }

    String keyStoreType = o.toString();
    try {
      KeyStore.getInstance(keyStoreType);
    } catch (KeyStoreException e) {
      ConfigException exception = new ConfigException(s, o, "Invalid KeyStore type");
      exception.initCause(e);
      throw exception;
    }
  };
}
 
Example 5
Source File: Validators.java    From connect-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Validator is used to ensure that the KeyManagerFactory Algorithm specified is valid.
 * @return
 */
public static Validator validKeyManagerFactory() {
  return (s, o) -> {
    if (!(o instanceof String)) {
      throw new ConfigException(s, o, "Must be a string.");
    }

    String keyStoreType = o.toString();
    try {
      KeyManagerFactory.getInstance(keyStoreType);
    } catch (NoSuchAlgorithmException e) {
      ConfigException exception = new ConfigException(s, o, "Invalid Algorithm");
      exception.initCause(e);
      throw exception;
    }
  };
}
 
Example 6
Source File: Validators.java    From connect-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Validator is used to ensure that the TrustManagerFactory Algorithm specified is valid.
 * @return
 */
public static Validator validTrustManagerFactory() {
  return (s, o) -> {
    if (!(o instanceof String)) {
      throw new ConfigException(s, o, "Must be a string.");
    }

    String keyStoreType = o.toString();
    try {
      TrustManagerFactory.getInstance(keyStoreType);
    } catch (NoSuchAlgorithmException e) {
      ConfigException exception = new ConfigException(s, o, "Invalid Algorithm");
      exception.initCause(e);
      throw exception;
    }
  };
}
 
Example 7
Source File: Validators.java    From connect-utils with Apache License 2.0 6 votes vote down vote up
/**
 * Validator is used to ensure that the TrustManagerFactory Algorithm specified is valid.
 * @return
 */
public static Validator validSSLContext() {
  return (s, o) -> {
    if (!(o instanceof String)) {
      throw new ConfigException(s, o, "Must be a string.");
    }

    String keyStoreType = o.toString();
    try {
      SSLContext.getInstance(keyStoreType);
    } catch (NoSuchAlgorithmException e) {
      ConfigException exception = new ConfigException(s, o, "Invalid Algorithm");
      exception.initCause(e);
      throw exception;
    }
  };
}
 
Example 8
Source File: ConfigUtils.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
static URL url(String key, String value) {
  try {
    return new URL(value);
  } catch (MalformedURLException e) {
    ConfigException configException = new ConfigException(
        key, value, "Could not parse to URL."
    );
    configException.initCause(e);

    throw configException;
  }
}
 
Example 9
Source File: ConfigUtils.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
static URI uri(String key, String value) {
  try {
    return new URI(value);
  } catch (URISyntaxException e) {
    ConfigException configException = new ConfigException(
        key, value, "Could not parse to URI."
    );
    configException.initCause(e);

    throw configException;
  }
}
 
Example 10
Source File: ConfigUtils.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Method will create a KeyStore based on the KeyStore type specified in the config.
 *
 * @param config Config to read from.
 * @param key    Key to read from
 * @return KeyStore based on the type specified in the config.
 */
public static KeyStore keyStore(AbstractConfig config, String key) {
  final String keyStoreType = config.getString(key);
  try {
    return KeyStore.getInstance(keyStoreType);
  } catch (KeyStoreException e) {
    ConfigException exception = new ConfigException(
        key,
        keyStoreType,
        "Invalid KeyStore type."
    );
    exception.initCause(e);
    throw exception;
  }
}
 
Example 11
Source File: ConfigUtils.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Method will create a KeyManagerFactory based on the Algorithm type specified in the config.
 *
 * @param config Config to read from.
 * @param key    Key to read from
 * @return KeyManagerFactory based on the type specified in the config.
 */
public static KeyManagerFactory keyManagerFactory(AbstractConfig config, String key) {
  final String keyManagerFactoryType = config.getString(key);
  try {
    return KeyManagerFactory.getInstance(keyManagerFactoryType);
  } catch (NoSuchAlgorithmException e) {
    ConfigException exception = new ConfigException(
        key,
        keyManagerFactoryType,
        "Unknown Algorithm."
    );
    exception.initCause(e);
    throw exception;
  }
}
 
Example 12
Source File: ConfigUtils.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Method will create a TrustManagerFactory based on the Algorithm type specified in the config.
 *
 * @param config Config to read from.
 * @param key    Key to read from
 * @return TrustManagerFactory based on the type specified in the config.
 */
public static TrustManagerFactory trustManagerFactory(AbstractConfig config, String key) {
  final String trustManagerFactoryType = config.getString(key);
  try {
    return TrustManagerFactory.getInstance(trustManagerFactoryType);
  } catch (NoSuchAlgorithmException e) {
    ConfigException exception = new ConfigException(
        key,
        trustManagerFactoryType,
        "Unknown Algorithm."
    );
    exception.initCause(e);
    throw exception;
  }
}
 
Example 13
Source File: ConfigUtils.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Method will create a SSLContext based on the Algorithm type specified in the config.
 *
 * @param config Config to read from.
 * @param key    Key to read from
 * @return SSLContext based on the type specified in the config.
 */
public static SSLContext sslContext(AbstractConfig config, String key) {
  final String trustManagerFactoryType = config.getString(key);
  try {
    return SSLContext.getInstance(trustManagerFactoryType);
  } catch (NoSuchAlgorithmException e) {
    ConfigException exception = new ConfigException(
        key,
        trustManagerFactoryType,
        "Unknown Algorithm."
    );
    exception.initCause(e);
    throw exception;
  }
}
 
Example 14
Source File: ConfigUtils.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
/**
 * Method is used to return a charset for a string key.
 *
 * @param config Config to read from.
 * @param key    Key to read from
 * @return
 */
public static Charset charset(AbstractConfig config, String key) {
  final String charsetName = config.getString(key);
  try {
    return Charset.forName(charsetName);
  } catch (final UnsupportedCharsetException ex) {
    ConfigException exception = new ConfigException(key, charsetName, "Invalid charset.");
    exception.initCause(ex);
    throw exception;
  }
}
 
Example 15
Source File: ValidCharset.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
static void validate(String config, String value) {
  try {
    Charset.forName(value);
  } catch (Exception ex) {
    ConfigException configException = new ConfigException(
        config, value, "Charset is invalid."
    );
    configException.initCause(ex);

    throw configException;
  }
}
 
Example 16
Source File: ValidUrl.java    From connect-utils with Apache License 2.0 5 votes vote down vote up
static void validate(String config, String value) {
  try {
    new URL(value);
  } catch (MalformedURLException e) {
    ConfigException configException = new ConfigException(
        config, value, "Could not parse to URL."
    );
    configException.initCause(e);

    throw configException;
  }
}