Skip to content

Commit 1dd20d3

Browse files
committed
Compatible with old version bucketInfo API.
1 parent 2c91fea commit 1dd20d3

File tree

3 files changed

+48
-4
lines changed

3 files changed

+48
-4
lines changed

src/main/java/com/aliyun/oss/internal/ResponseParsers.java

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -2351,8 +2351,10 @@ public static BucketInfo parseGetBucketInfo(InputStream responseBody) throws Res
23512351

23522352
// data redundancy type
23532353
String dataRedundancyString = bucketElem.getChildText("DataRedundancyType");
2354-
DataRedundancyType dataRedundancyType = DataRedundancyType.parse(dataRedundancyString);
2355-
bucketInfo.setDataRedundancyType(dataRedundancyType);
2354+
if (dataRedundancyString != null) {
2355+
DataRedundancyType dataRedundancyType = DataRedundancyType.parse(dataRedundancyString);
2356+
bucketInfo.setDataRedundancyType(dataRedundancyType);
2357+
}
23562358

23572359
// acl
23582360
String aclString = bucketElem.getChild("AccessControlList").getChildText("Grant");

src/test/java/com/aliyun/oss/common/parser/ResponseParsersTest.java

Lines changed: 43 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -552,4 +552,47 @@ public void testparseGetBucketCname() {
552552
Assert.assertEquals(new Boolean(true), result.get(0).getPurgeCdnCache());
553553
Assert.assertEquals(null, result.get(1).getPurgeCdnCache());
554554
}
555+
556+
@Test
557+
public void testParseGetBucketInfo() {
558+
String respBody = "" +
559+
"<BucketInfo>\n" +
560+
" <Bucket>\n" +
561+
" <CreationDate>2013-07-31T10:56:21.000Z</CreationDate>\n" +
562+
" <ExtranetEndpoint>oss-cn-hangzhou.aliyuncs.com</ExtranetEndpoint>\n" +
563+
" <IntranetEndpoint>oss-cn-hangzhou-internal.aliyuncs.com</IntranetEndpoint>\n" +
564+
" <Location>oss-cn-hangzhou</Location>\n" +
565+
" <Name>oss-example</Name>\n" +
566+
" <Owner>\n" +
567+
" <DisplayName>username</DisplayName>\n" +
568+
" <ID>27183473914****</ID>\n" +
569+
" </Owner>\n" +
570+
" <AccessControlList>\n" +
571+
" <Grant>private</Grant>\n" +
572+
" </AccessControlList>\n" +
573+
" <Comment>test</Comment>\n" +
574+
" </Bucket>\n" +
575+
" </BucketInfo>";
576+
577+
InputStream instream = null;
578+
try {
579+
instream = new ByteArrayInputStream(respBody.getBytes("utf-8"));
580+
} catch (UnsupportedEncodingException e) {
581+
e.printStackTrace();
582+
Assert.fail("UnsupportedEncodingException");
583+
}
584+
585+
BucketInfo result = null;
586+
try {
587+
result = ResponseParsers.parseGetBucketInfo(instream);
588+
} catch (ResponseParseException e) {
589+
e.printStackTrace();
590+
Assert.fail("parse bucket replication response body fail!");
591+
}
592+
593+
Assert.assertEquals("test", result.getComment());
594+
Assert.assertEquals(CannedAccessControlList.Private, result.getCannedACL());
595+
Assert.assertEquals("oss-cn-hangzhou", result.getBucket().getLocation());
596+
Assert.assertEquals("oss-example", result.getBucket().getName());
597+
}
555598
}

src/test/java/com/aliyun/oss/integrationtests/BucketReplicationTest.java

Lines changed: 1 addition & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -528,8 +528,7 @@ public void testUnormalSetBucketReplicationInvalidParam() throws ParseException
528528
ossClient.createBucket(bucketName);
529529

530530
AddBucketReplicationRequest request = new AddBucketReplicationRequest(bucketName);
531-
request.setTargetBucketName(targetBucketName);
532-
531+
533532
try {
534533
ossClient.addBucketReplication(request);
535534
Assert.fail("Get bucket replication should not be successful.");

0 commit comments

Comments
 (0)