Skip to content

Commit 4ddebd5

Browse files
author
jordanqin
committed
update qcloud sdk to 5.9.30
1 parent 6abfa04 commit 4ddebd5

File tree

74 files changed

+5546
-14
lines changed

Some content is hidden

Large Commits have some content hidden by default. Use the searchbox below for content that may be hidden.

74 files changed

+5546
-14
lines changed

QCloudCosXml/cos-android-base/build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,8 @@ android {
66
minSdkVersion 15
77
targetSdkVersion 28
88

9-
versionCode 50927
10-
versionName '5.9.27'
9+
versionCode 50928
10+
versionName '5.9.28'
1111

1212
testInstrumentationRunner 'androidx.test.runner.AndroidJUnitRunner'
1313

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

Lines changed: 28 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -60,6 +60,7 @@ public class CosXmlServiceConfig implements Parcelable {
6060
public static final String PATH_STYLE_HOST_FORMAT = "cos.${region}.myqcloud.com";
6161

6262
public static final String CI_HOST_FORMAT = "${bucket}.ci.${region}.myqcloud.com";
63+
public static final String CI_APPID_HOST_FORMAT = "${appid}.ci.${region}.myqcloud.com";
6364
public static final String CI_REGION_HOST_FORMAT = "ci.${region}.myqcloud.com";
6465
public static final String PIC_HOST_FORMAT = "${bucket}.pic.${region}.myqcloud.com";
6566

@@ -248,6 +249,22 @@ public String getRequestHost(String region, String bucket, String hostFormat) {
248249
return getFormatHost(hostFormat, region, bucket);
249250
}
250251

252+
/**
253+
* 获取请求host
254+
* @param region 区域
255+
* @param appid appid
256+
* @param hostFormat HOST 格式,支持通配符
257+
* @return 请求host
258+
*/
259+
public String getRequestHostByAppId(String region, String appid, String hostFormat) {
260+
if (!TextUtils.isEmpty(host)) {
261+
return host;
262+
}
263+
region = TextUtils.isEmpty(region) ? this.region : region; // 优先 request 中的 region
264+
265+
return getFormatHostByAppId(hostFormat, region, appid);
266+
}
267+
251268
/**
252269
* 获取请求host
253270
* @param region 区域
@@ -309,6 +326,17 @@ private String getFormatHost(String hostFormat, String region) {
309326
return hostFormat.replace("${region}", region);
310327
}
311328

329+
private String getFormatHostByAppId(String hostFormat, String region, String appid) {
330+
if(region == null){
331+
throw new IllegalArgumentException("please set request or config region !");
332+
}
333+
if(appid == null){
334+
throw new IllegalArgumentException("please set request appid !");
335+
}
336+
337+
return hostFormat.replace("${appid}", appid).replace("${region}", region);
338+
}
339+
312340
private String getHostFormat(boolean accelerate, boolean pathStyle) {
313341

314342
if (!TextUtils.isEmpty(hostFormat)) {

QCloudCosXml/cos-android-base/src/main/java/com/tencent/cos/xml/model/tag/CosError.java

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -22,6 +22,9 @@
2222

2323
package com.tencent.cos.xml.model.tag;
2424

25+
import org.json.JSONException;
26+
import org.json.JSONObject;
27+
2528
/**
2629
* COS错误信息
2730
* 请参考:<a href="https://cloud.tencent.com/document/product/436/7730">COS错误信息</a>
@@ -47,4 +50,14 @@ public class CosError {
4750
* 每次请求出错时,服务端将会自动为这个错误生成一个ID,遇到问题时,该 ID 能更快地协助 COS 定位问题
4851
*/
4952
public String traceId;
53+
54+
public static CosError fromJson(String json) throws JSONException {
55+
JSONObject jsonObject = new JSONObject(json);
56+
CosError cosError = new CosError();
57+
cosError.code = jsonObject.optString("Code");
58+
cosError.message = jsonObject.optString("Message");
59+
cosError.requestId = jsonObject.optString("RequestId");
60+
cosError.traceId = jsonObject.optString("TraceId");
61+
return cosError;
62+
}
5063
}

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

Lines changed: 22 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -30,9 +30,11 @@
3030
import com.tencent.cos.xml.utils.BaseXmlSlimParser;
3131
import com.tencent.qcloud.core.common.QCloudClientException;
3232
import com.tencent.qcloud.core.common.QCloudServiceException;
33+
import com.tencent.qcloud.core.http.HttpConstants;
3334
import com.tencent.qcloud.core.http.HttpResponse;
3435
import com.tencent.qcloud.core.http.ResponseBodyConverter;
3536

37+
import org.json.JSONException;
3638
import org.xmlpull.v1.XmlPullParserException;
3739

3840
import java.io.IOException;
@@ -64,21 +66,32 @@ private void parseCOSXMLError(HttpResponse response) throws CosXmlServiceExcepti
6466
CosXmlServiceException cosXmlServiceException = new CosXmlServiceException(message);
6567
cosXmlServiceException.setStatusCode(httpCode);
6668
cosXmlServiceException.setRequestId(response.header("x-cos-request-id"));
67-
InputStream inputStream = response.byteStream();
68-
if(inputStream != null){
69-
CosError cosError = new CosError();
69+
String contentType = response.header(HttpConstants.Header.CONTENT_TYPE);
70+
CosError cosError = new CosError();
71+
if(HttpConstants.ContentType.JSON.equalsIgnoreCase(contentType)){
7072
try {
71-
BaseXmlSlimParser.parseError(inputStream, cosError);
72-
if(cosError.code != null) cosXmlServiceException.setErrorCode(cosError.code);
73-
if(cosError.message != null) cosXmlServiceException.setErrorMessage(cosError.message);
74-
if(cosError.requestId != null) cosXmlServiceException.setRequestId(cosError.requestId);
75-
if(cosError.resource != null) cosXmlServiceException.setServiceName(cosError.resource);
76-
} catch (XmlPullParserException e) {
73+
cosError = CosError.fromJson(response.string());
74+
} catch (JSONException e) {
7775
throw new CosXmlClientException(ClientErrorCode.SERVERERROR.getCode(), e);
7876
} catch (IOException e) {
7977
throw new CosXmlClientException(ClientErrorCode.POOR_NETWORK.getCode(), e);
8078
}
79+
} else {
80+
InputStream inputStream = response.byteStream();
81+
if(inputStream != null){
82+
try {
83+
BaseXmlSlimParser.parseError(inputStream, cosError);
84+
} catch (XmlPullParserException e) {
85+
throw new CosXmlClientException(ClientErrorCode.SERVERERROR.getCode(), e);
86+
} catch (IOException e) {
87+
throw new CosXmlClientException(ClientErrorCode.POOR_NETWORK.getCode(), e);
88+
}
89+
}
8190
}
91+
if(cosError.code != null) cosXmlServiceException.setErrorCode(cosError.code);
92+
if(cosError.message != null) cosXmlServiceException.setErrorMessage(cosError.message);
93+
if(cosError.requestId != null) cosXmlServiceException.setRequestId(cosError.requestId);
94+
if(cosError.resource != null) cosXmlServiceException.setServiceName(cosError.resource);
8295
throw cosXmlServiceException;
8396
}
8497

QCloudCosXml/cos-android/build.gradle

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -172,6 +172,11 @@ dependencies {
172172
embed(name: 'qmsp-oaid2-1.0.4', ext: 'aar')
173173
}
174174

175+
// 非lite版本引入gson库,万象部分功能需要
176+
if (!android.defaultPublishConfig.contains("slim")) {
177+
implementation 'com.google.code.gson:gson:2.11.0'
178+
}
179+
175180
// kms 加密
176181
compileOnly 'com.tencentcloudapi:tencentcloud-sdk-java-kms:3.1.213'
177182
compileOnly 'xerces:xercesImpl:2.12.0'

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

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -37,6 +37,7 @@ public class TestConst {
3737
public static final String PERSIST_BUCKET_REPLICATION_REGION = BuildConfig.PERSIST_BUCKET_REPLICATION_REGION;
3838

3939
public static final String CI_BUCKET_REGION = "ap-beijing";
40+
public static final String CI_BUCKET_APPID = "1253960454";
4041
public static final String CI_BUCKET = "cos-sdk-citest-1253960454";
4142

4243
//审核

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import com.tencent.cos.xml.transfer.COSTransferTask;
1515
import com.tencent.cos.xml.transfer.COSXMLTask;
1616
import com.tencent.cos.xml.transfer.TransferState;
17+
import com.tencent.cos.xml.utils.QCloudJsonUtils;
1718
import com.tencent.cos.xml.utils.QCloudXmlUtils;
1819
import com.tencent.qcloud.core.common.QCloudClientException;
1920
import com.tencent.qcloud.core.common.QCloudServiceException;
@@ -83,6 +84,10 @@ private static boolean isXmlBean(Object object){
8384
}
8485
}
8586

87+
public static void printJson(Object object) {
88+
TestUtils.print(QCloudJsonUtils.toJson(object));
89+
}
90+
8691
public static <T> void printXML(T object) {
8792
if(isXmlBean(object)) {
8893
try {

0 commit comments

Comments
 (0)