Search in sources :

Example 66 with COSCredentials

use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.

the class COSClient method invoke.

private <X, Y extends CosServiceRequest> X invoke(CosHttpRequest<Y> request, HttpResponseHandler<CosServiceResponse<X>> responseHandler) throws CosClientException, CosServiceException {
    COSSigner cosSigner = clientConfig.getCosSigner();
    COSCredentials cosCredentials;
    CosServiceRequest cosServiceRequest = request.getOriginalRequest();
    if (cosServiceRequest != null && cosServiceRequest.getCosCredentials() != null) {
        cosCredentials = cosServiceRequest.getCosCredentials();
    } else {
        cosCredentials = fetchCredential();
    }
    Date expiredTime = new Date(System.currentTimeMillis() + clientConfig.getSignExpired() * 1000);
    boolean isCIWorkflowRequest = cosServiceRequest instanceof CIWorkflowServiceRequest;
    cosSigner.setCIWorkflowRequest(isCIWorkflowRequest);
    cosSigner.sign(request, cosCredentials, expiredTime);
    return this.cosHttpClient.exeute(request, responseHandler);
}
Also used : COSCredentials(com.qcloud.cos.auth.COSCredentials) COSSigner(com.qcloud.cos.auth.COSSigner) CosServiceRequest(com.qcloud.cos.internal.CosServiceRequest) CIWorkflowServiceRequest(com.qcloud.cos.internal.CIWorkflowServiceRequest) Date(java.util.Date)

Example 67 with COSCredentials

use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.

the class PutGetDelTest method testRequestSpecifiedTmpKeyInfoPutGetDel.

@Test
public void testRequestSpecifiedTmpKeyInfoPutGetDel() throws CosServiceException, IOException, InterruptedException {
    COSClient cosclient = buildTemporyCredentialsCOSClient(1800L);
    File localFile = buildTestFile(1024L);
    COSCredentials cosCredentials = new BasicCOSCredentials(secretId, secretKey);
    try {
        String key = "ut/request-specified-key";
        PutObjectRequest putObjectRequest = new PutObjectRequest(bucket, key, localFile);
        putObjectRequest.setCosCredentials(cosCredentials);
        cosclient.putObject(putObjectRequest);
        GetObjectRequest getObjectRequest = new GetObjectRequest(bucket, key);
        getObjectRequest.setCosCredentials(cosCredentials);
        cosclient.getObject(getObjectRequest);
        DeleteObjectRequest deleteObjectRequest = new DeleteObjectRequest(bucket, key);
        deleteObjectRequest.setCosCredentials(cosCredentials);
        cosclient.deleteObject(deleteObjectRequest);
    } finally {
        localFile.delete();
        cosclient.shutdown();
    }
}
Also used : DeleteObjectRequest(com.qcloud.cos.model.DeleteObjectRequest) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) AnonymousCOSCredentials(com.qcloud.cos.auth.AnonymousCOSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) File(java.io.File) GetObjectRequest(com.qcloud.cos.model.GetObjectRequest) PutObjectRequest(com.qcloud.cos.model.PutObjectRequest) Test(org.junit.Test)

Example 68 with COSCredentials

use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.

the class TransferManagerTest method testTransferManagerCopySmallFileFromDiffRegion.

// transfer manager对不同园区5G以下文件进行使用put object copy
@Ignore
public void testTransferManagerCopySmallFileFromDiffRegion() throws CosServiceException, CosClientException, InterruptedException {
    if (!judgeUserInfoValid()) {
        return;
    }
    COSCredentials srcCred = new BasicCOSCredentials(secretId, secretKey);
    String srcRegion = "ap-guangzhou";
    ClientConfig srcClientConfig = new ClientConfig(new Region(srcRegion));
    COSClient srcCOSClient = new COSClient(srcCred, srcClientConfig);
    String srcBucketName = "chengwus3gz-1251668577";
    String srcKey = "ut_copy/len1G.txt";
    String destKey = "ut_copy_dest/len1G.txt";
    CopyObjectRequest copyObjectRequest = new CopyObjectRequest(new Region(srcRegion), srcBucketName, srcKey, bucket, destKey);
    Copy copy = transferManager.copy(copyObjectRequest, srcCOSClient, null);
    CopyResult copyResult = copy.waitForCopyResult();
    assertNotNull(copyResult.getRequestId());
    assertNotNull(copyResult.getDateStr());
    clearObject(destKey);
}
Also used : CopyObjectRequest(com.qcloud.cos.model.CopyObjectRequest) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Copy(com.qcloud.cos.transfer.Copy) Region(com.qcloud.cos.region.Region) CopyResult(com.qcloud.cos.model.CopyResult) Ignore(org.junit.Ignore)

Example 69 with COSCredentials

use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.

the class TransferManagerTest method testTransferManagerCopyBigFileFromSameRegion.

// transfer manager对相同园区使用put object copy
@Ignore
public void testTransferManagerCopyBigFileFromSameRegion() throws CosServiceException, CosClientException, InterruptedException {
    if (!judgeUserInfoValid()) {
        return;
    }
    COSCredentials srcCred = new BasicCOSCredentials(secretId, secretKey);
    String srcRegion = region;
    ClientConfig srcClientConfig = new ClientConfig(new Region(srcRegion));
    COSClient srcCOSClient = new COSClient(srcCred, srcClientConfig);
    String srcBucketName = bucket;
    String srcKey = "ut_copy/len10G_1.txt";
    String destKey = "ut_copy_dest/len10G_2.txt";
    CopyObjectRequest copyObjectRequest = new CopyObjectRequest(new Region(srcRegion), srcBucketName, srcKey, bucket, destKey);
    Copy copy = transferManager.copy(copyObjectRequest, srcCOSClient, null);
    CopyResult copyResult = copy.waitForCopyResult();
    assertNotNull(copyResult.getRequestId());
    assertNotNull(copyResult.getDateStr());
}
Also used : CopyObjectRequest(com.qcloud.cos.model.CopyObjectRequest) COSCredentials(com.qcloud.cos.auth.COSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) BasicCOSCredentials(com.qcloud.cos.auth.BasicCOSCredentials) Copy(com.qcloud.cos.transfer.Copy) Region(com.qcloud.cos.region.Region) CopyResult(com.qcloud.cos.model.CopyResult) Ignore(org.junit.Ignore)

Example 70 with COSCredentials

use of com.qcloud.cos.auth.COSCredentials in project cos-java-sdk-v5 by tencentyun.

the class GetObjectURLDemo method getObjectUrlWithVersionId.

public static void getObjectUrlWithVersionId() {
    // getObjectUrl 不需要验证身份信息
    COSCredentials cred = new AnonymousCOSCredentials();
    // 设置bucket的区域, COS地域的简称请参照 https://www.qcloud.com/document/product/436/6224
    ClientConfig clientConfig = new ClientConfig(new Region("ap-guangzhou"));
    // 设置生成的 url 的协议名
    clientConfig.setHttpProtocol(HttpProtocol.https);
    // 生成cos客户端
    COSClient cosclient = new COSClient(cred, clientConfig);
    String key = "test/my_test中文.json";
    String bucketName = "mybucket-1251668577";
    String versionId = "xxxyyyzzz111222333";
    System.out.println(cosclient.getObjectUrl(bucketName, key, versionId));
}
Also used : COSClient(com.qcloud.cos.COSClient) AnonymousCOSCredentials(com.qcloud.cos.auth.AnonymousCOSCredentials) COSCredentials(com.qcloud.cos.auth.COSCredentials) Region(com.qcloud.cos.region.Region) AnonymousCOSCredentials(com.qcloud.cos.auth.AnonymousCOSCredentials) ClientConfig(com.qcloud.cos.ClientConfig)

Aggregations

COSCredentials (com.qcloud.cos.auth.COSCredentials)112 BasicCOSCredentials (com.qcloud.cos.auth.BasicCOSCredentials)105 Region (com.qcloud.cos.region.Region)105 ClientConfig (com.qcloud.cos.ClientConfig)99 COSClient (com.qcloud.cos.COSClient)96 CosClientException (com.qcloud.cos.exception.CosClientException)42 CosServiceException (com.qcloud.cos.exception.CosServiceException)38 File (java.io.File)22 TransferManager (com.qcloud.cos.transfer.TransferManager)13 ExecutorService (java.util.concurrent.ExecutorService)13 ObjectMetadata (com.qcloud.cos.model.ObjectMetadata)12 PutObjectRequest (com.qcloud.cos.model.PutObjectRequest)12 CopyObjectRequest (com.qcloud.cos.model.CopyObjectRequest)11 PutObjectResult (com.qcloud.cos.model.PutObjectResult)11 AnonymousCOSCredentials (com.qcloud.cos.auth.AnonymousCOSCredentials)10 Copy (com.qcloud.cos.transfer.Copy)8 CopyResult (com.qcloud.cos.model.CopyResult)7 GetObjectRequest (com.qcloud.cos.model.GetObjectRequest)7 Date (java.util.Date)7 LinkedList (java.util.LinkedList)7