Skip to content

Commit 3bc7912

Browse files
author
jordanqin
committed
update qcloud sdk to 5.9.6
1 parent 40c06f7 commit 3bc7912

File tree

18 files changed

+595
-53
lines changed

18 files changed

+595
-53
lines changed

QCloudCosXml/cos-android-base/src/main/java/com/tencent/cos/xml/BeaconService.java

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -481,6 +481,7 @@ private Map<String, String> parsePerfParams(@Nullable HttpTaskMetrics taskMetric
481481
params.put("http_write_body", String.valueOf(taskMetrics.writeRequestBodyTookTime()));
482482
params.put("http_full", String.valueOf(taskMetrics.fullTaskTookTime()));
483483
params.put("size", String.valueOf(taskMetrics.requestBodyByteCount() + taskMetrics.responseBodyByteCount()));
484+
params.put("retry_times", String.valueOf(taskMetrics.getRetryCount()));
484485

485486
return params;
486487
}
@@ -494,6 +495,7 @@ private Map<String, String> parseSimplePerfParams(@Nullable HttpTaskMetrics task
494495

495496
params.put("took_time", String.valueOf(taskMetrics.httpTaskFullTime()));
496497
params.put("size", String.valueOf(taskMetrics.requestBodyByteCount() + taskMetrics.responseBodyByteCount()));
498+
params.put("retry_times", String.valueOf(taskMetrics.getRetryCount()));
497499
return params;
498500
}
499501

QCloudCosXml/cos-android/src/androidTest/java/com/tencent/cos/xml/common/OtherTest.java

Lines changed: 39 additions & 13 deletions
Original file line numberDiff line numberDiff line change
@@ -22,41 +22,34 @@
2222

2323
package com.tencent.cos.xml.common;
2424

25+
import static org.junit.Assert.assertEquals;
26+
2527
import android.os.Environment;
2628

2729
import androidx.test.ext.junit.runners.AndroidJUnit4;
2830

31+
import com.tencent.cos.xml.CosXmlService;
2932
import com.tencent.cos.xml.CosXmlSimpleService;
3033
import com.tencent.cos.xml.core.ServiceFactory;
3134
import com.tencent.cos.xml.core.TestConst;
32-
import com.tencent.cos.xml.core.TestLocker;
3335
import com.tencent.cos.xml.core.TestUtils;
3436
import com.tencent.cos.xml.exception.CosXmlClientException;
3537
import com.tencent.cos.xml.exception.CosXmlServiceException;
3638
import com.tencent.cos.xml.listener.CosXmlProgressListener;
37-
import com.tencent.cos.xml.listener.CosXmlResultListener;
3839
import com.tencent.cos.xml.listener.CosXmlResultSimpleListener;
39-
import com.tencent.cos.xml.model.CosXmlRequest;
40-
import com.tencent.cos.xml.model.CosXmlResult;
4140
import com.tencent.cos.xml.model.PresignedUrlRequest;
4241
import com.tencent.cos.xml.model.object.GetObjectRequest;
43-
import com.tencent.cos.xml.transfer.COSDownloadTask;
44-
import com.tencent.cos.xml.transfer.TransferState;
45-
import com.tencent.cos.xml.transfer.TransferStateListener;
46-
import com.tencent.cos.xml.transfer.TransferTaskMetrics;
42+
import com.tencent.cos.xml.model.object.PutObjectRequest;
4743
import com.tencent.cos.xml.utils.DigestUtils;
48-
import com.tencent.cos.xml.utils.URLEncodeUtils;
4944
import com.tencent.qcloud.core.http.RequestBodySerializer;
5045
import com.tencent.qcloud.core.logger.QCloudLogger;
5146

5247
import org.junit.Assert;
5348
import org.junit.Test;
5449
import org.junit.runner.RunWith;
5550

56-
import java.io.ByteArrayInputStream;
5751
import java.io.File;
5852
import java.io.FileInputStream;
59-
import java.io.FileNotFoundException;
6053
import java.io.IOException;
6154
import java.math.BigInteger;
6255
import java.net.URLEncoder;
@@ -67,8 +60,6 @@
6760
import okhttp3.RequestBody;
6861
import okhttp3.Response;
6962

70-
import static org.junit.Assert.assertEquals;
71-
7263
/**
7364
*
7465
* <p>
@@ -195,4 +186,39 @@ public RequestBodySerializer getRequestBody() throws CosXmlClientException {
195186
}
196187

197188
}
189+
190+
@Test public void testSessionCredentialsExpired() {
191+
CosXmlService service = ServiceFactory.INSTANCE.newDefaultServiceBySessionCredentials();
192+
PutObjectRequest request = new PutObjectRequest(TestConst.PERSIST_BUCKET, TestConst.PERSIST_BUCKET_SMALL_OBJECT_PATH,
193+
TestUtils.smallFilePath());
194+
// GetObjectRequest request = new GetObjectRequest(TestConst.PERSIST_BUCKET, TestConst.PERSIST_BUCKET_BIG_OBJECT_PATH, TestUtils.localParentPath(), "test");
195+
request.addNoSignHeader("Content-Length");
196+
request.addNoSignHeader("User-Agent");
197+
request.addNoSignHeader("Host");
198+
request.addNoSignHeader("Content-MD5");
199+
request.setProgressListener(new CosXmlProgressListener() {
200+
@Override
201+
public void onProgress(long complete, long target) {
202+
TestUtils.print("Progress test" + ": " + complete + "/" + target);
203+
}
204+
});
205+
for (int i=0; i<100;i++){
206+
try {
207+
service.putObject(request);
208+
// service.getObject(request);
209+
} catch (CosXmlClientException e) {
210+
e.printStackTrace();
211+
break;
212+
} catch (CosXmlServiceException e) {
213+
e.printStackTrace();
214+
break;
215+
}
216+
try {
217+
Thread.sleep(3000);
218+
} catch (InterruptedException e) {
219+
e.printStackTrace();
220+
}
221+
}
222+
Assert.assertTrue(true);
223+
}
198224
}
Lines changed: 87 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,87 @@
1+
package com.tencent.cos.xml.core;/*
2+
* Copyright (c) 2010-2020 Tencent Cloud. All rights reserved.
3+
*
4+
* Permission is hereby granted, free of charge, to any person obtaining a copy
5+
* of this software and associated documentation files (the "Software"), to deal
6+
* in the Software without restriction, including without limitation the rights
7+
* to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
8+
* copies of the Software, and to permit persons to whom the Software is
9+
* furnished to do so, subject to the following conditions:
10+
*
11+
* The above copyright notice and this permission notice shall be included in all
12+
* copies or substantial portions of the Software.
13+
*
14+
* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
15+
* IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
16+
* FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
17+
* AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
18+
* LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
19+
* OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE
20+
* SOFTWARE.
21+
*/
22+
23+
import android.util.Log;
24+
25+
import com.tencent.qcloud.core.auth.BasicLifecycleCredentialProvider;
26+
import com.tencent.qcloud.core.auth.QCloudLifecycleCredentials;
27+
import com.tencent.qcloud.core.auth.SessionQCloudCredentials;
28+
import com.tencent.qcloud.core.common.QCloudClientException;
29+
30+
import org.json.JSONException;
31+
import org.json.JSONObject;
32+
import org.json.JSONTokener;
33+
34+
import java.io.IOException;
35+
36+
import okhttp3.Headers;
37+
import okhttp3.OkHttpClient;
38+
import okhttp3.Request;
39+
import okhttp3.Response;
40+
41+
public class MySessionCredentialProvider
42+
extends BasicLifecycleCredentialProvider {
43+
44+
@Override
45+
protected QCloudLifecycleCredentials fetchNewCredentials()
46+
throws QCloudClientException {
47+
48+
// 首先从您的临时密钥服务器获取包含了密钥信息的响应
49+
OkHttpClient client = new OkHttpClient();
50+
Request request = new Request.Builder()
51+
.url("http://9.135.33.98:3000/sts")
52+
.build();
53+
54+
Response response = null;
55+
try {
56+
response = client.newCall(request).execute();
57+
} catch (IOException e) {
58+
e.printStackTrace();
59+
}
60+
if (response == null || !response.isSuccessful())
61+
throw new QCloudClientException(new IOException("Unexpected code " + response));
62+
63+
Headers responseHeaders = response.headers();
64+
for (int i = 0; i < responseHeaders.size(); i++) {
65+
System.out.println(responseHeaders.name(i) + ": " + responseHeaders.value(i));
66+
}
67+
68+
try {
69+
String jsonStr = "";
70+
try {
71+
jsonStr = response.body().string();
72+
} catch (IOException e) {
73+
e.printStackTrace();
74+
}
75+
Log.d("MySessionCredentialProvider", jsonStr);
76+
JSONTokener jsonParser = new JSONTokener(jsonStr);
77+
JSONObject data = (JSONObject) jsonParser.nextValue();
78+
JSONObject credentials = data.getJSONObject("credentials");
79+
// return new SessionQCloudCredentials(credentials.getString("tmpSecretId"), credentials.getString("tmpSecretKey"),
80+
// credentials.getString("sessionToken"), data.getLong("startTime"), data.getLong("expiredTime"));
81+
return new SessionQCloudCredentials(credentials.getString("tmpSecretId"), credentials.getString("tmpSecretKey"),
82+
credentials.getString("sessionToken"), data.getLong("expiredTime"));
83+
} catch (JSONException ex) {
84+
throw new QCloudClientException(ex);
85+
}
86+
}
87+
}

QCloudCosXml/cos-android/src/androidTest/java/com/tencent/cos/xml/core/ServiceFactory.java

Lines changed: 25 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,8 +1,9 @@
11
package com.tencent.cos.xml.core;
22

3+
import static com.tencent.cos.xml.core.TestUtils.getContext;
4+
35
import com.tencent.cos.xml.CosXmlService;
46
import com.tencent.cos.xml.CosXmlServiceConfig;
5-
import com.tencent.cos.xml.CosXmlService;
67
import com.tencent.cos.xml.crypto.KMSEncryptionMaterialsProvider;
78
import com.tencent.cos.xml.exception.CosXmlClientException;
89
import com.tencent.cos.xml.transfer.TransferConfig;
@@ -15,8 +16,6 @@
1516
import com.tencent.qcloud.core.http.HttpConstants;
1617
import com.tencent.qcloud.core.http.QCloudHttpRequest;
1718

18-
import static com.tencent.cos.xml.core.TestUtils.getContext;
19-
2019
/**
2120
* <p>
2221
* Created by rickenwang on 2020/10/16.
@@ -40,6 +39,16 @@ public CosXmlService newDefaultService() {
4039
return newService(cosXmlServiceConfig);
4140
}
4241

42+
public CosXmlService newDefaultServiceBySessionCredentials() {
43+
CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder()
44+
.isHttps(true)
45+
.setDebuggable(true)
46+
.setRegion(TestConst.PERSIST_BUCKET_REGION)
47+
.builder();
48+
49+
return newServiceBySessionCredentials(cosXmlServiceConfig);
50+
}
51+
4352
public CosXmlService newQuicService() {
4453

4554
CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder()
@@ -140,6 +149,14 @@ public TransferManager newDefaultTransferManager() {
140149
return new TransferManager(newDefaultService(), transferConfig);
141150
}
142151

152+
public TransferManager newDefaultTransferManagerBySessionCredentials() {
153+
TransferConfig transferConfig = new TransferConfig.Builder()
154+
.setDivisionForUpload(2 * 1024 * 1024)
155+
.setSliceSizeForUpload(1024 * 1024)
156+
.build();
157+
return new TransferManager(newDefaultServiceBySessionCredentials(), transferConfig);
158+
}
159+
143160
public TransferService newDefaultTransferService() {
144161

145162
TransferConfig transferConfig = new TransferConfig.Builder()
@@ -214,6 +231,11 @@ public TransferManager newCdnTransferManager() {
214231
return new TransferManager(newCDNService(), new TransferConfig.Builder().build());
215232
}
216233

234+
private CosXmlService newServiceBySessionCredentials(CosXmlServiceConfig cosXmlServiceConfig) {
235+
return new CosXmlService(getContext(), cosXmlServiceConfig,
236+
new MySessionCredentialProvider());
237+
}
238+
217239
private CosXmlService newService(CosXmlServiceConfig cosXmlServiceConfig) {
218240
return new CosXmlService(getContext(), cosXmlServiceConfig,
219241
new ShortTimeCredentialProvider(TestConst.SECRET_ID, TestConst.SECRET_KEY,600) );

QCloudCosXml/cos-android/src/androidTest/java/com/tencent/cos/xml/core/TestConst.java

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -55,6 +55,17 @@ public class TestConst {
5555
public static final String ASR_OBJECT_OUTPUT = "asr/output.txt";
5656
public static final String ASR_QUEUE_ID = "p74b5265ab1df455782b7b355007d0dfc";
5757

58+
//声音识别(极速识别)
59+
public static final String ASR_FLASH_BUCKET_REGION = "ap-chongqing";
60+
public static final String ASR_FLASH_BUCKET = "tinna-media-1253960454";
61+
public static final String ASR_FLASH_OBJECT_FF_1C = "asr/ff-16b-1c-44100hz.aac";
62+
public static final String ASR_FLASH_OBJECT_FF_2C = "asr/ff-16b-2c-44100hz.aac";
63+
public static final String ASR_FLASH_OBJECT_GS_1C = "asr/gs-16b-1c-8000hz.amr";
64+
public static final String ASR_FLASH_OBJECT_GS_2C = "asr/gs-16b-2c-44100hz.aac";
65+
public static final String ASR_FLASH_OBJECT_LONG = "asr/aaa.m4a";
66+
public static final String ASR_FLASH_OBJECT_OUTPUT = "asr/output.txt";
67+
public static final String ASR_FLASH_QUEUE_ID = "pf4bb837618c84b5b905a1df5c8a56d20";
68+
5869
//分词
5970
public static final String WORDS_GENERALIZE_BUCKET_REGION = "ap-chongqing";
6071
public static final String WORDS_GENERALIZE_BUCKET = "tinna-media-1253960454";

QCloudCosXml/cos-android/src/androidTest/java/com/tencent/cos/xml/transfer/UploadTest.java

Lines changed: 2 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -23,7 +23,6 @@
2323
package com.tencent.cos.xml.transfer;
2424

2525
import android.net.Uri;
26-
import android.os.Environment;
2726
import android.util.Log;
2827

2928
import androidx.test.ext.junit.runners.AndroidJUnit4;
@@ -41,20 +40,16 @@
4140
import com.tencent.cos.xml.model.CosXmlRequest;
4241
import com.tencent.cos.xml.model.CosXmlResult;
4342
import com.tencent.cos.xml.model.object.PutObjectRequest;
44-
import com.tencent.cos.xml.model.tag.pic.PicOperationRule;
45-
import com.tencent.cos.xml.model.tag.pic.PicOperations;
4643
import com.tencent.qcloud.core.http.HttpTaskMetrics;
4744
import com.tencent.qcloud.core.logger.QCloudLogger;
4845
import com.tencent.qcloud.core.util.QCloudStringUtils;
4946

5047
import org.junit.Assert;
5148
import org.junit.Test;
52-
import org.junit.experimental.theories.suppliers.TestedOn;
5349
import org.junit.runner.RunWith;
5450

5551
import java.io.File;
5652
import java.io.IOException;
57-
import java.util.LinkedList;
5853
import java.util.Timer;
5954
import java.util.TimerTask;
6055
import java.util.concurrent.atomic.AtomicBoolean;
@@ -440,7 +435,8 @@ public void onStateChanged(TransferState state) {
440435

441436
@Test public void testUploadBigFileByUri() {
442437

443-
TransferManager transferManager = ServiceFactory.INSTANCE.newDefaultTransferManager();
438+
// TransferManager transferManager = ServiceFactory.INSTANCE.newDefaultTransferManager();
439+
TransferManager transferManager = ServiceFactory.INSTANCE.newDefaultTransferManagerBySessionCredentials();
444440
final COSXMLUploadTask uploadTask = transferManager.upload(TestConst.PERSIST_BUCKET, TestConst.PERSIST_BUCKET_BIG_OBJECT_PATH + 12,
445441
Uri.fromFile(new File(TestUtils.bigFilePath())), null);
446442

QCloudCosXml/cos-android/src/androidTest/res/xml/network_security_config.xml

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
<?xml version="1.0" encoding="utf-8"?>
22
<network-security-config>
3+
<base-config cleartextTrafficPermitted="true" />
34
<!--debug模式才信任user证书-->
45
<debug-overrides>
56
<trust-anchors>

0 commit comments

Comments
 (0)