Skip to content

Commit

Permalink
Merge pull request #558 from YangSen-qn/update_gson
Browse files Browse the repository at this point in the history
update gson version to 2.8.9
  • Loading branch information
bachue authored Oct 24, 2022
2 parents 90e14da + 686513c commit 701a4e3
Show file tree
Hide file tree
Showing 17 changed files with 505 additions and 141 deletions.
1 change: 1 addition & 0 deletions .codebeatsettings
Original file line number Diff line number Diff line change
@@ -1,5 +1,6 @@
{
"JAVA": {
"ABC": [15, 25, 50, 70],
"TOO_MANY_IVARS": [8, 15, 20, 25],
"ARITY": [5, 10, 15, 20]
}
Expand Down
4 changes: 2 additions & 2 deletions build.gradle
Original file line number Diff line number Diff line change
Expand Up @@ -21,7 +21,7 @@ jacocoTestReport {

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


def versionName() {
String config = 'src/main/java/com/qiniu/common/Constants.java'
String config = getProjectDir().getPath() + '/src/main/java/com/qiniu/common/Constants.java'
String fileContents = new File(config).text
Matcher myMatcher = fileContents =~ /VERSION = "(.+)";/
String version = myMatcher[0][1]
Expand Down
27 changes: 27 additions & 0 deletions src/main/java/com/qiniu/processing/OperationManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -160,15 +160,20 @@ public String pfop(String bucket, String key, String fops, String pipeline, Stri

/**
* 根据persistentId查询任务状态
*
* Use {@link OperationManager#prefop(String bucket, String persistentId)} instead
*/
@Deprecated
public OperationStatus prefop(String persistentId) throws QiniuException {
return prefop(persistentId, OperationStatus.class);
}

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

/**
* 根据persistentId查询任务状态,如果您配置的是 AutoRegion 请使用这个方法进行 prefop
*/
public OperationStatus prefop(String bucket, String persistentId) throws QiniuException {
return prefop(bucket, persistentId, OperationStatus.class);
}

/**
* 根据 persistentId 查询任务状态,如果您配置的是 AutoRegion 请使用这个方法进行 prefop
* 返回结果的 class
*/
public <T> T prefop(String bucket, String persistentId, Class<T> retClass) throws QiniuException {
String url = String.format("%s/status/get/prefop?id=%s", configuration.apiHost(auth.accessKey, bucket), persistentId);
Response response = this.client.get(url);
if (!response.isOK()) {
throw new QiniuException(response);
}
T object = response.jsonToObject(retClass);
response.close();
return object;
}

private class PfopResult {
public String persistentId;
}
Expand Down
37 changes: 36 additions & 1 deletion src/main/java/com/qiniu/storage/AutoRegion.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,7 @@ class AutoRegion extends Region {
/**
* uc接口域名
*/
private final String ucServer;
private String ucServer;

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

private AutoRegion(){
}

AutoRegion(String ucServer) {
this.ucServer = ucServer;
Expand Down Expand Up @@ -188,6 +190,9 @@ Region getCurrentRegion(RegionReqInfo regionReqInfo) {
*/
@Override
List<String> getSrcUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
if (regionReqInfo == null) {
return null;
}
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
return regionGroup.getSrcUpHost(regionReqInfo);
}
Expand All @@ -197,6 +202,9 @@ List<String> getSrcUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
*/
@Override
List<String> getAccUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
if (regionReqInfo == null) {
return null;
}
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
return regionGroup.getAccUpHost(regionReqInfo);
}
Expand All @@ -206,6 +214,9 @@ List<String> getAccUpHost(RegionReqInfo regionReqInfo) throws QiniuException {
*/
@Override
String getIovipHost(RegionReqInfo regionReqInfo) throws QiniuException {
if (regionReqInfo == null) {
return "";
}
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
return regionGroup.getIovipHost(regionReqInfo);
}
Expand All @@ -215,6 +226,9 @@ String getIovipHost(RegionReqInfo regionReqInfo) throws QiniuException {
*/
@Override
String getRsHost(RegionReqInfo regionReqInfo) throws QiniuException {
if (regionReqInfo == null) {
return "";
}
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
return regionGroup.getRsHost(regionReqInfo);
}
Expand All @@ -224,6 +238,9 @@ String getRsHost(RegionReqInfo regionReqInfo) throws QiniuException {
*/
@Override
String getRsfHost(RegionReqInfo regionReqInfo) throws QiniuException {
if (regionReqInfo == null) {
return "";
}
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
return regionGroup.getRsfHost(regionReqInfo);
}
Expand All @@ -233,10 +250,28 @@ String getRsfHost(RegionReqInfo regionReqInfo) throws QiniuException {
*/
@Override
String getApiHost(RegionReqInfo regionReqInfo) throws QiniuException {
if (regionReqInfo == null) {
return "";
}
RegionGroup regionGroup = queryRegionInfo(regionReqInfo);
return regionGroup.getApiHost(regionReqInfo);
}

@Override
String getUcHost(RegionReqInfo regionReqInfo) throws QiniuException {
String host = ucServer.replace("http://", "");
host = host.replace("https://", "");
return host;
}

public Object clone() {
AutoRegion newRegion = new AutoRegion();
newRegion.ucServer = ucServer;
newRegion.regions = regions;
newRegion.client = client;
return newRegion;
}

private static class RegionIndex {
private final String accessKey;
private final String bucket;
Expand Down
20 changes: 2 additions & 18 deletions src/main/java/com/qiniu/storage/BaseUploader.java
Original file line number Diff line number Diff line change
Expand Up @@ -36,13 +36,13 @@ private Response uploadWithRegionRetry() throws QiniuException {
while (true) {
try {
response = uploadFlows();
if (!couldSwitchRegionAndRetry(response, null)
if (!Retry.shouldSwitchRegionAndRetry(response, null)
|| !couldReloadSource() || !reloadSource()
|| config.region == null || !config.region.switchRegion(new UploadToken(upToken))) {
break;
}
} catch (QiniuException e) {
if (!couldSwitchRegionAndRetry(null, e)
if (!Retry.shouldSwitchRegionAndRetry(null, e)
|| !couldReloadSource() || !reloadSource()
|| config.region == null || !config.region.switchRegion(new UploadToken(upToken))) {
throw e;
Expand All @@ -57,20 +57,4 @@ private Response uploadWithRegionRetry() throws QiniuException {
abstract boolean couldReloadSource();

abstract boolean reloadSource();

private boolean couldSwitchRegionAndRetry(Response response, QiniuException exception) {
Response checkResponse = response;
if (checkResponse == null && exception != null) {
checkResponse = exception.response;
}

if (checkResponse != null) {
int statusCode = checkResponse.statusCode;
return (statusCode > -2 && statusCode < 200) || (statusCode > 299
&& statusCode != 401 && statusCode != 413 && statusCode != 419
&& statusCode != 608 && statusCode != 614 && statusCode != 630);
}

return exception == null || !exception.isUnrecoverable();
}
}
2 changes: 1 addition & 1 deletion src/main/java/com/qiniu/storage/BucketManager.java
Original file line number Diff line number Diff line change
Expand Up @@ -120,7 +120,7 @@ public Response bucketsResponse() throws QiniuException {
* @throws QiniuException
*/
public Response createBucket(String bucketName, String region) throws QiniuException {
String url = String.format("%s/mkbucketv3/%s/region/%s", configHelper.rsHost(),
String url = String.format("%s/mkbucketv3/%s/region/%s", configHelper.rsHost(auth.accessKey, bucketName),
bucketName, region);
Response res = post(url, null);
if (!res.isOK()) {
Expand Down
33 changes: 30 additions & 3 deletions src/main/java/com/qiniu/storage/ConfigHelper.java
Original file line number Diff line number Diff line change
Expand Up @@ -61,15 +61,42 @@ public String rsfHost(String ak, String bucket) throws QiniuException {
}

public String rsHost() {
return getScheme() + config.defaultRsHost;
String host = "";
try {
host = config.region.getRsHost(null);
} catch (QiniuException exception) {
exception.printStackTrace();
}
if (host == null || host.length() == 0) {
host = Configuration.defaultRsHost;
}
return getScheme() + host;
}

public String apiHost() {
return getScheme() + config.defaultApiHost;
String host = "";
try {
host = config.region.getApiHost(null);
} catch (QiniuException exception) {
exception.printStackTrace();
}
if (host == null || host.length() == 0) {
host = Configuration.defaultApiHost;
}
return getScheme() + host;
}

public String ucHost() {
return getScheme() + config.defaultUcHost;
String host = "";
try {
host = config.region.getUcHost(null);
} catch (QiniuException exception) {
exception.printStackTrace();
}
if (host == null || host.length() == 0) {
host = Configuration.defaultUcHost;
}
return getScheme() + host;
}

private String getScheme() {
Expand Down
6 changes: 5 additions & 1 deletion src/main/java/com/qiniu/storage/Configuration.java
Original file line number Diff line number Diff line change
Expand Up @@ -128,7 +128,11 @@ public Configuration() {
}

public Configuration(Region region) {
this.region = region;
if (region instanceof RegionGroup) {
this.region = (Region) region.clone();
} else {
this.region = region;
}
configHelper = new ConfigHelper(this);
}

Expand Down
Loading

0 comments on commit 701a4e3

Please sign in to comment.