15
|
1 import javax.ws.rs.core.MediaType;
|
|
2
|
16
|
3 import models.NodeModel;
|
|
4
|
15
|
5 import org.json.JSONException;
|
|
6 import org.json.JSONObject;
|
|
7
|
|
8 import com.sun.jersey.api.client.Client;
|
|
9 import com.sun.jersey.api.client.ClientResponse;
|
|
10 import com.sun.jersey.api.client.WebResource;
|
|
11
|
|
12
|
|
13 public class RequestTest {
|
|
14 final static String SERVER_ROOT_URI = "http://localhost:9000";
|
|
15
|
|
16 public static void main(String[] args) throws JSONException {
|
20
|
17 String user1 = "akifumi";
|
|
18 String user2 = "takaaki";
|
|
19 String user3 = "yosiaki";
|
15
|
20
|
20
|
21 createUser(user1);
|
|
22 createUser(user2);
|
|
23 createUser(user3);
|
22
|
24
|
20
|
25 String[] users = {user2,user3};
|
22
|
26 createClaim(user1, users);
|
|
27 createClaim(user1, users);
|
|
28
|
23
|
29 /*
|
22
|
30 getUser(user1);
|
20
|
31 getUserInfo(user2,"requests/");
|
23
|
32 getUserInfo(user2,"claims/");
|
|
33 */
|
|
34
|
20
|
35 getUserInfo(user3,"requests/");
|
21
|
36 getUserInfo(user3,"claims/");
|
23
|
37 getUserInfo(user3,"consensus/");
|
20
|
38
|
15
|
39 }
|
|
40
|
18
|
41 public static void createClaim(String author, String[] users) throws JSONException {
|
15
|
42 JSONObject toulmin = new JSONObject();
|
16
|
43 toulmin.put(NodeModel.TITLE, "アプリでGraphDBを利用する。");
|
|
44 toulmin.put(NodeModel.CONTENTS, "最近話題のデータベースとしてGraphDBがある。我々のアプリでは、新しい技術のためにもGraphDBを利用したい。");
|
|
45 toulmin.put(NodeModel.QUALIFIER, "絶対");
|
|
46 toulmin.put(NodeModel.WARRANT,"GraphDBの実用例 etc...");
|
|
47 toulmin.put(NodeModel.BACKING, "GraphDBの最新動向 etc...");
|
|
48 toulmin.put(NodeModel.DATA,"GraphDBの実用例 etc...");
|
|
49 toulmin.put(NodeModel.REBUTTLE,"");
|
|
50
|
15
|
51 JSONObject jobj = new JSONObject();
|
16
|
52 jobj.put(NodeModel.TOULMIN, toulmin);
|
18
|
53 jobj.put(NodeModel.L_AUTHOR, author);
|
16
|
54 jobj.put(NodeModel.USERS,users);
|
|
55 jobj.put(NodeModel.TYPE, "unanimously");
|
|
56
|
|
57 final String uri = SERVER_ROOT_URI + "/claims/create";
|
|
58 WebResource resource = Client.create().resource(uri);
|
|
59 ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
|
|
60 .entity(jobj.toString())
|
|
61 .post(ClientResponse.class);
|
|
62 System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus()));
|
|
63 System.out.println(response.getEntity(String.class));
|
|
64
|
15
|
65 }
|
|
66
|
|
67 public static void getUserInfo(String name, String preUri) {
|
|
68 final String uri = SERVER_ROOT_URI + "/users/"+preUri+name;
|
|
69 WebResource resource = Client.create().resource(uri);
|
|
70 ClientResponse response = resource.get(ClientResponse.class);
|
|
71 System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus()));
|
|
72 System.out.println(response.getEntity(String.class));
|
|
73 }
|
|
74
|
|
75 public static void createUser(String name) {
|
|
76 final String uri = SERVER_ROOT_URI + "/users/create/"+name;
|
|
77 WebResource resource = Client.create().resource(uri);
|
|
78 ClientResponse response = resource.put(ClientResponse.class);
|
|
79 System.out.println(String.format("PUT on [%s], status code [%d]", uri, response.getStatus()));
|
|
80 System.out.println(response.getEntity(String.class));
|
|
81
|
|
82 }
|
|
83
|
|
84 public static void getUser(String name) {
|
|
85 final String uri = SERVER_ROOT_URI + "/users/browse/"+name;
|
|
86 WebResource resource = Client.create().resource(uri);
|
|
87 ClientResponse response = resource.get(ClientResponse.class);
|
|
88 System.out.println(String.format("GET on [%s], status code [%d]", uri, response.getStatus()));
|
|
89 System.out.println(response.getEntity(String.class));
|
|
90 }
|
|
91
|
|
92
|
|
93 public static void postName() throws JSONException {
|
|
94 final String uri = SERVER_ROOT_URI + "/hello";
|
|
95 WebResource resource = Client.create().resource(uri);
|
|
96 JSONObject jobj = new JSONObject();
|
|
97 jobj.put("name","taro");
|
|
98 // ClientResponse response = resource.accept(MediaType.APPLICATION_JSON)
|
|
99 ClientResponse response = resource.header("Content-type",MediaType.APPLICATION_JSON)
|
|
100 .entity(jobj.toString())
|
|
101 .post(ClientResponse.class);
|
|
102 System.out.println(String.format("POST on [%s], status code [%d]", uri, response.getStatus()));
|
|
103 System.out.println(response.getEntity(String.class));
|
|
104
|
|
105 }
|
|
106
|
|
107
|
|
108
|
|
109 }
|