diff --git a/src/main/java/com/aliyun/oss/OSS.java b/src/main/java/com/aliyun/oss/OSS.java index 228b5471..fda39071 100644 --- a/src/main/java/com/aliyun/oss/OSS.java +++ b/src/main/java/com/aliyun/oss/OSS.java @@ -3248,6 +3248,23 @@ public BucketReplicationProgress getBucketReplicationProgress( public List getBucketReplicationLocation(GenericRequest genericRequest) throws OSSException, ClientException; + /** + * @param bucketName + * @return + * @throws OSSException + * @throws ClientException + */ + public BucketReplicationLocationResult getBucketReplicationLocationV2(String bucketName) throws OSSException, ClientException; + + /** + * @param genericRequest + * @return + * @throws OSSException + * @throws ClientException + */ + public BucketReplicationLocationResult getBucketReplicationLocationV2(GenericRequest genericRequest) + throws OSSException, ClientException; + /** * Adds a Cname for the {@link Bucket} instance. * @@ -5101,4 +5118,12 @@ public UdfApplicationLog getUdfApplicationLog(GetUdfApplicationLogRequest getUdf * If any errors occurred in OSS while processing the request. */ VoidResult closeMetaQuery(String bucketName) throws OSSException, ClientException; + + /** + * Turn RTC on or off for an existing cross region replication rule + * + * @param putBucketRTCRequest + * @return VoidResult + */ + VoidResult putBucketRTC(PutBucketRTCRequest putBucketRTCRequest) throws OSSException, ClientException; } diff --git a/src/main/java/com/aliyun/oss/OSSClient.java b/src/main/java/com/aliyun/oss/OSSClient.java index 8b995acb..fe9000d9 100644 --- a/src/main/java/com/aliyun/oss/OSSClient.java +++ b/src/main/java/com/aliyun/oss/OSSClient.java @@ -1292,6 +1292,16 @@ public List getBucketReplicationLocation(GenericRequest genericRequest) return this.bucketOperation.getBucketReplicationLocation(genericRequest); } + @Override + public BucketReplicationLocationResult getBucketReplicationLocationV2(String bucketName) throws OSSException, ClientException { + return this.bucketOperation.getBucketReplicationLocationV2(new GenericRequest(bucketName)); + } + + @Override + public BucketReplicationLocationResult getBucketReplicationLocationV2(GenericRequest genericRequest) throws OSSException, ClientException { + return this.bucketOperation.getBucketReplicationLocationV2(genericRequest); + } + @Override public AddBucketCnameResult addBucketCname(AddBucketCnameRequest addBucketCnameRequest) throws OSSException, ClientException { return this.bucketOperation.addBucketCname(addBucketCnameRequest); @@ -1957,6 +1967,11 @@ public VoidResult closeMetaQuery(String bucketName) throws OSSException, ClientE return this.bucketOperation.closeMetaQuery(new GenericRequest(bucketName)); } + @Override + public VoidResult putBucketRTC(PutBucketRTCRequest putBucketRTCRequest) throws OSSException, ClientException { + return this.bucketOperation.putBucketRTC(putBucketRTCRequest); + } + @Override public void shutdown() { try { diff --git a/src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java b/src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java index 9ede985b..9ec1cf14 100644 --- a/src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java +++ b/src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java @@ -100,6 +100,7 @@ public final class RequestMarshallers { public static final PutBucketTransferAccelerationRequestMarshaller putBucketTransferAccelerationRequestMarshaller = new PutBucketTransferAccelerationRequestMarshaller(); public static final PutBucketAccessMonitorRequestMarshaller putBucketAccessMonitorRequestMarshaller = new PutBucketAccessMonitorRequestMarshaller(); public static final DoMetaQueryRequestMarshaller doMetaQueryRequestMarshaller = new DoMetaQueryRequestMarshaller(); + public static final PutBucketRTCRequestMarshaller putBucketRTCRequestMarshaller = new PutBucketRTCRequestMarshaller(); public interface RequestMarshaller extends Marshaller { @@ -156,6 +157,34 @@ public FixedLengthInputStream marshall(ImageProcess imageProcessConf) { } xmlBody.append("" + imageProcessConf.getSourceFileProtectSuffix() + ""); + + if (imageProcessConf.getBucketChannelConfig() != null ) { + List bucketChannelConfigs = imageProcessConf.getBucketChannelConfig(); + xmlBody.append(""); + for (BucketChannelConfig item: bucketChannelConfigs) { + xmlBody.append(""); + xmlBody.append("" + item.getRuleName() + ""); + xmlBody.append("" + item.getRuleRegex()+ ""); + if (item.getFrontContent() != null) { + xmlBody.append("" + item.getFrontContent()+ ""); + } + + if (item.getCreateTime() != null) { + xmlBody.append("" + item.getCreateTime() + ""); + } + + if (item.getLastModifiedTime() != null) { + xmlBody.append("" + item.getLastModifiedTime() + ""); + } + xmlBody.append(""); + } + xmlBody.append(" "); + } + + if (imageProcessConf.getDeleteAllBucketChannel()) { + xmlBody.append(">"); + } + xmlBody.append("" + imageProcessConf.getStyleDelimiters() + ""); if (imageProcessConf.isSupportAtStyle() != null && imageProcessConf.isSupportAtStyle().booleanValue()) { xmlBody.append("Enabled"); @@ -216,7 +245,7 @@ public static final class CreateBucketRequestMarshaller implements RequestMarsha public FixedLengthInputStream marshall(CreateBucketRequest request) { StringBuffer xmlBody = new StringBuffer(); if (request.getLocationConstraint() != null - || request.getStorageClass() != null + || request.getStorageClass() != null || request.getDataRedundancyType() != null) { xmlBody.append(""); if (request.getLocationConstraint() != null) { @@ -245,6 +274,7 @@ public FixedLengthInputStream marshall(BucketReferer br) { StringBuffer xmlBody = new StringBuffer(); xmlBody.append(""); xmlBody.append("" + br.isAllowEmptyReferer() + ""); + xmlBody.append("" + br.isAllowTruncateQueryString() + ""); if (!br.getRefererList().isEmpty()) { xmlBody.append(""); @@ -306,6 +336,9 @@ public FixedLengthInputStream marshall(SetBucketWebsiteRequest request) { if (request.getErrorDocument() != null) { xmlBody.append(""); xmlBody.append("" + request.getErrorDocument() + ""); + if (request.getHttpStatus() != null) { + xmlBody.append("" + request.getHttpStatus() + ""); + } xmlBody.append(""); } @@ -597,7 +630,7 @@ public FixedLengthInputStream marshall(SetBucketLifecycleRequest request) { if (storageTransition.hasIsAccessTime()) { xmlBody.append("" + storageTransition.getIsAccessTime() + ""); } - if (storageTransition.hasReturnToStdWhenVisit()) { + if ("true".equals(storageTransition.getIsAccessTime()) && storageTransition.hasReturnToStdWhenVisit()) { xmlBody.append("" + storageTransition.getReturnToStdWhenVisit() + ""); } @@ -625,7 +658,7 @@ public FixedLengthInputStream marshall(SetBucketLifecycleRequest request) { if (transition.hasIsAccessTime()) { xmlBody.append("" + transition.getIsAccessTime() + ""); } - if (transition.hasReturnToStdWhenVisit()) { + if ("true".equals(transition.getIsAccessTime()) && transition.hasReturnToStdWhenVisit()) { xmlBody.append("" + transition.getReturnToStdWhenVisit() + ""); } @@ -949,6 +982,10 @@ public FixedLengthInputStream marshall(AddBucketReplicationRequest request) { xmlBody.append("" + request.getTargetCloudLocation() + ""); } + if (request.getTransferType() != null) { + xmlBody.append("" + request.getTransferType() + ""); + } + xmlBody.append(""); if (request.isEnableHistoricalObjectReplication()) { xmlBody.append("" + "enabled" + ""); @@ -988,6 +1025,12 @@ public FixedLengthInputStream marshall(AddBucketReplicationRequest request) { xmlBody.append(""); } + if (request.getRtcStatus() != null) { + xmlBody.append(""); + xmlBody.append("" + request.getRtcStatus() + ""); + xmlBody.append(""); + } + xmlBody.append(""); xmlBody.append(""); return stringMarshaller.marshall(xmlBody.toString()); @@ -1863,6 +1906,27 @@ public byte[] marshall(DoMetaQueryRequest input) { } } + public static final class PutBucketRTCRequestMarshaller implements RequestMarshaller2 { + @Override + public byte[] marshall(PutBucketRTCRequest input) { + StringBuffer xmlBody = new StringBuffer(); + xmlBody.append(""); + xmlBody.append(""); + xmlBody.append(""+ input.getStatus() +""); + xmlBody.append(""); + xmlBody.append(""+ input.getRuleID() +""); + xmlBody.append(""); + + byte[] rawData = null; + try { + rawData = xmlBody.toString().getBytes(DEFAULT_CHARSET_NAME); + } catch (UnsupportedEncodingException e) { + throw new ClientException("Unsupported encoding " + e.getMessage(), e); + } + return rawData; + } + } + private static enum EscapedChar { // "\r" RETURN(" "), diff --git a/src/main/java/com/aliyun/oss/internal/OSSBucketOperation.java b/src/main/java/com/aliyun/oss/internal/OSSBucketOperation.java index 56e40bb9..37d11bac 100644 --- a/src/main/java/com/aliyun/oss/internal/OSSBucketOperation.java +++ b/src/main/java/com/aliyun/oss/internal/OSSBucketOperation.java @@ -999,6 +999,28 @@ public List getBucketReplicationLocation(GenericRequest genericRequest) return doOperation(request, getBucketReplicationLocationResponseParser, bucketName, null, true); } + /*** + * New Get Bucket Replication Location + * @param genericRequest + * @throws OSSException + * @throws ClientException + */ + public BucketReplicationLocationResult getBucketReplicationLocationV2(GenericRequest genericRequest) + throws OSSException, ClientException { + assertParameterNotNull(genericRequest, "genericRequest"); + + String bucketName = genericRequest.getBucketName(); + + Map params = new HashMap(); + params.put(RequestParameters.SUBRESOURCE_REPLICATION_LOCATION, null); + + RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()) + .setMethod(HttpMethod.GET).setBucket(bucketName).setParameters(params) + .setOriginalRequest(genericRequest).build(); + + return doOperation(request, getBucketReplicationLocationV2ResponseParser, bucketName, null, true); + } + public AddBucketCnameResult addBucketCname(AddBucketCnameRequest addBucketCnameRequest) throws OSSException, ClientException { assertParameterNotNull(addBucketCnameRequest, "addBucketCnameRequest"); @@ -2120,4 +2142,18 @@ public VoidResult closeMetaQuery(GenericRequest genericRequest) throws OSSExcept return doOperation(request, requestIdResponseParser, bucketName, null, true); } + + public VoidResult putBucketRTC(PutBucketRTCRequest putBucketRTCRequest) throws OSSException, ClientException { + assertParameterNotNull(putBucketRTCRequest, "putBucketRTCRequest"); + String bucketName = putBucketRTCRequest.getBucketName(); + assertParameterNotNull(putBucketRTCRequest.getRuleID(), "ruleID"); + assertParameterNotNull(putBucketRTCRequest.getStatus(), "status"); + Map params = new HashMap(); + params.put(RTC, null); + byte[] rawContent = putBucketRTCRequestMarshaller.marshall(putBucketRTCRequest); + RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()) + .setMethod(HttpMethod.PUT).setBucket(bucketName).setParameters(params) + .setOriginalRequest(putBucketRTCRequest).setInputSize(rawContent.length).setInputStream(new ByteArrayInputStream(rawContent)).build(); + return doOperation(request, requestIdResponseParser, bucketName, null, true); + } } diff --git a/src/main/java/com/aliyun/oss/internal/RequestParameters.java b/src/main/java/com/aliyun/oss/internal/RequestParameters.java index e865d747..32b6e82a 100644 --- a/src/main/java/com/aliyun/oss/internal/RequestParameters.java +++ b/src/main/java/com/aliyun/oss/internal/RequestParameters.java @@ -129,6 +129,7 @@ public final class RequestParameters { public static final String PLAYLIST_NAME = "playlistName"; public static final String SINCE = "since"; public static final String TAIL = "tail"; + public static final String RTC = "rtc"; /* V1 signature params */ public static final String SIGNATURE = "Signature"; diff --git a/src/main/java/com/aliyun/oss/internal/ResponseParsers.java b/src/main/java/com/aliyun/oss/internal/ResponseParsers.java index ce5bc5c4..0c2dea45 100644 --- a/src/main/java/com/aliyun/oss/internal/ResponseParsers.java +++ b/src/main/java/com/aliyun/oss/internal/ResponseParsers.java @@ -141,6 +141,7 @@ public final class ResponseParsers { public static final GetBucketAccessMonitorResponseParser getBucketAccessMonitorResponseParser = new GetBucketAccessMonitorResponseParser(); public static final GetMetaQueryStatusResponseParser getMetaQueryStatusResponseParser = new GetMetaQueryStatusResponseParser(); public static final DoMetaQueryResponseParser doMetaQueryResponseParser = new DoMetaQueryResponseParser(); + public static final GetBucketReplicationLocationV2ResponseParser getBucketReplicationLocationV2ResponseParser = new GetBucketReplicationLocationV2ResponseParser(); public static Long parseLongWithDefault(String defaultValue){ if(defaultValue == null || "".equals(defaultValue)){ @@ -766,6 +767,18 @@ public List parse(ResponseMessage response) throws ResponseParseExceptio } + public static final class GetBucketReplicationLocationV2ResponseParser implements ResponseParser { + + @Override + public BucketReplicationLocationResult parse(ResponseMessage response) throws ResponseParseException { + try { + return parseGetBucketReplicationLocationV2(response.getContent()); + } finally { + safeCloseResponse(response); + } + } + } + public static final class ListObjectsReponseParser implements ResponseParser { @Override @@ -1603,6 +1616,11 @@ public static BucketReferer parseGetBucketReferer(InputStream responseBody) thro Element root = getXmlRootElement(responseBody); boolean allowEmptyReferer = Boolean.valueOf(root.getChildText("AllowEmptyReferer")); + boolean allowTruncateQueryString = true; + if (root.getChild("AllowTruncateQueryString") != null) { + allowTruncateQueryString = Boolean.valueOf(root.getChildText("AllowTruncateQueryString")); + } + List refererList = new ArrayList(); if (root.getChild("RefererList") != null) { Element refererListElem = root.getChild("RefererList"); @@ -1613,7 +1631,7 @@ public static BucketReferer parseGetBucketReferer(InputStream responseBody) thro } } } - return new BucketReferer(allowEmptyReferer, refererList); + return new BucketReferer(allowEmptyReferer, allowTruncateQueryString, refererList); } catch (JDOMParseException e) { throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e); } catch (Exception e) { @@ -2149,11 +2167,45 @@ public static BucketProcess parseGetBucketImageProcessConf(InputStream responseB String sourceFileProtectSuffix = root.getChildText("SourceFileProtectSuffix"); String styleDelimiters = root.getChildText("StyleDelimiters"); + // process bucket channel config + List bucketChannelConfigs = new ArrayList(); + + if (root.getChild("BucketChannelConfig") != null) { + List ruleElements = root.getChild("BucketChannelConfig").getChild("RuleList").getChildren("Rule"); + for(Element item: ruleElements) { + BucketChannelConfig bucketChannelConfig = new BucketChannelConfig(); + if (item.getChildText("RuleName") != null) { + bucketChannelConfig.setRuleName(item.getChildText("RuleName")); + } + + if (item.getChildText("RuleRegex") != null) { + bucketChannelConfig.setRuleRegex(item.getChildText("RuleRegex")); + } + + if (item.getChildText("FrontContent") != null) { + bucketChannelConfig.setFrontContent(item.getChildText("FrontContent")); + } + + if (item.getChildText("CreateTime") != null) { + bucketChannelConfig.setCreateTime(item.getChildText("CreateTime")); + } + + if (item.getChildText("LastModifiedTime") != null) { + bucketChannelConfig.setLastModifiedTime(item.getChildText("LastModifiedTime")); + } + + bucketChannelConfigs.add(bucketChannelConfig); + } + } + ImageProcess imageProcess = new ImageProcess(compliedHost, sourceFileProtect, sourceFileProtectSuffix, styleDelimiters); if (root.getChildText("Version") != null) { imageProcess.setVersion(Integer.parseInt(root.getChildText("Version"))); } + if (root.getChild("BucketChannelConfig") != null) { + imageProcess.setBucketChannelConfig(bucketChannelConfigs); + } return new BucketProcess(imageProcess); } catch (JDOMParseException e) { @@ -2186,6 +2238,9 @@ public static BucketWebsiteResult parseBucketWebsite(InputStream responseBody) t } if (root.getChild("ErrorDocument") != null) { result.setErrorDocument(root.getChild("ErrorDocument").getChildText("Key")); + if (root.getChild("ErrorDocument").getChild("HttpStatus") != null) { + result.setHttpStatus(root.getChild("ErrorDocument").getChildText("HttpStatus")); + } } if (root.getChild("RoutingRules") != null) { List ruleElements = root.getChild("RoutingRules").getChildren("RoutingRule"); @@ -2569,6 +2624,10 @@ public static List parseGetBucketReplication(InputStream respon repRule.setTargetBucketName(destination.getChildText("Bucket")); repRule.setTargetBucketLocation(destination.getChildText("Location")); + if (destination.getChild("TransferType") != null) { + repRule.setTransferType(destination.getChildText("TransferType")); + } + repRule.setTargetCloud(destination.getChildText("Cloud")); repRule.setTargetCloudLocation(destination.getChildText("CloudLocation")); @@ -2613,6 +2672,9 @@ public static List parseGetBucketReplication(InputStream respon if (ruleElem.getChild("Source") != null){ repRule.setSourceBucketLocation(ruleElem.getChild("Source").getChildText("Location")); } + if (ruleElem.getChild("RTC") != null) { + repRule.setRtcStatus(ruleElem.getChild("RTC").getChildText("Status")); + } repRules.add(repRule); } @@ -2693,6 +2755,60 @@ public static List parseGetBucketReplicationLocation(InputStream respons } } + public static BucketReplicationLocationResult parseGetBucketReplicationLocationV2(InputStream responseBody) + throws ResponseParseException { + try { + BucketReplicationLocationResult bucketReplicationLocationResult = new BucketReplicationLocationResult(); + + List locationTransferTypeConstraint = new ArrayList(); + List locationRtcList = new ArrayList(); + + Element root = getXmlRootElement(responseBody); + + List locationList = new ArrayList(); + List locElements = root.getChildren("Location"); + + for (Element locElem : locElements) { + locationList.add(locElem.getText()); + } + + if (root.getChild("LocationTransferTypeConstraint") != null ) { + List locationTransferTypes = root.getChild("LocationTransferTypeConstraint").getChildren("LocationTransferType"); + for (Element e: locationTransferTypes ) { + LocationTransferType locationTransferType = new LocationTransferType(); + locationTransferType.setRegion(e.getChildText("Location")); + List transferTypes = new ArrayList(); + List transferTypesElement = new ArrayList(); + if (e.getChild("TransferTypes") != null) { + transferTypesElement = e.getChild("TransferTypes").getChildren("Type"); + for (Element p :transferTypesElement) { + String typeContent = p.getText(); + transferTypes.add(typeContent); + } + } + locationTransferType.setTransferTypes(transferTypes); + locationTransferTypeConstraint.add(locationTransferType); + } + } + + if (root.getChild("LocationRTCConstraint") != null) { + List locationRtcElements = root.getChild("LocationRTCConstraint").getChildren("Location"); + for (Element locationRtcElem : locationRtcElements) { + locationRtcList.add(locationRtcElem.getText()); + } + } + + bucketReplicationLocationResult.setLocations(locationList); + bucketReplicationLocationResult.setLocationTransferTypeConstraint(locationTransferTypeConstraint); + bucketReplicationLocationResult.setLocationRTCConstraint(locationRtcList); + return bucketReplicationLocationResult; + } catch (JDOMParseException e) { + throw new ResponseParseException(e.getPartialDocument() + ": " + e.getMessage(), e); + } catch (Exception e) { + throw new ResponseParseException(e.getMessage(), e); + } + } + /** * Unmarshall get bucket info response body to bucket info. */ diff --git a/src/main/java/com/aliyun/oss/internal/SignParameters.java b/src/main/java/com/aliyun/oss/internal/SignParameters.java index 8f82f1ea..fcc3c10e 100644 --- a/src/main/java/com/aliyun/oss/internal/SignParameters.java +++ b/src/main/java/com/aliyun/oss/internal/SignParameters.java @@ -43,6 +43,6 @@ public class SignParameters { SUBRESOURCE_WORM_ID, SUBRESOURCE_WORM_EXTEND, SUBRESOURCE_CALLBACK, SUBRESOURCE_CALLBACK_VAR, SUBRESOURCE_DIR, SUBRESOURCE_RENAME, SUBRESOURCE_DIR_DELETE, SUBRESOURCE_TRANSFER_ACCELERATION, X_OSS_AC_SOURCE_IP, X_OSS_AC_SUBNET_MASK, X_OSS_AC_VPC_ID, X_OSS_AC_FORWARD_ALLOW, META_QUERY, SUBRESOURCE_RESOURCE_GROUP, - SUBRESOURCE_REGION_LIST}); + SUBRESOURCE_REGION_LIST, RTC}); } diff --git a/src/main/java/com/aliyun/oss/model/AddBucketReplicationRequest.java b/src/main/java/com/aliyun/oss/model/AddBucketReplicationRequest.java index a75517cb..42c528f9 100644 --- a/src/main/java/com/aliyun/oss/model/AddBucketReplicationRequest.java +++ b/src/main/java/com/aliyun/oss/model/AddBucketReplicationRequest.java @@ -184,6 +184,21 @@ public void setSourceBucketLocation(String sourceBucketLocation) { this.sourceBucketLocation = sourceBucketLocation; } + public RtcStatus getRtcStatus() { + return rtcStatus; + } + public void setRtcStatus(RtcStatus rtcStatus) { + this.rtcStatus = rtcStatus; + } + + public String getTransferType() { + return transferType; + } + + public void setTransferType(String transferType) { + this.transferType = transferType; + } + public static final String DISABLED = "Disabled"; public static final String ENABLED = "Enabled"; @@ -199,5 +214,6 @@ public void setSourceBucketLocation(String sourceBucketLocation) { private String replicaKmsKeyID; private String sseKmsEncryptedObjectsStatus; private String sourceBucketLocation; - + private RtcStatus rtcStatus; + private String transferType; } diff --git a/src/main/java/com/aliyun/oss/model/BucketChannelConfig.java b/src/main/java/com/aliyun/oss/model/BucketChannelConfig.java new file mode 100644 index 00000000..f034a016 --- /dev/null +++ b/src/main/java/com/aliyun/oss/model/BucketChannelConfig.java @@ -0,0 +1,56 @@ +package com.aliyun.oss.model; + +import java.io.Serializable; + +public class BucketChannelConfig implements Serializable { + //规则名 + private String ruleName; + //经过urlSafeBase64编码的正则表达式 + private String ruleRegex; + // 保存前端的数据,reserved + private String frontContent; + // GMT 时间转化为字符串 + private String createTime; + // GMT 时间转化为字符串 + private String lastModifiedTime; + + public String getRuleName() { + return ruleName; + } + + public void setRuleName(String ruleName) { + this.ruleName = ruleName; + } + + public String getRuleRegex() { + return ruleRegex; + } + + public void setRuleRegex(String ruleRegex) { + this.ruleRegex = ruleRegex; + } + + public String getFrontContent() { + return frontContent; + } + + public void setFrontContent(String frontContent) { + this.frontContent = frontContent; + } + + public String getCreateTime() { + return createTime; + } + + public void setCreateTime(String createTime) { + this.createTime = createTime; + } + + public String getLastModifiedTime() { + return lastModifiedTime; + } + + public void setLastModifiedTime(String lastModifiedTime) { + this.lastModifiedTime = lastModifiedTime; + } +} diff --git a/src/main/java/com/aliyun/oss/model/BucketReferer.java b/src/main/java/com/aliyun/oss/model/BucketReferer.java index 5143b566..f2a55bd9 100644 --- a/src/main/java/com/aliyun/oss/model/BucketReferer.java +++ b/src/main/java/com/aliyun/oss/model/BucketReferer.java @@ -33,6 +33,7 @@ */ public class BucketReferer extends GenericResult { private boolean allowEmptyReferer = true; + private boolean allowTruncateQueryString = true; private List refererList = new ArrayList(); public BucketReferer() { @@ -44,6 +45,12 @@ public BucketReferer(boolean allowEmptyReferer, List refererList) { setRefererList(refererList); } + public BucketReferer(boolean allowEmptyReferer, boolean allowTruncateQueryString, List refererList) { + setAllowEmptyReferer(allowEmptyReferer); + setAllowTruncateQueryString(allowTruncateQueryString); + setRefererList(refererList); + } + @Deprecated public boolean allowEmpty() { return this.allowEmptyReferer; @@ -71,4 +78,12 @@ public void setRefererList(List refererList) { public void clearRefererList() { this.refererList.clear(); } + + public boolean isAllowTruncateQueryString() { + return allowTruncateQueryString; + } + + public void setAllowTruncateQueryString(boolean allowTruncateQueryString) { + this.allowTruncateQueryString = allowTruncateQueryString; + } } diff --git a/src/main/java/com/aliyun/oss/model/BucketReplicationLocationResult.java b/src/main/java/com/aliyun/oss/model/BucketReplicationLocationResult.java new file mode 100644 index 00000000..0e2edbff --- /dev/null +++ b/src/main/java/com/aliyun/oss/model/BucketReplicationLocationResult.java @@ -0,0 +1,36 @@ +package com.aliyun.oss.model; + +import java.util.List; + +public class BucketReplicationLocationResult extends GenericResult { + + private List locations; + + private List locationTransferTypeConstraint; + + private List locationRTCConstraint; + + public List getLocations() { + return locations; + } + + public void setLocations(List locations) { + this.locations = locations; + } + + public List getLocationTransferTypeConstraint() { + return locationTransferTypeConstraint; + } + + public void setLocationTransferTypeConstraint(List locationTransferTypeConstraint) { + this.locationTransferTypeConstraint = locationTransferTypeConstraint; + } + + public List getLocationRTCConstraint() { + return locationRTCConstraint; + } + + public void setLocationRTCConstraint(List locationRTCConstraint) { + this.locationRTCConstraint = locationRTCConstraint; + } +} diff --git a/src/main/java/com/aliyun/oss/model/BucketWebsiteResult.java b/src/main/java/com/aliyun/oss/model/BucketWebsiteResult.java index f8c66bcf..4a9b4bfb 100644 --- a/src/main/java/com/aliyun/oss/model/BucketWebsiteResult.java +++ b/src/main/java/com/aliyun/oss/model/BucketWebsiteResult.java @@ -28,6 +28,7 @@ public class BucketWebsiteResult extends GenericResult { private boolean supportSubDir; private String subDirType; private List routingRules; + private String httpStatus; public String getIndexDocument() { return indexDocument; @@ -72,4 +73,12 @@ public String getSubDirType() { public void setSubDirType(String subDirType) { this.subDirType = subDirType; } + + public String getHttpStatus() { + return httpStatus; + } + + public void setHttpStatus(String httpStatus) { + this.httpStatus = httpStatus; + } } diff --git a/src/main/java/com/aliyun/oss/model/ImageProcess.java b/src/main/java/com/aliyun/oss/model/ImageProcess.java index 5f2f3229..8b18ea5c 100644 --- a/src/main/java/com/aliyun/oss/model/ImageProcess.java +++ b/src/main/java/com/aliyun/oss/model/ImageProcess.java @@ -19,6 +19,8 @@ package com.aliyun.oss.model; +import java.util.List; + public class ImageProcess { public ImageProcess(String compliedHost, Boolean sourceFileProtect, String sourceFileProtectSuffix, @@ -87,6 +89,22 @@ public void setSupportAtStyle(Boolean supportAtStyle) { this.supportAtStyle = supportAtStyle; } + public List getBucketChannelConfig() { + return bucketChannelConfig; + } + + public void setBucketChannelConfig(List bucketChannelConfig) { + this.bucketChannelConfig = bucketChannelConfig; + } + + public Boolean getDeleteAllBucketChannel() { + return isDeleteAllBucketChannel; + } + + public void setDeleteAllBucketChannel(Boolean deleteAllBucketChannel) { + isDeleteAllBucketChannel = deleteAllBucketChannel; + } + // Img表示设置的样式分隔符,只有Img能用;Both表示oss也能用Img的样式分隔符 private String compliedHost; // 是否开启原图保护 @@ -99,5 +117,9 @@ public void setSupportAtStyle(Boolean supportAtStyle) { private Integer version; // 用户是否能够通过OSS域名使用老版图片处理接口,@格式。默认Disabled private Boolean supportAtStyle; + // 启用原图保护新规则 + private List bucketChannelConfig; + // 不传 bucketchannelconfig保持原值, 传入覆盖 + private Boolean isDeleteAllBucketChannel; } diff --git a/src/main/java/com/aliyun/oss/model/LocationTransferType.java b/src/main/java/com/aliyun/oss/model/LocationTransferType.java new file mode 100644 index 00000000..4a86b2e8 --- /dev/null +++ b/src/main/java/com/aliyun/oss/model/LocationTransferType.java @@ -0,0 +1,25 @@ +package com.aliyun.oss.model; + +import java.util.List; + +public class LocationTransferType extends GenericResult { + + private String region; + private List transferTypes; + + public String getRegion() { + return region; + } + + public void setRegion(String region) { + this.region = region; + } + + public List getTransferTypes() { + return transferTypes; + } + + public void setTransferTypes(List transferTypes) { + this.transferTypes = transferTypes; + } +} \ No newline at end of file diff --git a/src/main/java/com/aliyun/oss/model/PutBucketRTCRequest.java b/src/main/java/com/aliyun/oss/model/PutBucketRTCRequest.java new file mode 100644 index 00000000..fdb02819 --- /dev/null +++ b/src/main/java/com/aliyun/oss/model/PutBucketRTCRequest.java @@ -0,0 +1,23 @@ +package com.aliyun.oss.model; + +public class PutBucketRTCRequest extends GenericRequest { + private RtcStatus status; + private String ruleID; + public PutBucketRTCRequest(String bucketName, String ruleID, RtcStatus status) { + super(bucketName); + this.ruleID = ruleID; + this.status = status; + } + public RtcStatus getStatus() { + return status; + } + public void setStatus(RtcStatus status) { + this.status = status; + } + public String getRuleID() { + return ruleID; + } + public void setRuleID(String ruleID) { + this.ruleID = ruleID; + } +} diff --git a/src/main/java/com/aliyun/oss/model/ReplicationRule.java b/src/main/java/com/aliyun/oss/model/ReplicationRule.java index a976b935..602d9dee 100644 --- a/src/main/java/com/aliyun/oss/model/ReplicationRule.java +++ b/src/main/java/com/aliyun/oss/model/ReplicationRule.java @@ -136,6 +136,22 @@ public void setSourceBucketLocation(String sourceBucketLocation) { this.sourceBucketLocation = sourceBucketLocation; } + public String getRtcStatus() { + return rtcStatus; + } + + public void setRtcStatus(String rtcStatus) { + this.rtcStatus = rtcStatus; + } + + public String getTransferType() { + return transferType; + } + + public void setTransferType(String transferType) { + this.transferType = transferType; + } + private String replicationRuleID; private ReplicationStatus replicationStatus; private String targetBucketName; @@ -149,5 +165,6 @@ public void setSourceBucketLocation(String sourceBucketLocation) { private String replicaKmsKeyID; private String sseKmsEncryptedObjectsStatus; private String sourceBucketLocation; - + private String rtcStatus; + private String transferType; } diff --git a/src/main/java/com/aliyun/oss/model/RtcStatus.java b/src/main/java/com/aliyun/oss/model/RtcStatus.java new file mode 100644 index 00000000..963f0d42 --- /dev/null +++ b/src/main/java/com/aliyun/oss/model/RtcStatus.java @@ -0,0 +1,34 @@ +package com.aliyun.oss.model; + +public enum RtcStatus { + /** + * Start RTC service. + */ + Enabled("enabled"), + /** + * Turn off RTC service. + */ + Disabled("disabled"), + /** + * Unknown + */ + Unknown("Unknown"); + + + private String statusString; + private RtcStatus(String rtcStatusString) { + this.statusString = rtcStatusString; + } + @Override + public String toString() { + return this.statusString; + } + public static RtcStatus parse(String rtcStatus) { + for (RtcStatus status : RtcStatus.values()) { + if (status.toString().equals(rtcStatus)) { + return status; + } + } + return Unknown; + } +} \ No newline at end of file diff --git a/src/main/java/com/aliyun/oss/model/SetBucketWebsiteRequest.java b/src/main/java/com/aliyun/oss/model/SetBucketWebsiteRequest.java index 6960f477..e2420ed4 100644 --- a/src/main/java/com/aliyun/oss/model/SetBucketWebsiteRequest.java +++ b/src/main/java/com/aliyun/oss/model/SetBucketWebsiteRequest.java @@ -28,6 +28,7 @@ public class SetBucketWebsiteRequest extends GenericRequest { private String errorDocument; private boolean supportSubDir; private SubDirType subDirType; + private String httpStatus; private List routingRules = new ArrayList(); @@ -88,4 +89,11 @@ public SubDirType getSubDirType() { public void setSubDirType(SubDirType subDirType) { this.subDirType = subDirType; } + public String getHttpStatus() { + return httpStatus; + } + + public void setHttpStatus(String httpStatus) { + this.httpStatus = httpStatus; + } } diff --git a/src/samples/BucketRTCSample.java b/src/samples/BucketRTCSample.java new file mode 100644 index 00000000..2d532a73 --- /dev/null +++ b/src/samples/BucketRTCSample.java @@ -0,0 +1,31 @@ +package samples; +import com.aliyun.oss.ClientException; +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import com.aliyun.oss.OSSException; +import com.aliyun.oss.model.*; +public class BucketRTCSample { + private static String endpoint = "*** Provide OSS endpoint ***"; + private static String accessKeyId = "*** Provide your AccessKeyId ***"; + private static String accessKeySecret = "*** Provide your AccessKeySecret ***"; + private static String bucketName = "*** Provide bucket name ***"; + public static void main(String[] args) { + OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + try { + String ruleId = "D2AG***D23DR4Q234D"; + // Start RTC service + ossClient.putBucketRTC(new PutBucketRTCRequest(bucketName, ruleId, RtcStatus.Enabled)); + } catch (OSSException oe) { + System.out.println("Error Message: " + oe.getErrorMessage()); + System.out.println("Error Code: " + oe.getErrorCode()); + System.out.println("Request ID: " + oe.getRequestId()); + System.out.println("Host ID: " + oe.getHostId()); + } catch (ClientException ce) { + System.out.println("Error Message: " + ce.getMessage()); + } finally { + if(ossClient != null){ + ossClient.shutdown(); + } + } + } +} diff --git a/src/test/java/com/aliyun/oss/common/parser/RequestMarshallersTest.java b/src/test/java/com/aliyun/oss/common/parser/RequestMarshallersTest.java index d79d8e84..b9cff0e8 100644 --- a/src/test/java/com/aliyun/oss/common/parser/RequestMarshallersTest.java +++ b/src/test/java/com/aliyun/oss/common/parser/RequestMarshallersTest.java @@ -1413,4 +1413,62 @@ public void testPutLifeCycleRequestMarshaller() { Assert.assertEquals("key2", root.getChild("Rule").getChild("Filter").getChildren("Not").get(1).getChild("Tag").getChildText("Key")); Assert.assertEquals("value2", root.getChild("Rule").getChild("Filter").getChildren("Not").get(1).getChild("Tag").getChildText("Value")); } + + @Test + public void testPutBucketRTCRequestMarshaller() { + PutBucketRTCRequest request = new PutBucketRTCRequest("bucket", "ruleId-1", RtcStatus.Enabled); + byte[] data = putBucketRTCRequestMarshaller.marshall(request); + ByteArrayInputStream is = new ByteArrayInputStream(data); + SAXBuilder builder = new SAXBuilder(); + Document doc = null; + try { + doc = builder.build(is); + } catch (JDOMException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + Element root = doc.getRootElement(); + Assert.assertEquals("ruleId-1", root.getChildText("ID")); + Assert.assertEquals("enabled", root.getChild("RTC").getChildText("Status")); + } + @Test + public void testAddBucketReplicationRequestMarshallerWithRTC() { + String bucketName = "alicloud-bucket"; + String targetBucketName = "alicloud-targetBucketName"; + String targetBucketLocation = "alicloud-targetBucketLocation"; + String targetCloud = "testTargetCloud"; + String targetCloudLocation = "testTargetCloudLocation"; + RtcStatus rtcStatus = RtcStatus.Disabled; + AddBucketReplicationRequest addBucketReplicationRequest = new AddBucketReplicationRequest(bucketName); + addBucketReplicationRequest.setTargetBucketName(targetBucketName); + addBucketReplicationRequest.setTargetBucketLocation(targetBucketLocation); + addBucketReplicationRequest.setTargetCloud(targetCloud); + addBucketReplicationRequest.setTargetCloudLocation(targetCloudLocation); + addBucketReplicationRequest.setRtcStatus(rtcStatus); + FixedLengthInputStream is = addBucketReplicationRequestMarshaller.marshall(addBucketReplicationRequest); + SAXBuilder builder = new SAXBuilder(); + Document doc = null; + try { + doc = builder.build(is); + } catch (JDOMException e) { + e.printStackTrace(); + } catch (IOException e) { + e.printStackTrace(); + } + Element root = doc.getRootElement(); + Element ruleElems = root.getChild("Rule"); + Element destination = ruleElems.getChild("Destination"); + String aTargetBucketName = destination.getChildText("Bucket"); + String aTargetLocation = destination.getChildText("Location"); + String aTargetCloud = destination.getChildText("Cloud"); + String aTargetCloudLocation = destination.getChildText("CloudLocation"); + String aRtcStatus = ruleElems.getChild("RTC").getChildText("Status"); + Assert.assertEquals(targetBucketName, aTargetBucketName); + Assert.assertEquals(targetBucketLocation, aTargetLocation); + Assert.assertNull(aTargetCloud); + Assert.assertNull(aTargetCloudLocation); + Assert.assertEquals(rtcStatus.toString(), aRtcStatus); + } + } diff --git a/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java b/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java index ae594d59..0e944b6d 100644 --- a/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java +++ b/src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java @@ -5140,4 +5140,114 @@ public void testParseListVersionsWithRestoreInfo() { Assert.assertEquals("object-with-special-restore", result.getVersionSummaries().get(0).getKey()); Assert.assertEquals("ongoing-request=\"true\"", result.getVersionSummaries().get(0).getRestoreInfo()); } + + @Test + public void testBucketReplicationResponseParserWithRTC() { + String respBody = "" + + "\n" + + " \n" + + " \n" + + " enabling\n" + + " \n" + + " \n" + + " prefix_1\n" + + " prefix_2\n" + + " \n" + + " doing\n" + + " ALL,PUT\n" + + " \n" + + " Target Bucket Name\n" + + " oss-cn-hangzhou\n" + + " oss_acc\n" + + " \n" + + " enabled\n" + + " \n" + + ""; + + InputStream instream = null; + try { + instream = new ByteArrayInputStream(respBody.getBytes("utf-8")); + } catch (UnsupportedEncodingException e) { + Assert.fail("UnsupportedEncodingException"); + } + + List rules = null; + try { + ResponseMessage response = new ResponseMessage(null); + response.setContent(instream); + rules = ResponseParsers.parseGetBucketReplication(instream); + } catch (ResponseParseException e) { + Assert.fail("parse delete directory response body fail!"); + } + ReplicationRule rule = rules.get(0); + Assert.assertEquals("enabling", rule.getRtcStatus().toString()); + Assert.assertEquals("prefix_1", rule.getObjectPrefixList().get(0)); + Assert.assertEquals("prefix_2", rule.getObjectPrefixList().get(1)); + Assert.assertEquals(AddBucketReplicationRequest.ReplicationAction.ALL, rule.getReplicationActionList().get(0)); + Assert.assertEquals(AddBucketReplicationRequest.ReplicationAction.PUT, rule.getReplicationActionList().get(1)); + Assert.assertEquals("Target Bucket Name", rule.getTargetBucketName()); + Assert.assertEquals("oss-cn-hangzhou", rule.getTargetBucketLocation()); + Assert.assertEquals("oss_acc", rule.getTransferType()); + Assert.assertEquals(true, rule.isEnableHistoricalObjectReplication()); + } + + @Test + public void testGetBucketReplicationLocationV2ResponseParser() { + String respBody = null; + InputStream instream = null; + + respBody = "" + + "\n" + + " oss-cn-beijing\n" + + " oss-cn-qingdao\n" + + " oss-cn-shenzhen\n" + + " oss-cn-hongkong\n" + + " oss-us-west-1\n" + + "\t\n" + + " oss-cn-qingdao\n" + + " oss-cn-hongkong\n" + + " \n" + + " \n" + + " \n" + + " oss-cn-hongkong\n" + + " \n" + + " oss_acc \n" + + " \n" + + " \n" + + " \n" + + " oss-us-west-1\n" + + " \n" + + " oss_acc\n" + + " \n" + + " \n" + + " \n" + + " "; + + try { + instream = new ByteArrayInputStream(respBody.getBytes("utf-8")); + } catch (UnsupportedEncodingException e) { + Assert.fail("UnsupportedEncodingException"); + } + + try { + ResponseMessage responseMessage = new ResponseMessage(null);; + responseMessage.setContent(instream); + ResponseParsers.GetBucketReplicationLocationV2ResponseParser parser = new ResponseParsers.GetBucketReplicationLocationV2ResponseParser(); + BucketReplicationLocationResult result = parser.parse(responseMessage); + Assert.assertEquals(result.getLocations().get(0), "oss-cn-beijing"); + Assert.assertEquals(result.getLocations().get(1), "oss-cn-qingdao"); + Assert.assertEquals(result.getLocations().get(2), "oss-cn-shenzhen"); + Assert.assertEquals(result.getLocations().get(3), "oss-cn-hongkong"); + Assert.assertEquals(result.getLocations().get(4), "oss-us-west-1"); + + Assert.assertEquals(result.getLocationTransferTypeConstraint().get(0).getRegion(), "oss-cn-hongkong"); + Assert.assertEquals(result.getLocationTransferTypeConstraint().get(0).getTransferTypes().get(0), "oss_acc"); + Assert.assertEquals(result.getLocationTransferTypeConstraint().get(1).getRegion(), "oss-us-west-1"); + Assert.assertEquals(result.getLocationTransferTypeConstraint().get(1).getTransferTypes().get(0), "oss_acc"); + Assert.assertEquals(result.getLocationRTCConstraint().get(0), "oss-cn-qingdao"); + Assert.assertEquals(result.getLocationRTCConstraint().get(1), "oss-cn-hongkong"); + } catch (ResponseParseException e) { + Assert.fail("UnsupportedEncodingException"); + } + } } diff --git a/src/test/java/com/aliyun/oss/integrationtests/BucketRefererOnlyTruncateTest.java b/src/test/java/com/aliyun/oss/integrationtests/BucketRefererOnlyTruncateTest.java new file mode 100644 index 00000000..cfac0c41 --- /dev/null +++ b/src/test/java/com/aliyun/oss/integrationtests/BucketRefererOnlyTruncateTest.java @@ -0,0 +1,52 @@ +package com.aliyun.oss.integrationtests; + +import com.aliyun.oss.OSS; +import com.aliyun.oss.OSSClientBuilder; +import com.aliyun.oss.model.BucketReferer; +import org.junit.Assert; + +import java.util.ArrayList; +import java.util.List; + +public class BucketRefererOnlyTruncateTest { + public static OSS initOssClient() { + String endpoint = "http://oss-us-west-1.aliyuncs.com"; + String accessKeyId = ""; + String accessKeySecret = ""; + OSS client = new OSSClientBuilder().build(endpoint, accessKeyId, accessKeySecret); + return client; + } + + public static void destroyOssClient(OSS client) { + client.shutdown(); + } + + public static void main(String[] args) { + String bucketName = "luanzhi-4-mx"; + OSS client = initOssClient(); + + BucketReferer bucketReferer = client.getBucketReferer(bucketName); + + String referer0 = "http://www.aliyun.com"; + String referer1 = "https://www.aliyun.com"; + String referer2 = "http://www.*.com"; + String referer3 = "https://www.?.aliyuncs.com"; + + // Set non-empty referer list + BucketReferer r = new BucketReferer(); + r.setAllowTruncateQueryString(false); + List refererList = new ArrayList(); + refererList.add(referer0); + refererList.add(referer1); + refererList.add(referer2); + refererList.add(referer3); + r.setRefererList(refererList); + client.setBucketReferer(bucketName, r); + + BucketReferer bucketReferer001 = client.getBucketReferer(bucketName); + Assert.assertEquals(bucketReferer001.isAllowEmptyReferer(), true); + Assert.assertEquals(bucketReferer001.isAllowTruncateQueryString(), false); + + System.out.println("test over"); + } +} diff --git a/src/test/java/com/aliyun/oss/integrationtests/BucketRtcTest.java b/src/test/java/com/aliyun/oss/integrationtests/BucketRtcTest.java new file mode 100644 index 00000000..b5ad6318 --- /dev/null +++ b/src/test/java/com/aliyun/oss/integrationtests/BucketRtcTest.java @@ -0,0 +1,47 @@ +package com.aliyun.oss.integrationtests; + +import com.aliyun.oss.model.*; +import junit.framework.Assert; +import org.junit.Test; +import java.util.List; +public class BucketRtcTest extends TestBase { + @Test + public void testNormalPutRtcStatus() { + final String bucketName = "test-bucket-rtc2"; + final String repRuleID = "~`!@#$%^&*()-_+=|\\[]{}<>:;\"',./?"; + final String targetBucketName = "test-bucket-rtc-target2"; + final String targetBucketLoc = "oss-cn-hangzhou"; + try { + if(!ossClient.doesBucketExist(bucketName)){ + ossClient.createBucket(bucketName); + } + if(!ossClient.doesBucketExist(targetBucketName)){ + ossClient.createBucket(targetBucketName); + } + //开启区域复制 + AddBucketReplicationRequest request = new AddBucketReplicationRequest(bucketName); + request.setReplicationRuleID(repRuleID); + request.setTargetBucketName(targetBucketName); + request.setTargetBucketLocation(targetBucketLoc); + request.setEnableHistoricalObjectReplication(false); + request.setRtcStatus(RtcStatus.Enabled); + ossClient.addBucketReplication(request); + //获取区域复制信息 + List rules = ossClient.getBucketReplication(bucketName); + Assert.assertEquals(rules.size(), 1); + Assert.assertEquals(rules.get(0).getRtcStatus(), RtcStatus.Enabled); + //开启rtc + ossClient.putBucketRTC(new PutBucketRTCRequest(bucketName, rules.get(0).getReplicationRuleID(), RtcStatus.Disabled)); + //查看rtc配置是否更改 + List rules2 = ossClient.getBucketReplication(bucketName); + Assert.assertEquals(rules2.size(), 1); + Assert.assertEquals(rules2.get(0).getRtcStatus(), RtcStatus.Disabled); + } catch (Exception e) { + e.printStackTrace(); + Assert.fail(e.getMessage()); + } finally { + ossClient.deleteBucket(bucketName); + ossClient.deleteBucket(targetBucketName); + } + } +} \ No newline at end of file