From a2f2b41797aba8168537cf406eaed4c94c996fc9 Mon Sep 17 00:00:00 2001 From: Vivek Singh Date: Wed, 13 Nov 2024 11:30:39 +0530 Subject: [PATCH] #813 - java 23 image. log rule errors. use rest template bean with same objectmapper. --- .circleci/config.yml | 10 +++++----- .../org/avni/server/service/RuleService.java | 1 + .../web/external/RuleServiceClient.java | 10 ++++++++-- .../avni/server/web/util/Configuration.java | 20 ++++++++++++++++++- 4 files changed, 33 insertions(+), 8 deletions(-) diff --git a/.circleci/config.yml b/.circleci/config.yml index 75f34ddc6..7b054f24d 100644 --- a/.circleci/config.yml +++ b/.circleci/config.yml @@ -94,7 +94,7 @@ commands: jobs: test: docker: - - image: circleci/openjdk:8-jdk + - image: cimg/openjdk:23.0.1 - image: circleci/postgres:12.7 environment: @@ -133,7 +133,7 @@ jobs: destination: testReports build: docker: - - image: circleci/openjdk:8-jdk + - image: cimg/openjdk:23.0.1 resource_class: medium working_directory: ~/avni-server @@ -244,7 +244,7 @@ jobs: UAT_deploy: docker: - - image: circleci/openjdk:8-jdk + - image: cimg/openjdk:23.0.1 working_directory: ~/ steps: - deploy: @@ -266,7 +266,7 @@ jobs: PERF_deploy: docker: - - image: circleci/openjdk:8-jdk + - image: cimg/openjdk:23.0.1 working_directory: ~/ steps: - aws-cli/setup: @@ -334,7 +334,7 @@ workflows: - build: <<: *tags_filter requires: - - test + - test - build_docker_image: context: - dockerhub diff --git a/avni-server-api/src/main/java/org/avni/server/service/RuleService.java b/avni-server-api/src/main/java/org/avni/server/service/RuleService.java index 2fb7efbf9..94f8fc420 100644 --- a/avni-server-api/src/main/java/org/avni/server/service/RuleService.java +++ b/avni-server-api/src/main/java/org/avni/server/service/RuleService.java @@ -373,6 +373,7 @@ private R createHttpHeaderAndSendRequest(Stri } return ruleResponseEntity; } catch (Exception e) { + logger.error("Error while executing rule", e); saveRuleError(ruleFailureLog, e.getMessage(), getStackTrace(e)); RuleError ruleError = new RuleError(); ruleError.setMessage(e.getMessage()); diff --git a/avni-server-api/src/main/java/org/avni/server/web/external/RuleServiceClient.java b/avni-server-api/src/main/java/org/avni/server/web/external/RuleServiceClient.java index c6ddb61a0..7439834ef 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/external/RuleServiceClient.java +++ b/avni-server-api/src/main/java/org/avni/server/web/external/RuleServiceClient.java @@ -5,6 +5,7 @@ import org.avni.server.framework.security.UserContextHolder; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import org.springframework.beans.factory.annotation.Autowired; import org.springframework.beans.factory.annotation.Value; import org.springframework.http.HttpEntity; import org.springframework.http.HttpHeaders; @@ -16,13 +17,18 @@ @Service public class RuleServiceClient { + private final RestTemplate restTemplate; @Value("${node.server.url}") private String NODE_SERVER_HOST; - private Logger logger = LoggerFactory.getLogger(RuleServiceClient.class); + private final Logger logger = LoggerFactory.getLogger(RuleServiceClient.class); + + @Autowired + public RuleServiceClient(RestTemplate restTemplate) { + this.restTemplate = restTemplate; + } public String post(String api, T jsonObj) throws HttpClientErrorException { String uri = NODE_SERVER_HOST.concat(api); - RestTemplate restTemplate = new RestTemplate(); HttpEntity entityCredentials = new HttpEntity<>(jsonObj, constructHeaders()); try { return restTemplate.postForObject(uri, entityCredentials, String.class); diff --git a/avni-server-api/src/main/java/org/avni/server/web/util/Configuration.java b/avni-server-api/src/main/java/org/avni/server/web/util/Configuration.java index 4c80e951f..54675adc6 100644 --- a/avni-server-api/src/main/java/org/avni/server/web/util/Configuration.java +++ b/avni-server-api/src/main/java/org/avni/server/web/util/Configuration.java @@ -1,7 +1,14 @@ package org.avni.server.web.util; +import org.avni.server.util.ObjectMapperSingleton; import org.springframework.boot.context.properties.ConfigurationProperties; +import org.springframework.context.annotation.Bean; +import org.springframework.http.converter.HttpMessageConverter; +import org.springframework.http.converter.json.MappingJackson2HttpMessageConverter; import org.springframework.stereotype.Component; +import org.springframework.web.client.RestTemplate; + +import java.util.ArrayList; import java.util.List; @Component @@ -16,4 +23,15 @@ public List getReportingSystems() { public void setReportingSystems(List reportingSystems) { this.reportingSystems = reportingSystems; } -} \ No newline at end of file + + @Bean + public RestTemplate restTemplate() { + RestTemplate restTemplate = new RestTemplate(); + List> messageConverters = new ArrayList<>(); + MappingJackson2HttpMessageConverter jsonMessageConverter = new MappingJackson2HttpMessageConverter(); + jsonMessageConverter.setObjectMapper(ObjectMapperSingleton.getObjectMapper()); + messageConverters.add(jsonMessageConverter); + restTemplate.setMessageConverters(messageConverters); + return restTemplate; + } +}