Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Support acc #511

Merged
merged 52 commits into from
Jun 24, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
Show all changes
52 commits
Select commit Hold shift + click to select a range
1f364ad
Merge pull request #475 from YangSen-qn/http3
xwen-winnie Dec 10, 2021
ef8169f
change uc query retry host order
Jul 19, 2023
bc3f3dc
Merge branch 'master' of YangSen-qn:qiniu/android-sdk into remove-reg…
Jul 20, 2023
112ff06
change test case
Jul 21, 2023
8193846
change test case
Jul 24, 2023
a052eb6
Merge branch 'master' of YangSen-qn:qiniu/android-sdk into remove-reg…
Jul 27, 2023
027d9ba
change mvn_push
Jul 31, 2023
47f87a6
update test token
Jul 31, 2023
21fff24
change gradle.properties: config jvm
Aug 1, 2023
5f060f7
change test case
Aug 2, 2023
4600249
Merge branch 'master' of YangSen-qn:qiniu/android-sdk into fix-publish
Aug 2, 2023
13ba1e5
update mvn_push.gradle
Aug 2, 2023
8608aa2
update test case
Aug 2, 2023
5d73445
version to 8.6.0
Aug 7, 2023
4ddce97
Merge branch 'fix-publish'
Aug 7, 2023
0f28b16
change publish
Oct 9, 2023
8a0b360
fix zone add createZonesInfo
Oct 11, 2023
06c6ae7
update android gradle plugin
Oct 11, 2023
ae58017
Merge branch 'master' of YangSen-qn:qiniu/android-sdk into fixzone
Oct 12, 2023
99a8f69
change publish
Oct 12, 2023
54c3003
add Cache - part 1
Oct 12, 2023
64d0057
auto zone support disk cache
Oct 19, 2023
b876c6b
optimize upload run
Oct 20, 2023
0d746d3
change test case
Oct 20, 2023
d96a439
change test token
Oct 20, 2023
cccaef5
change test case
Oct 20, 2023
546892a
Merge branch 'develop' of YangSen-qn:qiniu/android-sdk into query-dis…
Oct 24, 2023
21e3a11
Merge branch 'master' of YangSen-qn:qiniu/android-sdk into query-disk…
Oct 24, 2023
71e44cf
optimize some code
Oct 25, 2023
21f38d4
auto zone build date
Nov 3, 2023
79a7e12
cache timestamp unit to S
Nov 6, 2023
f48c2ca
uc query add host: uc.qiniuapi.com
Nov 13, 2023
e49840e
Merge branch 'master' of YangSen-qn:qiniu/android-sdk into uc-query-a…
Nov 13, 2023
fe832a3
change http scheme logic
Nov 16, 2023
16d92e0
change setHostScheme
Nov 16, 2023
5f22804
version to 8.7.0
Nov 23, 2023
4132537
Merge branch 'master' of YangSen-qn:qiniu/android-sdk
Nov 23, 2023
190d736
Merge branch 'master' of YangSen-qn:qiniu/android-sdk
Nov 27, 2023
e1ed20d
add some doc
Nov 27, 2023
3340c3e
add some doc
Nov 28, 2023
1e41eed
change some doc
Nov 29, 2023
b582e31
hidden some doc
Nov 30, 2023
7b27280
remove useless code
Nov 30, 2023
b091623
change javadoc
Nov 30, 2023
aa679cc
change doc
Nov 30, 2023
03355a3
optimize some code
Dec 7, 2023
5febea7
Merge branch 'multi-region'
Dec 7, 2023
1a697ee
delete useless code
Dec 11, 2023
0b32ed1
feature: support acc
May 24, 2024
96e5b12
Merge branch 'master' of YangSen-qn:qiniu/android-sdk
May 24, 2024
8557029
optimize some code
May 27, 2024
47179ca
change dns test
May 28, 2024
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
1 change: 0 additions & 1 deletion .idea/misc.xml

Some generated files are not rendered by default. Learn more about how customized files appear on GitHub.

1 change: 1 addition & 0 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@ allprojects {
repositories {
jcenter()
google()
mavenCentral()
}
// gradle.projectsEvaluated {
// tasks.withType(JavaCompile) {
Expand Down
14 changes: 7 additions & 7 deletions library/src/androidTest/java/com/qiniu/android/TestConfig.java
Original file line number Diff line number Diff line change
Expand Up @@ -10,23 +10,23 @@ public final class TestConfig {
// TODO: 2020-05-09 bad token for testPutBytesWithFixedZoneUseBackupDomains
// 华东上传凭证
public static final String bucket_z0 = "kodo-phone-zone0-space";
public static final String token_z0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:kCuN1lxE7wby0SgsYmgleVQh5pk=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjk1Mzg5MSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_z0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:gHBZrJTOKxxJlXjYoUxWmRSvuU8=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTAtc3BhY2UiLCJkZWFkbGluZSI6MTcyMTcwMDU5MiwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 华北上传凭证
public static final String bucket_z1 = "kodo-phone-zone1-space";
public static final String token_z1 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:6GJohI_Ldf_hBwGATV3iYeuMVZ0=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTEtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjk1Mzg5MSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_z1 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:8kFB5kF7f3INNSUZLToOBDTGMbU=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTEtc3BhY2UiLCJkZWFkbGluZSI6MTcyMTcwMDU5MiwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 华南上传凭证
public static final String bucket_z2 = "kodo-phone-zone2-space";
public static final String token_z2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:gy-wF5GQuoffNKUmRMKC0wVQDHQ=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTItc3BhY2UiLCJkZWFkbGluZSI6MTcwMjk1Mzg5MSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_z2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:CR7NjzaMWAqQAt6b7mPuwvwIzLs=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZTItc3BhY2UiLCJkZWFkbGluZSI6MTcyMTcwMDU5MiwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 北美上传凭证
public static final String bucket_na0 = "kodo-phone-zone-na0-space";
public static final String token_na0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:mEbYwqz9BbvKpjemh7arZA01SCY=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1uYTAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjk1Mzg5MSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_na0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:4TBEbspih6VzaNbPYlrpRIkm7xU=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1uYTAtc3BhY2UiLCJkZWFkbGluZSI6MTcyMTcwMDU5MiwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 东南亚上传凭证
public static final String bucket_as0 = "kodo-phone-zone-as0-space";
public static final String token_as0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:b5V9b1I3FCrNYJ1aQznlcGvyKe0=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1hczAtc3BhY2UiLCJkZWFkbGluZSI6MTcwMjk1Mzg5MSwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
public static final String token_as0 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:JczpyfXUYEan2qrimbu6GlOCADo=:eyJzY29wZSI6ImtvZG8tcGhvbmUtem9uZS1hczAtc3BhY2UiLCJkZWFkbGluZSI6MTcyMTcwMDU5MiwgInJldHVybkJvZHkiOiJ7XCJmb29cIjokKHg6Zm9vKSwgXCJiYXJcIjokKHg6YmFyKSwgXCJtaW1lVHlwZVwiOiQobWltZVR5cGUpLCBcImhhc2hcIjokKGV0YWcpLCBcImtleVwiOiQoa2V5KSwgXCJmbmFtZVwiOiQoZm5hbWUpLCBcImZzaXplXCI6JChmc2l6ZSl9In0=";
// 华北浙江2上传凭证
public static final String bucket_cn_east_2 = "kodo-phone-cn-east-2";
public static final String token_cn_east_2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:5wMZsrDWTJuYW-aYz6AsBJJhol4=:eyJzY29wZSI6ImtvZG8tcGhvbmUtY24tZWFzdC0yIiwiZGVhZGxpbmUiOjE3MDI5NTM4OTEsICJyZXR1cm5Cb2R5Ijoie1wiZm9vXCI6JCh4OmZvbyksIFwiYmFyXCI6JCh4OmJhciksIFwibWltZVR5cGVcIjokKG1pbWVUeXBlKSwgXCJoYXNoXCI6JChldGFnKSwgXCJrZXlcIjokKGtleSksIFwiZm5hbWVcIjokKGZuYW1lKSwgXCJmc2l6ZVwiOiQoZnNpemUpfSJ9";
public static final String invalidBucketToken = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:AF6tAFx4teQul_zEMXWzbN79_eI=:eyJzY29wZSI6InpvbmVfaW52YWxpZCIsImRlYWRsaW5lIjoxNzAyOTUzODkxLCAicmV0dXJuQm9keSI6IntcImZvb1wiOiQoeDpmb28pLCBcImJhclwiOiQoeDpiYXIpLCBcIm1pbWVUeXBlXCI6JChtaW1lVHlwZSksIFwiaGFzaFwiOiQoZXRhZyksIFwia2V5XCI6JChrZXkpLCBcImZuYW1lXCI6JChmbmFtZSksIFwiZnNpemVcIjokKGZzaXplKX0ifQ==";
public static final String token_cn_east_2 = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:LWCzEeHkDWcYVBViMzZdJ4IaZ0U=:eyJzY29wZSI6ImtvZG8tcGhvbmUtY24tZWFzdC0yIiwiZGVhZGxpbmUiOjE3MjE3MDA1OTIsICJyZXR1cm5Cb2R5Ijoie1wiZm9vXCI6JCh4OmZvbyksIFwiYmFyXCI6JCh4OmJhciksIFwibWltZVR5cGVcIjokKG1pbWVUeXBlKSwgXCJoYXNoXCI6JChldGFnKSwgXCJrZXlcIjokKGtleSksIFwiZm5hbWVcIjokKGZuYW1lKSwgXCJmc2l6ZVwiOiQoZnNpemUpfSJ9";
public static final String invalidBucketToken = "dxVQk8gyk3WswArbNhdKIwmwibJ9nFsQhMNUmtIM:FLgR-iEqqbGw-2vCdA9m5X7nOTY=:eyJzY29wZSI6InpvbmVfaW52YWxpZCIsImRlYWRsaW5lIjoxNzIxNzAwNTkyLCAicmV0dXJuQm9keSI6IntcImZvb1wiOiQoeDpmb28pLCBcImJhclwiOiQoeDpiYXIpLCBcIm1pbWVUeXBlXCI6JChtaW1lVHlwZSksIFwiaGFzaFwiOiQoZXRhZyksIFwia2V5XCI6JChrZXkpLCBcImZuYW1lXCI6JChmbmFtZSksIFwiZnNpemVcIjokKGZzaXplKX0ifQ==";

// -----------
public static final String ak = "bjtWBQXrcxgo7HWwlC_bgHg81j352_GhgBGZPeOW";
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -67,7 +67,7 @@ public void testPreFetch() {
FixedZone fixedZone = new FixedZone(new String[]{host});

final DnsPrefetcher dnsPrefetcher = DnsPrefetcher.getInstance();
dnsPrefetcher.checkAndPrefetchDnsIfNeed(fixedZone, UpToken.parse(TestConfig.token_z0));
dnsPrefetcher.checkAndPrefetchDnsIfNeed(null, fixedZone, UpToken.parse(TestConfig.token_z0));

wait(new WaitConditional() {
@Override
Expand Down Expand Up @@ -95,7 +95,7 @@ public void testMutiThreadPrefetch(){
new Thread(new Runnable() {
@Override
public void run() {
boolean isSuccess = DnsPrefetchTransaction.addDnsCheckAndPrefetchTransaction(zone, UpToken.parse(TestConfig.token_z0));
boolean isSuccess = DnsPrefetchTransaction.addDnsCheckAndPrefetchTransaction(null, zone, UpToken.parse(TestConfig.token_z0));
synchronized (this){
if (isSuccess){
param.successCount += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -68,7 +68,7 @@ public void test_CheckAndPrefetch(){
@Override
public void run() {

boolean isSuccess = DnsPrefetchTransaction.addDnsCheckAndPrefetchTransaction(zone, UpToken.parse(TestConfig.token_z0));
boolean isSuccess = DnsPrefetchTransaction.addDnsCheckAndPrefetchTransaction(null, zone, UpToken.parse(TestConfig.token_z0));
synchronized (this) {
if (isSuccess) {
successCount += 1;
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,9 +16,9 @@ public class SystemDnsTest extends BaseTest {

@Test
public void testDnsLookup() {
SystemDns dns = new SystemDns(5);
SystemDns dns = new SystemDns(10);
try {
List<IDnsNetworkAddress> result = dns.lookup("upload.qiniup.com");
List<IDnsNetworkAddress> result = dns.lookup("uplog.qbox.me");
assertTrue("testDnsLookup fail:", result != null && result.size() > 0);
} catch (UnknownHostException e) {
e.printStackTrace();
Expand All @@ -32,7 +32,7 @@ public void testDnsTimeout() {
int timeout = 5;
SystemDns dns = new SystemDns(timeout);
try {
List<IDnsNetworkAddress> result = dns.lookup("a.a.a.cn");
List<IDnsNetworkAddress> result = dns.lookup("abc.mock.cn");
assertTrue("testDnsTimeout fail:", result == null || result.size() == 0);
} catch (UnknownHostException e) {
e.printStackTrace();
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ public void testGetOneServer(){
String type = Utils.getIpType(null, host);
FixedZone zone = new FixedZone(new String[]{host});

UploadDomainRegion region = new UploadDomainRegion();
UploadDomainRegion region = new UploadDomainRegion(null);
region.setupRegionData(zone.getZonesInfo(null).zonesInfo.get(0));

UploadServerFreezeManager.getInstance().freezeType(type, 100);
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,6 @@
import com.qiniu.android.http.request.RequestTransaction;
import com.qiniu.android.storage.UpToken;
import com.qiniu.android.transaction.TransactionManager;
import com.qiniu.android.utils.AsyncRun;
import com.qiniu.android.utils.LogUtil;
import com.qiniu.android.utils.StringUtils;
import com.qiniu.android.utils.Utils;
Expand All @@ -24,7 +23,6 @@
import java.util.Date;
import java.util.List;
import java.util.concurrent.ExecutorService;
import java.util.concurrent.Executors;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;
Expand Down Expand Up @@ -254,7 +252,7 @@ private byte[] getLogData() {
randomAccessFile = new RandomAccessFile(recorderTempFile, "r");
ByteArrayOutputStream out = new ByteArrayOutputStream(fileSize);
int len = 0;
byte[] buff = new byte[fileSize];
byte[] buff = new byte[32*1024];
while ((len = randomAccessFile.read(buff)) >= 0) {
out.write(buff, 0, len);
}
Expand Down
73 changes: 55 additions & 18 deletions library/src/main/java/com/qiniu/android/common/AutoZone.java
Original file line number Diff line number Diff line change
Expand Up @@ -4,8 +4,11 @@
import com.qiniu.android.http.dns.DnsPrefetchTransaction;
import com.qiniu.android.http.metrics.UploadRegionRequestMetrics;
import com.qiniu.android.http.request.RequestTransaction;
import com.qiniu.android.storage.Configuration;
import com.qiniu.android.storage.UpToken;
import com.qiniu.android.storage.UploadOptions;
import com.qiniu.android.utils.Cache;
import com.qiniu.android.utils.ListUtils;
import com.qiniu.android.utils.SingleFlight;
import com.qiniu.android.utils.UrlSafeBase64;

Expand All @@ -14,7 +17,6 @@
import java.util.ArrayList;
import java.util.Arrays;
import java.util.Collections;
import java.util.HashMap;
import java.util.List;
import java.util.Map;
import java.util.concurrent.ConcurrentHashMap;
Expand Down Expand Up @@ -111,11 +113,12 @@ private String[] getUcServerArray() {
}

@Override
@Deprecated
public ZonesInfo getZonesInfo(UpToken token) {
if (token == null) {
return null;
}
String cacheKey = makeCacheKey(token.index());
String cacheKey = makeCacheKey(null, token.index());
ZonesInfo zonesInfo = zonesInfoMap.get(cacheKey);
if (zonesInfo != null) {
try {
Expand All @@ -128,15 +131,35 @@ public ZonesInfo getZonesInfo(UpToken token) {

@Override
public void preQuery(final UpToken token, final QueryHandler completeHandler) {
query(null, token, new QueryHandlerV2() {
@Override
public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics metrics, ZonesInfo zonesInfo) {
if (completeHandler != null) {
int code = ResponseInfo.NetworkError;
if (responseInfo != null) {
if (responseInfo.isOK()) {
code = 0;
} else {
code = responseInfo.statusCode;
}
}
completeHandler.complete(code, responseInfo, metrics);
}
}
});
}

@Override
public void query(Configuration configuration, UpToken token, QueryHandlerV2 completeHandler) {
if (token == null || !token.isValid()) {
completeHandler.complete(-1, ResponseInfo.invalidToken("invalid token"), null);
completeHandler.complete(ResponseInfo.invalidToken("invalid token"), null, null);
return;
}

UploadRegionRequestMetrics localMetrics = new UploadRegionRequestMetrics(null);
localMetrics.start();

final String cacheKey = makeCacheKey(token.index());
final String cacheKey = makeCacheKey(configuration, token.index());

ZonesInfo zonesInfo = null;
Cache.Object object = zoneCache.cacheForKey(cacheKey);
Expand All @@ -147,7 +170,7 @@ public void preQuery(final UpToken token, final QueryHandler completeHandler) {
if (zonesInfo != null && zonesInfo.isValid()) {
localMetrics.end();
zonesInfoMap.put(cacheKey, zonesInfo);
completeHandler.complete(0, ResponseInfo.successResponse(), localMetrics);
completeHandler.complete(ResponseInfo.successResponse(), localMetrics, zonesInfo);
return;
}

Expand All @@ -159,7 +182,7 @@ public void preQuery(final UpToken token, final QueryHandler completeHandler) {
@Override
public void action(final com.qiniu.android.utils.SingleFlight.CompleteHandler<SingleFlightValue> completeHandler) throws Exception {

final RequestTransaction transaction = createUploadRequestTransaction(token);
final RequestTransaction transaction = createUploadRequestTransaction(configuration, token);
transaction.queryUploadHosts(true, new RequestTransaction.RequestCompleteHandler() {
@Override
public void complete(ResponseInfo responseInfo, UploadRegionRequestMetrics requestMetrics, JSONObject response) {
Expand All @@ -186,36 +209,47 @@ public void complete(SingleFlightValue singleFlightValue) {
if (zonesInfoP.isValid()) {
zoneCache.cache(cacheKey, zonesInfoP, true);
zonesInfoMap.put(cacheKey, zonesInfoP);
completeHandler.complete(0, responseInfo, requestMetrics);
completeHandler.complete(responseInfo, requestMetrics, zonesInfoP);
} else {
completeHandler.complete(ResponseInfo.ParseError, responseInfo, requestMetrics);
responseInfo = ResponseInfo.parseError("origin response:" + responseInfo);
completeHandler.complete(responseInfo, requestMetrics, null);
}
} else {
if (defaultZone != null) {
// 备用只能用一次
ZonesInfo defaultZoneZonesInfo = defaultZone.getZonesInfo(token);
zonesInfoMap.put(cacheKey, defaultZoneZonesInfo);
completeHandler.complete(0, responseInfo, requestMetrics);
String message = "origin response:" + responseInfo;
responseInfo = ResponseInfo.successResponse();
responseInfo.message = message;
completeHandler.complete(responseInfo, requestMetrics, defaultZoneZonesInfo);
} else if (finalZonesInfo != null) {
// 缓存有,但是失效也可使用
zonesInfoMap.put(cacheKey, finalZonesInfo);
completeHandler.complete(0, responseInfo, requestMetrics);
String message = "origin response:" + responseInfo;
responseInfo = ResponseInfo.successResponse();
responseInfo.message = message;
completeHandler.complete(responseInfo, requestMetrics, finalZonesInfo);
} else {
completeHandler.complete(ResponseInfo.NetworkError, responseInfo, requestMetrics);
completeHandler.complete(responseInfo, requestMetrics, null);
}
}
}
});

} catch (Exception e) {
/// 此处永远不会执行,回调只为占位
completeHandler.complete(ResponseInfo.NetworkError, ResponseInfo.localIOError(e.toString()), null);
completeHandler.complete(ResponseInfo.localIOError(e.toString()), null, null);
}
}

private String makeCacheKey(String akAndBucket) {
private String makeCacheKey(Configuration configuration, String akAndBucket) {
String key = akAndBucket;
if (configuration != null) {
key += akAndBucket + ":" + configuration.accelerateUploading;
}
List<String> ucHosts = getUcServerList();
if (ucHosts == null || ucHosts.isEmpty()) {
if (ListUtils.isEmpty(ucHosts)) {
return akAndBucket;
}

Expand All @@ -227,13 +261,16 @@ private String makeCacheKey(String akAndBucket) {
hosts.append(host).append(":");
}

return UrlSafeBase64.encodeToString(hosts + akAndBucket);
return UrlSafeBase64.encodeToString(hosts + key);
}

private RequestTransaction createUploadRequestTransaction(UpToken token) {
private RequestTransaction createUploadRequestTransaction(Configuration configuration, UpToken token) {
List<String> hosts = getUcServerList();

RequestTransaction transaction = new RequestTransaction(hosts, ZoneInfo.EmptyRegionId, token);
if (configuration == null) {
configuration = new Configuration.Builder().build();
}
RequestTransaction transaction = new RequestTransaction(configuration, UploadOptions.defaultOptions(),
hosts, ZoneInfo.EmptyRegionId, null, token);
transactions.add(transaction);
return transaction;
}
Expand Down
3 changes: 2 additions & 1 deletion library/src/main/java/com/qiniu/android/common/Config.java
Original file line number Diff line number Diff line change
Expand Up @@ -87,6 +87,7 @@ public final class Config {
/**
* preQuery host
*/
@Deprecated
public static String preQueryHost03 = "api.qiniu.com";

/**
Expand All @@ -95,7 +96,7 @@ public final class Config {
* @return preQuery hosts
*/
public static String[] preQueryHosts() {
return new String[]{preQueryHost00, preQueryHost01, preQueryHost02, preQueryHost03};
return new String[]{preQueryHost00, preQueryHost01, preQueryHost02};
}

/**
Expand Down
Loading
Loading