Search in sources :

Example 6 with DefaultCredentialProvider

use of com.aliyun.oss.common.auth.DefaultCredentialProvider in project aliyun-oss-java-sdk by aliyun.

the class BucketAclTest method testUnormalDoesBucketExist.

@Test
public void testUnormalDoesBucketExist() {
    final String nonexistentBucket = "unormal-does-bucket-exist";
    try {
        Credentials credentials = new DefaultCredentials(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET);
        OSSClient ossClient = new OSSClient("http://oss-cn-taikang.aliyuncs.com", new DefaultCredentialProvider(credentials));
        ossClient.doesBucketExist(nonexistentBucket);
        Assert.fail("Does bucket exist should not be successful");
    } catch (Exception e) {
        Assert.assertEquals("UnknownHost", e.getMessage());
    }
}
Also used : DefaultCredentials(com.aliyun.oss.common.auth.DefaultCredentials) OSSClient(com.aliyun.oss.OSSClient) DefaultCredentialProvider(com.aliyun.oss.common.auth.DefaultCredentialProvider) Credentials(com.aliyun.oss.common.auth.Credentials) DefaultCredentials(com.aliyun.oss.common.auth.DefaultCredentials) OSSException(com.aliyun.oss.OSSException) Test(org.junit.Test)

Example 7 with DefaultCredentialProvider

use of com.aliyun.oss.common.auth.DefaultCredentialProvider in project aliyun-oss-java-sdk by aliyun.

the class OSSObjectOperationTest method testPopulateCopyObjectHeaders.

@Test
public void testPopulateCopyObjectHeaders() throws IllegalAccessException, IllegalArgumentException, InvocationTargetException, URISyntaxException {
    CopyObjectRequest request = new CopyObjectRequest("srcbucket", "srckey", "destbucket", "destkey");
    request.setServerSideEncryption(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION);
    Method[] testMethods = OSSObjectOperation.class.getDeclaredMethods();
    Method testMethod = null;
    for (Method m : testMethods) {
        if (m.getName().equals("populateCopyObjectHeaders")) {
            testMethod = m;
        }
    }
    testMethod.setAccessible(true);
    OSSObjectOperation operations = new OSSObjectOperation(new DefaultServiceClient(new ClientConfiguration()), new DefaultCredentialProvider(new DefaultCredentials("id", "key")));
    Map<String, String> headers = new HashMap<String, String>();
    Object[] params = new Object[2];
    params[0] = request;
    params[1] = headers;
    testMethod.invoke(operations, params);
    assertEquals("/srcbucket/srckey", headers.get(OSSHeaders.COPY_OBJECT_SOURCE));
    assertEquals(ObjectMetadata.AES_256_SERVER_SIDE_ENCRYPTION, headers.get(OSSHeaders.OSS_SERVER_SIDE_ENCRYPTION));
    assertEquals(null, headers.get(OSSHeaders.COPY_OBJECT_METADATA_DIRECTIVE));
}
Also used : OSSObjectOperation(com.aliyun.oss.internal.OSSObjectOperation) HashMap(java.util.HashMap) DefaultCredentialProvider(com.aliyun.oss.common.auth.DefaultCredentialProvider) Method(java.lang.reflect.Method) DefaultCredentials(com.aliyun.oss.common.auth.DefaultCredentials) CopyObjectRequest(com.aliyun.oss.model.CopyObjectRequest) DefaultServiceClient(com.aliyun.oss.common.comm.DefaultServiceClient) Test(org.junit.Test)

Aggregations

DefaultCredentialProvider (com.aliyun.oss.common.auth.DefaultCredentialProvider)7 OSSClient (com.aliyun.oss.OSSClient)6 Test (org.junit.Test)6 OSSClientBuilder (com.aliyun.oss.OSSClientBuilder)4 ClientBuilderConfiguration (com.aliyun.oss.ClientBuilderConfiguration)3 Credentials (com.aliyun.oss.common.auth.Credentials)3 DefaultCredentials (com.aliyun.oss.common.auth.DefaultCredentials)3 BucketInfo (com.aliyun.oss.model.BucketInfo)3 OSSObject (com.aliyun.oss.model.OSSObject)3 ObjectMetadata (com.aliyun.oss.model.ObjectMetadata)3 ByteArrayInputStream (java.io.ByteArrayInputStream)3 InputStream (java.io.InputStream)3 ClientConfiguration (com.aliyun.oss.ClientConfiguration)1 OSSException (com.aliyun.oss.OSSException)1 DefaultServiceClient (com.aliyun.oss.common.comm.DefaultServiceClient)1 OSSObjectOperation (com.aliyun.oss.internal.OSSObjectOperation)1 CopyObjectRequest (com.aliyun.oss.model.CopyObjectRequest)1 Method (java.lang.reflect.Method)1 HashMap (java.util.HashMap)1