Skip to content

Commit b3b0f4d

Browse files
committed
Merge pull request #170 from simon-liubin/fix/entity
entry除了fetch接口外,其它都包含分号:
2 parents 455d5a3 + 56e69c4 commit b3b0f4d

File tree

2 files changed

+40
-5
lines changed

2 files changed

+40
-5
lines changed

src/main/java/com/qiniu/storage/BucketManager.java

Lines changed: 19 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -37,9 +37,24 @@ public BucketManager(Auth auth) {
3737
* @return urlsafe_base64_encode(Bucket:Key)
3838
*/
3939
public static String entry(String bucket, String key) {
40-
String en = bucket;
41-
if (key != null) {
42-
en = bucket + ":" + key;
40+
return entry(bucket, key, true);
41+
}
42+
43+
44+
/**
45+
* EncodedEntryURI格式
46+
* 当 mustHaveKey 为 false, 且 key 为 null 时,返回 urlsafe_base64_encode(Bucket);
47+
* 其它条件下返回 urlsafe_base64_encode(Bucket:Key)
48+
*
49+
* @param bucket
50+
* @param key
51+
* @param mustHaveKey
52+
* @return urlsafe_base64_encode(entry)
53+
*/
54+
public static String entry(String bucket, String key, boolean mustHaveKey) {
55+
String en = bucket + ":" + key;
56+
if (!mustHaveKey && (key == null)) {
57+
en = bucket;
4358
}
4459
return UrlSafeBase64.encodeToString(en);
4560
}
@@ -207,7 +222,7 @@ public DefaultPutRet fetch(String url, String bucket) throws QiniuException {
207222
*/
208223
public DefaultPutRet fetch(String url, String bucket, String key) throws QiniuException {
209224
String resource = UrlSafeBase64.encodeToString(url);
210-
String to = entry(bucket, key);
225+
String to = entry(bucket, key, false);
211226
String path = "/fetch/" + resource + "/to/" + to;
212227
Response r = ioPost(path);
213228
return r.jsonToObject(DefaultPutRet.class);

src/test/java/com/qiniu/storage/BucketTest.java

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -79,6 +79,13 @@ public void testStat() {
7979
assertEquals(612, e.code());
8080
}
8181

82+
try {
83+
bucketManager.stat(TestConfig.bucket, null);
84+
fail();
85+
} catch (QiniuException e) {
86+
assertEquals(612, e.code());
87+
}
88+
8289
try {
8390
bucketManager.stat("noBucket", "noFile");
8491
fail();
@@ -95,6 +102,20 @@ public void testDelete() {
95102
} catch (QiniuException e) {
96103
assertEquals(612, e.code());
97104
}
105+
106+
try {
107+
bucketManager.delete(TestConfig.bucket, null);
108+
fail();
109+
} catch (QiniuException e) {
110+
assertEquals(612, e.code());
111+
}
112+
113+
try {
114+
bucketManager.delete("noBucket", null);
115+
fail();
116+
} catch (QiniuException e) {
117+
assertEquals(631, e.code());
118+
}
98119
}
99120

100121
@Test
@@ -149,7 +170,6 @@ public void testFetch() {
149170
bucketManager.fetch("http://developer.qiniu.com/docs/v6/sdk/java-sdk.html",
150171
TestConfig.bucket, "fetch.html");
151172
} catch (QiniuException e) {
152-
e.printStackTrace();
153173
fail();
154174
}
155175
}

0 commit comments

Comments
 (0)