use of com.aliyun.oss.OSSClientBuilder in project aliyun-oss-java-sdk by aliyun.
the class DoesObjectExistTest method testUnormalDoesObjectExist.
@Test
public void testUnormalDoesObjectExist() {
final String nonexistentKey = "test-unormal-does-object-exist";
// SignatureDoesNotMatch
OSS client = new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET + " ");
try {
client.doesObjectExist(bucketName, nonexistentKey);
Assert.fail("Does object exist should not be successful");
} catch (OSSException ex) {
Assert.assertEquals(OSSErrorCode.SIGNATURE_DOES_NOT_MATCH, ex.getErrorCode());
} finally {
client.shutdown();
}
}
use of com.aliyun.oss.OSSClientBuilder in project aliyun-oss-java-sdk by aliyun.
the class MultiInstanceClientTest method keepUsingAfterClose.
@Test
public void keepUsingAfterClose() {
final String key = "key0";
OSS client = new OSSClientBuilder().build(OSS_TEST_ENDPOINT, OSS_TEST_ACCESS_KEY_ID, OSS_TEST_ACCESS_KEY_SECRET);
InputStream content = TestUtils.genFixedLengthInputStream(128 * 1024);
client.putObject(bucketName, key, content, null);
client.shutdown();
try {
content = TestUtils.genFixedLengthInputStream(128 * 1024);
client.putObject(bucketName, key, content, null);
} catch (ClientException ce) {
System.out.println(ce.getMessage());
} catch (Exception e) {
System.out.println(e.getMessage());
}
}
use of com.aliyun.oss.OSSClientBuilder 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
* @param conf the configuration for this UFS
* @return the created {@link OSSUnderFileSystem} instance
*/
public static OSSUnderFileSystem createInstance(AlluxioURI uri, UnderFileSystemConfiguration conf) throws Exception {
String bucketName = UnderFileSystemUtils.getBucketName(uri);
Preconditions.checkArgument(conf.isSet(PropertyKey.OSS_ACCESS_KEY), "Property %s is required to connect to OSS", PropertyKey.OSS_ACCESS_KEY);
Preconditions.checkArgument(conf.isSet(PropertyKey.OSS_SECRET_KEY), "Property %s is required to connect to OSS", PropertyKey.OSS_SECRET_KEY);
Preconditions.checkArgument(conf.isSet(PropertyKey.OSS_ENDPOINT_KEY), "Property %s is required to connect to OSS", PropertyKey.OSS_ENDPOINT_KEY);
String accessId = conf.getString(PropertyKey.OSS_ACCESS_KEY);
String accessKey = conf.getString(PropertyKey.OSS_SECRET_KEY);
String endPoint = conf.getString(PropertyKey.OSS_ENDPOINT_KEY);
ClientBuilderConfiguration ossClientConf = initializeOSSClientConfig(conf);
OSS ossClient = new OSSClientBuilder().build(endPoint, accessId, accessKey, ossClientConf);
return new OSSUnderFileSystem(uri, ossClient, bucketName, conf);
}
use of com.aliyun.oss.OSSClientBuilder in project aliyun-oss-java-sdk by aliyun.
the class ProxyTest method testProxy.
@Ignore
public void testProxy() {
String key = "test/test.txt";
String content = "Hello OSS.";
try {
ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
conf.setProxyHost(TestConfig.PROXY_HOST);
conf.setProxyPort(TestConfig.PROXY_PORT);
conf.setProxyUsername(TestConfig.PROXY_USER);
conf.setProxyPassword(TestConfig.PROXY_PASSWORD);
OSS ossClient = new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET, conf);
BucketInfo info = ossClient.getBucketInfo(bucketName);
Assert.assertEquals(info.getBucket().getName(), bucketName);
ObjectMetadata metadata = new ObjectMetadata();
metadata.setContentLength(content.getBytes().length);
ossClient.putObject(bucketName, key, new ByteArrayInputStream(content.getBytes()), metadata);
OSSObject ossObject = ossClient.getObject(bucketName, key);
InputStream inputStream = ossObject.getObjectContent();
inputStream.close();
ossClient.deleteObject(bucketName, key);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.OSSClientBuilder in project aliyun-oss-java-sdk by aliyun.
the class RequestTimeoutTest method testClientConfigIndependent.
/**
* Testing connection timeout.
*/
@Test
public void testClientConfigIndependent() throws Exception {
String key = "test-client-config-independent";
ClientBuilderConfiguration config = new ClientBuilderConfiguration();
config.setRequestTimeout(requestTimeout);
config.setRequestTimeoutEnabled(true);
config.setConnectionTimeout(1);
OSS client = new OSSClientBuilder().build(endpoint, accessId, accessKey, config);
try {
client.putObject(bucketName, key, TestUtils.genFixedLengthInputStream(1024));
Assert.fail("Put object should not be successful");
} catch (ClientException e) {
Assert.assertEquals(ClientErrorCode.CONNECTION_TIMEOUT, e.getErrorCode());
} finally {
client.shutdown();
}
}
Aggregations