use of com.aliyun.oss.common.comm.ResponseMessage 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.ResponseMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSMultipartOperation method uploadPart.
/**
* Upload part.
*/
public UploadPartResult uploadPart(UploadPartRequest uploadPartRequest) throws OSSException, ClientException {
assertParameterNotNull(uploadPartRequest, "uploadPartRequest");
String key = uploadPartRequest.getKey();
String bucketName = uploadPartRequest.getBucketName();
String uploadId = uploadPartRequest.getUploadId();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
assertParameterNotNull(key, "key");
ensureObjectKeyValid(key);
assertStringNotNullOrEmpty(uploadId, "uploadId");
if (uploadPartRequest.getInputStream() == null) {
throw new IllegalArgumentException(OSS_RESOURCE_MANAGER.getString("MustSetContentStream"));
}
InputStream repeatableInputStream = null;
try {
repeatableInputStream = newRepeatableInputStream(uploadPartRequest.buildPartialStream());
} catch (IOException ex) {
logException("Cannot wrap to repeatable input stream: ", ex);
throw new ClientException("Cannot wrap to repeatable input stream: ", ex);
}
int partNumber = uploadPartRequest.getPartNumber();
if (!checkParamRange(partNumber, 0, false, MAX_PART_NUMBER, true)) {
throw new IllegalArgumentException(OSS_RESOURCE_MANAGER.getString("PartNumberOutOfRange"));
}
Map<String, String> headers = new HashMap<String, String>();
populateUploadPartOptionalHeaders(uploadPartRequest, headers);
// Use a LinkedHashMap to preserve the insertion order.
Map<String, String> params = new LinkedHashMap<String, String>();
params.put(PART_NUMBER, Integer.toString(partNumber));
params.put(UPLOAD_ID, uploadId);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.PUT).setBucket(bucketName).setKey(key).setParameters(params).setHeaders(headers).setInputStream(repeatableInputStream).setInputSize(uploadPartRequest.getPartSize()).setUseChunkEncoding(uploadPartRequest.isUseChunkEncoding()).setOriginalRequest(uploadPartRequest).build();
final ProgressListener listener = uploadPartRequest.getProgressListener();
ResponseMessage response = null;
try {
publishProgress(listener, ProgressEventType.TRANSFER_PART_STARTED_EVENT);
response = doOperation(request, emptyResponseParser, bucketName, key);
publishProgress(listener, ProgressEventType.TRANSFER_PART_COMPLETED_EVENT);
} catch (RuntimeException e) {
publishProgress(listener, ProgressEventType.TRANSFER_PART_FAILED_EVENT);
throw e;
}
UploadPartResult result = new UploadPartResult();
result.setPartNumber(partNumber);
result.setETag(trimQuotes(response.getHeaders().get(OSSHeaders.ETAG)));
result.setRequestId(response.getRequestId());
result.setPartSize(uploadPartRequest.getPartSize());
ResponseParsers.setCRC(result, response);
if (getInnerClient().getClientConfiguration().isCrcCheckEnabled()) {
OSSUtils.checkChecksum(result.getClientCRC(), result.getServerCRC(), result.getRequestId());
}
return result;
}
use of com.aliyun.oss.common.comm.ResponseMessage in project aliyun-oss-java-sdk by aliyun.
the class ResourceUtils method loadResponseFromResource.
public static ResponseMessage loadResponseFromResource(String resourceName) throws FileNotFoundException {
ResponseMessage response = new ResponseMessage(null);
if (resourceName != null) {
String filename = getTestFilename(resourceName);
File file = new File(filename);
FileInputStream fis = new FileInputStream(file);
response.setContent(fis);
response.setContentLength(file.length());
}
return response;
}
use of com.aliyun.oss.common.comm.ResponseMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSBucketOperation method getBucketMetadata.
public BucketMetadata getBucketMetadata(GenericRequest genericRequest) throws OSSException, ClientException {
assertParameterNotNull(genericRequest, "genericRequest");
String bucketName = genericRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.HEAD).setBucket(bucketName).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_BUCKET, OSS_RESOURCE_MANAGER.getString("NoSuchBucket"));
}
}
});
return doOperation(request, ResponseParsers.getBucketMetadataResponseParser, bucketName, null, true, null, reponseHandlers);
}
use of com.aliyun.oss.common.comm.ResponseMessage in project aliyun-oss-java-sdk by aliyun.
the class OSSBucketOperation method createBucket.
/**
* Create a bucket.
*/
public Bucket createBucket(CreateBucketRequest createBucketRequest) throws OSSException, ClientException {
assertParameterNotNull(createBucketRequest, "createBucketRequest");
String bucketName = createBucketRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
Map<String, String> headers = new HashMap<String, String>();
addOptionalACLHeader(headers, createBucketRequest.getCannedACL());
RequestMessage request = new OSSRequestMessageBuilder(getInnerClient()).setEndpoint(getEndpoint()).setMethod(HttpMethod.PUT).setBucket(bucketName).setHeaders(headers).setInputStreamWithLength(createBucketRequestMarshaller.marshall(createBucketRequest)).setOriginalRequest(createBucketRequest).build();
ResponseMessage result = doOperation(request, emptyResponseParser, bucketName, null);
return new Bucket(bucketName, result.getRequestId());
}
Aggregations