Skip to content

Commit

Permalink
Merge pull request #164 from zzq996/master
Browse files Browse the repository at this point in the history
Version 3.24.9
  • Loading branch information
zzq996 authored Sep 30, 2024
2 parents 9ff77dd + eaeb54d commit c509f1d
Show file tree
Hide file tree
Showing 27 changed files with 378 additions and 92 deletions.
8 changes: 8 additions & 0 deletions README-Android.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 3.24.9
Resolved issues:
1. Fixed the issue that can't auto add ContentType webp
2. Optimized logic of building xml when using CompleteMultiPart
3. Optimized logic of parsing xml
4. Added auto retry logic when request failed with wrong date
5. Added Element ExpiredObjectDeleteMarker in LifeCycleConfiguration
-----------------------------------------------------------------------------------
Version 3.24.8
Resolved issues:
1. PutObject、Getobject、GetObjectMetadata、UploadPart、AppendObject、CopyObject、CopyPart、CompeleMultiUploadPart now supports crc64 checksum.
Expand Down
8 changes: 8 additions & 0 deletions README-Java.md
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 3.24.9
Resolved issues:
1. Fixed the issue that can't auto add ContentType webp
2. Optimized logic of building xml when using CompleteMultiPart
3. Optimized logic of parsing xml
4. Added auto retry logic when request failed with wrong date
5. Added Element ExpiredObjectDeleteMarker in LifeCycleConfiguration
-----------------------------------------------------------------------------------
Version 3.24.8
Resolved issues:
1. PutObject、Getobject、GetObjectMetadata、UploadPart、AppendObject、CopyObject、CopyPart、CompeleMultiUploadPart now supports crc64 checksum.
Expand Down
8 changes: 8 additions & 0 deletions README.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 3.24.9
Resolved issues:
1. Fixed the issue that can't auto add ContentType webp
2. Optimized logic of building xml when using CompleteMultiPart
3. Optimized logic of parsing xml
4. Added auto retry logic when request failed with wrong date
5. Added Element ExpiredObjectDeleteMarker in LifeCycleConfiguration
-----------------------------------------------------------------------------------
Version 3.24.8
Resolved issues:
1. PutObject、Getobject、GetObjectMetadata、UploadPart、AppendObject、CopyObject、CopyPart、CompeleMultiUploadPart now supports crc64 checksum.
Expand Down
8 changes: 8 additions & 0 deletions README_CN.MD
Original file line number Diff line number Diff line change
@@ -1,3 +1,11 @@
Version 3.24.9
Resolved issues:
1. 修复无法自动添加webp格式的ContentType的问题
2. 优化合并段的xml构建逻辑
3. 优化xml解析逻辑
4. 增加时间不正确导致请求失败时的自动重试
5. 生命周期规则新增ExpiredObjectDeleteMarker属性
-----------------------------------------------------------------------------------
Version 3.24.8
Resolved issues:
1. PutObject、Getobject、GetObjectMetadata、UploadPart、AppendObject、CopyObject、CopyPart、CompeleMultiUploadPart支持crc64校验
Expand Down
9 changes: 9 additions & 0 deletions app/src/main/java/com/obs/services/AbstractClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -65,6 +65,7 @@ protected void init(String accessKey, String secretKey, String securityToken, Ob
this.credentials = credentials;
this.keyManagerFactory = config.getKeyManagerFactory();
this.trustManagerFactory = config.getTrustManagerFactory();
this.localTimeUtil = config.getLocalTimeUtil();
if (this.isAuthTypeNegotiation()) {
this.getProviderCredentials().setIsAuthTypeNegotiation(true);
}
Expand Down Expand Up @@ -183,6 +184,8 @@ public V4TemporarySignatureResponse createV4TemporarySignature(V4TemporarySignat
ILOG.error(reqBean);
}
throw new ObsException(e.getMessage(), e);
} finally {
AccessLoggerUtils.printLog();
}
}

Expand Down Expand Up @@ -229,6 +232,8 @@ public TemporarySignatureResponse createTemporarySignature(TemporarySignatureReq
ILOG.error(reqBean);
}
throw new ObsException(e.getMessage(), e);
} finally {
AccessLoggerUtils.printLog();
}
}

Expand Down Expand Up @@ -262,6 +267,8 @@ public TemporarySignatureResponse createGetTemporarySignature(String bucketName,
return this.createTemporarySignatureResponse(request);
} catch (Exception e) {
throw new ObsException(e.getMessage(), e);
} finally {
AccessLoggerUtils.printLog();
}
}

Expand Down Expand Up @@ -295,6 +302,8 @@ public TemporarySignatureResponse createGetTemporarySignature(String bucketName,
return this.createTemporarySignatureResponse(request);
} catch (Exception e) {
throw new ObsException(e.getMessage(), e);
} finally {
AccessLoggerUtils.printLog();
}
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,7 @@

package com.obs.services;

import com.obs.services.exception.ObsException;
import com.obs.services.internal.security.BasicSecurityKey;
import com.obs.services.model.ISecurityKey;

Expand All @@ -37,11 +38,11 @@ public BasicObsCredentialsProvider(String accessKey, String secretKey, String se

private static void checkSecurityKey(String accessKey, String secretKey) {
if (accessKey == null) {
throw new IllegalArgumentException("accessKey should not be null.");
throw new ObsException("accessKey should not be null.");
}

if (secretKey == null) {
throw new IllegalArgumentException("secretKey should not be null.");
throw new ObsException("secretKey should not be null.");
}
}

Expand Down
18 changes: 14 additions & 4 deletions app/src/main/java/com/obs/services/ObsConfiguration.java
Original file line number Diff line number Diff line change
Expand Up @@ -19,6 +19,7 @@
import javax.net.ssl.TrustManagerFactory;

import com.obs.services.internal.ObsConstraint;
import com.obs.services.internal.utils.LocalTimeUtil;
import com.obs.services.model.AuthTypeEnum;
import com.obs.services.model.HttpProtocolTypeEnum;

Expand Down Expand Up @@ -106,6 +107,7 @@ public class ObsConfiguration implements Cloneable {

private String xmlDocumentBuilderFactoryClass;
private EventListener.Factory eventListenerFactory;
private LocalTimeUtil localTimeUtil;

/**
* Constructor
Expand Down Expand Up @@ -141,6 +143,7 @@ public ObsConfiguration() {
this.xmlDocumentBuilderFactoryClass = ObsConstraint.OBS_XML_DOC_BUILDER_FACTORY_CLASS;
this.localAuthTypeCacheCapacity = ObsConstraint.DEFAULT_LOCAL_AUTH_TYPE_CACHE_CAPACITY;
this.secureRandom = new SecureRandom();
this.localTimeUtil = new LocalTimeUtil();
}

public String getDelimiter() {
Expand Down Expand Up @@ -942,14 +945,21 @@ public void setSecureRandom(SecureRandom secureRandom) {
this.secureRandom = secureRandom;
}

public EventListener.Factory getEventListenerFactory()
{
public EventListener.Factory getEventListenerFactory() {
return eventListenerFactory;
}

public void setEventListenerFactory(EventListener.Factory eventListenerFactory)
{
public void setEventListenerFactory(EventListener.Factory eventListenerFactory) {
this.eventListenerFactory = eventListenerFactory;
}

public LocalTimeUtil getLocalTimeUtil() {
return localTimeUtil;
}

public void setLocalTimeUtil(LocalTimeUtil localTimeUtil) {
this.localTimeUtil = localTimeUtil;
}


}
63 changes: 40 additions & 23 deletions app/src/main/java/com/obs/services/exception/ObsException.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,7 +14,6 @@

package com.obs.services.exception;

import java.util.Locale;
import java.util.Map;
import java.util.regex.Matcher;
import java.util.regex.Pattern;
Expand Down Expand Up @@ -44,6 +43,10 @@ public class ObsException extends RuntimeException {

private String errorIndicator = null;

private String obsExceptionString = null;

private boolean calledToSting = false;

public ObsException(String message) {
this(message, null, null);
}
Expand All @@ -65,32 +68,46 @@ public ObsException(String message, String xmlMessage, Throwable cause) {

@Override
public String toString() {
StringBuilder myString = new StringBuilder(super.toString());

if (responseCode != -1) {
myString.append(" -- ResponseCode: ")
.append(responseCode)
.append(", ResponseStatus: ")
.append(responseStatus);
if (obsExceptionString != null) {
return obsExceptionString;
}
if (isParsedFromXmlMessage()) {
myString.append(", XML Error Message: ").append(xmlMessage);
} else if (errorRequestId != null) {
myString.append(", RequestId: ").append(errorRequestId).append(", HostId: ").append(errorHostId);
}
// 遍历Map的entry,打印所有报错相关头域
Map<String, String> headers = getResponseHeaders();
if (headers != null) {
for (Map.Entry<String, String> header : headers.entrySet()) {
if (header.getKey().toLowerCase(Locale.ROOT).contains("error")) {
myString.append(", ErrorHeaderKey: ")
.append(header.getKey())
.append(", ErrorHeaderValue: ")
.append(header.getValue());
try {
calledToSting = true;
StringBuilder myString = new StringBuilder(super.toString());

if (responseCode != -1) {
myString.append(" -- ResponseCode: ")
.append(responseCode)
.append(", ResponseStatus: ")
.append(responseStatus);
}
if (isParsedFromXmlMessage()) {
myString.append(", XML Error Message: ").append(xmlMessage);
} else if (errorRequestId != null) {
myString.append(", RequestId: ").append(errorRequestId).append(", HostId: ").append(errorHostId);
}
// 遍历Map的entry,打印所有报错相关头域
Map<String, String> headers = getResponseHeaders();
if (headers != null) {
myString.append("headers{");
for (Map.Entry<String, String> header : headers.entrySet()) {
myString.append(header.getKey())
.append(":")
.append(header.getValue())
.append(",");
}
myString.append("}");
}
obsExceptionString = myString.toString();
return obsExceptionString;
} finally {
calledToSting = false;
}
return myString.toString();
}

@Override
public String getMessage() {
return calledToSting ? super.getMessage() : this.toString();
}

private boolean isParsedFromXmlMessage() {
Expand Down
5 changes: 4 additions & 1 deletion app/src/main/java/com/obs/services/internal/Constants.java
Original file line number Diff line number Diff line change
Expand Up @@ -215,7 +215,7 @@ public static class ObsRequestParams {

public static final TimeZone GMT_TIMEZONE = TimeZone.getTimeZone("GMT");

public static final String OBS_SDK_VERSION = "3.24.8";
public static final String OBS_SDK_VERSION = "3.24.9";

public static final String USER_AGENT_VALUE = "obs-sdk-java/" + Constants.OBS_SDK_VERSION;

Expand Down Expand Up @@ -269,6 +269,9 @@ public static class ObsRequestParams {
public static final long MAX_PART_SIZE = 5 * 1024 * 1024 * 1024L;

public static final long MIN_PART_SIZE = 100 * 1024L;
public static final String REQUEST_TIME_TOO_SKEWED_CODE = "RequestTimeTooSkewed";
public static final String ERROR_CODE_HEADER_OBS = "x-obs-error-code";
public static final String ERROR_CODE_HEADER_AMZ = "x-amz-error-code";

public static final List<String> ALLOWED_RESPONSE_HTTP_HEADER_METADATA_NAMES = Collections.unmodifiableList(
Arrays.asList("content-type", "content-md5", "content-length", "content-language", "expires", "origin",
Expand Down
5 changes: 0 additions & 5 deletions app/src/main/java/com/obs/services/internal/IConvertor.java
Original file line number Diff line number Diff line change
Expand Up @@ -14,8 +14,6 @@

package com.obs.services.internal;

import java.util.List;

import com.obs.services.model.AccessControlList;
import com.obs.services.model.BucketCors;
import com.obs.services.model.BucketDirectColdAccess;
Expand All @@ -29,7 +27,6 @@
import com.obs.services.model.GroupGranteeEnum;
import com.obs.services.model.KeyAndVersion;
import com.obs.services.model.LifecycleConfiguration;
import com.obs.services.model.PartEtag;
import com.obs.services.model.ReplicationConfiguration;
import com.obs.services.model.RestoreObjectRequest;
import com.obs.services.model.StorageClassEnum;
Expand All @@ -40,8 +37,6 @@

public interface IConvertor {

String transCompleteMultipartUpload(List<PartEtag> parts) throws ServiceException;

String transBucketLoction(String location) throws ServiceException;

String transVersioningConfiguration(String bucketName, String status) throws ServiceException;
Expand Down
6 changes: 4 additions & 2 deletions app/src/main/java/com/obs/services/internal/ObsService.java
Original file line number Diff line number Diff line change
Expand Up @@ -33,6 +33,7 @@
import com.obs.services.internal.task.BlockRejectedExecutionHandler;
import com.obs.services.internal.task.DefaultTaskProgressStatus;
import com.obs.services.internal.utils.AbstractAuthentication;
import com.obs.services.internal.utils.LocalTimeUtil;
import com.obs.services.internal.utils.RestUtils;
import com.obs.services.internal.utils.ServiceUtils;
import com.obs.services.internal.utils.V2Authentication;
Expand Down Expand Up @@ -175,7 +176,7 @@ private String getExpiresParams(AbstractTemporarySignatureRequest request) {
TemporarySignatureRequest tempRequest = (TemporarySignatureRequest) request;
long secondsSinceEpoch = tempRequest.getExpires() <= 0 ? ObsConstraint.DEFAULT_EXPIRE_SECONEDS
: tempRequest.getExpires();
secondsSinceEpoch += System.currentTimeMillis() / 1000;
secondsSinceEpoch += LocalTimeUtil.currentTimeMillisWithTimeDiff() / 1000;
expiresOrPolicy = String.valueOf(secondsSinceEpoch);
} else if (request instanceof PolicyTempSignatureRequest) {
PolicyTempSignatureRequest policyRequest = (PolicyTempSignatureRequest) request;
Expand Down Expand Up @@ -322,7 +323,7 @@ private String getFormatExpiration(PostSignatureRequest request) {
Date expiryDate = request.getExpiryDate() == null ? new Date(requestDate.getTime()
+ (request.getExpires() <= 0 ? ObsConstraint.DEFAULT_EXPIRE_SECONEDS : request.getExpires()) * 1000)
: request.getExpiryDate();

expiryDate = LocalTimeUtil.dateWithTimeDiff(expiryDate);
String expiration = expirationDateFormat.format(expiryDate);
return expiration;
}
Expand Down Expand Up @@ -396,6 +397,7 @@ protected TemporarySignatureResponse createV4TemporarySignature(TemporarySignatu
if (requestDate == null) {
requestDate = new Date();
}
requestDate = LocalTimeUtil.dateWithTimeDiff(requestDate);
String shortDate = ServiceUtils.getShortDateFormat().format(requestDate);
String longDate = ServiceUtils.getLongDateFormat().format(requestDate);

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -29,6 +29,7 @@
import com.obs.log.LoggerBuilder;
import com.obs.services.internal.security.ProviderCredentials;
import com.obs.services.internal.trans.NewTransResult;
import com.obs.services.internal.utils.LocalTimeUtil;
import com.obs.services.internal.utils.RestUtils;
import com.obs.services.internal.utils.ServiceUtils;
import com.obs.services.model.HttpMethodEnum;
Expand Down Expand Up @@ -58,6 +59,8 @@ public class RestConnectionService {

protected volatile ProviderCredentials credentials;

protected LocalTimeUtil localTimeUtil;

protected void initHttpClient(Dispatcher httpDispatcher, Dns customizedDnsImpl, HostnameVerifier hostnameVerifier,
EventListener.Factory eventListenerFactory) {

Expand Down Expand Up @@ -256,4 +259,13 @@ protected boolean isCname() {
protected boolean getHttpsOnly() {
return this.obsProperties.getBoolProperty(ObsConstraint.HTTPS_ONLY, true);
}

public LocalTimeUtil getLocalTimeUtil() {
return localTimeUtil;
}

public void setLocalTimeUtil(LocalTimeUtil localTimeUtil) {
this.localTimeUtil = localTimeUtil;
}

}
Loading

0 comments on commit c509f1d

Please sign in to comment.