From a5a90912a4b7c6583922ba9dd84e370d53464257 Mon Sep 17 00:00:00 2001 From: Someshbose Date: Fri, 20 Nov 2020 23:18:27 +0530 Subject: [PATCH] Consumer logic enhancemnt --- fileconsumer/pom.xml | 7 +++++++ .../FileConsumerAppApplication.java | 4 +--- .../app/shared/CommonRestTemplate.java | 21 +++++++++++++++++++ 3 files changed, 29 insertions(+), 3 deletions(-) create mode 100644 fileconsumer/src/main/java/somesh/github/io/fileconsumer/app/shared/CommonRestTemplate.java diff --git a/fileconsumer/pom.xml b/fileconsumer/pom.xml index c091ada..163acb4 100644 --- a/fileconsumer/pom.xml +++ b/fileconsumer/pom.xml @@ -102,6 +102,13 @@ + + + org.projectlombok + lombok + 1.18.12 + provided + diff --git a/fileconsumer/src/main/java/somesh/github/io/fileconsumer/FileConsumerAppApplication.java b/fileconsumer/src/main/java/somesh/github/io/fileconsumer/FileConsumerAppApplication.java index 8f5f19c..7c875b6 100644 --- a/fileconsumer/src/main/java/somesh/github/io/fileconsumer/FileConsumerAppApplication.java +++ b/fileconsumer/src/main/java/somesh/github/io/fileconsumer/FileConsumerAppApplication.java @@ -5,10 +5,9 @@ import lombok.extern.slf4j.Slf4j; /** - * FileConsumer Application. + * FileConsumer Application main class. * * @author sombose - * */ @Slf4j @SpringBootApplication @@ -24,5 +23,4 @@ public static void main(String[] args) { SpringApplication.run(FileConsumerAppApplication.class, args); log.info("File Consumer App is started."); } - } diff --git a/fileconsumer/src/main/java/somesh/github/io/fileconsumer/app/shared/CommonRestTemplate.java b/fileconsumer/src/main/java/somesh/github/io/fileconsumer/app/shared/CommonRestTemplate.java new file mode 100644 index 0000000..6213768 --- /dev/null +++ b/fileconsumer/src/main/java/somesh/github/io/fileconsumer/app/shared/CommonRestTemplate.java @@ -0,0 +1,21 @@ +package somesh.github.io.fileconsumer.app.shared; + +import java.util.Arrays; +import org.springframework.http.HttpEntity; +import org.springframework.http.HttpHeaders; +import org.springframework.http.HttpMethod; +import org.springframework.http.MediaType; +import org.springframework.web.client.RestTemplate; + +public interface CommonRestTemplate { + + RestTemplate getrestTemplate(); + + default void restCall() { + HttpHeaders headers = new HttpHeaders(); + headers.setAccept(Arrays.asList(MediaType.APPLICATION_JSON)); + HttpEntity entity = new HttpEntity(headers); + + getrestTemplate().exchange("http://localhost:8080/products", HttpMethod.GET, entity, String.class).getBody(); + } +}