|
|
@@ -33,19 +33,22 @@ public class AliyunCdn {
|
|
|
this.aliyunAccountRepository = aliyunAccountRepository;
|
|
|
}
|
|
|
|
|
|
- @PostConstruct
|
|
|
- public void initClient() throws Exception {
|
|
|
- AliyunAccount aliyunAccount = aliyunAccountRepository.findByType("cdn");
|
|
|
- String endpoint = aliyunAccount.getEndpoint();
|
|
|
- String accessKeyId = aliyunAccount.getAccessKeyId();
|
|
|
- String accessKeySecret = aliyunAccount.getAccessKeySecret();
|
|
|
- Config config = new Config()
|
|
|
- // 必填,您的 AccessKey ID
|
|
|
- .setAccessKeyId(accessKeyId)
|
|
|
- // 必填,您的 AccessKey Secret
|
|
|
- .setAccessKeySecret(accessKeySecret)
|
|
|
- .setEndpoint(endpoint);
|
|
|
- this.client = new Client(config);
|
|
|
+ public Client getClient() throws Exception {
|
|
|
+ if (client == null) {
|
|
|
+ AliyunAccount aliyunAccount = aliyunAccountRepository.findByType("cdn");
|
|
|
+ String endpoint = aliyunAccount.getEndpoint();
|
|
|
+ String accessKeyId = aliyunAccount.getAccessKeyId();
|
|
|
+ String accessKeySecret = aliyunAccount.getAccessKeySecret();
|
|
|
+ Config config = new Config()
|
|
|
+ // 必填,您的 AccessKey ID
|
|
|
+ .setAccessKeyId(accessKeyId)
|
|
|
+ // 必填,您的 AccessKey Secret
|
|
|
+ .setAccessKeySecret(accessKeySecret)
|
|
|
+ .setEndpoint(endpoint);
|
|
|
+ client = new Client(config);
|
|
|
+ }
|
|
|
+
|
|
|
+ return client;
|
|
|
}
|
|
|
|
|
|
public String refreshCdn(String domain) {
|
|
|
@@ -68,7 +71,7 @@ public class AliyunCdn {
|
|
|
// 加速的文件位置,wdtest.licai.cn为配置的域名,后加加速的文件名
|
|
|
req.objectPath = objectPath;
|
|
|
try {
|
|
|
- RefreshObjectCachesResponse resp = client.refreshObjectCaches(req);
|
|
|
+ RefreshObjectCachesResponse resp = getClient().refreshObjectCaches(req);
|
|
|
Map<String, Object> map = TeaModel.buildMap(resp);
|
|
|
Map<String, Object> map1 = (Map<String, Object>)map.get("body");
|
|
|
String taskId = (String) map1.get("RefreshTaskId");
|
|
|
@@ -96,7 +99,7 @@ public class AliyunCdn {
|
|
|
DescribeRefreshTasksRequest request = new DescribeRefreshTasksRequest();
|
|
|
request.taskId = taskId;
|
|
|
try {
|
|
|
- DescribeRefreshTasksResponse resp = client.describeRefreshTasks(request);
|
|
|
+ DescribeRefreshTasksResponse resp = getClient().describeRefreshTasks(request);
|
|
|
Map<String, Object> map = TeaModel.buildMap(resp);
|
|
|
Map<String, Object> bodyMap = (Map)map.get("body");
|
|
|
List list = (List) ((Map) bodyMap.get("Tasks")).get("CDNTask");
|