内容分发网络CDN

    加速域名管理

    新建加速域名

    如下代码可以新建一个加速域名:

    public void testCreateDomain(CdnClient client) {
        String domainName = “my.test.com”;
        ArrayList<OriginPeer> origin = new ArrayList<OriginPeer>();
        origin.add(new OriginPeer().withPeer("1.2.3.4"));  // 添加源站 1.2.3.4
        origin.add(new OriginPeer().withPeer("2.3.4.5"));  // 添加源站 2.3.4.5
        CreateDomainRequest request = new CreateDomainRequest()
                    .withDomain(domainName)
                    .withOrigin(origin);
        CreateDomainResponse response = client.createDomain(request);
        System.out.println(response.getCname());  // 创建成功,获取对应的CNAME
    }

    注意:由于加速域名在所有区域中是唯一的,所以需要保证domain不与其他所有区域上的加速域名名称相同

    查询用户名下所有域名

     public void listUserDomains() throws Exception {
            ListUserDomainsRequest request=new ListUserDomainsRequest();
            request.setStatus("RUNNING");
            request.setRule("");
            List<Domain> domains = cdnClient.listUserDomains(request).getDomains();
            System.out.println(domains);
        }

    查看加速域名列表

    如下代码可以列出用户所有的域名:

    public void listDomains (CdnClient client) {
        // 获取用户的加速域名列表
        List<Domain> domains = client.listDomains().getDomains();
        // 遍历加速域名
        for (Domain domain : domains) {
            System.out.println(domain.getName());
        }
    } 

    删除加速域名

    如下代码可以删除一个加速域名:

    public void deleteDomain (CdnClient client, String domainName) {
        client.deleteDomain(domainName); 
    }

    查询域名是否可添加

        public void checkDomainValid(){
            String domain="www.baidu.com";
            DomainCanBeAddedResponse response = cdnClient.checkDomainCanBeAdded(domain);
            System.out.println(response);
        }

    创建加速域名接口

    public void testCreateDomain() {
            ArrayList<OriginPeer> origin = new ArrayList<OriginPeer>();
            origin.add(new OriginPeer().withPeer("1.2.3.4"));
            origin.add(new OriginPeer().withPeer("2.3.4.5"));
            
            CreateDomainRequest request = new CreateDomainRequest()
                    .withDomain(DOMAIN)
                    .withOrigin(origin);
            CreateDomainResponse response = cdnClient.createDomain(request);
            System.out.println(response.getCname());
        }

    启用加速域名接口

        public void enableDomain(){
            String domain="vd3.bdstatic.com";
            EnableDomainResponse response = cdnClient.enableDomain(domain);
            System.out.println(response);
        }

    停用加速域名接口

     public void disableDomain(){
            String domain="vd3.bdstatic.com";
            DisableDomainResponse disableDomainResponse = cdnClient.disableDomain(domain);
            System.out.println(disableDomainResponse);
        }

    查询域名是否备案

    public void getIcpStatus() {
            String domain="vd1.bdstatic.com";
            IcpStatusRequest request=new IcpStatusRequest().withDoamin(domain);
            IcpStatusResponse response = cdnClient.getIcpStatus(request);
            System.out.println(response);
        }

    单域名复制接口

     public void copyDomainConfig() throws Exception {
            String domain="vd1.bdstatic.com";
            CopyDomainConfigResponse copyDomainConfigResponse = cdnClient.copyDomainConfig(domain);
            System.out.println(copyDomainConfigResponse);
        }
    上一篇
    CdnClient
    下一篇
    域名配置