Search in sources :

Example 6 with InvalidSchemaException

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

the class KafkaSchemaRegistry method canonicalizeSchema.

private ParsedSchema canonicalizeSchema(Schema schema, boolean isNew, boolean normalize) throws InvalidSchemaException {
    if (schema == null || schema.getSchema() == null || schema.getSchema().trim().isEmpty()) {
        log.error("Empty schema");
        throw new InvalidSchemaException("Empty schema");
    }
    ParsedSchema parsedSchema = parseSchema(schema, isNew);
    try {
        parsedSchema.validate();
    } catch (Exception e) {
        String errMsg = "Invalid schema " + schema + ", details: " + e.getMessage();
        log.error(errMsg, e);
        throw new InvalidSchemaException(errMsg, e);
    }
    if (normalize) {
        parsedSchema = parsedSchema.normalize();
    }
    schema.setSchema(parsedSchema.canonicalString());
    schema.setReferences(parsedSchema.references());
    return parsedSchema;
}
Also used : InvalidSchemaException(io.confluent.kafka.schemaregistry.exceptions.InvalidSchemaException) ParsedSchema(io.confluent.kafka.schemaregistry.ParsedSchema) SchemaString(io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString) IncompatibleSchemaException(io.confluent.kafka.schemaregistry.exceptions.IncompatibleSchemaException) RestException(io.confluent.rest.exceptions.RestException) SchemaRegistryException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException) TimeoutException(java.util.concurrent.TimeoutException) ReferenceExistsException(io.confluent.kafka.schemaregistry.exceptions.ReferenceExistsException) InvalidSchemaException(io.confluent.kafka.schemaregistry.exceptions.InvalidSchemaException) RestClientException(io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException) SchemaRegistryStoreException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException) StoreTimeoutException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreTimeoutException) UnknownLeaderException(io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException) StoreException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreException) OperationNotPermittedException(io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException) SchemaVersionNotSoftDeletedException(io.confluent.kafka.schemaregistry.exceptions.SchemaVersionNotSoftDeletedException) IdGenerationException(io.confluent.kafka.schemaregistry.exceptions.IdGenerationException) SchemaRegistryTimeoutException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException) SubjectNotSoftDeletedException(io.confluent.kafka.schemaregistry.exceptions.SubjectNotSoftDeletedException) IOException(java.io.IOException) IdDoesNotMatchException(io.confluent.kafka.schemaregistry.exceptions.IdDoesNotMatchException) SchemaRegistryInitializationException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryInitializationException) ExecutionException(java.util.concurrent.ExecutionException) StoreInitializationException(io.confluent.kafka.schemaregistry.storage.exceptions.StoreInitializationException) SchemaRegistryRequestForwardingException(io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException)

Aggregations

InvalidSchemaException (io.confluent.kafka.schemaregistry.exceptions.InvalidSchemaException)6 SchemaRegistryException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryException)5 SchemaRegistryStoreException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryStoreException)5 AvroSchema (io.confluent.kafka.schemaregistry.avro.AvroSchema)4 Schema (io.confluent.kafka.schemaregistry.client.rest.entities.Schema)4 IdDoesNotMatchException (io.confluent.kafka.schemaregistry.exceptions.IdDoesNotMatchException)3 IncompatibleSchemaException (io.confluent.kafka.schemaregistry.exceptions.IncompatibleSchemaException)3 OperationNotPermittedException (io.confluent.kafka.schemaregistry.exceptions.OperationNotPermittedException)3 SchemaRegistryRequestForwardingException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryRequestForwardingException)3 SchemaRegistryTimeoutException (io.confluent.kafka.schemaregistry.exceptions.SchemaRegistryTimeoutException)3 UnknownLeaderException (io.confluent.kafka.schemaregistry.exceptions.UnknownLeaderException)3 PerformanceMetric (io.confluent.rest.annotations.PerformanceMetric)3 Operation (io.swagger.v3.oas.annotations.Operation)3 POST (javax.ws.rs.POST)3 ParsedSchema (io.confluent.kafka.schemaregistry.ParsedSchema)2 SchemaString (io.confluent.kafka.schemaregistry.client.rest.entities.SchemaString)2 CompatibilityCheckResponse (io.confluent.kafka.schemaregistry.client.rest.entities.requests.CompatibilityCheckResponse)2 RestClientException (io.confluent.kafka.schemaregistry.client.rest.exceptions.RestClientException)2 IdGenerationException (io.confluent.kafka.schemaregistry.exceptions.IdGenerationException)2 ReferenceExistsException (io.confluent.kafka.schemaregistry.exceptions.ReferenceExistsException)2