Updated DepositAccountService from Rest Template to Web Client

WebClient
parent 6a4bd310d9
commit 4fb244faba

@ -2,13 +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.http.client.HttpComponentsClientHttpRequestFactory;
import org.springframework.stereotype.Service; import org.springframework.stereotype.Service;
import org.springframework.web.client.RestTemplate;
import java.util.Map;
@Service @Service
public class DepositAccountService { public class DepositAccountService {
@ -16,10 +13,9 @@ public class DepositAccountService {
@Value("${app.deposit.uri}") @Value("${app.deposit.uri}")
private String depositURI; private String depositURI;
private final WebClientConfig webClientConfig;
private final RestTemplate restTemplate; public DepositAccountService(WebClientConfig webClientConfig) {
public DepositAccountService(RestTemplate restTemplate) { this.webClientConfig = webClientConfig;
this.restTemplate = restTemplate;
} }
public Object createIndividualDeposit(WorkflowRequestDTO workflowRequestDTO, String token) { public Object createIndividualDeposit(WorkflowRequestDTO workflowRequestDTO, String token) {
@ -31,16 +27,12 @@ public class DepositAccountService {
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());
} }
@ -53,17 +45,12 @@ public class DepositAccountService {
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(
restTemplate.setRequestFactory(new HttpComponentsClientHttpRequestFactory());
ResponseEntity<Map> response = restTemplate.exchange(
url, url,
HttpMethod.PATCH, workflowRequestDTO,
entity, headers
Map.class )
); .getBody();
return ResponseEntity.status(response.getStatusCode()).body(response.getBody());
} }
public Object createBusinessDeposit(WorkflowRequestDTO workflowRequestDTO, String token) { public Object createBusinessDeposit(WorkflowRequestDTO workflowRequestDTO, String token) {
@ -75,15 +62,11 @@ public class DepositAccountService {
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());
} }
} }

Loading…
Cancel
Save