From c2b3194fb990540ddf2bef6ec2275b5eeb6b0d6a Mon Sep 17 00:00:00 2001 From: jmaxwell Date: Tue, 13 Feb 2018 14:30:45 -0600 Subject: [PATCH] 1222 DefaultSchemaRegistryClient should accept a custom RestTemplate. Added protected accessors to allow subclasses access to RestTemplate and endpoint fields. --- .../client/DefaultSchemaRegistryClient.java | 20 ++++++++++++++++++- 1 file changed, 19 insertions(+), 1 deletion(-) diff --git a/spring-cloud-stream-schema/src/main/java/org/springframework/cloud/stream/schema/client/DefaultSchemaRegistryClient.java b/spring-cloud-stream-schema/src/main/java/org/springframework/cloud/stream/schema/client/DefaultSchemaRegistryClient.java index d1ca29c1a..c3f81606c 100644 --- a/spring-cloud-stream-schema/src/main/java/org/springframework/cloud/stream/schema/client/DefaultSchemaRegistryClient.java +++ b/spring-cloud-stream-schema/src/main/java/org/springframework/cloud/stream/schema/client/DefaultSchemaRegistryClient.java @@ -36,7 +36,16 @@ public class DefaultSchemaRegistryClient implements SchemaRegistryClient { private String endpoint = "http://localhost:8990"; public DefaultSchemaRegistryClient() { - this.template = new RestTemplate(); + this(new RestTemplate()); + } + + public DefaultSchemaRegistryClient(RestTemplate restTemplate) { + Assert.notNull(restTemplate,"restTemplate cannot be null."); + this.template = restTemplate; + } + + protected String getEndpoint() { + return this.endpoint; } public void setEndpoint(String endpoint) { @@ -44,6 +53,15 @@ public class DefaultSchemaRegistryClient implements SchemaRegistryClient { this.endpoint = endpoint; } + protected RestTemplate getRestTemplate() { + return this.template; + } + + public void setRestTemplate(RestTemplate restTemplate) { + Assert.notNull(restTemplate,"restTemplate cannot be null."); + this.template = restTemplate; + } + @Override public SchemaRegistrationResponse register(String subject, String format, String schema) { Map requestBody = new HashMap<>();