use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSObjectOperation method getObjectMetadata.
/**
* Get object matadata.
*/
public ObjectMetadata getObjectMetadata(GenericRequest genericRequest) throws OSSException, ClientException {
assertParameterNotNull(genericRequest, "genericRequest");
String bucketName = genericRequest.getBucketName();
String key = genericRequest.getKey();
assertParameterNotNull(bucketName, "bucketName");
assertParameterNotNull(key, "key");
ensureBucketNameValid(bucketName);
ensureObjectKeyValid(key);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.HEAD).setBucket(bucketName).setKey(key).setOriginalRequest(genericRequest).build();
List<ResponseHandler> reponseHandlers = new ArrayList<ResponseHandler>();
reponseHandlers.add(new ResponseHandler() {
@Override
public void handle(ResponseMessage response) throws ServiceException, ClientException {
if (response.getStatusCode() == HttpStatus.SC_NOT_FOUND) {
safeCloseResponse(response);
throw ExceptionFactory.createOSSException(response.getHeaders().get(OSSHeaders.OSS_HEADER_REQUEST_ID), OSSErrorCode.NO_SUCH_KEY, OSS_RESOURCE_MANAGER.getString("NoSuchKey"));
}
}
});
return doOperation(request, getObjectMetadataResponseParser, bucketName, key, true, null, reponseHandlers);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSObjectOperation method headObject.
/**
* Check if the object key exists under the specified bucket.
*/
public void headObject(HeadObjectRequest headObjectRequest) throws OSSException, ClientException {
assertParameterNotNull(headObjectRequest, "headObjectRequest");
String bucketName = headObjectRequest.getBucketName();
String key = headObjectRequest.getKey();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
assertParameterNotNull(key, "key");
ensureObjectKeyValid(key);
Map<String, String> headers = new HashMap<String, String>();
addDateHeader(headers, OSSHeaders.HEAD_OBJECT_IF_MODIFIED_SINCE, headObjectRequest.getModifiedSinceConstraint());
addDateHeader(headers, OSSHeaders.HEAD_OBJECT_IF_UNMODIFIED_SINCE, headObjectRequest.getUnmodifiedSinceConstraint());
addStringListHeader(headers, OSSHeaders.HEAD_OBJECT_IF_MATCH, headObjectRequest.getMatchingETagConstraints());
addStringListHeader(headers, OSSHeaders.HEAD_OBJECT_IF_NONE_MATCH, headObjectRequest.getNonmatchingETagConstraints());
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.HEAD).setBucket(bucketName).setKey(key).setHeaders(headers).setOriginalRequest(headObjectRequest).build();
doOperation(request, emptyResponseParser, bucketName, key);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSObjectOperation method setObjectAcl.
public void setObjectAcl(SetObjectAclRequest setObjectAclRequest) throws OSSException, ClientException {
assertParameterNotNull(setObjectAclRequest, "setObjectAclRequest");
String bucketName = setObjectAclRequest.getBucketName();
String key = setObjectAclRequest.getKey();
CannedAccessControlList cannedAcl = setObjectAclRequest.getCannedACL();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
assertParameterNotNull(key, "key");
ensureObjectKeyValid(key);
assertParameterNotNull(cannedAcl, "cannedAcl");
Map<String, String> headers = new HashMap<String, String>();
headers.put(OSSHeaders.OSS_OBJECT_ACL, cannedAcl.toString());
Map<String, String> params = new HashMap<String, String>();
params.put(SUBRESOURCE_ACL, null);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.PUT).setBucket(bucketName).setKey(key).setParameters(params).setHeaders(headers).setOriginalRequest(setObjectAclRequest).build();
doOperation(request, emptyResponseParser, bucketName, key);
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSObjectOperation method getObject.
/**
* Pull an object from oss.
*/
public OSSObject getObject(GetObjectRequest getObjectRequest) throws OSSException, ClientException {
assertParameterNotNull(getObjectRequest, "getObjectRequest");
String bucketName = null;
String key = null;
RequestMessage request = null;
if (!getObjectRequest.isUseUrlSignature()) {
assertParameterNotNull(getObjectRequest, "getObjectRequest");
bucketName = getObjectRequest.getBucketName();
key = getObjectRequest.getKey();
assertParameterNotNull(bucketName, "bucketName");
assertParameterNotNull(key, "key");
ensureBucketNameValid(bucketName);
ensureObjectKeyValid(key);
Map<String, String> headers = new HashMap<String, String>();
populateGetObjectRequestHeaders(getObjectRequest, headers);
Map<String, String> params = new HashMap<String, String>();
populateResponseHeaderParameters(params, getObjectRequest.getResponseHeaders());
String process = getObjectRequest.getProcess();
if (process != null) {
params.put(RequestParameters.SUBRESOURCE_PROCESS, process);
}
request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.GET).setBucket(bucketName).setKey(key).setHeaders(headers).setParameters(params).setOriginalRequest(getObjectRequest).build();
} else {
request = new RequestMessage(getObjectRequest, bucketName, key);
request.setMethod(HttpMethod.GET);
request.setAbsoluteUrl(getObjectRequest.getAbsoluteUri());
request.setUseUrlSignature(true);
request.setHeaders(getObjectRequest.getHeaders());
}
final ProgressListener listener = getObjectRequest.getProgressListener();
OSSObject ossObject = null;
try {
publishProgress(listener, ProgressEventType.TRANSFER_STARTED_EVENT);
ossObject = doOperation(request, new GetObjectResponseParser(bucketName, key), bucketName, key, true);
InputStream instream = ossObject.getObjectContent();
ProgressInputStream progressInputStream = new ProgressInputStream(instream, listener) {
@Override
protected void onEOF() {
publishProgress(getListener(), ProgressEventType.TRANSFER_COMPLETED_EVENT);
}
};
CRC64 crc = new CRC64();
CheckedInputStream checkedInputstream = new CheckedInputStream(progressInputStream, crc);
ossObject.setObjectContent(checkedInputstream);
} catch (RuntimeException e) {
publishProgress(listener, ProgressEventType.TRANSFER_FAILED_EVENT);
throw e;
}
return ossObject;
}
use of com.aliyun.oss.common.comm.RequestMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSObjectOperation method putObject.
/**
* Upload input stream to oss by using url signature.
*/
public PutObjectResult putObject(URL signedUrl, InputStream requestContent, long contentLength, Map<String, String> requestHeaders, boolean useChunkEncoding) throws OSSException, ClientException {
assertParameterNotNull(signedUrl, "signedUrl");
assertParameterNotNull(requestContent, "requestContent");
if (requestHeaders == null) {
requestHeaders = new HashMap<String, String>();
}
RequestMessage request = new RequestMessage(null, null);
request.setMethod(HttpMethod.PUT);
request.setAbsoluteUrl(signedUrl);
request.setUseUrlSignature(true);
request.setContent(requestContent);
request.setContentLength(determineInputStreamLength(requestContent, contentLength, useChunkEncoding));
request.setHeaders(requestHeaders);
request.setUseChunkEncoding(useChunkEncoding);
PutObjectResult result = null;
if (requestHeaders.get(OSSHeaders.OSS_HEADER_CALLBACK) == null) {
result = doOperation(request, putObjectReponseParser, null, null, true);
} else {
result = doOperation(request, putObjectProcessReponseParser, null, null, true);
}
if (isCrcCheckEnabled()) {
OSSUtils.checkChecksum(result.getClientCRC(), result.getServerCRC(), result.getRequestId());
}
return result;
}
Aggregations