use of com.aliyun.oss.OSSClientBuilder in project aliyun-oss-java-sdk by aliyun.
the class ProxySignTest method testProxyAuth.
@Ignore
public void testProxyAuth() {
String bucketName = "sdk-test-md-1";
String key = "mingdi/test.txt";
String content = "Hello OSS.";
String proxyHost = "";
String endpoint = "";
String accessKeyId = "";
String secretAccessKey = "";
try {
ClientBuilderConfiguration conf = new ClientBuilderConfiguration();
conf.setProxyHost(proxyHost);
conf.setProxyPort(8080);
Credentials credentials = new ProxyCredentials("mingditest");
ProxyRequestSigner proxySigner = new ProxyRequestSigner(credentials);
List<RequestSigner> signerHandlers = new LinkedList<RequestSigner>();
signerHandlers.add(proxySigner);
conf.setSignerHandlers(signerHandlers);
Map<String, String> proxyHeaders = new LinkedHashMap<String, String>();
proxyHeaders.put(HEADER_PROXY_TYPE, "default");
proxyHeaders.put(HEADER_PROXY_USER, "diff_bucket_sync_test_user_1");
proxyHeaders.put(HEADER_PROXY_DEST, "cn-qingdao");
proxyHeaders.put(HEADER_PROXY_DEST_REGION, "cn-qingdao");
proxyHeaders.put(HEADER_PROXY_REAL_HOST, endpoint);
conf.setDefaultHeaders(proxyHeaders);
OSS ossClient = new OSSClientBuilder().build(endpoint, accessKeyId, secretAccessKey, conf);
ossClient.putObject(bucketName, key, new ByteArrayInputStream(content.getBytes()));
ossClient.getObject(bucketName, key);
ossClient.deleteObject(bucketName, key);
} catch (Throwable e) {
e.printStackTrace();
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.OSSClientBuilder in project aliyun-oss-java-sdk by aliyun.
the class UrlSignatureTest method testPutObject.
@Ignore
public void testPutObject() {
OSS client = new OSSClientBuilder().build(endpoint, accessId, accessKey);
try {
Date expiration = DateUtil.parseRfc822Date("Thu, 19 Mar 2015 18:00:00 GMT");
GeneratePresignedUrlRequest request = new GeneratePresignedUrlRequest(bucketName, key, HttpMethod.PUT);
request.setExpiration(expiration);
request.setContentType("application/octet-stream");
request.addUserMetadata("author", "aliy");
URL signedUrl = client.generatePresignedUrl(request);
System.out.println("signed url for putObject: " + signedUrl);
File f = new File(filePath);
FileInputStream fin = new FileInputStream(f);
Map<String, String> customHeaders = new HashMap<String, String>();
customHeaders.put("Content-Type", "application/octet-stream");
customHeaders.put("x-oss-meta-author", "aliy");
PutObjectResult result = client.putObject(signedUrl, fin, f.length(), customHeaders);
fin = new FileInputStream(f);
byte[] binaryData = IOUtils.readStreamAsByteArray(fin);
String expectedETag = BinaryUtil.encodeMD5(binaryData);
String actualETag = result.getETag();
Assert.assertEquals(expectedETag, actualETag);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.OSSClientBuilder in project aliyun-oss-java-sdk by aliyun.
the class BucketReplicationTest method beforeClass.
@BeforeClass
public static void beforeClass() {
if (replicationClient == null) {
replicationClient = new OSSClientBuilder().build(OSS_TEST_REPLICATION_ENDPOINT, OSS_TEST_REPLICATION_ACCESS_KEY_ID, OSS_TEST_REPLICATION_ACCESS_KEY_SECRET);
replicationClient.createBucket(targetBucketName);
BucketList buckets = replicationClient.listBuckets(targetBucketName, "", 100);
Assert.assertEquals(1, buckets.getBucketList().size());
}
}
use of com.aliyun.oss.OSSClientBuilder in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderWithAll.
@Test
public void testClientBuilderWithAll() {
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), config);
Assert.assertTrue(ossClient.getClientConfiguration().isSupportCname());
Assert.assertEquals(ossClient.getClientConfiguration().getConnectionTimeout(), 10000);
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.OSSClientBuilder in project aliyun-oss-java-sdk by aliyun.
the class ClientBuilderTest method testClientBuilderDefault.
@Test
public void testClientBuilderDefault() {
try {
OSSClient ossClient = (OSSClient) new OSSClientBuilder().build(TestConfig.OSS_TEST_ENDPOINT, TestConfig.OSS_TEST_ACCESS_KEY_ID, TestConfig.OSS_TEST_ACCESS_KEY_SECRET);
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());
}
}
Aggregations