Search in sources :

Example 6 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project connect-utils by jcustenborder.

the class ValidHostnameAndPortTests method ensureValidExceptions.

@Test
public void ensureValidExceptions() {
    ConfigException exception = assertThrows(ConfigException.class, () -> {
        validator.ensureValid("test", null);
    });
    assertTrue(exception.getMessage().contains("must be a string or a list."));
    exception = assertThrows(ConfigException.class, () -> {
        validator.ensureValid("test", "");
    });
    assertTrue(exception.getMessage().contains("does not match pattern"));
    exception = assertThrows(ConfigException.class, () -> {
        validator.ensureValid("test", "localhost:99999");
    });
    assertTrue(exception.getMessage().contains("Port must be between 1 and 65535"));
}
Also used : ConfigException(org.apache.kafka.common.config.ConfigException) Test(org.junit.jupiter.api.Test)

Example 7 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.

the class SessionWindowedSerializer method configure.

@SuppressWarnings("unchecked")
@Override
public void configure(final Map<String, ?> configs, final boolean isKey) {
    if (inner == null) {
        String propertyName = isKey ? StreamsConfig.DEFAULT_WINDOWED_KEY_SERDE_INNER_CLASS : StreamsConfig.DEFAULT_WINDOWED_VALUE_SERDE_INNER_CLASS;
        String value = (String) configs.get(propertyName);
        try {
            inner = Serde.class.cast(Utils.newInstance(value, Serde.class)).serializer();
            inner.configure(configs, isKey);
        } catch (final ClassNotFoundException e) {
            throw new ConfigException(propertyName, value, "Serde class " + value + " could not be found.");
        }
    }
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 8 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.

the class TimeWindowedSerializer method configure.

@SuppressWarnings("unchecked")
@Override
public void configure(final Map<String, ?> configs, final boolean isKey) {
    if (inner == null) {
        final String propertyName = isKey ? StreamsConfig.DEFAULT_WINDOWED_KEY_SERDE_INNER_CLASS : StreamsConfig.DEFAULT_WINDOWED_VALUE_SERDE_INNER_CLASS;
        final String value = (String) configs.get(propertyName);
        try {
            inner = Serde.class.cast(Utils.newInstance(value, Serde.class)).serializer();
            inner.configure(configs, isKey);
        } catch (final ClassNotFoundException e) {
            throw new ConfigException(propertyName, value, "Serde class " + value + " could not be found.");
        }
    }
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 9 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.

the class SessionWindowedDeserializer method configure.

@SuppressWarnings("unchecked")
@Override
public void configure(final Map<String, ?> configs, final boolean isKey) {
    if (inner == null) {
        final String propertyName = isKey ? StreamsConfig.DEFAULT_WINDOWED_KEY_SERDE_INNER_CLASS : StreamsConfig.DEFAULT_WINDOWED_VALUE_SERDE_INNER_CLASS;
        final String value = (String) configs.get(propertyName);
        try {
            inner = Serde.class.cast(Utils.newInstance(value, Serde.class)).deserializer();
            inner.configure(configs, isKey);
        } catch (final ClassNotFoundException e) {
            throw new ConfigException(propertyName, value, "Serde class " + value + " could not be found.");
        }
    }
}
Also used : Serde(org.apache.kafka.common.serialization.Serde) ConfigException(org.apache.kafka.common.config.ConfigException)

Example 10 with ConfigException

use of org.apache.kafka.common.config.ConfigException in project apache-kafka-on-k8s by banzaicloud.

the class RestServer method createConnector.

/**
 * Creates Jetty connector according to configuration
 */
public Connector createConnector(String listener) {
    Pattern listenerPattern = Pattern.compile("^(.*)://\\[?([0-9a-zA-Z\\-%._:]*)\\]?:(-?[0-9]+)");
    Matcher listenerMatcher = listenerPattern.matcher(listener);
    if (!listenerMatcher.matches())
        throw new ConfigException("Listener doesn't have the right format (protocol://hostname:port).");
    String protocol = listenerMatcher.group(1).toLowerCase(Locale.ENGLISH);
    if (!PROTOCOL_HTTP.equals(protocol) && !PROTOCOL_HTTPS.equals(protocol))
        throw new ConfigException(String.format("Listener protocol must be either \"%s\" or \"%s\".", PROTOCOL_HTTP, PROTOCOL_HTTPS));
    String hostname = listenerMatcher.group(2);
    int port = Integer.parseInt(listenerMatcher.group(3));
    ServerConnector connector;
    if (PROTOCOL_HTTPS.equals(protocol)) {
        SslContextFactory ssl = SSLUtils.createSslContextFactory(config);
        connector = new ServerConnector(jettyServer, ssl);
        connector.setName(String.format("%s_%s%d", PROTOCOL_HTTPS, hostname, port));
    } else {
        connector = new ServerConnector(jettyServer);
        connector.setName(String.format("%s_%s%d", PROTOCOL_HTTP, hostname, port));
    }
    if (!hostname.isEmpty())
        connector.setHost(hostname);
    connector.setPort(port);
    return connector;
}
Also used : ServerConnector(org.eclipse.jetty.server.ServerConnector) Pattern(java.util.regex.Pattern) SslContextFactory(org.eclipse.jetty.util.ssl.SslContextFactory) Matcher(java.util.regex.Matcher) 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