Updated LoanAccountService from Rest Template to Web Client

WebClient
parent 4fb244faba
commit 2c1745cf62

@ -2,12 +2,10 @@ package com.mfsys.aconnect.client.service;
import com.mfsys.aconnect.client.dto.WorkflowApprovalDTO; import com.mfsys.aconnect.client.dto.WorkflowApprovalDTO;
import com.mfsys.aconnect.client.dto.WorkflowRequestDTO; import com.mfsys.aconnect.client.dto.WorkflowRequestDTO;
import com.mfsys.aconnect.configuration.config.WebClientConfig;
import org.springframework.beans.factory.annotation.Value; import org.springframework.beans.factory.annotation.Value;
import org.springframework.http.*; import org.springframework.http.*;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
@Service @Service
public class LoanAccountService { public class LoanAccountService {
@ -15,9 +13,9 @@ public class LoanAccountService {
@Value("${app.loan.uri}") @Value("${app.loan.uri}")
private String loanURI; private String loanURI;
private final RestTemplate restTemplate; private final WebClientConfig webClientConfig;
public LoanAccountService(RestTemplate restTemplate) { public LoanAccountService(WebClientConfig webClientConfig) {
this.restTemplate = restTemplate; this.webClientConfig = webClientConfig;
} }
public Object createIndividualLoan(WorkflowRequestDTO workflowRequestDTO, String token) { public Object createIndividualLoan(WorkflowRequestDTO workflowRequestDTO, String token) {
@ -29,16 +27,12 @@ public class LoanAccountService {
headers.set("SUS_USERCODE", workflowRequestDTO.getSusUsercode()); headers.set("SUS_USERCODE", workflowRequestDTO.getSusUsercode());
headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<WorkflowRequestDTO> entity = new HttpEntity<>(workflowRequestDTO, headers); return webClientConfig.post(
ResponseEntity<Map> response = restTemplate.exchange(
url, url,
HttpMethod.POST, workflowRequestDTO,
entity, headers
Map.class )
); .getBody();
return ResponseEntity.status(response.getStatusCode()).body(response.getBody());
} }
public Object approvalIndividualLoan(WorkflowApprovalDTO workflowRequestDTO, String token) { public Object approvalIndividualLoan(WorkflowApprovalDTO workflowRequestDTO, String token) {
@ -50,16 +44,12 @@ public class LoanAccountService {
headers.set("SUS_USERCODE", workflowRequestDTO.getSusUserCode()); headers.set("SUS_USERCODE", workflowRequestDTO.getSusUserCode());
headers.setContentType(MediaType.APPLICATION_JSON); headers.setContentType(MediaType.APPLICATION_JSON);
HttpEntity<WorkflowApprovalDTO> entity = new HttpEntity<>(workflowRequestDTO, headers); return webClientConfig.patch(
ResponseEntity<Map> response = restTemplate.exchange(
url, url,
HttpMethod.PATCH, workflowRequestDTO,
entity, headers
Map.class )
); .getBody();
return ResponseEntity.status(response.getStatusCode()).body(response.getBody());
} }
} }

Loading…
Cancel
Save