resolve conflict
This commit is contained in:
@@ -0,0 +1,85 @@
|
||||
package com.billpaymentservice.bbps.serviceImpl;
|
||||
|
||||
|
||||
import java.net.http.HttpClient;
|
||||
import java.time.Duration;
|
||||
import java.util.HashMap;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
import org.slf4j.LoggerFactory;
|
||||
import org.springframework.http.HttpHeaders;
|
||||
import org.springframework.http.MediaType;
|
||||
import org.springframework.http.ResponseEntity;
|
||||
import org.springframework.http.client.JdkClientHttpRequestFactory;
|
||||
import org.springframework.stereotype.Service;
|
||||
import java.time.Duration;
|
||||
import org.springframework.web.client.HttpClientErrorException;
|
||||
import org.springframework.web.client.HttpServerErrorException;
|
||||
import org.springframework.web.client.RestClient;
|
||||
|
||||
@Service
|
||||
public class HttpService {
|
||||
private static final Logger log = LoggerFactory.getLogger(HttpService.class);
|
||||
private final RestClient restClient;
|
||||
|
||||
HttpService() {
|
||||
HttpClient httpClient = HttpClient.newBuilder()
|
||||
.connectTimeout(Duration.ofSeconds(5))
|
||||
.build();
|
||||
|
||||
JdkClientHttpRequestFactory factory = new JdkClientHttpRequestFactory(httpClient);
|
||||
factory.setReadTimeout(Duration.ofSeconds(10));
|
||||
|
||||
this.restClient = RestClient.builder()
|
||||
.requestFactory(factory)
|
||||
.build();
|
||||
}
|
||||
|
||||
public HashMap<String, String> postRequest(String url, String payload) {
|
||||
HashMap<String, String> response = new HashMap<>();
|
||||
try {
|
||||
HttpHeaders headers = new HttpHeaders();
|
||||
headers.setContentType(MediaType.APPLICATION_JSON);
|
||||
log.info("📡 Bank POST Request to URL: {}", url);
|
||||
|
||||
ResponseEntity<String> restResponse = restClient.post()
|
||||
.uri(url)
|
||||
.headers(h -> h.addAll(headers))
|
||||
.body(payload)
|
||||
.retrieve()
|
||||
.toEntity(String.class);
|
||||
|
||||
response.put("respCode", String.valueOf(restResponse.getStatusCode().value()));
|
||||
response.put("data", restResponse.getBody());
|
||||
|
||||
} catch (HttpClientErrorException | HttpServerErrorException httpException) {
|
||||
response.put("respCode", String.valueOf(httpException.getStatusCode()));
|
||||
response.put("data", "Exception : " + httpException.getResponseBodyAsString());
|
||||
} catch (Exception e) {
|
||||
response.put("data", "Exception :" + e.getMessage());
|
||||
log.error("❌ Exception during POST call to {} -> {}", url, e.getMessage());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
|
||||
public HashMap<String, String> getRequest(String url) {
|
||||
HashMap<String, String> response = new HashMap<>();
|
||||
try {
|
||||
log.info("🌐 Bank GET Request to URL: {}", url);
|
||||
|
||||
ResponseEntity<String> restResponse = restClient.get()
|
||||
.uri(url)
|
||||
.retrieve()
|
||||
.toEntity(String.class);
|
||||
|
||||
response.put("data", restResponse.getBody());
|
||||
|
||||
} catch (HttpClientErrorException | HttpServerErrorException httpException) {
|
||||
response.put("data", "Exception : " + httpException.getResponseBodyAsString());
|
||||
} catch (Exception e) {
|
||||
response.put("data", "Exception :" + e.getMessage());
|
||||
log.error("❌ Exception during GET call to {} -> {}", url, e.getMessage());
|
||||
}
|
||||
return response;
|
||||
}
|
||||
}
|
||||
@@ -3,6 +3,7 @@ package com.billpaymentservice.bbps.serviceImpl;
|
||||
import java.util.ArrayList;
|
||||
import java.util.HashMap;
|
||||
import java.util.List;
|
||||
import java.util.Map;
|
||||
import java.util.Optional;
|
||||
|
||||
import org.slf4j.Logger;
|
||||
@@ -19,10 +20,14 @@ import com.billpaymentservice.bbps.dto.response.BillerDataResponse;
|
||||
import com.billpaymentservice.bbps.dto.response.BillerResponse;
|
||||
import com.billpaymentservice.bbps.entites.BBPSMerchantValidation;
|
||||
import com.billpaymentservice.bbps.exception.AppException;
|
||||
import com.billpaymentservice.bbps.exception.CustomException;
|
||||
import com.billpaymentservice.bbps.repository.MerchantRepository;
|
||||
import com.billpaymentservice.bbps.service.MasterDataService;
|
||||
import com.billpaymentservice.bbps.util.BBPSConstant;
|
||||
import com.billpaymentservice.bbps.util.ResponseParser;
|
||||
import com.fasterxml.jackson.core.JsonProcessingException;
|
||||
import com.fasterxml.jackson.core.type.TypeReference;
|
||||
import com.fasterxml.jackson.databind.ObjectMapper;
|
||||
|
||||
import jakarta.servlet.http.HttpServletRequest;
|
||||
|
||||
@@ -43,10 +48,46 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
@Autowired
|
||||
private ResponseParser responseParser;
|
||||
|
||||
private static final Logger log = LoggerFactory.getLogger(MasterDataServiceImpl.class);
|
||||
private final HttpService httpService;
|
||||
private final ObjectMapper objectMapper = new ObjectMapper();
|
||||
@Value("${bbps.billerDataFetch.url}")
|
||||
private String billerDataFetchUrl;
|
||||
|
||||
// Inject HttpService
|
||||
public MasterDataServiceImpl(HttpService httpService) {
|
||||
this.httpService = httpService;
|
||||
}
|
||||
|
||||
@Override
|
||||
public BillerDataResponse getBillerByBillerId(BillerDetailRequest billerDetailRequest) {
|
||||
// TODO Auto-generated method stub
|
||||
return null;
|
||||
|
||||
String billerId = billerDetailRequest.getBillerId();
|
||||
String url = billerDataFetchUrl + billerId;
|
||||
|
||||
Map<String, String> responseMap = httpService.getRequest(url);
|
||||
String responseData = responseMap.get("data");
|
||||
log.info("data is :{}", responseData);
|
||||
|
||||
ObjectMapper objectMapper = new ObjectMapper();
|
||||
|
||||
try {
|
||||
Map<String, Object> dataMap = objectMapper.readValue(responseData,
|
||||
new TypeReference<Map<String, Object>>() {
|
||||
});
|
||||
if (!dataMap.containsKey("generalResp")) {
|
||||
throw new CustomException(String.valueOf(dataMap.get("statusCode")),
|
||||
String.valueOf(dataMap.get("status")), String.valueOf(dataMap.get("message")),
|
||||
String.valueOf(dataMap.get("remarks")));
|
||||
}
|
||||
BillerDataResponse responseWrapper = objectMapper.convertValue(dataMap, BillerDataResponse.class);
|
||||
return responseWrapper;
|
||||
|
||||
} catch (JsonProcessingException e) {
|
||||
log.error("Error parsing responseData JSON: {}", e.getMessage());
|
||||
throw new CustomException("Invalid JSON received from API");
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
@Override
|
||||
@@ -101,8 +142,7 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
String category, int pageStart, int pageEnd) {
|
||||
LOGGER.info("Fetching Master Data Category-wise for MID={}, Category={}, PageStart={}, PageEnd={}",
|
||||
requestModel.getMid(), category, pageStart, pageEnd);
|
||||
//bollean
|
||||
//if(validate(arequetsModel)
|
||||
|
||||
BBPSMerchantValidation merchantValidation = merchantRegisterRepo.findByMid(requestModel.getMid());
|
||||
BillerResponse responseModel = new BillerResponse();
|
||||
// if Start merchant validations
|
||||
@@ -146,5 +186,4 @@ public class MasterDataServiceImpl implements MasterDataService {
|
||||
return ResponseEntity.ok(responseModel);
|
||||
|
||||
}
|
||||
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user