use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSMultipartOperation method abortMultipartUpload.
/**
* Abort multipart upload.
*/
public void abortMultipartUpload(AbortMultipartUploadRequest abortMultipartUploadRequest) throws OSSException, ClientException {
assertParameterNotNull(abortMultipartUploadRequest, "abortMultipartUploadRequest");
String key = abortMultipartUploadRequest.getKey();
String bucketName = abortMultipartUploadRequest.getBucketName();
String uploadId = abortMultipartUploadRequest.getUploadId();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
assertParameterNotNull(key, "key");
ensureObjectKeyValid(key);
assertStringNotNullOrEmpty(uploadId, "uploadId");
Map<String, String> parameters = new HashMap<String, String>();
parameters.put(UPLOAD_ID, uploadId);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.DELETE).setBucket(bucketName).setKey(key).setParameters(parameters).setOriginalRequest(abortMultipartUploadRequest).build();
doOperation(request, emptyResponseParser, bucketName, key);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class CORSOperation method getBucketCORSRules.
/**
* Return a list of CORS rules of the specified bucket.
*/
public List<CORSRule> getBucketCORSRules(GenericRequest genericRequest) {
assertParameterNotNull(genericRequest, "genericRequest");
String bucketName = genericRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
Map<String, String> parameters = new LinkedHashMap<String, String>();
parameters.put(SUBRESOURCE_CORS, null);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setParameters(parameters).setBucket(bucketName).setOriginalRequest(genericRequest).build();
return doOperation(request, getBucketCorsResponseParser, bucketName, null, true);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSClient method generatePresignedUrl.
@Override
public URL generatePresignedUrl(GeneratePresignedUrlRequest request) throws ClientException {
assertParameterNotNull(request, "request");
String bucketName = request.getBucketName();
if (request.getBucketName() == null) {
throw new IllegalArgumentException(OSS_RESOURCE_MANAGER.getString("MustSetBucketName"));
}
ensureBucketNameValid(request.getBucketName());
if (request.getExpiration() == null) {
throw new IllegalArgumentException(OSS_RESOURCE_MANAGER.getString("MustSetExpiration"));
}
Credentials currentCreds = credsProvider.getCredentials();
String accessId = currentCreds.getAccessKeyId();
String accessKey = currentCreds.getSecretAccessKey();
boolean useSecurityToken = currentCreds.useSecurityToken();
HttpMethod method = request.getMethod() != null ? request.getMethod() : HttpMethod.GET;
String expires = String.valueOf(request.getExpiration().getTime() / 1000L);
String key = request.getKey();
ClientConfiguration config = serviceClient.getClientConfiguration();
String resourcePath = OSSUtils.determineResourcePath(bucketName, key, config.isSLDEnabled());
RequestMessage requestMessage = new RequestMessage(bucketName, key);
requestMessage.setEndpoint(OSSUtils.determineFinalEndpoint(endpoint, bucketName, config));
requestMessage.setMethod(method);
requestMessage.setResourcePath(resourcePath);
requestMessage.setHeaders(request.getHeaders());
requestMessage.addHeader(HttpHeaders.DATE, expires);
if (request.getContentType() != null && !request.getContentType().trim().equals("")) {
requestMessage.addHeader(HttpHeaders.CONTENT_TYPE, request.getContentType());
}
if (request.getContentMD5() != null && request.getContentMD5().trim().equals("")) {
requestMessage.addHeader(HttpHeaders.CONTENT_MD5, request.getContentMD5());
}
for (Map.Entry<String, String> h : request.getUserMetadata().entrySet()) {
requestMessage.addHeader(OSSHeaders.OSS_USER_METADATA_PREFIX + h.getKey(), h.getValue());
}
Map<String, String> responseHeaderParams = new HashMap<String, String>();
populateResponseHeaderParameters(responseHeaderParams, request.getResponseHeaders());
if (responseHeaderParams.size() > 0) {
requestMessage.setParameters(responseHeaderParams);
}
if (request.getQueryParameter() != null && request.getQueryParameter().size() > 0) {
for (Map.Entry<String, String> entry : request.getQueryParameter().entrySet()) {
requestMessage.addParameter(entry.getKey(), entry.getValue());
}
}
if (request.getProcess() != null && !request.getProcess().trim().equals("")) {
requestMessage.addParameter(RequestParameters.SUBRESOURCE_PROCESS, request.getProcess());
}
if (useSecurityToken) {
requestMessage.addParameter(SECURITY_TOKEN, currentCreds.getSecurityToken());
}
String canonicalResource = "/" + ((bucketName != null) ? bucketName : "") + ((key != null ? "/" + key : ""));
String canonicalString = SignUtils.buildCanonicalString(method.toString(), canonicalResource, requestMessage, expires);
String signature = ServiceSignature.create().computeSignature(accessKey, canonicalString);
Map<String, String> params = new LinkedHashMap<String, String>();
params.put(HttpHeaders.EXPIRES, expires);
params.put(OSS_ACCESS_KEY_ID, accessId);
params.put(SIGNATURE, signature);
params.putAll(requestMessage.getParameters());
String queryString = HttpUtil.paramToQueryString(params, DEFAULT_CHARSET_NAME);
/* Compse HTTP request uri. */
String url = requestMessage.getEndpoint().toString();
if (!url.endsWith("/")) {
url += "/";
}
url += resourcePath + "?" + queryString;
try {
return new URL(url);
} catch (MalformedURLException e) {
throw new ClientException(e);
}
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class CORSOperation method setBucketCORS.
/**
* Set bucket cors.
*/
public void setBucketCORS(SetBucketCORSRequest setBucketCORSRequest) {
checkSetBucketCORSRequestValidity(setBucketCORSRequest);
Map<String, String> parameters = new LinkedHashMap<String, String>();
parameters.put(SUBRESOURCE_CORS, null);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.PUT).setBucket(setBucketCORSRequest.getBucketName()).setParameters(parameters).setInputStreamWithLength(setBucketCORSRequestMarshaller.marshall(setBucketCORSRequest)).setOriginalRequest(setBucketCORSRequest).build();
doOperation(request, emptyResponseParser, setBucketCORSRequest.getBucketName(), null);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class CORSOperation method deleteBucketCORS.
/**
* Delete bucket cors.
*/
public void deleteBucketCORS(GenericRequest genericRequest) {
assertParameterNotNull(genericRequest, "genericRequest");
String bucketName = genericRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
Map<String, String> parameters = new LinkedHashMap<String, String>();
parameters.put(SUBRESOURCE_CORS, null);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.DELETE).setParameters(parameters).setBucket(bucketName).setOriginalRequest(genericRequest).build();
doOperation(request, emptyResponseParser, bucketName, null);
}
Aggregations