Skip to content

Commit

Permalink
#813 - java 23 image. log rule errors. use rest template bean with sa…
Browse files Browse the repository at this point in the history
…me objectmapper.
  • Loading branch information
petmongrels committed Nov 13, 2024
1 parent 1393294 commit a2f2b41
Showing 4 changed files with 33 additions and 8 deletions.
10 changes: 5 additions & 5 deletions .circleci/config.yml
Original file line number Diff line number Diff line change
@@ -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
Original file line number Diff line number Diff line change
@@ -373,6 +373,7 @@ private <R extends BaseRuleResponseEntity> 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());
Original file line number Diff line number Diff line change
@@ -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 <T> String post(String api, T jsonObj) throws HttpClientErrorException {
String uri = NODE_SERVER_HOST.concat(api);
RestTemplate restTemplate = new RestTemplate();
HttpEntity<Object> entityCredentials = new HttpEntity<>(jsonObj, constructHeaders());
try {
return restTemplate.postForObject(uri, entityCredentials, String.class);
Original file line number Diff line number Diff line change
@@ -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<ReportingSystem> getReportingSystems() {
public void setReportingSystems(List<ReportingSystem> reportingSystems) {
this.reportingSystems = reportingSystems;
}
}

@Bean
public RestTemplate restTemplate() {
RestTemplate restTemplate = new RestTemplate();
List<HttpMessageConverter<?>> messageConverters = new ArrayList<>();
MappingJackson2HttpMessageConverter jsonMessageConverter = new MappingJackson2HttpMessageConverter();
jsonMessageConverter.setObjectMapper(ObjectMapperSingleton.getObjectMapper());
messageConverters.add(jsonMessageConverter);
restTemplate.setMessageConverters(messageConverters);
return restTemplate;
}
}

0 comments on commit a2f2b41

Please sign in to comment.