use of com.aliyun.oss.OSSClient in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderWithCredentialProvider.
@Test
public void testClientBuilderWithCredentialProvider() {
try {
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET), null);
Assert.assertFalse(ossClient.getClientConfiguration().isSupportCname());
BucketInfo info = ossClient.getBucketInfo(bucketName);
Assert.assertEquals(info.getBucket().getName(), bucketName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(TEST_CONTENT.getBytes().length);
ossClient.putObject(bucketName, TEST_KEY, new ByteArrayInputStream(TEST_CONTENT.getBytes()), metadata);
OSSObject ossObject = ossClient.getObject(bucketName, TEST_KEY);
InputStream inputStream = ossObject.getObjectContent();
inputStream.close();
ossClient.deleteObject(bucketName, TEST_KEY);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.OSSClient in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderWithSTS.
@Test
public void testClientBuilderWithSTS() {
try {
ClientBuilderConfiguration config = new ClientBuilderConfiguration();
config.setSupportCname(true);
config.setConnectionTimeout(10000);
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET, "TOKEN"), config);
Assert.assertTrue(ossClient.getClientConfiguration().isSupportCname());
Assert.assertEquals(ossClient.getClientConfiguration().getConnectionTimeout(), 10000);
Credentials cred = ossClient.getCredentialsProvider().getCredentials();
Assert.assertEquals(cred.getAccessKeyId(), TestConfig.OSS_TEST_ACCESS_KEY_ID);
Assert.assertEquals(cred.getSecretAccessKey(), TestConfig.OSS_TEST_ACCESS_KEY_SECRET);
Assert.assertEquals(cred.getSecurityToken(), "TOKEN");
Assert.assertTrue(cred.useSecurityToken());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.OSSClient in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderWithBuilderConfiguration.
@Test
public void testClientBuilderWithBuilderConfiguration() {
try {
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, new DefaultCredentialProvider(TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET), new ClientBuilderConfiguration());
Assert.assertFalse(ossClient.getClientConfiguration().isSupportCname());
BucketInfo info = ossClient.getBucketInfo(bucketName);
Assert.assertEquals(info.getBucket().getName(), bucketName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(TEST_CONTENT.getBytes().length);
ossClient.putObject(bucketName, TEST_KEY, new ByteArrayInputStream(TEST_CONTENT.getBytes()), metadata);
OSSObject ossObject = ossClient.getObject(bucketName, TEST_KEY);
InputStream inputStream = ossObject.getObjectContent();
inputStream.close();
ossClient.deleteObject(bucketName, TEST_KEY);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.OSSClient in project alluxio by Alluxio.
the class OSSUnderFileSystem method createInstance.
/**
* Constructs a new instance of {@link OSSUnderFileSystem}.
*
* @param uri the {@link AlluxioURI} for this UFS
* @return the created {@link OSSUnderFileSystem} instance
* @throws Exception when a connection to GCS could not be created
*/
public static OSSUnderFileSystem createInstance(AlluxioURI uri) throws Exception {
String bucketName = uri.getHost();
Preconditions.checkArgument(Configuration.containsKey(PropertyKey.OSS_ACCESS_KEY), "Property " + PropertyKey.OSS_ACCESS_KEY + " is required to connect to OSS");
Preconditions.checkArgument(Configuration.containsKey(PropertyKey.OSS_SECRET_KEY), "Property " + PropertyKey.OSS_SECRET_KEY + " is required to connect to OSS");
Preconditions.checkArgument(Configuration.containsKey(PropertyKey.OSS_ENDPOINT_KEY), "Property " + PropertyKey.OSS_ENDPOINT_KEY + " is required to connect to OSS");
String accessId = Configuration.get(PropertyKey.OSS_ACCESS_KEY);
String accessKey = Configuration.get(PropertyKey.OSS_SECRET_KEY);
String endPoint = Configuration.get(PropertyKey.OSS_ENDPOINT_KEY);
ClientConfiguration ossClientConf = initializeOSSClientConfig();
OSSClient ossClient = new OSSClient(endPoint, accessId, accessKey, ossClientConf);
return new OSSUnderFileSystem(uri, ossClient, bucketName);
}
use of com.aliyun.oss.OSSClient in project free-framework by a601942905git.
the class AliyunOssBucketUtils method createDefaultBucketName.
/**
* 创建bucket
* @param bucketName bucket名称
*/
public static Bucket createDefaultBucketName(String bucketName) {
OSSClient ossClient = AliyunOssUtils.createOssClient();
Bucket bucket = ossClient.createBucket(bucketName);
log.info("创建的bucket:{}", bucket);
AliyunOssUtils.shutDownClient(ossClient);
return bucket;
}
Aggregations