Skip to content

Commit 2e290aa

Browse files
Andy Palmerolegz
Andy Palmer
authored andcommitted
GH-3103 Fix the retrieval of the schema version registered on serializing an Avro message with the ConfluentSchemaRegistryClient
Signed-off-by: Andy Palmer <[email protected]> Resolves #3103 Resolves #3107
1 parent 18bc7d1 commit 2e290aa

File tree

2 files changed

+10
-10
lines changed

2 files changed

+10
-10
lines changed

schema-registry/spring-cloud-stream-schema-registry-client/src/main/java/org/springframework/cloud/stream/schema/registry/client/ConfluentSchemaRegistryClient.java

Lines changed: 8 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -16,14 +16,8 @@
1616

1717
package org.springframework.cloud.stream.schema.registry.client;
1818

19-
import java.util.Arrays;
20-
import java.util.HashMap;
21-
import java.util.List;
22-
import java.util.Map;
23-
2419
import com.fasterxml.jackson.core.JsonProcessingException;
2520
import com.fasterxml.jackson.databind.ObjectMapper;
26-
2721
import org.springframework.cloud.stream.schema.registry.SchemaNotFoundException;
2822
import org.springframework.cloud.stream.schema.registry.SchemaReference;
2923
import org.springframework.cloud.stream.schema.registry.SchemaRegistrationResponse;
@@ -37,6 +31,11 @@
3731
import org.springframework.web.client.HttpStatusCodeException;
3832
import org.springframework.web.client.RestTemplate;
3933

34+
import java.util.Arrays;
35+
import java.util.HashMap;
36+
import java.util.List;
37+
import java.util.Map;
38+
4039
/**
4140
* @author Vinicius Carvalho
4241
* @author Marius Bogoevici
@@ -102,11 +101,12 @@ public SchemaRegistrationResponse register(String subject, String format, String
102101

103102
try {
104103
ResponseEntity<List> response = this.template.getForEntity(
105-
this.endpoint + "/subjects/" + subject + "/versions", List.class);
104+
this.endpoint + "/schemas/ids/" + id + "/versions", List.class);
106105

107106
final List body = response.getBody();
108107
if (!CollectionUtils.isEmpty(body)) {
109-
version = (Integer) body.get(body.size() - 1);
108+
// Assume only a single version is registered for this ID
109+
version = (Integer) ((Map<String, Object>) body.get(0)).get("version");
110110
}
111111
}
112112
catch (HttpStatusCodeException httpException) {

schema-registry/spring-cloud-stream-schema-registry-client/src/test/java/org/springframework/cloud/stream/schema/avro/client/ConfluentSchemaRegistryClientTests.java

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -66,9 +66,9 @@ public void registerSchema() throws Exception {
6666
.andRespond(withSuccess("{\"id\":101,\"version\":1}", MediaType.APPLICATION_JSON));
6767

6868
this.mockRestServiceServer
69-
.expect(requestTo("http://localhost:8081/subjects/user/versions"))
69+
.expect(requestTo("http://localhost:8081/schemas/ids/101/versions"))
7070
.andExpect(method(HttpMethod.GET))
71-
.andRespond((withSuccess("[1]", MediaType.APPLICATION_JSON)));
71+
.andRespond((withSuccess("[{\"subject\":\"user\",\"version\":1}]", MediaType.APPLICATION_JSON)));
7272

7373
ConfluentSchemaRegistryClient client = new ConfluentSchemaRegistryClient(
7474
this.restTemplate);

0 commit comments

Comments
 (0)