AEM integration with Akamai Fast Purge API for Single/multiple urls
Map<String, List<String>> akamaiRequestMap = Maps.newHashMap();
ArrayList<String> arrayList = new ArrayList<>();
arrayList.add("Add URLS Here"); // Add full public facing urls
akamaiRequestMap.put("objects", arrayList);
new Gson().toJson(akamaiRequestMap)
// Need to send a HTTP Request to the OPEN API Interface,
// therefore we are using the com.google.api.client.http Helper Classes
HttpTransport httpTransport = new ApacheHttpTransport();
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
URI uri = null;
try {
// End Point Ex: /ccu/v3/invalidate/url/production
uri = new URI("https", "AKAMAI HOST READ IT FROM CONFIGURATION", "REFER END POINT", null, null);
} catch (URISyntaxException e1) {
log.error("URL gone wrong! {}", e1.getMessage());
}
// It is important to send the Request with the Content-Type application/json
if (uri != null && purgeObject != null) {
HttpRequest akamaiRequest = requestFactory.buildPostRequest(new GenericUrl(uri),
ByteArrayContent.fromString("application/json", purgeObject));
HttpHeaders headers = akamaiRequest.getHeaders();
headers.set("Host", "SET AKAMAI HOST FROM CONFIGURATION");
if (StringUtils.isNotBlank("CHECK ACCESS TOKEN IS BLANK OR NOT")
&& StringUtils.isNotBlank("CHECK CLIENT SECRET IS BLANK OR NOT")
&& StringUtils.isNotBlank("CHECK CLIENT TOKEN IS BLANK OR NOT"
&& StringUtils.isNotBlank("CHECK AKAMAI HOST IS BLANK OR NOT") {
GoogleHttpClientEdgeGridRequestSigner requestSigner = new GoogleHttpClientEdgeGridRequestSigner(akamaiClientCredentials(akamaiPurgeService));
try {
requestSigner.sign(akamaiRequest);
// Adding delay of minimum 5secs to allow dispatcher cache to be cleared before Akamai CC
Thread.sleep(akamaiPurgeService.getDelayTime());
} catch (RequestSigningException | InterruptedException e) {
log.error("Error in signing request to Akamai: {}", e.getMessage());
}
HttpResponse akamaiResponse = null;
try {
akamaiResponse = akamaiRequest.execute();
} catch (Exception e) {
log.error("Exception while executing akamaiRequest {}", e.getMessage());
}
purgeResponse = akamaiResponseCheck(akamaiResponse);
} else {
purgeResponse = "Akamai Fast Purge Not Configured";
log.warn("Akamai Fast Purge Not Configured");
}
Comments
Post a Comment