Bo Lee 6 anni fa
parent
commit
7cc0cb5192

+ 9
- 2
Client/Client.iml Vedi File

@@ -5,8 +5,6 @@
5 5
     <output-test url="file://$MODULE_DIR$/target/test-classes" />
6 6
     <content url="file://$MODULE_DIR$">
7 7
       <sourceFolder url="file://$MODULE_DIR$/src/main/java" isTestSource="false" />
8
-      <sourceFolder url="file://$MODULE_DIR$/src/main/resources" type="java-resource" />
9
-      <sourceFolder url="file://$MODULE_DIR$/src/test/java" isTestSource="true" />
10 8
       <excludeFolder url="file://$MODULE_DIR$/target" />
11 9
     </content>
12 10
     <orderEntry type="inheritedJdk" />
@@ -14,5 +12,14 @@
14 12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
15 13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
16 14
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
15
+    <orderEntry type="library" name="Maven: com.mashape.unirest:unirest-java:1.4.9" level="project" />
16
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.3.6" level="project" />
17
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.3.3" level="project" />
18
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.3" level="project" />
19
+    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.6" level="project" />
20
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpasyncclient:4.0.2" level="project" />
21
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore-nio:4.3.2" level="project" />
22
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.3.6" level="project" />
23
+    <orderEntry type="library" name="Maven: org.json:json:20140107" level="project" />
17 24
   </component>
18 25
 </module>

+ 32
- 0
Client/pom.xml Vedi File

@@ -11,5 +11,37 @@
11 11
 
12 12
     <artifactId>Client</artifactId>
13 13
 
14
+    <dependencies>
15
+        <dependency>
16
+            <groupId>com.fasterxml.jackson.core</groupId>
17
+            <artifactId>jackson-databind</artifactId>
18
+            <version>2.8.6</version>
19
+        </dependency>
20
+        <dependency>
21
+            <groupId>com.mashape.unirest</groupId>
22
+            <artifactId>unirest-java</artifactId>
23
+            <version>1.4.9</version>
24
+        </dependency>
25
+        <dependency>
26
+            <groupId>org.apache.httpcomponents</groupId>
27
+            <artifactId>httpclient</artifactId>
28
+            <version>4.3.6</version>
29
+        </dependency>
30
+        <dependency>
31
+            <groupId>org.apache.httpcomponents</groupId>
32
+            <artifactId>httpasyncclient</artifactId>
33
+            <version>4.0.2</version>
34
+        </dependency>
35
+        <dependency>
36
+            <groupId>org.apache.httpcomponents</groupId>
37
+            <artifactId>httpmime</artifactId>
38
+            <version>4.3.6</version>
39
+        </dependency>
40
+        <dependency>
41
+            <groupId>org.json</groupId>
42
+            <artifactId>json</artifactId>
43
+            <version>20140107</version>
44
+        </dependency>
14 45
 
46
+    </dependencies>
15 47
 </project>

+ 58
- 0
Client/src/main/java/Id.java Vedi File

@@ -0,0 +1,58 @@
1
+import com.mashape.unirest.http.HttpResponse;
2
+import com.mashape.unirest.http.Unirest;
3
+import com.mashape.unirest.http.exceptions.UnirestException;
4
+
5
+public class Id {
6
+
7
+    private String userId;
8
+    private String name;
9
+    private String github;
10
+
11
+
12
+    public Id() throws UnirestException {
13
+    }
14
+
15
+    public Id(String name, String github) {
16
+        this.name = name;
17
+        this.github = github;
18
+    }
19
+
20
+    public Id(String userId, String name, String github) {
21
+        this.userId = userId;
22
+        this.name = name;
23
+        this.github = github;
24
+    }
25
+
26
+    public String getUserId() {
27
+        return userId;
28
+    }
29
+
30
+    public void setUserId(String userId) {
31
+        this.userId = userId;
32
+    }
33
+
34
+    public String getName() {
35
+        return name;
36
+    }
37
+
38
+    public void setName(String name) {
39
+        this.name = name;
40
+    }
41
+
42
+    public String getGithub() {
43
+        return github;
44
+    }
45
+
46
+    public void setGithub(String github) {
47
+        this.github = github;
48
+    }
49
+
50
+    @Override
51
+    public String toString() {
52
+        return "Id{" +
53
+                "userId:'" + userId + '\'' +
54
+                ", name:'" + name + '\'' +
55
+                ", github:'" + github + '\'' +
56
+                '}';
57
+    }
58
+}

+ 87
- 0
Client/src/main/java/Message.java Vedi File

@@ -0,0 +1,87 @@
1
+import com.mashape.unirest.http.HttpResponse;
2
+import com.mashape.unirest.http.Unirest;
3
+import com.mashape.unirest.http.exceptions.UnirestException;
4
+
5
+import java.sql.Time;
6
+
7
+public class Message {
8
+
9
+
10
+    //final HttpResponse<String> MESSAGES = Unirest.get("http://zipcode.rocks:8085/messages").asString();
11
+
12
+    private String sequence;
13
+    private String timeStamp;
14
+    private String fromId;
15
+    private String toId;
16
+    private String message;
17
+
18
+
19
+
20
+    public Message() throws UnirestException {
21
+    }
22
+
23
+    public Message(String sequence, String timeStamp, String fromId, String toId, String message) {
24
+        this.sequence = sequence;
25
+        this.timeStamp = timeStamp;
26
+        this.fromId = fromId;
27
+        this.toId = toId;
28
+        this.message = message;
29
+    }
30
+
31
+    public Message(String fromId, String toId, String message) {
32
+        this.fromId = fromId;
33
+        this.toId = toId;
34
+        this.message = message;
35
+    }
36
+
37
+    public String getSequence() {
38
+        return sequence;
39
+    }
40
+
41
+    public void setSequence(String sequence) {
42
+        this.sequence = sequence;
43
+    }
44
+
45
+    public String getTimeStamp() {
46
+        return timeStamp;
47
+    }
48
+
49
+    public void setTimeStamp(String timeStamp) {
50
+        this.timeStamp = timeStamp;
51
+    }
52
+
53
+    public String getFromId() {
54
+        return fromId;
55
+    }
56
+
57
+    public void setFromId(String fromId) {
58
+        this.fromId = fromId;
59
+    }
60
+
61
+    public String getToId() {
62
+        return toId;
63
+    }
64
+
65
+    public void setToId(String toId) {
66
+        this.toId = toId;
67
+    }
68
+
69
+    public String getMessage() {
70
+        return message;
71
+    }
72
+
73
+    public void setMessage(String message) {
74
+        this.message = message;
75
+    }
76
+
77
+    @Override
78
+    public String toString() {
79
+        return "Message{" +
80
+                "sequence:'" + sequence + '\'' +
81
+                ", timeStamp:'" + timeStamp + '\'' +
82
+                ", fromId:'" + fromId + '\'' +
83
+                ", toId:'" + toId + '\'' +
84
+                ", message:'" + message + '\'' +
85
+                '}';
86
+    }
87
+}

+ 37
- 9
Client/src/main/java/SimpleShell.java Vedi File

@@ -1,24 +1,37 @@
1
-import java.io.BufferedReader;
2
-import java.io.IOException;
3
-import java.io.InputStream;
4
-import java.io.InputStreamReader;
1
+import com.fasterxml.jackson.core.type.TypeReference;
2
+import com.fasterxml.jackson.databind.ObjectMapper;
3
+import com.mashape.unirest.http.HttpResponse;
4
+import com.mashape.unirest.http.Unirest;
5
+import com.mashape.unirest.http.exceptions.UnirestException;
6
+
7
+import java.io.*;
8
+import java.net.MalformedURLException;
9
+import java.net.URL;
5 10
 import java.util.ArrayList;
6 11
 import java.util.List;
12
+import java.util.Map;
7 13
 
8 14
 public class SimpleShell {
9 15
 
10 16
 
11
-    public static void prettyPrint(String output) {
17
+
18
+    public SimpleShell() throws UnirestException {
19
+    }
20
+
21
+
22
+    public static void prettyPrint(String output) throws IOException {
23
+        ObjectMapper objectMapper = new ObjectMapper();
24
+        Map<String, String> map = objectMapper.readValue(output, new TypeReference<Map<String, String>>(){});
25
+
12 26
         // yep, make an effort to format things nicely, eh?
13
-        System.out.println(output);
27
+        System.out.println(map.toString());
14 28
     }
15 29
     public static void main(String[] args) throws java.io.IOException {
16 30
 
17 31
         YouAreEll webber = new YouAreEll();
18 32
         String commandLine;
19
-        BufferedReader console = new BufferedReader
20
-                (new InputStreamReader(System.in));
21
-
33
+        BufferedReader console = new BufferedReader(new InputStreamReader(System.in));
34
+        //ProcessBuilder class used to help create operating system process
22 35
         ProcessBuilder pb = new ProcessBuilder();
23 36
         List<String> history = new ArrayList<String>();
24 37
         int index = 0;
@@ -87,6 +100,9 @@ public class SimpleShell {
87 100
                 }
88 101
 
89 102
                 // wait, wait, what curiousness is this?
103
+                //Process class is an executing program
104
+                //Used to perform input, output, waiting for the process to complete,
105
+                //checking exit status of the pocess and destroying process
90 106
                 Process process = pb.start();
91 107
 
92 108
                 //obtain the input stream
@@ -116,6 +132,18 @@ public class SimpleShell {
116 132
              * 5. output the contents returned by the command
117 133
              */
118 134
 
135
+//            ProcessBuilder pb1 = new ProcessBuilder();
136
+//            pb1.start();
137
+//            OutputStream outputStream = new OutputStream() {
138
+//                @Override
139
+//                public void write(int b) throws IOException {
140
+//
141
+//                }
142
+//            };
143
+
144
+
145
+
146
+
119 147
         }
120 148
 
121 149
 

+ 63
- 3
Client/src/main/java/YouAreEll.java Vedi File

@@ -1,23 +1,83 @@
1
+import com.fasterxml.jackson.core.JsonProcessingException;
2
+import com.fasterxml.jackson.databind.ObjectMapper;
3
+import com.mashape.unirest.http.Unirest;
4
+import com.mashape.unirest.http.exceptions.UnirestException;
5
+import com.mashape.unirest.request.GetRequest;
6
+import com.mashape.unirest.request.HttpRequestWithBody;
7
+
1 8
 public class YouAreEll {
2 9
 
3 10
     YouAreEll() {
4 11
     }
5 12
 
6
-    public static void main(String[] args) {
13
+
14
+
15
+    public static void main(String[] args) throws JsonProcessingException {
7 16
         YouAreEll urlhandler = new YouAreEll();
8
-        System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
9
-        System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
17
+     //   System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
18
+     //   System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
19
+     //   urlhandler.postId("Bo", "bell7692");
20
+     //   urlhandler.postMessage("bell7692", "kfennimore", "The best is yet to come");
21
+        urlhandler.get_messages();
22
+
23
+
24
+    }
25
+    public void postId (String name, String githubID) throws JsonProcessingException {
26
+        ObjectMapper objectMapper = new ObjectMapper();
27
+        Id myId = new Id(name, githubID);
28
+        String payload = objectMapper.writeValueAsString(myId);
29
+        MakeURLCall("/ids", "POST", payload);
30
+
10 31
     }
11 32
 
33
+    public void postMessage(String fromId, String toId, String message) throws JsonProcessingException {
34
+        ObjectMapper objectMapper = new ObjectMapper();
35
+        Message myMessage = new Message(fromId, toId, message);
36
+        String payload = objectMapper.writeValueAsString(myMessage);
37
+        String url = "/ids/" +toId +"/messages";
38
+        MakeURLCall(url, "POST", payload);
39
+    }
12 40
     public String get_ids() {
13 41
         return MakeURLCall("/ids", "GET", "");
14 42
     }
15 43
 
44
+//    public String get_20_messages(){
45
+//
46
+//    }
16 47
     public String get_messages() {
17 48
         return MakeURLCall("/messages", "GET", "");
18 49
     }
19 50
 
20 51
     public String MakeURLCall(String mainurl, String method, String jpayload) {
52
+        String url= "http://zipcode.rocks:8085" + mainurl;
53
+        GetRequest request = Unirest.get(url);
54
+        HttpRequestWithBody requestWithBody = Unirest.post(url);
55
+        HttpRequestWithBody requestWithBody1 = Unirest.put(url);
56
+
57
+        if(method.equals("GET")){
58
+            try {
59
+                return request.asJson().getBody().toString();
60
+            } catch (UnirestException e) {
61
+                e.printStackTrace();
62
+            }
63
+        }
64
+
65
+        else if(method.equals("POST")){
66
+            try {
67
+                return requestWithBody.body(jpayload).asJson().getBody().toString();
68
+            } catch (UnirestException e) {
69
+                e.printStackTrace();
70
+            }
71
+        }
72
+
73
+//        else if (method.equals("PUT")){
74
+//            try {
75
+//                return requestWithBody1.body(jpayload).asJson().getBody().toString();
76
+//            } catch (UnirestException e) {
77
+//                e.printStackTrace();
78
+//            }
79
+//        }
80
+
21 81
         return "nada";
22 82
     }
23 83
 }

+ 9
- 0
YouAreEll.iml Vedi File

@@ -11,5 +11,14 @@
11 11
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
12 12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
13 13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
14
+    <orderEntry type="library" name="Maven: com.mashape.unirest:unirest-java:1.4.9" level="project" />
15
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.3.6" level="project" />
16
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.3.3" level="project" />
17
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.3" level="project" />
18
+    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.6" level="project" />
19
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpasyncclient:4.0.2" level="project" />
20
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore-nio:4.3.2" level="project" />
21
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.3.6" level="project" />
22
+    <orderEntry type="library" name="Maven: org.json:json:20140107" level="project" />
14 23
   </component>
15 24
 </module>

+ 25
- 0
pom.xml Vedi File

@@ -18,5 +18,30 @@
18 18
             <artifactId>jackson-databind</artifactId>
19 19
             <version>2.8.6</version>
20 20
         </dependency>
21
+        <dependency>
22
+            <groupId>com.mashape.unirest</groupId>
23
+            <artifactId>unirest-java</artifactId>
24
+            <version>1.4.9</version>
25
+        </dependency>
26
+        <dependency>
27
+            <groupId>org.apache.httpcomponents</groupId>
28
+            <artifactId>httpclient</artifactId>
29
+            <version>4.3.6</version>
30
+        </dependency>
31
+        <dependency>
32
+            <groupId>org.apache.httpcomponents</groupId>
33
+            <artifactId>httpasyncclient</artifactId>
34
+            <version>4.0.2</version>
35
+        </dependency>
36
+        <dependency>
37
+            <groupId>org.apache.httpcomponents</groupId>
38
+            <artifactId>httpmime</artifactId>
39
+            <version>4.3.6</version>
40
+        </dependency>
41
+        <dependency>
42
+            <groupId>org.json</groupId>
43
+            <artifactId>json</artifactId>
44
+            <version>20140107</version>
45
+        </dependency>
21 46
     </dependencies>
22 47
 </project>