use of org.wso2.carbon.apimgt.gateway.dto.RevokedJWTTokenDTO in project carbon-apimgt by wso2.
the class RevokedJWTTokensRetriever method retrieveRevokedJWTTokensData.
/**
* This method will retrieve revoked JWT tokens by calling a web service.
*
* @return List of RevokedJWTTokensDTOs.
*/
private RevokedJWTTokenDTO[] retrieveRevokedJWTTokensData() {
try {
// The resource resides in the throttle web app. Hence reading throttle configs
String url = getEventHubConfiguration().getServiceUrl().concat(APIConstants.INTERNAL_WEB_APP_EP).concat("/revokedjwt");
HttpGet method = new HttpGet(url);
byte[] credentials = Base64.encodeBase64((getEventHubConfiguration().getUsername() + ":" + getEventHubConfiguration().getPassword()).getBytes(StandardCharsets.UTF_8));
method.setHeader("Authorization", "Basic " + new String(credentials, StandardCharsets.UTF_8));
URL keyMgtURL = new URL(url);
int keyMgtPort = keyMgtURL.getPort();
String keyMgtProtocol = keyMgtURL.getProtocol();
HttpClient httpClient = APIUtil.getHttpClient(keyMgtPort, keyMgtProtocol);
HttpResponse httpResponse = null;
int retryCount = 0;
boolean retry;
do {
try {
httpResponse = httpClient.execute(method);
retry = false;
} catch (IOException ex) {
retryCount++;
if (retryCount < revokedJWTTokensRetrievalRetries) {
retry = true;
log.warn("Failed retrieving revoked JWT token signatures from remote endpoint: " + ex.getMessage() + ". Retrying after " + revokedJWTTokensRetrievalTimeoutInSeconds + " seconds...");
Thread.sleep(revokedJWTTokensRetrievalTimeoutInSeconds * 1000);
} else {
throw ex;
}
}
} while (retry);
String responseString = EntityUtils.toString(httpResponse.getEntity(), "UTF-8");
if (responseString != null && !responseString.isEmpty()) {
return new Gson().fromJson(responseString, RevokedJWTTokenDTO[].class);
}
} catch (IOException | InterruptedException e) {
log.error("Exception when retrieving revoked JWT tokens from remote endpoint ", e);
}
return null;
}
Aggregations