Skip to content

Commit 4878a2c

Browse files
committed
Merge pull request #143 from longbai/ajust_host
调整服务器host设置方式
2 parents 58aab36 + 333050c commit 4878a2c

File tree

16 files changed

+326
-277
lines changed

16 files changed

+326
-277
lines changed

CHANGELOG.md

Lines changed: 4 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1,12 +1,14 @@
11
#Changelog
22

3-
## 7.0.8 (2015-10-09)
3+
## 7.0.8 (2015-10-10)
44

5-
### 调整
5+
### 修改
66
* android-async-http 最低版本要求 1.4.9, 为了兼容 Android 6.0 感谢 Haoxiqiang
77
* 升级SDK环境
88
* 默认http port 为80
99
* 首选dns server 改为 119.29.29.29
10+
* 变更上传服务器地址设置方式
11+
* 增加https支持
1012

1113
## 7.0.7.1 (2015-08-05)
1214

library/src/androidTest/java/com/qiniu/android/FormUploadTest.java

Lines changed: 48 additions & 9 deletions
Original file line numberDiff line numberDiff line change
@@ -5,12 +5,13 @@
55
import android.test.suitebuilder.annotation.SmallTest;
66
import android.util.Log;
77

8+
import com.qiniu.android.common.ServiceAddress;
9+
import com.qiniu.android.common.Zone;
810
import com.qiniu.android.http.ResponseInfo;
911
import com.qiniu.android.storage.Configuration;
1012
import com.qiniu.android.storage.UpCompletionHandler;
1113
import com.qiniu.android.storage.UploadManager;
1214
import com.qiniu.android.storage.UploadOptions;
13-
import com.qiniu.android.storage.Zone;
1415

1516
import junit.framework.Assert;
1617

@@ -50,7 +51,6 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
5051
}
5152
}, opt);
5253

53-
5454
try {
5555
signal.await(120, TimeUnit.SECONDS); // wait for callback
5656
Assert.assertNotNull("timeout", info);
@@ -61,7 +61,6 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
6161
Assert.assertTrue(info.toString(), info.isOK());
6262
Assert.assertNotNull(info.reqId);
6363
Assert.assertNotNull(resp);
64-
Assert.assertEquals("/", info.path);
6564
}
6665

6766
@SmallTest
@@ -95,7 +94,6 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
9594
Assert.assertTrue(info.toString(), info.isOK());
9695

9796
Assert.assertNotNull(info.reqId);
98-
Assert.assertEquals("/", info.path);
9997
Assert.assertNotNull(resp);
10098
Assert.assertEquals("Fqr0xh3cxeii2r7eDztILNmuqUNN", resp.optString("key", ""));
10199
}
@@ -269,10 +267,12 @@ public void testNoComplete() {
269267

270268
@SmallTest
271269
public void testIpBack() throws Throwable {
272-
270+
ServiceAddress s = new ServiceAddress("http://upwelcome.qiniu.com", Zone.zone0.up.backupIps);
271+
Zone z = new Zone(s, Zone.zone0.upBackup);
273272
Configuration c = new Configuration.Builder()
274-
.zone(new Zone("upwelcome.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp, Zone.zone0.upIp2))
273+
.zone(z)
275274
.build();
275+
276276
UploadManager uploadManager2 = new UploadManager(c);
277277
final String expectKey = "你好;\"\r\n\r\n\r\n";
278278
Map<String, String> params = new HashMap<String, String>();
@@ -305,9 +305,10 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
305305

306306
@SmallTest
307307
public void testPortBackup() throws Throwable {
308+
ServiceAddress s = new ServiceAddress("http://upload.qiniu.com:9999", null);
309+
Zone z = new Zone(s, Zone.zone0.upBackup);
308310
Configuration c = new Configuration.Builder()
309-
.zone(new Zone("upload.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp, Zone.zone0.upIp2))
310-
.upPort(9999)
311+
.zone(z)
311312
.build();
312313
UploadManager uploadManager2 = new UploadManager(c);
313314
final String expectKey = "你好;\"\r\n\r\n\r\n";
@@ -341,8 +342,10 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
341342

342343
@SmallTest
343344
public void testDnsHijacking() throws Throwable {
345+
ServiceAddress s = new ServiceAddress("http://uphijacktest.qiniu.com", Zone.zone0.up.backupIps);
346+
Zone z = new Zone(s, Zone.zone0.upBackup);
344347
Configuration c = new Configuration.Builder()
345-
.zone(new Zone("uphijacktest.qiniu.com", Zone.zone0.upHostBackup, Zone.zone0.upIp, Zone.zone0.upIp2))
348+
.zone(z)
346349
.build();
347350
UploadManager uploadManager2 = new UploadManager(c);
348351
final String expectKey = "你好;\"\r\n\r\n\r\n";
@@ -373,4 +376,40 @@ public void complete(String k, ResponseInfo rinfo, JSONObject response) {
373376
Assert.assertNotNull(info.reqId);
374377
Assert.assertNotNull(resp);
375378
}
379+
380+
@SmallTest
381+
public void testHttps() throws Throwable {
382+
383+
final String expectKey = "你好;\"\r\n\r\n\r\n";
384+
Map<String, String> params = new HashMap<String, String>();
385+
params.put("x:foo", "fooval");
386+
final UploadOptions opt = new UploadOptions(params, null, true, null, null);
387+
ServiceAddress s = new ServiceAddress("https://up.qbox.me", null);
388+
Zone z = new Zone(s, Zone.zone0.upBackup);
389+
Configuration c = new Configuration.Builder()
390+
.zone(z)
391+
.build();
392+
UploadManager uploadManager2 = new UploadManager(c);
393+
uploadManager2.put("hello".getBytes(), expectKey, TestConfig.token, new UpCompletionHandler() {
394+
public void complete(String k, ResponseInfo rinfo, JSONObject response) {
395+
Log.i("qiniutest", k + rinfo);
396+
key = k;
397+
info = rinfo;
398+
resp = response;
399+
signal.countDown();
400+
}
401+
}, opt);
402+
403+
404+
try {
405+
signal.await(120, TimeUnit.SECONDS); // wait for callback
406+
Assert.assertNotNull("timeout", info);
407+
} catch (InterruptedException e) {
408+
e.printStackTrace();
409+
}
410+
Assert.assertEquals(info.toString(), expectKey, key);
411+
Assert.assertTrue(info.toString(), info.isOK());
412+
Assert.assertNotNull(info.reqId);
413+
Assert.assertNotNull(resp);
414+
}
376415
}

library/src/androidTest/java/com/qiniu/android/HttpTest.java

Lines changed: 60 additions & 45 deletions
Original file line numberDiff line numberDiff line change
@@ -12,6 +12,8 @@
1212

1313
import org.json.JSONObject;
1414

15+
import java.net.URI;
16+
import java.net.URISyntaxException;
1517
import java.util.concurrent.CountDownLatch;
1618
import java.util.concurrent.TimeUnit;
1719

@@ -25,7 +27,15 @@ public class HttpTest extends InstrumentationTestCase {
2527
final CountDownLatch signal = new CountDownLatch(1);
2628
private HttpManager httpManager;
2729
private ResponseInfo info;
28-
private JSONObject resp;
30+
31+
private static URI newURI(String s) {
32+
try {
33+
return new URI(s);
34+
} catch (URISyntaxException e) {
35+
e.printStackTrace();
36+
}
37+
return null;
38+
}
2939

3040
@Override
3141
protected void setUp() throws Exception {
@@ -34,14 +44,14 @@ protected void setUp() throws Exception {
3444

3545
@SmallTest
3646
public void testPost1() throws Throwable {
37-
httpManager.postData("http://www.baidu.com", "hello".getBytes(), null, null, new CompletionHandler() {
47+
httpManager.postData(newURI("http://www.baidu.com"), "hello".getBytes(), null, null, new CompletionHandler() {
3848
@Override
3949
public void complete(ResponseInfo rinfo, JSONObject response) {
4050
Log.d("qiniutest", rinfo.toString());
4151
info = rinfo;
4252
signal.countDown();
4353
}
44-
}, null, false);
54+
}, null);
4555

4656
try {
4757
signal.await(6000, TimeUnit.SECONDS); // wait for callback
@@ -54,14 +64,14 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
5464
@SmallTest
5565
public void testPost2() throws Throwable {
5666

57-
httpManager.postData("http://up.qiniu.com", "hello".getBytes(), null, null, new CompletionHandler() {
67+
httpManager.postData(newURI("http://up.qiniu.com"), "hello".getBytes(), null, null, new CompletionHandler() {
5868
@Override
5969
public void complete(ResponseInfo rinfo, JSONObject response) {
6070
Log.d("qiniutest", rinfo.toString());
6171
info = rinfo;
6272
signal.countDown();
6373
}
64-
}, null, false);
74+
}, null);
6575

6676
try {
6777
signal.await(60, TimeUnit.SECONDS); // wait for callback
@@ -75,14 +85,15 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
7585
public void testPost3() throws Throwable {
7686
runTestOnUiThread(new Runnable() { // THIS IS THE KEY TO SUCCESS
7787
public void run() {
78-
httpManager.postData("http://httpbin.org/status/500", "hello".getBytes(), null, null, new CompletionHandler() {
79-
@Override
80-
public void complete(ResponseInfo rinfo, JSONObject response) {
81-
Log.d("qiniutest", rinfo.toString());
82-
info = rinfo;
83-
signal.countDown();
84-
}
85-
}, null, false);
88+
httpManager.postData(newURI("http://httpbin.org/status/500"), "hello".getBytes(),
89+
null, null, new CompletionHandler() {
90+
@Override
91+
public void complete(ResponseInfo rinfo, JSONObject response) {
92+
Log.d("qiniutest", rinfo.toString());
93+
info = rinfo;
94+
signal.countDown();
95+
}
96+
}, null);
8697
}
8798
});
8899

@@ -99,14 +110,15 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
99110
public void testPost4() throws Throwable {
100111
runTestOnUiThread(new Runnable() { // THIS IS THE KEY TO SUCCESS
101112
public void run() {
102-
httpManager.postData("http://httpbin.org/status/418", "hello".getBytes(), null, null, new CompletionHandler() {
103-
@Override
104-
public void complete(ResponseInfo rinfo, JSONObject response) {
105-
Log.d("qiniutest", rinfo.toString());
106-
info = rinfo;
107-
signal.countDown();
108-
}
109-
}, null, false);
113+
httpManager.postData(newURI("http://httpbin.org/status/418"), "hello".getBytes(),
114+
null, null, new CompletionHandler() {
115+
@Override
116+
public void complete(ResponseInfo rinfo, JSONObject response) {
117+
Log.d("qiniutest", rinfo.toString());
118+
info = rinfo;
119+
signal.countDown();
120+
}
121+
}, null);
110122
}
111123
});
112124

@@ -122,14 +134,15 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
122134
@SmallTest
123135
public void testPostNoDomain() throws Throwable {
124136

125-
httpManager.postData("http://no-domain.qiniu.com", "hello".getBytes(), null, null, new CompletionHandler() {
126-
@Override
127-
public void complete(ResponseInfo rinfo, JSONObject response) {
128-
Log.d("qiniutest", rinfo.toString());
129-
info = rinfo;
130-
signal.countDown();
131-
}
132-
}, null, false);
137+
httpManager.postData(newURI("http://no-domain.qiniu.com"), "hello".getBytes(),
138+
null, null, new CompletionHandler() {
139+
@Override
140+
public void complete(ResponseInfo rinfo, JSONObject response) {
141+
Log.d("qiniutest", rinfo.toString());
142+
info = rinfo;
143+
signal.countDown();
144+
}
145+
}, null);
133146

134147
try {
135148
signal.await(60, TimeUnit.SECONDS); // wait for callback
@@ -143,14 +156,15 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
143156
@SmallTest
144157
public void testPostNoPort() throws Throwable {
145158

146-
httpManager.postData("http://up.qiniu.com:12345", "hello".getBytes(), null, null, new CompletionHandler() {
147-
@Override
148-
public void complete(ResponseInfo rinfo, JSONObject response) {
149-
Log.d("qiniutest", rinfo.toString());
150-
info = rinfo;
151-
signal.countDown();
152-
}
153-
}, null, false);
159+
httpManager.postData(newURI("http://up.qiniu.com:12345"), "hello".getBytes(),
160+
null, null, new CompletionHandler() {
161+
@Override
162+
public void complete(ResponseInfo rinfo, JSONObject response) {
163+
Log.d("qiniutest", rinfo.toString());
164+
info = rinfo;
165+
signal.countDown();
166+
}
167+
}, null);
154168

155169
try {
156170
signal.await(60, TimeUnit.SECONDS); // wait for callback
@@ -164,14 +178,15 @@ public void complete(ResponseInfo rinfo, JSONObject response) {
164178
@SmallTest
165179
public void testPostIP() throws Throwable {
166180
Header[] x = {new BasicHeader("Host", "www.qiniu.com")};
167-
httpManager.postData("http://183.136.139.12/", "hello".getBytes(), x, null, new CompletionHandler() {
168-
@Override
169-
public void complete(ResponseInfo rinfo, JSONObject response) {
170-
Log.d("qiniutest", rinfo.toString());
171-
info = rinfo;
172-
signal.countDown();
173-
}
174-
}, null, false);
181+
httpManager.postData(newURI("http://183.136.139.12/"), "hello".getBytes(),
182+
x, null, new CompletionHandler() {
183+
@Override
184+
public void complete(ResponseInfo rinfo, JSONObject response) {
185+
Log.d("qiniutest", rinfo.toString());
186+
info = rinfo;
187+
signal.countDown();
188+
}
189+
}, null);
175190

176191
try {
177192
signal.await(60, TimeUnit.SECONDS); // wait for callback

library/src/androidTest/java/com/qiniu/android/PortTest.java

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,6 +5,8 @@
55
import android.test.suitebuilder.annotation.SmallTest;
66
import android.util.Log;
77

8+
import com.qiniu.android.common.ServiceAddress;
9+
import com.qiniu.android.common.Zone;
810
import com.qiniu.android.http.ResponseInfo;
911
import com.qiniu.android.storage.Configuration;
1012
import com.qiniu.android.storage.UpCompletionHandler;
@@ -33,7 +35,9 @@ public class PortTest extends InstrumentationTestCase {
3335

3436
@Override
3537
protected void setUp() throws Exception {
36-
Configuration config = new Configuration.Builder().upPort(8888).build();
38+
ServiceAddress s1 = new ServiceAddress("http://upload.qiniu.com:8888");
39+
Zone z = new Zone(s1, s1);
40+
Configuration config = new Configuration.Builder().zone(z).build();
3741
uploadManager = new UploadManager(config);
3842
}
3943

0 commit comments

Comments
 (0)