-
-
Notifications
You must be signed in to change notification settings - Fork 1
Expand file tree
/
Copy pathAsynTest.java
More file actions
54 lines (46 loc) · 1.45 KB
/
Copy pathAsynTest.java
File metadata and controls
54 lines (46 loc) · 1.45 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
import juno.concurrent.Callback;
import juno.http.HttpClient;
import juno.http.HttpRequest;
import juno.http.HttpResult;
import juno.http.HttpTask;
import juno.http.HttpUrl;
public class AsynTest {
HttpClient client = HttpClient.getInstance()
.setDebug(true)
;
public HttpTask<String> getIpLocation() {
HttpUrl url = new HttpUrl("http://ip-api.com/")
.addPath("json")
.addPath("24.48.0.1")
.addQueryParameter("fields", "status,message,query,country,city")
.addQueryParameter("lang", "en")
;
HttpRequest request = HttpRequest.get(url)
;
return client.newTask(request, String.class);
}
public void async() {
HttpTask<String> task = getIpLocation();
task.async(new Callback<HttpResult<String>>() {
@Override
public void onResponse(HttpResult<String> result) throws Exception {
String str = result.data;
System.out.println(str);
}
@Override
public void onFailure(Exception e) {
e.printStackTrace();
}
});
}
public void sync() throws Exception {
HttpResult<String> result = getIpLocation().sync();
String str = result.data;
System.out.println(str);
}
public static void main(String[] args) throws Exception {
AsynTest test = new AsynTest();
//test.async();
test.sync();
}
}