From b10a014273b9d7414a67d82dc9937908bbd99eaf Mon Sep 17 00:00:00 2001 From: Ilayaperumal Gopinathan Date: Mon, 17 Jul 2017 07:49:27 +0530 Subject: [PATCH] Minor refactoring --- .../client/ConfluentSchemaRegistryClient.java | 20 +++++++++---------- 1 file changed, 10 insertions(+), 10 deletions(-) diff --git a/spring-cloud-stream-schema/src/main/java/org/springframework/cloud/stream/schema/client/ConfluentSchemaRegistryClient.java b/spring-cloud-stream-schema/src/main/java/org/springframework/cloud/stream/schema/client/ConfluentSchemaRegistryClient.java index 0698d796e..64be7d01a 100644 --- a/spring-cloud-stream-schema/src/main/java/org/springframework/cloud/stream/schema/client/ConfluentSchemaRegistryClient.java +++ b/spring-cloud-stream-schema/src/main/java/org/springframework/cloud/stream/schema/client/ConfluentSchemaRegistryClient.java @@ -18,6 +18,7 @@ package org.springframework.cloud.stream.schema.client; import java.util.Arrays; import java.util.Collections; +import java.util.List; import java.util.Map; import com.fasterxml.jackson.core.JsonProcessingException; @@ -42,6 +43,9 @@ import org.springframework.web.client.RestTemplate; */ public class ConfluentSchemaRegistryClient implements SchemaRegistryClient { + private static final List ACCEPT_HEADERS = Arrays.asList("application/vnd.schemaregistry.v1+json", + "application/vnd.schemaregistry+json", "application/json"); + private RestTemplate template; private String endpoint = "http://localhost:8081"; @@ -53,7 +57,7 @@ public class ConfluentSchemaRegistryClient implements SchemaRegistryClient { } public ConfluentSchemaRegistryClient(RestTemplate template) { - this(template,new ObjectMapper()); + this(template, new ObjectMapper()); } public ConfluentSchemaRegistryClient(RestTemplate template, ObjectMapper mapper) { @@ -71,8 +75,7 @@ public class ConfluentSchemaRegistryClient implements SchemaRegistryClient { Assert.isTrue("avro".equals(format), "Only Avro is supported"); String path = String.format("/subjects/%s/versions", subject); HttpHeaders headers = new HttpHeaders(); - headers.put("Accept", Arrays.asList("application/vnd.schemaregistry.v1+json", - "application/vnd.schemaregistry+json", "application/json")); + headers.put("Accept", ACCEPT_HEADERS); headers.add("Content-Type", "application/json"); Integer version = null; Integer id = null; @@ -110,13 +113,12 @@ public class ConfluentSchemaRegistryClient implements SchemaRegistryClient { * subject. After a successful registration we can inquire the server to get the * version of a schema * @param subject - * @return + * @return the version of the returned schema */ private Integer getSubjectVersion(String subject, String payload) { String path = String.format("/subjects/%s", subject); HttpHeaders headers = new HttpHeaders(); - headers.put("Accept", Arrays.asList("application/vnd.schemaregistry.v1+json", - "application/vnd.schemaregistry+json", "application/json")); + headers.put("Accept", ACCEPT_HEADERS); headers.add("Content-Type", "application/json"); Integer version = null; try { @@ -141,8 +143,7 @@ public class ConfluentSchemaRegistryClient implements SchemaRegistryClient { String path = String.format("/subjects/%s/versions/%d", schemaReference.getSubject(), schemaReference.getVersion()); HttpHeaders headers = new HttpHeaders(); - headers.put("Accept", Arrays.asList("application/vnd.schemaregistry.v1+json", - "application/vnd.schemaregistry+json", "application/json")); + headers.put("Accept", ACCEPT_HEADERS); headers.add("Content-Type", "application/vnd.schemaregistry.v1+json"); HttpEntity request = new HttpEntity<>("", headers); try { @@ -165,8 +166,7 @@ public class ConfluentSchemaRegistryClient implements SchemaRegistryClient { public String fetch(int id) { String path = String.format("/schemas/ids/%d", id); HttpHeaders headers = new HttpHeaders(); - headers.put("Accept", Arrays.asList("application/vnd.schemaregistry.v1+json", - "application/vnd.schemaregistry+json", "application/json")); + headers.put("Accept", ACCEPT_HEADERS); headers.add("Content-Type", "application/vnd.schemaregistry.v1+json"); HttpEntity request = new HttpEntity<>("", headers); try {