This is the sample code in API that we use: (*The method is using for retrieve all world check iso country list.)
static String gatewayurl = "/v1/";
static String gatewayhost = "api-worldcheck.refinitiv.com";
public static void processingGetIsoCountryList() throws IOException {
_log.info("Entering the processingGetIsoCountryList method");
CloseableHttpClient httpclient = HttpClients.createDefault();
try {
Date now = new Date();
// format for date string Mon, 27 Mar 2017 15:19:36 GMT
DateFormat df = new SimpleDateFormat("EEE, dd MMM yyyy HH:mm:ss z");
df.setTimeZone(TimeZone.getTimeZone("GMT"));
String date = df.format(now);
String dataToSign = "(request-target): get " + gatewayurl
+ "reference/countries\n" + "host: " + gatewayhost + "\n"
+ "date: " + date;
String hmac = generateAuthHeader(dataToSign, apisecret);
String authorisation = "Signature keyId=\""
+ apikey
+ "\",algorithm=\"hmac-sha256\",headers=\"(request-target) host date\",signature=\""
+ hmac + "\"";
_log.info("dataToSign is......" + dataToSign);
_log.info("hmac is......" + hmac);
_log.info("authorisation is......" + authorisation);
HttpGet httpGet = new HttpGet(httpsUrl + "reference/countries");
httpGet.addHeader("Authorization", authorisation);
httpGet.addHeader("Cache-Control", "no-cache");
httpGet.addHeader("date", date);
CloseableHttpResponse response = httpclient.execute(httpGet);
try {
HttpEntity entity = response.getEntity();
_log.info("response.getStatusLine is.........."+ response.getStatusLine());
String json = EntityUtils.toString(response.getEntity());
_log.info("entity is......." + entity);
_log.info("json is......." + json);
ObjectMapper mapper = new ObjectMapper();
Object jsonObj = mapper.readValue(json, Object.class);
String indented = mapper.writerWithDefaultPrettyPrinter()
.writeValueAsString(jsonObj);
_log.info("indented is..........." + indented);
EntityUtils.consume(entity);
}
catch (Exception e) {
_log.info(e.getMessage());
} finally {
response.close();
}
} catch (Exception e) {
_log.info(e.getMessage());
} finally {
httpclient.close();
}
_log.info("Exiting the processingGetIsoCountryList method");
}
In the API.log, you will notice that after executing the code CloseableHttpResponse response = httpclient.execute(httpGet);
The connection was reset. It didn’t get any response.
This line of code was not called: _log.info("response.getStatusLine is.........."+ response.getStatusLine());
Here's the result in API.log
14:41:37.435 [http-thread-pool-8083(2)] INFO com.tr.worldCheckApi.GetRequest - Entering the processingGetIsoCountryList method
14:41:38.224 [http-thread-pool-8083(2)] INFO com.tr.worldCheckApi.GetRequest - dataToSign is......(request-target): get /v1/reference/countries
host: api-worldcheck.refinitiv.com
date: Mon, 10 May 2021 06:41:38 GMT
14:41:38.224 [http-thread-pool-8083(2)] INFO com.tr.worldCheckApi.GetRequest - hmac is......sCGRBNlS5we5RKGJEr7TARZ60Smy4zXzOujNgeMSEEo=
14:41:38.225 [http-thread-pool-8083(2)] INFO com.tr.worldCheckApi.GetRequest - authorisation is......Signature keyId="1ad3ff6b-2870-4478-bc23-cae4cc4f2422",algorithm="hmac-sha256",headers="(request-target) host date",signature="sCGRBNlS5we5RKGJEr7TARZ60Smy4zXzOujNgeMSEEo="
14:41:42.069 [http-thread-pool-8083(2)] INFO com.tr.worldCheckApi.GetRequest - Connection reset
14:41:42.071 [http-thread-pool-8083(2)] INFO com.tr.worldCheckApi.GetRequest - Exiting the processingGetIsoCountryList method