This is an automated email from the ASF dual-hosted git repository.
davsclaus pushed a commit to branch main
in repository https://gitbox.apache.org/repos/asf/camel.git
The following commit(s) were added to refs/heads/main by this push:
new 583d7d83e97c CAMEL-27175: camel-kafka - reject schemaRegistryVendor
apicurio with schemaFormat json (#30650)
583d7d83e97c is described below
commit 583d7d83e97c8dd541e603b0fbc0bda37d21f0fd
Author: Guillaume Nodet <[email protected]>
AuthorDate: Mon Nov 23 13:14:51 2026 +0100
CAMEL-27175: camel-kafka - reject schemaRegistryVendor apicurio with
schemaFormat json (#30650)
Fail fast with a clear IllegalArgumentException when
schemaRegistryVendor=apicurio and schemaFormat=json are configured together and
com.networknt:json-schema-validator 3.x is on the classpath, instead of letting
the Apicurio serde throw a cryptic IncompatibleClassChangeError at runtime.
The Apicurio JSON Schema serde depends on json-schema-validator 1.5.x,
where SchemaLoader is an interface; in 3.x (CAMEL-23172) it is a class. The
check is conditional: only reject when SchemaLoader is a class. The message
gives the workarounds: avro or protobuf with apicurio, or the confluent vendor
with json.
A package-private vendor(String, String, boolean) overload makes the
detection testable whatever the test classpath has. Docs (vendor table,
Apicurio note) and the catalog copy are updated. No upgrade-guide entry:
schemaRegistryVendor is new in 4.24 (CAMEL-27130).
Relates to CAMEL-27175, which stays open for the real fix.
Co-authored-by: Claude Sonnet 4.6 <[email protected]>
---
.../apache/camel/catalog/docs/kafka-component.adoc | 11 ++++++--
.../camel/component/kafka/KafkaSchemaRegistry.java | 33 ++++++++++++++++++++++
.../camel-kafka/src/main/docs/kafka-component.adoc | 11 ++++++--
.../kafka/KafkaSchemaRegistryVendorTest.java | 16 +++++++++++
4 files changed, 67 insertions(+), 4 deletions(-)
diff --git
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kafka-component.adoc
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kafka-component.adoc
index 7679e3c13ae1..fa71ded6f167 100644
---
a/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kafka-component.adoc
+++
b/catalog/camel-catalog/src/generated/resources/org/apache/camel/catalog/docs/kafka-component.adoc
@@ -993,12 +993,13 @@ The `schemaRegistryURL` option is set as the registry URL
of the vendor.
|===
| schemaRegistryVendor | schemaFormat | What Camel sets
| confluent | avro, json, protobuf | The `KafkaAvroSerializer`,
`KafkaJsonSchemaSerializer` or `KafkaProtobufSerializer` (and the matching
deserializer) of Confluent, and `schema.registry.url`. The producer registers
the schemas (the Confluent default). Several registries implement the Confluent
registry API, such as Karapace, the Redpanda schema registry and the Confluent
compatible API of Apicurio Registry, so `confluent` works for them too.
-| apicurio | avro, json, protobuf | The `AvroKafkaSerializer`,
`JsonSchemaKafkaSerializer` or `ProtobufKafkaSerializer` (and the matching
deserializer) of Apicurio Registry 3.x, `apicurio.registry.url`, and on the
producer `apicurio.registry.auto-register=true`.
+| apicurio | avro, json, protobuf | The `AvroKafkaSerializer`,
`JsonSchemaKafkaSerializer` or `ProtobufKafkaSerializer` (and the matching
deserializer) of Apicurio Registry 3.x, `apicurio.registry.url`, and on the
producer `apicurio.registry.auto-register=true`. JSON Schema
(`schemaFormat=json`) fails at startup when
`com.networknt:json-schema-validator` 3.x is on the classpath
(<<apicurio-json-incompatibility,see below>>).
| aws-glue | avro, json, protobuf | The `GlueSchemaRegistryKafkaSerializer`
and `GlueSchemaRegistryKafkaDeserializer`, `dataFormat`, on the producer
`schemaAutoRegistrationEnabled=true`, and on the consumer of Avro
`avroRecordType=GENERIC_RECORD`. The `schemaRegistryURL` is optional and is set
as `endpoint` (to override the endpoint of the Glue service).
| azure | avro | The `KafkaAvroSerializer` and `KafkaAvroDeserializer` of the
Azure Schema Registry, `schema.registry.url` (the fully qualified namespace of
the Event Hubs namespace), `use.azure.credential=true`, and on the producer
`auto.register.schemas=true`.
|===
-The `schemaFormat` is `avro` by default. A format that the vendor does not
support, such as `azure` with `protobuf`, fails when the producer or consumer
starts.
+The `schemaFormat` is `avro` by default. A format that the vendor does not
support fails when the producer or consumer starts:
+`azure` with `json` or `protobuf`, and `apicurio` with `json` when
`com.networknt:json-schema-validator` 3.x is on the classpath (see the note in
the Apicurio section).
The `specificAvroReader` option is set under the property of the vendor.
What you set yourself takes precedence: a `valueSerializer` or
`valueDeserializer` other than the default, and any `additionalProperties`,
such as a property of the vendor that Camel also sets.
@@ -1083,7 +1084,13 @@ YAML::
*Apicurio Registry*
+[[apicurio-json-incompatibility]]
NOTE: Supports Avro, JSON Schema and Protobuf, with the serdes of Apicurio
Registry 3.x. The 2.x serdes have other artifact names and property names, and
are not set up by `apicurio`.
+JSON Schema (`schemaFormat=json`) fails at startup when
`com.networknt:json-schema-validator` 3.x is on the classpath:
+the Apicurio JSON Schema serde
(`io.apicurio:apicurio-registry-jsonschema-serde-kafka` 3.x) depends on
`com.networknt:json-schema-validator` 1.5.x, while for example
`camel-yaml-dsl-validator`, `camel-json-validator` and Camel JBang use
`com.networknt:json-schema-validator` 3.x (upgraded for Jackson 3 in
CAMEL-23172).
+In 3.x, `SchemaLoader` changed from an interface to a class, so the 1.5.x
classes of the serde fail to link against the 3.x classes already loaded, with
an `IncompatibleClassChangeError`.
+Use `schemaFormat=avro` or `schemaFormat=protobuf` with `apicurio`, or use
`schemaRegistryVendor=confluent` with `schemaFormat=json`
+(the Confluent compatible API of Apicurio Registry works with `confluent`).
The URL is the URL of the registry API of Apicurio Registry 3.x, which ends
with `/apis/registry/v3`.
diff --git
a/components/camel-kafka-common/src/main/java/org/apache/camel/component/kafka/KafkaSchemaRegistry.java
b/components/camel-kafka-common/src/main/java/org/apache/camel/component/kafka/KafkaSchemaRegistry.java
index da3b00213bb2..fcfc9c927292 100644
---
a/components/camel-kafka-common/src/main/java/org/apache/camel/component/kafka/KafkaSchemaRegistry.java
+++
b/components/camel-kafka-common/src/main/java/org/apache/camel/component/kafka/KafkaSchemaRegistry.java
@@ -90,6 +90,14 @@ final class KafkaSchemaRegistry {
* format the vendor does not support.
*/
static String vendor(String vendor, String format) {
+ return vendor(vendor, format, hasJsonSchemaValidator3x());
+ }
+
+ /**
+ * Like {@link #vendor(String, String)} but with an explicit flag for the
json-schema-validator version check, which
+ * allows unit tests to cover both the rejection and the happy path
without depending on the classpath.
+ */
+ static String vendor(String vendor, String format, boolean
jsonSchemaValidator3x) {
if (ObjectHelper.isEmpty(vendor)) {
return null;
}
@@ -107,9 +115,34 @@ final class KafkaSchemaRegistry {
+ ": the Azure Schema Registry
serde for Kafka "
+
"(com.microsoft.azure:azure-schemaregistry-kafka-avro) is for Avro only.");
}
+ if (APICURIO.equals(v) && JSON.equals(f) && jsonSchemaValidator3x) {
+ throw new IllegalArgumentException(
+ "schemaRegistryVendor apicurio with schemaFormat json
fails at runtime with an IncompatibleClassChangeError:"
+ + "
com.networknt:json-schema-validator 3.x is on the classpath, while the Apicurio
Registry JSON Schema"
+ + " serde
(io.apicurio:apicurio-registry-jsonschema-serde-kafka 3.x) depends on"
+ + "
com.networknt:json-schema-validator 1.5.x. In 3.x, SchemaLoader changed from an
interface to a class,"
+ + " so the serde classes fail
to link against the 3.x classes already loaded."
+ + " For example,
camel-yaml-dsl-validator, camel-json-validator and Camel JBang bring 3.x."
+ + " Use schemaFormat avro or
protobuf with apicurio, or use schemaRegistryVendor confluent with"
+ + " schemaFormat json (the
Confluent compatible API of Apicurio Registry works with confluent).");
+ }
return v;
}
+ /**
+ * Returns true when com.networknt:json-schema-validator 3.x is on the
classpath. In 3.x, SchemaLoader changed from
+ * an interface to a class. The Apicurio Registry JSON Schema serde
depends on 1.5.x (where it is an interface), so
+ * loading it on a classpath with 3.x throws an
IncompatibleClassChangeError.
+ */
+ static boolean hasJsonSchemaValidator3x() {
+ try {
+ ClassLoader cl = KafkaSchemaRegistry.class.getClassLoader();
+ return
!Class.forName("com.networknt.schema.resource.SchemaLoader", false,
cl).isInterface();
+ } catch (ClassNotFoundException e) {
+ return false;
+ }
+ }
+
private static String format(String format) {
if (ObjectHelper.isEmpty(format)) {
return AVRO;
diff --git a/components/camel-kafka/src/main/docs/kafka-component.adoc
b/components/camel-kafka/src/main/docs/kafka-component.adoc
index 7679e3c13ae1..fa71ded6f167 100644
--- a/components/camel-kafka/src/main/docs/kafka-component.adoc
+++ b/components/camel-kafka/src/main/docs/kafka-component.adoc
@@ -993,12 +993,13 @@ The `schemaRegistryURL` option is set as the registry URL
of the vendor.
|===
| schemaRegistryVendor | schemaFormat | What Camel sets
| confluent | avro, json, protobuf | The `KafkaAvroSerializer`,
`KafkaJsonSchemaSerializer` or `KafkaProtobufSerializer` (and the matching
deserializer) of Confluent, and `schema.registry.url`. The producer registers
the schemas (the Confluent default). Several registries implement the Confluent
registry API, such as Karapace, the Redpanda schema registry and the Confluent
compatible API of Apicurio Registry, so `confluent` works for them too.
-| apicurio | avro, json, protobuf | The `AvroKafkaSerializer`,
`JsonSchemaKafkaSerializer` or `ProtobufKafkaSerializer` (and the matching
deserializer) of Apicurio Registry 3.x, `apicurio.registry.url`, and on the
producer `apicurio.registry.auto-register=true`.
+| apicurio | avro, json, protobuf | The `AvroKafkaSerializer`,
`JsonSchemaKafkaSerializer` or `ProtobufKafkaSerializer` (and the matching
deserializer) of Apicurio Registry 3.x, `apicurio.registry.url`, and on the
producer `apicurio.registry.auto-register=true`. JSON Schema
(`schemaFormat=json`) fails at startup when
`com.networknt:json-schema-validator` 3.x is on the classpath
(<<apicurio-json-incompatibility,see below>>).
| aws-glue | avro, json, protobuf | The `GlueSchemaRegistryKafkaSerializer`
and `GlueSchemaRegistryKafkaDeserializer`, `dataFormat`, on the producer
`schemaAutoRegistrationEnabled=true`, and on the consumer of Avro
`avroRecordType=GENERIC_RECORD`. The `schemaRegistryURL` is optional and is set
as `endpoint` (to override the endpoint of the Glue service).
| azure | avro | The `KafkaAvroSerializer` and `KafkaAvroDeserializer` of the
Azure Schema Registry, `schema.registry.url` (the fully qualified namespace of
the Event Hubs namespace), `use.azure.credential=true`, and on the producer
`auto.register.schemas=true`.
|===
-The `schemaFormat` is `avro` by default. A format that the vendor does not
support, such as `azure` with `protobuf`, fails when the producer or consumer
starts.
+The `schemaFormat` is `avro` by default. A format that the vendor does not
support fails when the producer or consumer starts:
+`azure` with `json` or `protobuf`, and `apicurio` with `json` when
`com.networknt:json-schema-validator` 3.x is on the classpath (see the note in
the Apicurio section).
The `specificAvroReader` option is set under the property of the vendor.
What you set yourself takes precedence: a `valueSerializer` or
`valueDeserializer` other than the default, and any `additionalProperties`,
such as a property of the vendor that Camel also sets.
@@ -1083,7 +1084,13 @@ YAML::
*Apicurio Registry*
+[[apicurio-json-incompatibility]]
NOTE: Supports Avro, JSON Schema and Protobuf, with the serdes of Apicurio
Registry 3.x. The 2.x serdes have other artifact names and property names, and
are not set up by `apicurio`.
+JSON Schema (`schemaFormat=json`) fails at startup when
`com.networknt:json-schema-validator` 3.x is on the classpath:
+the Apicurio JSON Schema serde
(`io.apicurio:apicurio-registry-jsonschema-serde-kafka` 3.x) depends on
`com.networknt:json-schema-validator` 1.5.x, while for example
`camel-yaml-dsl-validator`, `camel-json-validator` and Camel JBang use
`com.networknt:json-schema-validator` 3.x (upgraded for Jackson 3 in
CAMEL-23172).
+In 3.x, `SchemaLoader` changed from an interface to a class, so the 1.5.x
classes of the serde fail to link against the 3.x classes already loaded, with
an `IncompatibleClassChangeError`.
+Use `schemaFormat=avro` or `schemaFormat=protobuf` with `apicurio`, or use
`schemaRegistryVendor=confluent` with `schemaFormat=json`
+(the Confluent compatible API of Apicurio Registry works with `confluent`).
The URL is the URL of the registry API of Apicurio Registry 3.x, which ends
with `/apis/registry/v3`.
diff --git
a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/KafkaSchemaRegistryVendorTest.java
b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/KafkaSchemaRegistryVendorTest.java
index b2e06348813b..6aa30bb51fc0 100644
---
a/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/KafkaSchemaRegistryVendorTest.java
+++
b/components/camel-kafka/src/test/java/org/apache/camel/component/kafka/KafkaSchemaRegistryVendorTest.java
@@ -500,6 +500,20 @@ class KafkaSchemaRegistryVendorTest {
}
}
+ @Test
+ void apicurioWithJsonFailsWhenJsonSchemaValidator3xIsOnTheClasspath() {
+ // Test the rejection branch directly via the injectable overload,
without depending on the classpath.
+ IllegalArgumentException e =
assertThrows(IllegalArgumentException.class,
+ () -> KafkaSchemaRegistry.vendor("apicurio", "json", true));
+ assertTrue(e.getMessage().contains("schemaRegistryVendor apicurio with
schemaFormat json fails at runtime"),
+ e.getMessage());
+ assertTrue(e.getMessage().contains("IncompatibleClassChangeError"),
e.getMessage());
+
assertTrue(e.getMessage().contains("com.networknt:json-schema-validator"),
e.getMessage());
+
+ // The happy path (json-schema-validator 1.5.x on the classpath) must
not reject it.
+ assertDoesNotThrow(() -> KafkaSchemaRegistry.vendor("apicurio",
"json", false));
+ }
+
@Test
void unknownVendorOrFormatFails() {
KafkaConfiguration config = new KafkaConfiguration();
@@ -536,6 +550,8 @@ class KafkaSchemaRegistryVendorTest {
} finally {
producer.stop();
}
+ // The apicurio+json rejection is tested via the injectable vendor()
overload in
+ // apicurioWithJsonFailsWhenJsonSchemaValidator3xIsOnTheClasspath.
}
static Stream<Arguments> artifacts() {