Skip to content

Commit 71b08b6

Browse files
author
jordanqin
committed
update qcloud sdk to 5.9.43
1 parent e18c27f commit 71b08b6

31 files changed

+1069
-43
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 50942
10-
versionName '5.9.40'
9+
versionCode 50943
10+
versionName '5.9.41'
1111

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

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

Lines changed: 11 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -26,6 +26,7 @@
2626
import com.tencent.cos.xml.exception.CosXmlServiceException;
2727
import com.tencent.cos.xml.listener.CosXmlResultListener;
2828
import com.tencent.cos.xml.model.CosXmlRequest;
29+
import com.tencent.cos.xml.model.CosXmlResult;
2930
import com.tencent.cos.xml.model.object.BasePutObjectRequest;
3031
import com.tencent.cos.xml.model.object.BasePutObjectResult;
3132
import com.tencent.cos.xml.model.object.GetObjectBytesRequest;
@@ -57,6 +58,16 @@
5758
*/
5859

5960
public interface BaseCosXml {
61+
/**
62+
* 通用接口同步方法
63+
*/
64+
<T1 extends CosXmlRequest, T2 extends CosXmlResult> T2 commonInterface(T1 request, Class<T2> resultClass) throws CosXmlClientException, CosXmlServiceException;
65+
66+
/**
67+
* 通用接口异步方法
68+
*/
69+
<T1 extends CosXmlRequest, T2 extends CosXmlResult> void commonInterfaceAsync(T1 request, Class<T2> resultClass, final CosXmlResultListener cosXmlResultListener);
70+
6071
/**
6172
* <p>
6273
* 下载 COS 对象的同步方法.&nbsp;

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

Lines changed: 47 additions & 8 deletions
Original file line numberDiff line numberDiff line change
@@ -49,7 +49,6 @@
4949
import com.tencent.cos.xml.transfer.ResponseFileBodySerializer;
5050
import com.tencent.cos.xml.transfer.ResponseXmlS3BodySerializer;
5151
import com.tencent.cos.xml.utils.StringUtils;
52-
import com.tencent.cos.xml.utils.URLEncodeUtils;
5352
import com.tencent.qcloud.core.auth.QCloudCredentialProvider;
5453
import com.tencent.qcloud.core.auth.QCloudCredentials;
5554
import com.tencent.qcloud.core.auth.QCloudSelfSigner;
@@ -88,6 +87,8 @@
8887
import java.util.UUID;
8988
import java.util.concurrent.Executor;
9089

90+
import okhttp3.HttpUrl;
91+
9192

9293
/**
9394
* 提供用于访问Tencent Cloud COS服务的基础服务类。
@@ -656,6 +657,8 @@ public String getAccessUrl(CosXmlRequest cosXmlRequest) {
656657
int index = requestURL.indexOf("?");
657658
return index > 0 ? requestURL.substring(0, index) : requestURL;
658659
}
660+
HttpUrl.Builder httpUrlBuilder = new HttpUrl.Builder();
661+
httpUrlBuilder.scheme(config.getProtocol());
659662
String host = null;
660663
try {
661664
// host = cosXmlRequest.getHost(config, false);
@@ -664,14 +667,16 @@ public String getAccessUrl(CosXmlRequest cosXmlRequest) {
664667
CosTrackService.getInstance().reportError(TAG, e);
665668
e.printStackTrace();
666669
}
667-
String path = "/";
668-
try {
669-
path = URLEncodeUtils.cosPathEncode(cosXmlRequest.getPath(config));
670-
} catch (CosXmlClientException e) {
671-
CosTrackService.getInstance().reportError(TAG, e);
672-
e.printStackTrace();
670+
httpUrlBuilder.host(host);
671+
672+
String path = cosXmlRequest.getPath(config);
673+
if (path.startsWith("/")) {
674+
path = path.substring(1);
673675
}
674-
return config.getProtocol() + "://" + host + path;
676+
if (path.length() > 0) {
677+
httpUrlBuilder.addPathSegments(path);
678+
}
679+
return httpUrlBuilder.build().toString();
675680
}
676681

677682
/**
@@ -825,6 +830,40 @@ public String getObjectUrl(String bucket, String region, String key) {
825830
return getAccessUrl(putObjectRequest);
826831
}
827832

833+
/**
834+
* 通用接口同步方法
835+
*/
836+
@Override
837+
public <T1 extends CosXmlRequest, T2 extends CosXmlResult> T2 commonInterface(T1 request, Class<T2> resultClass) throws CosXmlClientException, CosXmlServiceException {
838+
try {
839+
return execute(request, resultClass.newInstance());
840+
} catch (IllegalAccessException e) {
841+
throw new CosXmlClientException(ClientErrorCode.INVALID_ARGUMENT.getCode(),
842+
"Failed to create result instance", e);
843+
} catch (InstantiationException e) {
844+
throw new CosXmlClientException(ClientErrorCode.INVALID_ARGUMENT.getCode(),
845+
"Failed to create result instance", e);
846+
}
847+
}
848+
849+
/**
850+
* 通用接口异步方法
851+
*/
852+
@Override
853+
public <T1 extends CosXmlRequest, T2 extends CosXmlResult> void commonInterfaceAsync(T1 request, Class<T2> resultClass, CosXmlResultListener cosXmlResultListener) {
854+
try {
855+
schedule(request, resultClass.newInstance(), cosXmlResultListener);
856+
} catch (IllegalAccessException e) {
857+
cosXmlResultListener.onFail(request,
858+
new CosXmlClientException(ClientErrorCode.INVALID_ARGUMENT.getCode(),
859+
"Failed to create result instance", e), null);
860+
} catch (InstantiationException e) {
861+
cosXmlResultListener.onFail(request,
862+
new CosXmlClientException(ClientErrorCode.INVALID_ARGUMENT.getCode(),
863+
"Failed to create result instance", e), null);
864+
}
865+
}
866+
828867
/**
829868
* 取消请求任务.&nbsp;
830869
* 详细介绍,请查看:{@link BaseCosXml#cancel(CosXmlRequest)}

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

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -35,10 +35,12 @@ public class CosXmlServiceException extends QCloudServiceException {
3535
private static final long serialVersionUID = 1L;
3636

3737
private String httpMsg;
38+
private String host;
3839

39-
public CosXmlServiceException(String httpMsg) {
40+
public CosXmlServiceException(String httpMsg, String host) {
4041
super(null);
4142
this.httpMsg = httpMsg;
43+
this.host = host;
4244
}
4345

4446
public CosXmlServiceException(String errorMessage, Exception cause) {
@@ -49,6 +51,10 @@ public String getHttpMessage(){
4951
return httpMsg;
5052
}
5153

54+
public String getHost(){
55+
return host;
56+
}
57+
5258
public CosXmlServiceException(QCloudServiceException qcloudServiceException){
5359
super(null);
5460
this.setErrorCode(qcloudServiceException.getErrorCode());

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -439,6 +439,18 @@ public void setSign(String sign){
439439
addHeader(HttpConstants.Header.AUTHORIZATION, sign);
440440
}
441441

442+
/**
443+
* 设置签名Authorization和token
444+
* @param sign Authorization
445+
* @param token token
446+
*/
447+
public void setSign(String sign, String token){
448+
addHeader(HttpConstants.Header.AUTHORIZATION, sign);
449+
if(TextUtils.isEmpty(token)){
450+
addHeader("x-cos-security-token", token);
451+
}
452+
}
453+
442454
/**
443455
* 获取签名原料提供器
444456
* @return 签名原料提供器

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

Lines changed: 5 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -43,6 +43,10 @@
4343
*/
4444

4545
public abstract class CosXmlResult {
46+
/**
47+
* 最终响应结果的host
48+
*/
49+
public String host;
4650
/**
4751
* http状态码
4852
*/
@@ -70,6 +74,7 @@ public void parseResponseBody(HttpResponse response) throws CosXmlClientExceptio
7074
httpCode = response.code();
7175
httpMessage = response.message();
7276
headers = response.headers();
77+
host = response.host();
7378

7479
try {
7580
xmlParser(response);

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -61,7 +61,7 @@ private void parseCOSXMLError(HttpResponse response) throws CosXmlServiceExcepti
6161
int httpCode = response.code();
6262
if(httpCode >= 200 && httpCode < 300)return;
6363
String message = response.message();
64-
CosXmlServiceException cosXmlServiceException = new CosXmlServiceException(message);
64+
CosXmlServiceException cosXmlServiceException = new CosXmlServiceException(message, response.host());
6565
cosXmlServiceException.setStatusCode(httpCode);
6666
cosXmlServiceException.setRequestId(response.header("x-cos-request-id"));
6767
InputStream inputStream = response.byteStream();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -71,7 +71,7 @@ private void parseCOSXMLError(HttpResponse response) throws CosXmlServiceExcepti
7171
int httpCode = response.code();
7272
if(httpCode >= 200 && httpCode < 300)return;
7373
String message = response.message();
74-
CosXmlServiceException cosXmlServiceException = new CosXmlServiceException(message);
74+
CosXmlServiceException cosXmlServiceException = new CosXmlServiceException(message, response.host());
7575
cosXmlServiceException.setStatusCode(httpCode);
7676
cosXmlServiceException.setRequestId(response.header("x-cos-request-id"));
7777
InputStream inputStream = response.byteStream();

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

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -63,7 +63,7 @@ private void parseCOSXMLError(HttpResponse response) throws CosXmlServiceExcepti
6363
int httpCode = response.code();
6464
if(httpCode >= 200 && httpCode < 300)return;
6565
String message = response.message();
66-
CosXmlServiceException cosXmlServiceException = new CosXmlServiceException(message);
66+
CosXmlServiceException cosXmlServiceException = new CosXmlServiceException(message, response.host());
6767
cosXmlServiceException.setStatusCode(httpCode);
6868
cosXmlServiceException.setRequestId(response.header("x-cos-request-id"));
6969
String contentType = response.header(HttpConstants.Header.CONTENT_TYPE);

QCloudCosXml/cos-android/build.gradle

Lines changed: 3 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -142,6 +142,9 @@ dependencies {
142142

143143
androidTestCompileOnly project(path: ':cos-android')
144144
androidTestCompileOnly project(path: ':cos-android-base')
145+
androidTestCompileOnly project(path: ':xmlAnnoation')
146+
androidTestAnnotationProcessor project(':xmlCompiler')
147+
145148
// kms 加密
146149
androidTestImplementation 'com.tencentcloudapi:tencentcloud-sdk-java-kms:3.1.213'
147150
androidTestImplementation 'xerces:xercesImpl:2.12.0'

0 commit comments

Comments
 (0)