Last active
September 13, 2022 19:09
-
-
Save AstinCHOI/417b520ed7bf8bc7f5b5eb61fdc8eb42 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
/* 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 | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Can you share "akamai purge example" using http client if you have any