Skip to content

Commit

Permalink
Merge pull request #357 from aihamh/1.1.5.3
Browse files Browse the repository at this point in the history
[MOSIP-18156] Fixed New RestTemplate issue
  • Loading branch information
ckm007 authored Nov 4, 2021
2 parents 1ece621 + 332af1f commit ef78e35
Show file tree
Hide file tree
Showing 2 changed files with 16 additions and 46 deletions.
Original file line number Diff line number Diff line change
Expand Up @@ -326,8 +326,8 @@ public Map<String, String> prepareRequestMap(MainRequestDTO<?> requestDto) {
* @param identityKey pass identityKey
* @return values from JSON based on key
*
* @throws ParseException On json Parsing Failed
* @throws org.json.simple.parser.ParseException
* @throws ParseException On json Parsing Failed
* @throws org.json.simple.parser.ParseException
*
*/
public JSONArray getValueFromIdentity(byte[] demographicData, String identityKey)
Expand All @@ -346,8 +346,8 @@ public JSONArray getValueFromIdentity(byte[] demographicData, String identityKey
* @param identityKey pass postalcode
* @return values from JSON
*
* @throws ParseException On json Parsing Failed
* @throws org.json.simple.parser.ParseException
* @throws ParseException On json Parsing Failed
* @throws org.json.simple.parser.ParseException
*
*/

Expand Down Expand Up @@ -537,7 +537,7 @@ public String getSchema() {
HttpEntity<RequestWrapper<RegistrationCenterResponseDto>> entity = new HttpEntity<>(headers);
String uriBuilder = regbuilder.build().encode().toUriString();

ResponseEntity<ResponseWrapper<IdSchemaDto>> responseEntity = getRestTemplate().exchange(uriBuilder,
ResponseEntity<ResponseWrapper<IdSchemaDto>> responseEntity = restTemplate.exchange(uriBuilder,
HttpMethod.GET, entity, new ParameterizedTypeReference<ResponseWrapper<IdSchemaDto>>() {
});
if (responseEntity.getBody().getErrors() != null && !responseEntity.getBody().getErrors().isEmpty()) {
Expand All @@ -552,7 +552,7 @@ public String getSchema() {
DemographicErrorMessages.ID_SCHEMA_FETCH_FAILED.getMessage());
}

} catch (RestClientException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException ex) {
} catch (RestClientException ex) {

throw new RestCallException(DemographicErrorCodes.PRG_PAM_APP_020.getCode(),
DemographicErrorMessages.ID_SCHEMA_FETCH_FAILED.getMessage());
Expand Down Expand Up @@ -593,28 +593,29 @@ public ResponseEntity<?> callAuthService(String url, HttpMethod httpMethodType,
request = new HttpEntity<>(headers);
}
log.info("sessionId", "idType", "id", "In call to kernel rest service :" + url);
response = getRestTemplate().exchange(url, httpMethodType, request, responseClass);
} catch (RestClientException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException ex) {
response = restTemplate.exchange(url, httpMethodType, request, responseClass);
} catch (RestClientException ex) {
log.error("sessionId", "idType", "id", "Kernel rest call exception " + ExceptionUtils.getStackTrace(ex));
throw new RestClientException("rest call failed");
}
return response;

}

public MainResponseDTO<DeleteBookingDTO> deleteBooking (String preRegId) {
public MainResponseDTO<DeleteBookingDTO> deleteBooking(String preRegId) {
MainResponseDTO<DeleteBookingDTO> response = new MainResponseDTO<>();
String url = deleteAppointmentResourseUrl + '/' + "appointment"+"?preRegistrationId=" + preRegId;
String url = deleteAppointmentResourseUrl + '/' + "appointment" + "?preRegistrationId=" + preRegId;
MultiValueMap<String, String> param = new LinkedMultiValueMap<>();
String regbuilder = UriComponentsBuilder.fromHttpUrl(url).toString();
try {
log.info("sessionId", "idType", "id", "In callBookingService method of DemographicServiceUtil"+regbuilder);
log.info("sessionId", "idType", "id",
"In callBookingService method of DemographicServiceUtil" + regbuilder);
HttpHeaders headers = new HttpHeaders();
headers.setContentType(MediaType.APPLICATION_JSON);
headers.set("Cookie", getAuthToken());
HttpEntity<?> entity = new HttpEntity<>(headers);

ResponseEntity<MainResponseDTO<DeleteBookingDTO>> responseEntity = getRestTemplate().exchange(url,
ResponseEntity<MainResponseDTO<DeleteBookingDTO>> responseEntity = restTemplate.exchange(url,
HttpMethod.DELETE, entity, new ParameterizedTypeReference<MainResponseDTO<DeleteBookingDTO>>() {
});
log.debug("sessionId", "idType", "id", responseEntity.toString());
Expand All @@ -624,27 +625,12 @@ public MainResponseDTO<DeleteBookingDTO> deleteBooking (String preRegId) {
}
response.setResponse(responseEntity.getBody().getResponse());
log.info("sessionId", "idType", "id", "In call to booking rest service :" + regbuilder);
} catch (RestClientException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException ex) {
} catch (RestClientException ex) {
log.error("sessionId", "idType", "id", "Booking rest call exception " + ExceptionUtils.getStackTrace(ex));
throw new RestClientException("rest call failed");
}
return response;

}

public RestTemplate getRestTemplate() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {

TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;

SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy)
.build();

SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);

CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClient);
return new RestTemplate(requestFactory);
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -169,8 +169,8 @@ public ResponseEntity<?> callAuthService(String url, HttpMethod httpMethodType,
request = new HttpEntity<>(headers);
}
log.info("In call to kernel rest service :{}", url);
response = getRestTemplate().exchange(url, httpMethodType, request, responseClass);
} catch (RestClientException | KeyManagementException | NoSuchAlgorithmException | KeyStoreException ex) {
response = restTemplate.exchange(url, httpMethodType, request, responseClass);
} catch (RestClientException ex) {
log.debug("Kernel rest call exception ", ex);
throw new RestClientException("rest call failed");
}
Expand Down Expand Up @@ -462,22 +462,6 @@ Integer tryParsePropertiesToInteger(String prop) {
}
}

public RestTemplate getRestTemplate() throws KeyManagementException, NoSuchAlgorithmException, KeyStoreException {

TrustStrategy acceptingTrustStrategy = (X509Certificate[] chain, String authType) -> true;

SSLContext sslContext = org.apache.http.ssl.SSLContexts.custom().loadTrustMaterial(null, acceptingTrustStrategy)
.build();

SSLConnectionSocketFactory csf = new SSLConnectionSocketFactory(sslContext);

CloseableHttpClient httpClient = HttpClients.custom().setSSLSocketFactory(csf).build();
HttpComponentsClientHttpRequestFactory requestFactory = new HttpComponentsClientHttpRequestFactory();

requestFactory.setHttpClient(httpClient);
return new RestTemplate(requestFactory);
}

public CaptchaResposneDTO validateCaptchaToken(String captchaToken) throws PreRegLoginException {

if (captchaToken == null || captchaToken.isBlank()) {
Expand Down

0 comments on commit ef78e35

Please sign in to comment.