Итак, наконец я смог это сделать. Этот подход, который я использовал, является подходом быстрой очистки, предоставленным Akamai.
Пример кода :
public class AkamaiFastPurge {
private static final String HTTPS = "https";
public static void main(String... s) throws URISyntaxException, IOException, RequestSigningException {
ClientCredential credential = ClientCredential.builder()
.accessToken("Your-access-token")
.clientToken("Your-client-token")
.clientSecret("Your-client-secret")
.host("Your-host")
.build();
ArrayList arrayList = new ArrayList<String>();
// You can add multiple urls.
arrayList.add("*****-Actual-url-you-want-to-purge*****");
HttpResponse response = invalidateUrls(credential, arrayList, "production");
System.out.println(response.getStatusCode());
System.out.println(response.getStatusMessage());
}
public static HttpResponse invalidateUrls(ClientCredential clientCredential, List<String> urls, String network) {
HttpTransport httpTransport = new ApacheHttpTransport();
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
HttpRequest request = null;
try {
// This is fast purge approach
URI uri = new URI(HTTPS, "api.ccu.akamai.com", "/ccu/v3/invalidate/url/" + network, null, null);
String requestBody = getStringRequestBody(urls);
request = requestFactory.buildPostRequest(new GenericUrl(uri), ByteArrayContent.fromString("application/json", requestBody));
GoogleHttpClientEdgeGridRequestSigner requestSigner = new GoogleHttpClientEdgeGridRequestSigner(clientCredential);
requestSigner.sign(request);
return request.execute();
} catch (IOException e) {
// log.error("IOException in Akamai Utility", e);
} catch (RequestSigningException e) {
// log.error("RequestSigningException in Akamai Utility", e);
} catch (URISyntaxException e) {
// log.error("UriSyntaxException in Akamai Utility", e);
}
return null;
}
public static String getStringRequestBody(List<String> urls) {
Map<String, List<String>> akamaiRequestMap = Maps.newHashMap();
akamaiRequestMap.put("objects", urls);
return new Gson().toJson(akamaiRequestMap);
}
}
Зависимости, которые я использовал для этого:
<dependency>
<groupId>com.akamai.edgegrid</groupId>
<artifactId>edgegrid-signer-google-http-client</artifactId>
<version>3.0.1</version>
</dependency>
<dependency>
<groupId>com.google.code.gson</groupId>
<artifactId>gson</artifactId>
<version>2.8.5</version>
</dependency>
</dependencies>