Search in sources :

Example 16 with SchemaProvider

use of io.confluent.kafka.schemaregistry.SchemaProvider in project schema-registry by confluentinc.

the class JsonSchemaTest method testParseSchema.

@Test
public void testParseSchema() {
    SchemaProvider jsonSchemaProvider = new JsonSchemaProvider();
    ParsedSchema parsedSchema = jsonSchemaProvider.parseSchemaOrElseThrow(recordSchemaString, new ArrayList<>(), false);
    Optional<ParsedSchema> parsedSchemaOptional = jsonSchemaProvider.parseSchema(recordSchemaString, new ArrayList<>(), false);
    assertNotNull(parsedSchema);
    assertTrue(parsedSchemaOptional.isPresent());
}
Also used : SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Test(org.junit.Test)

Example 17 with SchemaProvider

use of io.confluent.kafka.schemaregistry.SchemaProvider in project schema-registry by confluentinc.

the class SchemaRegistryMojo method client.

protected SchemaRegistryClient client() {
    if (null == this.client) {
        Map<String, String> config = new HashMap<>();
        if (configs != null && !configs.isEmpty()) {
            config.putAll(configs);
        }
        if (userInfoConfig != null) {
            // Note that BASIC_AUTH_CREDENTIALS_SOURCE is not configurable as the plugin only supports
            // a single schema registry URL, so there is no additional utility of the URL source.
            config.put(SchemaRegistryClientConfig.BASIC_AUTH_CREDENTIALS_SOURCE, "USER_INFO");
            config.put(SchemaRegistryClientConfig.USER_INFO_CONFIG, userInfoConfig);
        }
        List<SchemaProvider> providers = schemaProviders != null && !schemaProviders.isEmpty() ? schemaProviders() : MojoUtils.defaultSchemaProviders();
        this.client = new CachedSchemaRegistryClient(this.schemaRegistryUrls, 1000, providers, config, httpHeaders);
    }
    return this.client;
}
Also used : HashMap(java.util.HashMap) SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)

Example 18 with SchemaProvider

use of io.confluent.kafka.schemaregistry.SchemaProvider in project schema-registry by confluentinc.

the class SchemaMessageReader method getSchemaRegistryClient.

private SchemaRegistryClient getSchemaRegistryClient(Properties props, String url) {
    Map<String, Object> originals = getPropertiesMap(props);
    final List<String> schemaRegistryUrls = Collections.singletonList(url);
    final List<SchemaProvider> schemaProviders = Collections.singletonList(getProvider());
    final String maybeMockScope = MockSchemaRegistry.validateAndMaybeGetMockScope(schemaRegistryUrls);
    SchemaRegistryClient schemaRegistry;
    if (maybeMockScope == null) {
        schemaRegistry = new CachedSchemaRegistryClient(url, AbstractKafkaSchemaSerDeConfig.MAX_SCHEMAS_PER_SUBJECT_DEFAULT, schemaProviders, originals);
    } else {
        schemaRegistry = MockSchemaRegistry.getClientForScope(maybeMockScope, schemaProviders);
    }
    return schemaRegistry;
}
Also used : SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient) SchemaRegistryClient(io.confluent.kafka.schemaregistry.client.SchemaRegistryClient) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)

Example 19 with SchemaProvider

use of io.confluent.kafka.schemaregistry.SchemaProvider in project schema-registry by confluentinc.

the class AbstractKafkaSchemaSerDe method configureClientProperties.

protected void configureClientProperties(AbstractKafkaSchemaSerDeConfig config, SchemaProvider provider) {
    List<String> urls = config.getSchemaRegistryUrls();
    int maxSchemaObject = config.getMaxSchemasPerSubject();
    Map<String, Object> originals = config.originalsWithPrefix("");
    if (null == schemaRegistry) {
        String mockScope = MockSchemaRegistry.validateAndMaybeGetMockScope(urls);
        List<SchemaProvider> providers = Collections.singletonList(provider);
        if (mockScope != null) {
            schemaRegistry = MockSchemaRegistry.getClientForScope(mockScope, providers);
        } else {
            schemaRegistry = new CachedSchemaRegistryClient(urls, maxSchemaObject, providers, originals, config.requestHeaders());
        }
    }
    contextNameStrategy = config.contextNameStrategy();
    keySubjectNameStrategy = config.keySubjectNameStrategy();
    valueSubjectNameStrategy = config.valueSubjectNameStrategy();
    useSchemaReflection = config.useSchemaReflection();
}
Also used : SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) CachedSchemaRegistryClient(io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)

Example 20 with SchemaProvider

use of io.confluent.kafka.schemaregistry.SchemaProvider in project schema-registry by confluentinc.

the class ProtobufSchemaTest method testParseSchema.

@Test
public void testParseSchema() {
    SchemaProvider protobufSchemaProvider = new ProtobufSchemaProvider();
    ParsedSchema parsedSchema = protobufSchemaProvider.parseSchemaOrElseThrow(recordSchemaString, new ArrayList<>(), false);
    Optional<ParsedSchema> parsedSchemaOptional = protobufSchemaProvider.parseSchema(recordSchemaString, new ArrayList<>(), false);
    assertNotNull(parsedSchema);
    assertTrue(parsedSchemaOptional.isPresent());
}
Also used : SchemaProvider(io.confluent.kafka.schemaregistry.SchemaProvider) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) Test(org.junit.Test)

Aggregations

SchemaProvider (io.confluent.kafka.schemaregistry.SchemaProvider)22 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)9 AvroSchemaProvider (io.confluent.kafka.schemaregistry.avro.AvroSchemaProvider)7 JsonSchemaProvider (io.confluent.kafka.schemaregistry.json.JsonSchemaProvider)7 ProtobufSchemaProvider (io.confluent.kafka.schemaregistry.protobuf.ProtobufSchemaProvider)7 BadRequestException (io.confluent.kafkarest.exceptions.BadRequestException)5 IOException (java.io.IOException)5 Test (org.junit.Test)5 CachedSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.CachedSchemaRegistryClient)4 SchemaRegistryClient (io.confluent.kafka.schemaregistry.client.SchemaRegistryClient)4 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)3 EmbeddedFormat (io.confluent.kafkarest.entities.EmbeddedFormat)3 Test (org.junit.jupiter.api.Test)3 MockSchemaRegistryClient (io.confluent.kafka.schemaregistry.client.MockSchemaRegistryClient)2 SchemaString (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)2 StoreException (io.confluent.kafka.schemaregistry.storage.exceptions.StoreException)2 TopicNameStrategy (io.confluent.kafka.serializers.subject.TopicNameStrategy)2 HashMap (java.util.HashMap)2 SchemaParseException (org.apache.avro.SchemaParseException)2 CompatibilityChecker (io.confluent.kafka.schemaregistry.CompatibilityChecker)1