gpt4 book ai didi

java - 使用 JAVA 项目或 AEM 实现 Akamai CCU V3 快速清除

转载 作者:行者123 更新时间:2023-12-02 11:35:19 26 4
gpt4 key购买 nike

有没有人尝试过将 Java 代码从 CCU V2 集成到 CCU V3 并进行快速清除。我阅读了文档,但无法理解基于 java 的项目需要做什么。在 Akamai 控制台中配置客户端后,我们如何编写代码来访问和清除。非常感谢任何帮助。

谢谢,图沙尔

最佳答案

一般方法是编写一些代码,向快速清除端点发出 HTTP 请求。

这是一个例子:

import com.akamai.edgegrid.auth.*;
//other imports

public void callAkamaiFastPurgeForUrls(Set<String> urlsToPurge) throws URISyntaxException, IOException, RequestSigningException {
if(!urlsToPurge.isEmpty()) {
int status;
String json = getPurgeJson(urlsToPurge);
HttpRequest signedRequest = getHttpRequest(json, compProperty);
HttpResponse response = signedRequest.execute();

status = response.getStatusCode();

if (status == 201) {
//handle success responses as you see fit
} else {
//handle non-success responses as you see fit
}
}
}

private static String getPurgeJson(Set<String> pathsToPurge) {
//your code to turn the list of urls into JSON in this format:
//{"objects":["https://www.yourdomain.com/page1.html","https://www.yourdomain.com/page2.html"]}

return //JSON string such as the example above
}


private HttpRequest getHttpRequest(String json, Dictionary<String, Object> dispatcherAndAkamaiServletProperties) throws URISyntaxException, IOException, RequestSigningException {
String hostName = yourCodeToFetchConfigValues("hostname");
String accessToken = yourCodeToFetchConfigValues("accesstoken");
String clientToken = yourCodeToFetchConfigValues("clienttoken");
String clientSecret = yourCodeToFetchConfigValues("clientsecret");
String apiUrl = yourCodeToFetchConfigValues("apiurl");
String proxyServer = yourCodeToFetchConfigValues("proxyhostakamai");
int proxyPort = yourCodeToFetchConfigValues("proxyport");

HttpTransport httpTransport = new NetHttpTransport.Builder()
.setProxy(new Proxy(Proxy.Type.HTTP, new InetSocketAddress(proxyServer, proxyPort))).build();

HttpRequestFactory requestFactory = httpTransport.createRequestFactory();

URI uri = new URI(HTTPS, hostName, apiUrl, null, null);
HttpContent body = new ByteArrayContent("application/json", json.getBytes());
HttpRequest request = requestFactory.buildPostRequest(new GenericUrl(uri), body);
HttpHeaders headers = request.getHeaders();
headers.set("Host", hostName);
ClientCredential credential = new DefaultCredential(clientToken, accessToken, clientSecret);
RequestSigner signer = new EdgeGridV1Signer(Collections.emptyList(), 1024 * 2);

return signer.sign(request, credential);
}

此外,您可能需要更新您的信任库以包含您正在调用的 Akamai 端点的证书,以便可以进行 SSL 通信。

关于java - 使用 JAVA 项目或 AEM 实现 Akamai CCU V3 快速清除,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/48982246/

26 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com