use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.
the class ConfigUtils method charsets.
/**
* 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;
}
use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.
the class Validators method validKeyManagerFactory.
/**
* 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;
}
};
}
use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.
the class Validators method validTrustManagerFactory.
/**
* 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;
}
};
}
use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.
the class Validators method validSSLContext.
/**
* 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;
}
};
}
use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.
the class PatternValidator method ensureValid.
@Override
public void ensureValid(String setting, Object value) {
if (value instanceof String) {
String s = (String) value;
validatePattern(setting, s);
} else if (value instanceof List) {
List<String> list = (List<String>) value;
for (String s : list) {
validatePattern(setting, s);
}
} else {
throw new ConfigException(setting, value, "value must be a String or List.");
}
}
Aggregations