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

标签 java aem akamai

有没有人尝试过将 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/

相关文章:

html - 如何从包含的jsp更改jsp基页中body标签的类

java - JCR SQL2 查询 : binding of ISDESCENDANTNODE param

css - 有没有可以让你动态编译文件的CDN?

html - 错误: The requested URL “[no URL]” ,无效

java - Cassandra Java 请求

Java 打印时区和全文

java - Java 中 equals() 方法的逻辑运算符有更优雅的语法吗?

aem - 多字段组件问题

asp.net - asp :RadioButtonList 'RepeatLayout' being ignored through CDN

java - 如何在Swing中设置tooltip的背景?