Skip to content

Instantly share code, notes, and snippets.

@AstinCHOI
Last active September 13, 2022 19:09
Show Gist options
  • Star 2 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save AstinCHOI/417b520ed7bf8bc7f5b5eb61fdc8eb42 to your computer and use it in GitHub Desktop.
Save AstinCHOI/417b520ed7bf8bc7f5b5eb61fdc8eb42 to your computer and use it in GitHub Desktop.
/* using gradle */
// dependencies {
// compile 'com.akamai.edgegrid:edgegrid-signer-google-http-client:2.1.1'
// compile 'com.akamai.edgegrid:edgegrid-signer-core:2.1.1'
// compile 'com.akamai.edgegrid:edgegrid-signer-rest-assured:2.1.1'
// }
package akamai.purge;
import com.akamai.edgegrid.signer.ClientCredential;
import com.akamai.edgegrid.signer.googlehttpclient.GoogleHttpClientEdgeGridRequestSigner;
import com.google.api.client.http.*;
import com.google.api.client.http.apache.ApacheHttpTransport;
import java.net.URI;
import java.nio.charset.StandardCharsets;
import java.util.Scanner;
public class AkamaiPurgeExample {
public static void main(String args[]) throws Exception {
ClientCredential credential = ClientCredential.builder()
.accessToken("")
.clientToken("")
.clientSecret("")
.host("")
.build();
HttpTransport httpTransport = new ApacheHttpTransport();
HttpRequestFactory requestFactory = httpTransport.createRequestFactory();
URI uri = URI.create("https://YOUR_HOST/ccu/v3/invalidate/cpcode/production");
String requestBody = "{\"objects\": [YOUR_CPCODE]}";
HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(uri), ByteArrayContent.fromString("application/json", requestBody));
GoogleHttpClientEdgeGridRequestSigner requestSigner = new GoogleHttpClientEdgeGridRequestSigner(credential);
requestSigner.sign(request);
HttpResponse response = request.execute();
System.out.println(response.getStatusCode()); // response status code
String text = null;
try (Scanner scanner = new Scanner(response.getContent(), StandardCharsets.UTF_8.name())) {
text = scanner.useDelimiter("\\A").next();
}
System.out.println(text); // response body
}
}
@shahid15p
Copy link

Can you share "akamai purge example" using http client if you have any

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment