Skip to content

Commit 701a4e3

Browse files
authored
Merge pull request #558 from YangSen-qn/update_gson
update gson version to 2.8.9
2 parents 90e14da + 686513c commit 701a4e3

17 files changed

+505
-141
lines changed

.codebeatsettings

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,6 @@
11
{
22
"JAVA": {
3+
"ABC": [15, 25, 50, 70],
34
"TOO_MANY_IVARS": [8, 15, 20, 25],
45
"ARITY": [5, 10, 15, 20]
56
}

build.gradle

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -21,7 +21,7 @@ jacocoTestReport {
2121

2222
dependencies {
2323
implementation group: 'com.squareup.okhttp3', name: 'okhttp', version: '3.14.4'
24-
implementation 'com.google.code.gson:gson:2.8.5'
24+
implementation 'com.google.code.gson:gson:2.8.9'
2525
implementation 'org.projectlombok:lombok:1.18.22'
2626
testImplementation group: 'com.qiniu', name: 'happy-dns-java', version: '0.1.6'
2727
testImplementation 'org.junit.jupiter:junit-jupiter-api:5.3.1'
@@ -52,7 +52,7 @@ apply plugin: 'checkstyle'
5252

5353

5454
def versionName() {
55-
String config = 'src/main/java/com/qiniu/common/Constants.java'
55+
String config = getProjectDir().getPath() + '/src/main/java/com/qiniu/common/Constants.java'
5656
String fileContents = new File(config).text
5757
Matcher myMatcher = fileContents =~ /VERSION = "(.+)";/
5858
String version = myMatcher[0][1]

src/main/java/com/qiniu/processing/OperationManager.java

Lines changed: 27 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -160,15 +160,20 @@ public String pfop(String bucket, String key, String fops, String pipeline, Stri
160160

161161
/**
162162
* 根据persistentId查询任务状态
163+
*
164+
* Use {@link OperationManager#prefop(String bucket, String persistentId)} instead
163165
*/
166+
@Deprecated
164167
public OperationStatus prefop(String persistentId) throws QiniuException {
165168
return prefop(persistentId, OperationStatus.class);
166169
}
167170

168171
/**
169172
* 根据persistentId查询任务状态
170173
* 返回结果的 class
174+
* Use {@link OperationManager#prefop(String bucket, String persistentId, Class<T>)} instead
171175
*/
176+
@Deprecated
172177
public <T> T prefop(String persistentId, Class<T> retClass) throws QiniuException {
173178
String url = String.format("%s/status/get/prefop?id=%s", configuration.apiHost(), persistentId);
174179
Response response = this.client.get(url);
@@ -180,6 +185,28 @@ public <T> T prefop(String persistentId, Class<T> retClass) throws QiniuExceptio
180185
return object;
181186
}
182187

188+
/**
189+
* 根据persistentId查询任务状态,如果您配置的是 AutoRegion 请使用这个方法进行 prefop
190+
*/
191+
public OperationStatus prefop(String bucket, String persistentId) throws QiniuException {
192+
return prefop(bucket, persistentId, OperationStatus.class);
193+
}
194+
195+
/**
196+
* 根据 persistentId 查询任务状态,如果您配置的是 AutoRegion 请使用这个方法进行 prefop
197+
* 返回结果的 class
198+
*/
199+
public <T> T prefop(String bucket, String persistentId, Class<T> retClass) throws QiniuException {
200+
String url = String.format("%s/status/get/prefop?id=%s", configuration.apiHost(auth.accessKey, bucket), persistentId);
201+
Response response = this.client.get(url);
202+
if (!response.isOK()) {
203+
throw new QiniuException(response);
204+
}
205+
T object = response.jsonToObject(retClass);
206+
response.close();
207+
return object;
208+
}
209+
183210
private class PfopResult {
184211
public String persistentId;
185212
}

src/main/java/com/qiniu/storage/AutoRegion.java

Lines changed: 36 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -14,7 +14,7 @@ class AutoRegion extends Region {
1414
/**
1515
* uc接口域名
1616
*/
17-
private final String ucServer;
17+
private String ucServer;
1818

1919
/**
2020
* 空间机房,域名信息缓存
@@ -26,6 +26,8 @@ class AutoRegion extends Region {
2626
*/
2727
private Client client;
2828

29+
private AutoRegion(){
30+
}
2931

3032
AutoRegion(String ucServer) {
3133
this.ucServer = ucServer;
@@ -188,6 +190,9 @@ Region getCurrentRegion(RegionReqInfo regionReqInfo) {
188190
*/
189191
@Override
190192
List<String> getSrcUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
193+
if (regionReqInfo == null) {
194+
return null;
195+
}
191196
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
192197
return regionGroup.getSrcUpHost(regionReqInfo);
193198
}
@@ -197,6 +202,9 @@ List<String> getSrcUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
197202
*/
198203
@Override
199204
List<String> getAccUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
205+
if (regionReqInfo == null) {
206+
return null;
207+
}
200208
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
201209
return regionGroup.getAccUpHost(regionReqInfo);
202210
}
@@ -206,6 +214,9 @@ List<String> getAccUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
206214
*/
207215
@Override
208216
String getIovipHost(RegionReqInfo regionReqInfo) throws QiniuException {
217+
if (regionReqInfo == null) {
218+
return "";
219+
}
209220
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
210221
return regionGroup.getIovipHost(regionReqInfo);
211222
}
@@ -215,6 +226,9 @@ String getIovipHost(RegionReqInfo regionReqInfo) throws QiniuException {
215226
*/
216227
@Override
217228
String getRsHost(RegionReqInfo regionReqInfo) throws QiniuException {
229+
if (regionReqInfo == null) {
230+
return "";
231+
}
218232
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
219233
return regionGroup.getRsHost(regionReqInfo);
220234
}
@@ -224,6 +238,9 @@ String getRsHost(RegionReqInfo regionReqInfo) throws QiniuException {
224238
*/
225239
@Override
226240
String getRsfHost(RegionReqInfo regionReqInfo) throws QiniuException {
241+
if (regionReqInfo == null) {
242+
return "";
243+
}
227244
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
228245
return regionGroup.getRsfHost(regionReqInfo);
229246
}
@@ -233,10 +250,28 @@ String getRsfHost(RegionReqInfo regionReqInfo) throws QiniuException {
233250
*/
234251
@Override
235252
String getApiHost(RegionReqInfo regionReqInfo) throws QiniuException {
253+
if (regionReqInfo == null) {
254+
return "";
255+
}
236256
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
237257
return regionGroup.getApiHost(regionReqInfo);
238258
}
239259

260+
@Override
261+
String getUcHost(RegionReqInfo regionReqInfo) throws QiniuException {
262+
String host = ucServer.replace("http://", "");
263+
host = host.replace("https://", "");
264+
return host;
265+
}
266+
267+
public Object clone() {
268+
AutoRegion newRegion = new AutoRegion();
269+
newRegion.ucServer = ucServer;
270+
newRegion.regions = regions;
271+
newRegion.client = client;
272+
return newRegion;
273+
}
274+
240275
private static class RegionIndex {
241276
private final String accessKey;
242277
private final String bucket;

src/main/java/com/qiniu/storage/BaseUploader.java

Lines changed: 2 additions & 18 deletions
Original file line numberDiff line numberDiff line change
@@ -36,13 +36,13 @@ private Response uploadWithRegionRetry() throws QiniuException {
3636
while (true) {
3737
try {
3838
response = uploadFlows();
39-
if (!couldSwitchRegionAndRetry(response, null)
39+
if (!Retry.shouldSwitchRegionAndRetry(response, null)
4040
|| !couldReloadSource() || !reloadSource()
4141
|| config.region == null || !config.region.switchRegion(new UploadToken(upToken))) {
4242
break;
4343
}
4444
} catch (QiniuException e) {
45-
if (!couldSwitchRegionAndRetry(null, e)
45+
if (!Retry.shouldSwitchRegionAndRetry(null, e)
4646
|| !couldReloadSource() || !reloadSource()
4747
|| config.region == null || !config.region.switchRegion(new UploadToken(upToken))) {
4848
throw e;
@@ -57,20 +57,4 @@ private Response uploadWithRegionRetry() throws QiniuException {
5757
abstract boolean couldReloadSource();
5858

5959
abstract boolean reloadSource();
60-
61-
private boolean couldSwitchRegionAndRetry(Response response, QiniuException exception) {
62-
Response checkResponse = response;
63-
if (checkResponse == null && exception != null) {
64-
checkResponse = exception.response;
65-
}
66-
67-
if (checkResponse != null) {
68-
int statusCode = checkResponse.statusCode;
69-
return (statusCode > -2 && statusCode < 200) || (statusCode > 299
70-
&& statusCode != 401 && statusCode != 413 && statusCode != 419
71-
&& statusCode != 608 && statusCode != 614 && statusCode != 630);
72-
}
73-
74-
return exception == null || !exception.isUnrecoverable();
75-
}
7660
}

src/main/java/com/qiniu/storage/BucketManager.java

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -120,7 +120,7 @@ public Response bucketsResponse() throws QiniuException {
120120
* @throws QiniuException
121121
*/
122122
public Response createBucket(String bucketName, String region) throws QiniuException {
123-
String url = String.format("%s/mkbucketv3/%s/region/%s", configHelper.rsHost(),
123+
String url = String.format("%s/mkbucketv3/%s/region/%s", configHelper.rsHost(auth.accessKey, bucketName),
124124
bucketName, region);
125125
Response res = post(url, null);
126126
if (!res.isOK()) {

src/main/java/com/qiniu/storage/ConfigHelper.java

Lines changed: 30 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -61,15 +61,42 @@ public String rsfHost(String ak, String bucket) throws QiniuException {
6161
}
6262

6363
public String rsHost() {
64-
return getScheme() + config.defaultRsHost;
64+
String host = "";
65+
try {
66+
host = config.region.getRsHost(null);
67+
} catch (QiniuException exception) {
68+
exception.printStackTrace();
69+
}
70+
if (host == null || host.length() == 0) {
71+
host = Configuration.defaultRsHost;
72+
}
73+
return getScheme() + host;
6574
}
6675

6776
public String apiHost() {
68-
return getScheme() + config.defaultApiHost;
77+
String host = "";
78+
try {
79+
host = config.region.getApiHost(null);
80+
} catch (QiniuException exception) {
81+
exception.printStackTrace();
82+
}
83+
if (host == null || host.length() == 0) {
84+
host = Configuration.defaultApiHost;
85+
}
86+
return getScheme() + host;
6987
}
7088

7189
public String ucHost() {
72-
return getScheme() + config.defaultUcHost;
90+
String host = "";
91+
try {
92+
host = config.region.getUcHost(null);
93+
} catch (QiniuException exception) {
94+
exception.printStackTrace();
95+
}
96+
if (host == null || host.length() == 0) {
97+
host = Configuration.defaultUcHost;
98+
}
99+
return getScheme() + host;
73100
}
74101

75102
private String getScheme() {

src/main/java/com/qiniu/storage/Configuration.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -128,7 +128,11 @@ public Configuration() {
128128
}
129129

130130
public Configuration(Region region) {
131-
this.region = region;
131+
if (region instanceof RegionGroup) {
132+
this.region = (Region) region.clone();
133+
} else {
134+
this.region = region;
135+
}
132136
configHelper = new ConfigHelper(this);
133137
}
134138

0 commit comments

Comments
 (0)