Search in sources :

Example 76 with ConfigException

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;
}
Also used : UnsupportedCharsetException(java.nio.charset.UnsupportedCharsetException) ArrayList(java.util.ArrayList) Charset(java.nio.charset.Charset) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 77 with ConfigException

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;
        }
    };
}
Also used : ValidEnum(com.github.jcustenborder.kafka.connect.utils.config.ValidEnum) SSLContext(javax.net.ssl.SSLContext) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) ConfigException(org.apache.kafka.common.config.ConfigException) ValidPattern(com.github.jcustenborder.kafka.connect.utils.config.ValidPattern) ValidPort(com.github.jcustenborder.kafka.connect.utils.config.ValidPort) Validator(org.apache.kafka.common.config.ConfigDef.Validator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Preconditions(com.google.common.base.Preconditions) Pattern(java.util.regex.Pattern) ConfigException(org.apache.kafka.common.config.ConfigException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 78 with ConfigException

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;
        }
    };
}
Also used : ValidEnum(com.github.jcustenborder.kafka.connect.utils.config.ValidEnum) SSLContext(javax.net.ssl.SSLContext) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) ConfigException(org.apache.kafka.common.config.ConfigException) ValidPattern(com.github.jcustenborder.kafka.connect.utils.config.ValidPattern) ValidPort(com.github.jcustenborder.kafka.connect.utils.config.ValidPort) Validator(org.apache.kafka.common.config.ConfigDef.Validator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Preconditions(com.google.common.base.Preconditions) Pattern(java.util.regex.Pattern) ConfigException(org.apache.kafka.common.config.ConfigException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 79 with ConfigException

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;
        }
    };
}
Also used : ValidEnum(com.github.jcustenborder.kafka.connect.utils.config.ValidEnum) SSLContext(javax.net.ssl.SSLContext) TrustManagerFactory(javax.net.ssl.TrustManagerFactory) KeyManagerFactory(javax.net.ssl.KeyManagerFactory) KeyStore(java.security.KeyStore) KeyStoreException(java.security.KeyStoreException) ConfigException(org.apache.kafka.common.config.ConfigException) ValidPattern(com.github.jcustenborder.kafka.connect.utils.config.ValidPattern) ValidPort(com.github.jcustenborder.kafka.connect.utils.config.ValidPort) Validator(org.apache.kafka.common.config.ConfigDef.Validator) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException) Preconditions(com.google.common.base.Preconditions) Pattern(java.util.regex.Pattern) ConfigException(org.apache.kafka.common.config.ConfigException) NoSuchAlgorithmException(java.security.NoSuchAlgorithmException)

Example 80 with ConfigException

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.");
    }
}
Also used : List(java.util.List) ConfigException(org.apache.kafka.common.config.ConfigException)

Aggregations

ConfigException (org.apache.kafka.common.config.ConfigException)136 HashMap (java.util.HashMap)29 Test (org.junit.jupiter.api.Test)28 Test (org.junit.Test)20 Properties (java.util.Properties)10 KafkaException (org.apache.kafka.common.KafkaException)10 ArrayList (java.util.ArrayList)9 List (java.util.List)9 Pattern (java.util.regex.Pattern)9 Serde (org.apache.kafka.common.serialization.Serde)8 SimpleConfig (org.apache.kafka.connect.transforms.util.SimpleConfig)8 File (java.io.File)7 SSLContext (javax.net.ssl.SSLContext)7 Map (java.util.Map)6 ByteArraySerializer (org.apache.kafka.common.serialization.ByteArraySerializer)6 KeyStore (java.security.KeyStore)5 KeyManagerFactory (javax.net.ssl.KeyManagerFactory)5 TrustManagerFactory (javax.net.ssl.TrustManagerFactory)5 ConfigDef (org.apache.kafka.common.config.ConfigDef)5 IOException (java.io.IOException)4