Skip to content

Commit 42b1bd5

Browse files
author
jordanqin
committed
update qcloud sdk to 5.9.35
1 parent 3c408e4 commit 42b1bd5

File tree

10 files changed

+277
-12
lines changed

10 files changed

+277
-12
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 50932
10-
versionName '5.9.32'
9+
versionCode 50933
10+
versionName '5.9.33'
1111

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

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

Lines changed: 2 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -226,6 +226,8 @@ private void init(QCloudHttpClient.Builder builder, CosXmlServiceConfig configur
226226
builder.dnsCache(configuration.isDnsCache());
227227
builder.addPrefetchHost(configuration.getEndpointSuffix());
228228
builder.setVerifySSLEnable(configuration.isVerifySSLEnable());
229+
builder.setClientCertificate(configuration.getClientCertificateBytes(), configuration.getClientCertificatePassword());
230+
builder.setRedirectEnable(configuration.isRedirectEnable());
229231
}
230232

231233
public void setNetworkClient(CosXmlServiceConfig configuration){

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

Lines changed: 49 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -111,6 +111,10 @@ public class CosXmlServiceConfig implements Parcelable {
111111
private final int downloadMaxThreadCount;
112112
private final boolean domainSwitch;
113113
private final boolean verifySSLEnable;
114+
private final boolean redirectEnable;
115+
116+
private final byte[] clientCertificateBytes;
117+
private final char[] clientCertificatePassword;
114118

115119
public CosXmlServiceConfig(Builder builder) {
116120
this.protocol = builder.protocol;
@@ -150,6 +154,9 @@ public CosXmlServiceConfig(Builder builder) {
150154
this.downloadMaxThreadCount = builder.downloadMaxThreadCount;
151155
this.domainSwitch = builder.domainSwitch;
152156
this.verifySSLEnable = builder.verifySSLEnable;
157+
this.clientCertificateBytes = builder.clientCertificateBytes;
158+
this.clientCertificatePassword = builder.clientCertificatePassword;
159+
this.redirectEnable = builder.redirectEnable;
153160
}
154161

155162
public Builder newBuilder() {
@@ -443,6 +450,18 @@ public boolean isVerifySSLEnable(){
443450
return verifySSLEnable;
444451
}
445452

453+
public byte[] getClientCertificateBytes() {
454+
return clientCertificateBytes;
455+
}
456+
457+
public char[] getClientCertificatePassword() {
458+
return clientCertificatePassword;
459+
}
460+
461+
public boolean isRedirectEnable() {
462+
return redirectEnable;
463+
}
464+
446465
@Deprecated
447466
public String getEndpointSuffix() {
448467
return getEndpointSuffix(region, false);
@@ -648,6 +667,10 @@ public final static class Builder {
648667
private int downloadMaxThreadCount;
649668
private boolean domainSwitch;
650669
private boolean verifySSLEnable;
670+
private boolean redirectEnable;
671+
672+
private byte[] clientCertificateBytes;
673+
private char[] clientCertificatePassword;
651674

652675
public Builder() {
653676
protocol = HTTPS_PROTOCOL;
@@ -658,6 +681,9 @@ public Builder() {
658681
downloadMaxThreadCount = TaskExecutors.DOWNLOAD_THREAD_COUNT;
659682
domainSwitch = true;
660683
verifySSLEnable = true;
684+
clientCertificateBytes = null;
685+
clientCertificatePassword = null;
686+
redirectEnable = false;
661687
}
662688

663689
public Builder(CosXmlServiceConfig config) {
@@ -698,6 +724,9 @@ public Builder(CosXmlServiceConfig config) {
698724
downloadMaxThreadCount = config.downloadMaxThreadCount;
699725
domainSwitch = config.domainSwitch;
700726
verifySSLEnable = config.verifySSLEnable;
727+
clientCertificateBytes = config.clientCertificateBytes;
728+
clientCertificatePassword = config.clientCertificatePassword;
729+
redirectEnable = config.redirectEnable;
701730
}
702731

703732
/**
@@ -755,13 +784,32 @@ public Builder setDomainSwitch(boolean domainSwitch) {
755784
}
756785

757786
/**
758-
* 设置是否开启SSL证书校验,默认开启
787+
* 设置是否开启TLS证书校验,默认开启
759788
*/
760789
public Builder setVerifySSLEnable(boolean verifySSLEnable) {
761790
this.verifySSLEnable = verifySSLEnable;
762791
return this;
763792
}
764793

794+
/**
795+
* 设置tls客户端证书
796+
* @param certificateBytes 客户端证书字节数组, 需要为BKS格式
797+
* @param password BKS文件的密码,如果你的BKS文件没有密码,请传入null
798+
*/
799+
public Builder setClientCertificate(byte[] certificateBytes, String password) {
800+
this.clientCertificateBytes = certificateBytes;
801+
this.clientCertificatePassword = password.toCharArray();
802+
return this;
803+
}
804+
805+
/**
806+
* 设置是否开启重定向,默认不开启
807+
*/
808+
public Builder setRedirectEnable(boolean redirectEnable) {
809+
this.redirectEnable = redirectEnable;
810+
return this;
811+
}
812+
765813
/**
766814
* 设置是否 Https 协议,默认为 Https
767815
*

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

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,6 +10,7 @@
1010
import com.tencent.cos.xml.CosXmlSimpleService;
1111
import com.tencent.cos.xml.crypto.KMSEncryptionMaterialsProvider;
1212
import com.tencent.cos.xml.exception.CosXmlClientException;
13+
import com.tencent.cos.xml.test.R;
1314
import com.tencent.cos.xml.transfer.TransferConfig;
1415
import com.tencent.cos.xml.transfer.TransferManager;
1516
import com.tencent.cos.xml.transfer.TransferService;
@@ -27,6 +28,7 @@
2728
import com.tencent.qcloud.core.http.HttpConstants;
2829
import com.tencent.qcloud.core.http.QCloudHttpRequest;
2930

31+
import java.io.IOException;
3032
import java.net.InetAddress;
3133
import java.net.UnknownHostException;
3234
import java.util.ArrayList;
@@ -94,6 +96,7 @@ public CosXmlSimpleService newDefaultServiceBySessionCredentials() {
9496
CosXmlServiceConfig cosXmlServiceConfig = new CosXmlServiceConfig.Builder()
9597
.isHttps(true)
9698
.setDebuggable(true)
99+
.setRedirectEnable(true)
97100
.setRegion(TestConst.PERSIST_BUCKET_REGION)
98101
.builder();
99102

@@ -228,6 +231,34 @@ public CosXmlSimpleService newCDNService() {
228231
return new CosXmlSimpleService(getContext(), cosXmlServiceConfig);
229232
}
230233

234+
public CosXmlSimpleService newDualCheckService() {
235+
CosXmlServiceConfig cosXmlServiceConfig = null;
236+
237+
try {
238+
// tls客户端证书字节数组, 需要为BKS格式
239+
byte[] certificateBytes = TestUtils.inputStreamToByteArray(
240+
TestUtils.getContext().getResources().openRawResource(R.raw.client)
241+
);
242+
// BKS文件的密码,如果你的BKS文件没有密码,请传入null
243+
String password = "123456";
244+
245+
cosXmlServiceConfig = new CosXmlServiceConfig.Builder()
246+
.isHttps(true)
247+
.setDebuggable(true)
248+
.setConnectionTimeout(10000)
249+
.setSocketTimeout(10000)
250+
.setRegion(TestConst.DUALCHECK_PERSIST_BUCKET_REGION)
251+
.setHost("dual-check.mynewcos.com")
252+
// 设置tls客户端证书
253+
.setClientCertificate(certificateBytes, password)
254+
.builder();
255+
} catch (IOException e) {
256+
throw new RuntimeException(e);
257+
}
258+
259+
return newService(cosXmlServiceConfig);
260+
}
261+
231262
public TransferManager newDefaultTransferManager() {
232263

233264
TransferConfig transferConfig = new TransferConfig.Builder()
@@ -431,6 +462,18 @@ public TransferManager newBigSliceSize369TransferManager() {
431462
return new TransferManager(newDefaultService(), transferConfig);
432463
}
433464

465+
public TransferManager newDualCheckTransferManager() {
466+
TransferConfig transferConfig = new TransferConfig.Builder()
467+
.setDivisionForUpload(2 * 1024 * 1024)
468+
.setSliceSizeForUpload(1024 * 1024)
469+
.setVerifyCRC64(true)
470+
.setSliceSizeForCopy(5242880)
471+
.setDividsionForCopy(5242880)
472+
.build();
473+
Log.d(TestConst.UT_TAG, String.valueOf(transferConfig.getDivisionForCopy()));
474+
return new TransferManager(newDualCheckService(), transferConfig);
475+
}
476+
434477

435478
private CosXmlSimpleService newServiceBySessionCredentials(CosXmlServiceConfig cosXmlServiceConfig) {
436479
// return new CosXmlSimpleService(getContext(), cosXmlServiceConfig,

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

Lines changed: 8 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -78,11 +78,13 @@ public class TestConst {
7878
public static final long PERSIST_BUCKET_SMALL_OBJECT_SIZE = 1024 * 1024;
7979
public static final long PERSIST_BUCKET_BIG_OBJECT_SIZE = 10 * 1024 * 1024;
8080
public static final long PERSIST_BUCKET_BIG_60M_OBJECT_SIZE = 60 * 1024 * 1024;
81+
public static final long PERSIST_BUCKET_BIG_300M_OBJECT_SIZE = 300 * 1024 * 1024;
8182

8283
public static final String PERSIST_BUCKET_SMALL_OBJECT_PATH = "do_not_remove/small_object";
8384
public static final String PERSIST_BUCKET_BIG_OBJECT_PATH = "do_not_remove/big_object";
8485
public static final String PERSIST_BUCKET_BATCH_OBJECT_PATH = "do_not_remove//batch/small_object";
8586
public static final String PERSIST_BUCKET_BIG_60M_OBJECT_PATH = "do_not_remove/big_60m_object";
87+
public static final String PERSIST_BUCKET_BIG_300M_OBJECT_PATH = "do_not_remove/big_300m_object";
8688
public static final String PERSIST_BUCKET_BIG_1G_OBJECT_PATH = "do_not_remove/big_file.zip";
8789
public static final String PERSIST_BUCKET_CSE_SMALL_OBJECT_PATH = "do_not_remove/cse_small_object";
8890
public static final String PERSIST_BUCKET_CSE_BIG_OBJECT_PATH = "do_not_remove/cse_big_object";
@@ -111,4 +113,10 @@ public class TestConst {
111113
public static final String CALLBACK_SECRET_KEY = BuildConfig.CALLBACK_SECRET_KEY;
112114
public static final String CALLBACK_PERSIST_BUCKET_REGION = "ap-shanghai";
113115
public static final String CALLBACK_PERSIST_BUCKET = "test-callback-1252246555";
116+
117+
public static final String DUALCHECK_PERSIST_BUCKET_REGION = "ap-nanjing";
118+
public static final String DUALCHECK_PERSIST_BUCKET = "dual-check-nj-1253960454";
119+
120+
121+
114122
}

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

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -165,6 +165,18 @@ public static String big60mFilePath() {
165165
return null;
166166
}
167167

168+
public static String big300mFilePath() {
169+
170+
String filePath = localPath(TestConst.PERSIST_BUCKET_BIG_300M_OBJECT_PATH);
171+
try {
172+
boolean success = createFile(filePath, TestConst.PERSIST_BUCKET_BIG_300M_OBJECT_SIZE);
173+
return filePath;
174+
} catch (IOException e) {
175+
e.printStackTrace();
176+
}
177+
return null;
178+
}
179+
168180
public static String bigPlusFilePath() {
169181

170182
String filePath = localPath(TestConst.PERSIST_BUCKET_BIG_OBJECT_PATH);

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

Lines changed: 19 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -722,4 +722,23 @@ private void getObjectBytesByPath(String cosPath, boolean isFail, boolean isObje
722722
}
723723
}
724724
}
725+
726+
@Test public void testDualCheckSmallDownloadToUri() {
727+
CosXmlSimpleService cosXmlSimpleService = ServiceFactory.INSTANCE.newDualCheckService();
728+
729+
GetObjectRequest getObjectRequest = new GetObjectRequest(TestConst.DUALCHECK_PERSIST_BUCKET,
730+
"index.html",
731+
Uri.fromFile(new File(smallFilePath())));
732+
Assert.assertNotNull(getObjectRequest.getFileContentUri());
733+
try {
734+
cosXmlSimpleService.getObject(getObjectRequest);
735+
} catch (CosXmlClientException e) {
736+
e.printStackTrace();
737+
return;
738+
} catch (CosXmlServiceException e) {
739+
e.printStackTrace();
740+
return;
741+
}
742+
Assert.assertTrue(true);
743+
}
725744
}

0 commit comments

Comments
 (0)