zoukankan      html  css  js  c++  java
  • 记一次调用RefreshObjectCaches刷新节点上的文件内容

    1、pom文件里引入阿里云cdn依赖,很重要!!!  官方文档阿里云RefreshObjectCaches

    <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>aliyun-java-sdk-cdn</artifactId>
        <version>3.0.10</version>
    </dependency>
    <dependency>
        <groupId>com.aliyun</groupId>
        <artifactId>aliyun-java-sdk-core</artifactId>
        <version>4.1.0</version>
    </dependency>

    2、看一下需要的参数

    3、上代码

    public static Result updateCdn(@NotNull List<String> path, String type) {
        //初始化
    //CommonConstant.SMS_REGION 地区"cn-hangzhou"
    //CommonConstant.SMS_ACCESS_KEY_ID阿里管理员给的accessKeyId
    //CommonConstant.SMS_ACCESS_KEYSECRET阿里管理员给的accessSecret
    IClientProfile profile = DefaultProfile.getProfile(CommonConstant.SMS_REGION,
    CommonConstant.SMS_ACCESS_KEY_ID, CommonConstant.SMS_ACCESS_KEYSECRET);
    IAcsClient client = new DefaultAcsClient(profile);
    RefreshObjectCachesRequest request = new RefreshObjectCachesRequest();
    StringBuffer sb = new StringBuffer();
    
    //循环list里面url做处理,多个URL之间需要用换行符(
    )或(
    )分隔。
    for ( int i = 0; i < path.size(); i++ ) {
    String n = i == (path.size() - 1) ? "" : "
    ";
    sb.append(path.get(i) + n);
    }
    request.setRegionId(CommonConstant.SMS_REGION);
    // 此参数为刷新的类型, 其值可以为File或Directory。默认值:File。
    request.setObjectType(CommonConstant.OBJECT_TYPE_FILE);
    
    // 要刷新域名加文件拼接,多个路径用
    分割(域名和资源不分开)
    request.setObjectPath(sb.toString());
    request.setAcceptFormat(FormatType.JSON);
    try {
    RefreshObjectCachesResponse response = client.getAcsResponse(request);
            //处理自己的逻辑
    HttpResponse httpResponse = client.doAction(request);
    //整个完整连接httpResponse.getUrl
    System.out.println(httpResponse.getUrl());
            //打印出来的返回数据{"RefreshTaskId":"6616645908","RequestId":"9D464237-5833-4222-B30F-299860A89785"}
    System.out.println(new String(httpResponse.getHttpContent()));
    //状态码
    System.out.println(httpResponse.getStatus());
    } catch (ServerException e) {
    e.printStackTrace();
    } catch (ClientException e) {
        //域名必须是https://www.baidu.com/格式
    System.out.println("请检查输入的OBJECT_PATH输入是否正确");
    
    }
    return Result.ok();
    }

    4.测试

    public static void main(String[] args) {
        List<String> list = new ArrayList<>();
        list.add("http://appdev.malls.com/");
        Result file = updateCdn(list, "File");
    }
    
    //结果
    {"RefreshTaskId":"6616645908","RequestId":"9D464237-5833-4222-B30F-299860A89785"}
    200
  • 相关阅读:
    错误libvirtError: invalid argument: could not find capabilities for domaintype=kvm
    容器部署ES 和 ES head插件
    squid配置yum源代理服务器
    coredns 1.2.2 反复重启问题
    ansible debugger 模块
    入门篇-contrail-command(对接openstack)All-In-One
    目标文件是什么鬼?
    汇编指令集
    切换GCC编译器版本
    kubernetes-dashboard登录出现forbidden 403
  • 原文地址:https://www.cnblogs.com/Iron-1995/p/14371020.html
Copyright © 2011-2022 走看看