Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
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
49 changes: 49 additions & 0 deletions src/main/java/com/aliyun/oss/OSS.java
Original file line number Diff line number Diff line change
Expand Up @@ -5101,4 +5101,53 @@ public UdfApplicationLog getUdfApplicationLog(GetUdfApplicationLogRequest getUdf
* If any errors occurred in OSS while processing the request.
*/
VoidResult closeMetaQuery(String bucketName) throws OSSException, ClientException;

/**
* Sets the callback policy on the {@link Bucket} instance.
*
* @param setBucketCallbackPolicyRequest
* {@link SetBucketCallbackPolicyRequest} instance that has bucket
* information as well as policy information.
*
* @return A {@link VoidResult} instance wrapped void return and
* contains some basic response options, such as requestId.
*
* @throws OSSException
* If any errors are encountered in the client while making the
* request or handling the response.
* @throws ClientException
* If any errors occurred in OSS while processing the request.
*/
public VoidResult setBucketCallbackPolicy(SetBucketCallbackPolicyRequest setBucketCallbackPolicyRequest) throws OSSException, ClientException;

/**
* Gets callback policy of the {@link Bucket} instance.
*
* @param genericRequest
* {@link GenericRequest} instance that has the bucket name.
* @return The policy's content in {@link InputStream}.
* @throws OSSException
* If any errors are encountered in the client while making the
* request or handling the response.
* @throws ClientException
* If any errors occurred in OSS while processing the request.
*/
public GetBucketCallbackPolicyResult getBucketCallbackPolicy(GenericRequest genericRequest) throws OSSException, ClientException;

/**
* Delete callback policy of the {@link Bucket} instance.
*
* @param genericRequest
* {@link GenericRequest} instance that has the bucket name.
*
* @return A {@link VoidResult} instance wrapped void return and
* contains some basic response options, such as requestId.
*
* @throws OSSException
* If any errors are encountered in the client while making the
* request or handling the response.
* @throws ClientException
* If any errors occurred in OSS while processing the request.
*/
public VoidResult deleteBucketCallbackPolicy(GenericRequest genericRequest) throws OSSException, ClientException;
}
15 changes: 15 additions & 0 deletions src/main/java/com/aliyun/oss/OSSClient.java
Original file line number Diff line number Diff line change
Expand Up @@ -1957,6 +1957,21 @@ public VoidResult closeMetaQuery(String bucketName) throws OSSException, ClientE
return this.bucketOperation.closeMetaQuery(new GenericRequest(bucketName));
}

@Override
public VoidResult setBucketCallbackPolicy(SetBucketCallbackPolicyRequest setBucketCallbackPolicyRequest) throws OSSException, ClientException {
return this.bucketOperation.setBucketCallbackPolicy(setBucketCallbackPolicyRequest);
}

@Override
public GetBucketCallbackPolicyResult getBucketCallbackPolicy(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.getBucketCallbackPolicy(genericRequest);
}

@Override
public VoidResult deleteBucketCallbackPolicy(GenericRequest genericRequest) throws OSSException, ClientException {
return this.bucketOperation.deleteBucketCallbackPolicy(genericRequest);
}

@Override
public void shutdown() {
try {
Expand Down
38 changes: 38 additions & 0 deletions src/main/java/com/aliyun/oss/common/parser/RequestMarshallers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 SetBucketCallbackPolicyRequestMarshaller setBucketCallbackPolicyRequestMarshaller = new SetBucketCallbackPolicyRequestMarshaller();

public interface RequestMarshaller<R> extends Marshaller<FixedLengthInputStream, R> {

Expand Down Expand Up @@ -1863,6 +1864,43 @@ public byte[] marshall(DoMetaQueryRequest input) {
}
}

public static final class SetBucketCallbackPolicyRequestMarshaller implements RequestMarshaller2<SetBucketCallbackPolicyRequest> {

@Override
public byte[] marshall(SetBucketCallbackPolicyRequest request) {
StringBuffer xmlBody = new StringBuffer();
xmlBody.append("<BucketCallbackPolicy>");

if(request.getPolicyCallbackItems() != null && request.getPolicyCallbackItems().size() > 0){
for(PolicyCallbackItem policy : request.getPolicyCallbackItems()){
xmlBody.append("<PolicyItem>");
if(!StringUtils.isNullOrEmpty(policy.getPolicyName())){
xmlBody.append("<PolicyName>"+ policy.getPolicyName() +"</PolicyName>");
}
if(!StringUtils.isNullOrEmpty(policy.getCallback())){
xmlBody.append("<Callback>"+ policy.getCallback() +"</Callback>");
}
if(StringUtils.isNullOrEmpty(policy.getCallbackVar())){
xmlBody.append("<CallbackVar></CallbackVar>");
} else {
xmlBody.append("<CallbackVar>"+ policy.getCallbackVar() +"</CallbackVar>");
}

xmlBody.append("</PolicyItem>");
}
}
xmlBody.append("</BucketCallbackPolicy>");

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("&#x000D;"),
Expand Down
57 changes: 57 additions & 0 deletions src/main/java/com/aliyun/oss/internal/OSSBucketOperation.java
Original file line number Diff line number Diff line change
Expand Up @@ -2120,4 +2120,61 @@ public VoidResult closeMetaQuery(GenericRequest genericRequest) throws OSSExcept

return doOperation(request, requestIdResponseParser, bucketName, null, true);
}

public VoidResult setBucketCallbackPolicy(SetBucketCallbackPolicyRequest setBucketCallbackPolicyRequest) throws OSSException, ClientException {

assertParameterNotNull(setBucketCallbackPolicyRequest, "setBucketCallbackPolicyRequest");

String bucketName = setBucketCallbackPolicyRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
Map<String, String> params = new HashMap<String, String>();
params.put(SUBRESOURCE_POLICY, null);
params.put(SUBRESOURCE_COMP, SUBRESOURCE_CALLBACK);

byte[] rawContent = setBucketCallbackPolicyRequestMarshaller.marshall(setBucketCallbackPolicyRequest);
Map<String, String> headers = new HashMap<String, String>();
addRequestRequiredHeaders(headers, rawContent);

RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint(setBucketCallbackPolicyRequest))
.setMethod(HttpMethod.PUT).setBucket(bucketName).setParameters(params)
.setInputSize(rawContent.length).setInputStream(new ByteArrayInputStream(rawContent))
.setOriginalRequest(setBucketCallbackPolicyRequest).build();

return doOperation(request, requestIdResponseParser, bucketName, null);
}

public GetBucketCallbackPolicyResult getBucketCallbackPolicy(GenericRequest genericRequest) throws OSSException, ClientException {
assertParameterNotNull(genericRequest, "genericRequest");

String bucketName = genericRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
Map<String, String> params = new HashMap<String, String>();
params.put(SUBRESOURCE_POLICY, null);
params.put(SUBRESOURCE_COMP, SUBRESOURCE_CALLBACK);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint(genericRequest))
.setMethod(HttpMethod.GET).setBucket(bucketName).setParameters(params)
.setOriginalRequest(genericRequest).build();
return doOperation(request, getBucketCallbackPolicyResponseParser, bucketName, null, true);
}

public VoidResult deleteBucketCallbackPolicy(GenericRequest genericRequest) throws OSSException, ClientException {

assertParameterNotNull(genericRequest, "genericRequest");

String bucketName = genericRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);

Map<String, String> params = new HashMap<String, String>();
params.put(SUBRESOURCE_POLICY, null);
params.put(SUBRESOURCE_COMP, SUBRESOURCE_CALLBACK);

RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint(genericRequest))
.setMethod(HttpMethod.DELETE).setBucket(bucketName).setParameters(params)
.setOriginalRequest(genericRequest).build();

return doOperation(request, requestIdResponseParser, bucketName, null);
}
}
36 changes: 36 additions & 0 deletions src/main/java/com/aliyun/oss/internal/ResponseParsers.java
Original file line number Diff line number Diff line change
Expand Up @@ -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 GetBucketCallbackPolicyResponseParser getBucketCallbackPolicyResponseParser = new GetBucketCallbackPolicyResponseParser();

public static Long parseLongWithDefault(String defaultValue){
if(defaultValue == null || "".equals(defaultValue)){
Expand Down Expand Up @@ -4157,4 +4158,39 @@ private DoMetaQueryResult parseDoMetaQueryResult(InputStream inputStream) throws
}
}
}

public static final class GetBucketCallbackPolicyResponseParser implements ResponseParser<GetBucketCallbackPolicyResult> {

@Override
public GetBucketCallbackPolicyResult parse(ResponseMessage response) throws ResponseParseException {
GetBucketCallbackPolicyResult result = parseGetBucketCallbackPolicy(response.getContent());
setResultParameter(result, response);
return result;
}

private GetBucketCallbackPolicyResult parseGetBucketCallbackPolicy(InputStream inputStream) throws ResponseParseException {
GetBucketCallbackPolicyResult result = new GetBucketCallbackPolicyResult();
if (inputStream == null) {
return result;
}

try {
Element root = getXmlRootElement(inputStream);

List<Element> fileElem = root.getChildren();
List<PolicyCallbackItem> policyCallbackItems = new ArrayList<PolicyCallbackItem>();
if(fileElem.size() >0 ){
for(Element elem : fileElem){
PolicyCallbackItem policyCallbackItem = new PolicyCallbackItem(elem.getChildText("PolicyName"), elem.getChildText("Callback"));
policyCallbackItem.setCallbackVar(elem.getChildText("CallbackVar"));
policyCallbackItems.add(policyCallbackItem);
}
}
result.setPolicyCallbackItems(policyCallbackItems);
return result;
} catch (Exception e) {
throw new ResponseParseException(e.getMessage(), e);
}
}
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,17 @@
package com.aliyun.oss.model;

import java.util.ArrayList;
import java.util.List;

public class GetBucketCallbackPolicyResult extends GenericResult {

private List<PolicyCallbackItem> policyCallbackItems = new ArrayList<PolicyCallbackItem>();

public List<PolicyCallbackItem> getPolicyCallbackItems() {
return policyCallbackItems;
}

public void setPolicyCallbackItems(List<PolicyCallbackItem> policyCallbackItems) {
this.policyCallbackItems = policyCallbackItems;
}
}
44 changes: 44 additions & 0 deletions src/main/java/com/aliyun/oss/model/PolicyCallbackItem.java
Original file line number Diff line number Diff line change
@@ -0,0 +1,44 @@
package com.aliyun.oss.model;

public class PolicyCallbackItem {
// policy名称
private String policyName;
// 回调参数
private String callback;
// 自定义回调参数
private String callbackVar;

public PolicyCallbackItem(String policyName, String callback) {
this.policyName = policyName;
this.callback = callback;
}

public String getPolicyName() {
return policyName;
}

public void setPolicyName(String policyName) {
this.policyName = policyName;
}

public String getCallback() {
return callback;
}

public void setCallback(String callback) {
this.callback = callback;
}

public String getCallbackVar() {
return callbackVar;
}

public void setCallbackVar(String callbackVar) {
this.callbackVar = callbackVar;
}

public PolicyCallbackItem withCallbackVar(String callbackVar) {
this.callbackVar = callbackVar;
return this;
}
}
Original file line number Diff line number Diff line change
@@ -0,0 +1,31 @@
package com.aliyun.oss.model;

import java.util.ArrayList;
import java.util.List;

public class SetBucketCallbackPolicyRequest extends GenericRequest {

private List<PolicyCallbackItem> policyCallbackItems = new ArrayList<PolicyCallbackItem>();

public SetBucketCallbackPolicyRequest(String bucketName) {
super(bucketName);
}

public SetBucketCallbackPolicyRequest(String bucketName, List<PolicyCallbackItem> policyCallbackItems) {
super(bucketName);
this.policyCallbackItems = policyCallbackItems;
}

public List<PolicyCallbackItem> getPolicyCallbackItems() {
return policyCallbackItems;
}

public void setPolicyCallbackItems(List<PolicyCallbackItem> policyCallbackItems) {
this.policyCallbackItems = policyCallbackItems;
}

public SetBucketCallbackPolicyRequest withPolicyCallbackItems(List<PolicyCallbackItem> policyCallbackItems) {
this.policyCallbackItems = policyCallbackItems;
return this;
}
}
Loading