use of com.aliyun.oss.model.GenericRequest in project aliyun-oss-java-sdk by aliyun.
the class OSSClientRequestTest method testBucketLocationRequest.
@Test
public void testBucketLocationRequest() {
TestAction test = new TestAction() {
@Override
public void run() throws Exception {
bucketOp.getBucketLocation(new GenericRequest(bucketName));
}
};
executeTest(test, HttpMethod.GET, bucketName + "." + endpoint.getHost(), "?location", null);
}
use of com.aliyun.oss.model.GenericRequest in project aliyun-oss-java-sdk by aliyun.
the class TestForImg method testGenernicRequest.
// 已抓包看了所有请求头
public void testGenernicRequest() {
PutBucketImageRequest request = new PutBucketImageRequest(bucketName);
GenericRequest req = new GenericRequest();
request.addHeader("oss-request-ip", "31.71.68.91");
request.addHeader("oss-request-agent", "oss-java-sdk");
request.addHeader("oss-operation", "PutBucketImage");
try {
clientImg.putBucketImage(request);
} catch (Exception e) {
}
req.addHeader("oss-operation", "GetBucketImage");
try {
clientImg.getBucketImage(bucketName, req);
} catch (Exception e) {
}
req.addHeader("oss-operation", "DeleteBucketImage");
try {
clientImg.deleteBucketImage(bucketName, req);
} catch (Exception e) {
}
PutImageStyleRequest requestStyle = new PutImageStyleRequest();
requestStyle.SetBucketName(bucketName);
String styleName = "style";
String styleContent = "200w";
requestStyle.SetStyle(styleName);
requestStyle.SetStyleName(styleContent);
requestStyle.addHeader("oss-operation", "PutImageStyle");
try {
clientImg.putImageStyle(requestStyle);
} catch (Exception e) {
}
req.addHeader("oss-operation", "DeleteImageStyle");
try {
clientImg.deleteImageStyle(bucketName, styleName, req);
} catch (Exception e) {
}
req.addHeader("oss-operation", "GetImageStyle");
try {
clientImg.getImageStyle(bucketName, styleName, req);
} catch (Exception e) {
}
req.addHeader("oss-operation", "ListImageStyle");
try {
clientImg.listImageStyle(bucketName, req);
} catch (Exception e) {
}
}
use of com.aliyun.oss.model.GenericRequest in project aliyun-oss-java-sdk by aliyun.
the class BucketTaggingTest method testSetBucketTagging.
@Test
public void testSetBucketTagging() {
try {
SetBucketTaggingRequest request = new SetBucketTaggingRequest(bucketName);
request.setTag("tk1", "tv1");
request.setTag("tk2", "tv2");
ossClient.setBucketTagging(request);
TagSet tagSet = ossClient.getBucketTagging(new GenericRequest(bucketName));
Assert.assertEquals(tagSet.getRequestId().length(), REQUEST_ID_LEN);
Map<String, String> tags = tagSet.getAllTags();
Assert.assertEquals(2, tags.size());
Assert.assertTrue(tags.containsKey("tk1"));
Assert.assertTrue(tags.containsKey("tk2"));
ossClient.deleteBucketTagging(new GenericRequest(bucketName));
waitForCacheExpiration(5);
tagSet = ossClient.getBucketTagging(new GenericRequest(bucketName));
Assert.assertEquals(tagSet.getRequestId().length(), REQUEST_ID_LEN);
tags = tagSet.getAllTags();
Assert.assertTrue(tags.isEmpty());
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.GenericRequest in project aliyun-oss-java-sdk by aliyun.
the class BucketProcesTest method testBucketImageProcessConf.
@Test
public void testBucketImageProcessConf() {
try {
// get default
BucketProcess bucketProcess = ossClient.getBucketProcess(bucketName);
Assert.assertEquals(bucketProcess.getImageProcess().getCompliedHost(), "Both");
Assert.assertFalse(bucketProcess.getImageProcess().isSourceFileProtect());
Assert.assertEquals(bucketProcess.getImageProcess().getSourceFileProtectSuffix(), "");
Assert.assertEquals(bucketProcess.getImageProcess().getStyleDelimiters(), "");
Assert.assertEquals(bucketProcess.getImageProcess().getVersion().intValue(), 2);
Assert.assertEquals(bucketProcess.getImageProcess().isSupportAtStyle(), null);
Assert.assertEquals(bucketProcess.getRequestId().length(), REQUEST_ID_LEN);
// put 1
ImageProcess imageProcess = new ImageProcess("Img", true, "jpg,png", "/,-");
SetBucketProcessRequest request = new SetBucketProcessRequest(bucketName, imageProcess);
ossClient.setBucketProcess(request);
// get 1
bucketProcess = ossClient.getBucketProcess(new GenericRequest(bucketName));
Assert.assertEquals(bucketProcess.getImageProcess().getCompliedHost(), "Img");
Assert.assertTrue(bucketProcess.getImageProcess().isSourceFileProtect());
Assert.assertEquals(bucketProcess.getImageProcess().getSourceFileProtectSuffix(), "jpg,png");
Assert.assertEquals(bucketProcess.getImageProcess().getStyleDelimiters(), "-,/");
Assert.assertEquals(bucketProcess.getImageProcess().getVersion().intValue(), 2);
Assert.assertEquals(bucketProcess.getImageProcess().isSupportAtStyle(), null);
Assert.assertEquals(bucketProcess.getRequestId().length(), REQUEST_ID_LEN);
// put 2
imageProcess = new ImageProcess("Both", false, "gif", "-");
request = new SetBucketProcessRequest(bucketName, imageProcess);
ossClient.setBucketProcess(request);
// get 2
bucketProcess = ossClient.getBucketProcess(new GenericRequest(bucketName));
Assert.assertEquals(bucketProcess.getImageProcess().getCompliedHost(), "Both");
Assert.assertFalse(bucketProcess.getImageProcess().isSourceFileProtect());
Assert.assertEquals(bucketProcess.getImageProcess().getSourceFileProtectSuffix(), "");
Assert.assertEquals(bucketProcess.getImageProcess().getStyleDelimiters(), "-");
Assert.assertEquals(bucketProcess.getImageProcess().getVersion().intValue(), 2);
Assert.assertEquals(bucketProcess.getImageProcess().isSupportAtStyle(), null);
Assert.assertEquals(bucketProcess.getRequestId().length(), REQUEST_ID_LEN);
// put 3
imageProcess = new ImageProcess("Img", true, "*", "/", true);
request = new SetBucketProcessRequest(bucketName, imageProcess);
ossClient.setBucketProcess(request);
// get 3
bucketProcess = ossClient.getBucketProcess(new GenericRequest(bucketName));
Assert.assertEquals(bucketProcess.getImageProcess().getCompliedHost(), "Img");
Assert.assertTrue(bucketProcess.getImageProcess().isSourceFileProtect());
Assert.assertEquals(bucketProcess.getImageProcess().getSourceFileProtectSuffix(), "*");
Assert.assertEquals(bucketProcess.getImageProcess().getStyleDelimiters(), "/");
Assert.assertEquals(bucketProcess.getImageProcess().getVersion().intValue(), 2);
Assert.assertEquals(bucketProcess.getImageProcess().isSupportAtStyle(), null);
Assert.assertEquals(bucketProcess.getRequestId().length(), REQUEST_ID_LEN);
} catch (Exception e) {
Assert.fail(e.getMessage());
}
}
use of com.aliyun.oss.model.GenericRequest in project aliyun-oss-java-sdk by aliyun.
the class OSSBucketOperation method doesBucketExists.
/**
* Determine whether a bucket exists or not.
*/
public boolean doesBucketExists(GenericRequest genericRequest) throws OSSException, ClientException {
assertParameterNotNull(genericRequest, "genericRequest");
String bucketName = genericRequest.getBucketName();
assertParameterNotNull(bucketName, "bucketName");
ensureBucketNameValid(bucketName);
try {
getBucketAcl(new GenericRequest(bucketName));
} catch (OSSException oe) {
if (oe.getErrorCode().equals(OSSErrorCode.NO_SUCH_BUCKET)) {
return false;
}
}
return true;
}
Aggregations