GH-3103 Fix the retrieval of the schema version registered on serializing an Avro message with the ConfluentSchemaRegistryClient

Signed-off-by: Andy Palmer <andy.palmer@aexp.com>

Resolves #3103
Resolves #3107
This commit is contained in:
Andy Palmer
2025-04-08 12:42:45 +01:00
committed by Oleg Zhurakousky
parent 18bc7d1fe7
commit 2e290aa7d0
2 changed files with 10 additions and 10 deletions

View File

@@ -16,14 +16,8 @@
package org.springframework.cloud.stream.schema.registry.client;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import com.fasterxml.jackson.core.JsonProcessingException;
import com.fasterxml.jackson.databind.ObjectMapper;
import org.springframework.cloud.stream.schema.registry.SchemaNotFoundException;
import org.springframework.cloud.stream.schema.registry.SchemaReference;
import org.springframework.cloud.stream.schema.registry.SchemaRegistrationResponse;
@@ -37,6 +31,11 @@ import org.springframework.util.CollectionUtils;
import org.springframework.web.client.HttpStatusCodeException;
import org.springframework.web.client.RestTemplate;
import java.util.Arrays;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
/**
* @author Vinicius Carvalho
* @author Marius Bogoevici
@@ -102,11 +101,12 @@ public class ConfluentSchemaRegistryClient implements SchemaRegistryClient {
try {
ResponseEntity<List> response = this.template.getForEntity(
this.endpoint + "/subjects/" + subject + "/versions", List.class);
this.endpoint + "/schemas/ids/" + id + "/versions", List.class);
final List body = response.getBody();
if (!CollectionUtils.isEmpty(body)) {
version = (Integer) body.get(body.size() - 1);
// Assume only a single version is registered for this ID
version = (Integer) ((Map<String, Object>) body.get(0)).get("version");
}
}
catch (HttpStatusCodeException httpException) {

View File

@@ -66,9 +66,9 @@ class ConfluentSchemaRegistryClientTests {
.andRespond(withSuccess("{\"id\":101,\"version\":1}", MediaType.APPLICATION_JSON));
this.mockRestServiceServer
.expect(requestTo("http://localhost:8081/subjects/user/versions"))
.expect(requestTo("http://localhost:8081/schemas/ids/101/versions"))
.andExpect(method(HttpMethod.GET))
.andRespond((withSuccess("[1]", MediaType.APPLICATION_JSON)));
.andRespond((withSuccess("[{\"subject\":\"user\",\"version\":1}]", MediaType.APPLICATION_JSON)));
ConfluentSchemaRegistryClient client = new ConfluentSchemaRegistryClient(
this.restTemplate);