Karousha Fennimore пре 6 година
родитељ
комит
85070acaab

+ 10
- 3
Client/Client.iml Прегледај датотеку

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

+ 33
- 0
Client/pom.xml Прегледај датотеку

@@ -10,6 +10,39 @@
10 10
     <modelVersion>4.0.0</modelVersion>
11 11
 
12 12
     <artifactId>Client</artifactId>
13
+<dependencies>
14
+    <dependency>
15
+    <groupId>com.mashape.unirest</groupId>
16
+    <artifactId>unirest-java</artifactId>
17
+    <version>1.4.9</version>
18
+</dependency>
19
+    <dependency>
20
+        <groupId>org.apache.httpcomponents</groupId>
21
+        <artifactId>httpclient</artifactId>
22
+        <version>4.3.6</version>
23
+    </dependency>
24
+    <!-- https://mvnrepository.com/artifact/com.fasterxml.jackson.core/jackson-core -->
25
+    <dependency>
26
+        <groupId>com.fasterxml.jackson.core</groupId>
27
+        <artifactId>jackson-core</artifactId>
28
+        <version>2.8.5</version>
29
+    </dependency>
13 30
 
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>
46
+</dependencies>
14 47
 
15 48
 </project>

+ 75
- 0
Client/src/main/java/Message.java Прегледај датотеку

@@ -0,0 +1,75 @@
1
+public class Message {
2
+
3
+    private String sequence;
4
+    private String timestamp;
5
+    private String fromid;
6
+    private String toid;
7
+    private String message;
8
+
9
+    public Message(String sequence, String timeStamp, String fromId, String toId, String message) {
10
+        this.sequence = sequence;
11
+        this.timestamp = timestamp;
12
+        this.fromid = fromid;
13
+        this.toid = toid;
14
+        this.message = message;
15
+    }
16
+
17
+    public Message(String fromId, String toId, String message) {
18
+        this.fromid = fromid;
19
+        this.toid = toid;
20
+        this.message = message;
21
+    }
22
+
23
+    public String getSequence() {
24
+        return sequence;
25
+    }
26
+
27
+    public void setSequence(String sequence) {
28
+        this.sequence = sequence;
29
+    }
30
+
31
+    public String getTimestamp() {
32
+        return timestamp;
33
+    }
34
+
35
+    public void setTimestamp(String timeStamp) {
36
+        this.timestamp = timeStamp;
37
+    }
38
+
39
+    public String getFromId() {
40
+        return fromid;
41
+    }
42
+
43
+    public void setFromId(String fromId) {
44
+        this.fromid = fromid;
45
+    }
46
+
47
+    public String getToId() {
48
+        return toid;
49
+    }
50
+
51
+    public void setToId(String toId) {
52
+        this.toid = toid;
53
+    }
54
+
55
+    public String getMessage() {
56
+        return message;
57
+    }
58
+
59
+    public void setMessage(String message) {
60
+        this.message = message;
61
+    }
62
+
63
+    @Override
64
+    public String toString() {
65
+
66
+        return "Message{" +
67
+                "sequence: '" + sequence + '\'' +
68
+                ", timeStamp:'" + timestamp + '\'' +
69
+                ", fromId:'" + fromid + '\'' +
70
+                ", toId:'" + toid + '\'' +
71
+                ", message:'" + message + '\'' +
72
+                '}';
73
+    }
74
+
75
+}

+ 3
- 3
Client/src/main/java/SimpleShell.java Прегледај датотеку

@@ -25,7 +25,7 @@ public class SimpleShell {
25 25
         //we break out with <ctrl c>
26 26
         while (true) {
27 27
             //read what the user enters
28
-            System.out.println("cmd? ");
28
+            System.out.println("Request: ");
29 29
             commandLine = console.readLine();
30 30
 
31 31
             //input parsed into array of strings(command and arguments)
@@ -35,8 +35,8 @@ public class SimpleShell {
35 35
             //if the user entered a return, just loop again
36 36
             if (commandLine.equals(""))
37 37
                 continue;
38
-            if (commandLine.equals("exit")) {
39
-                System.out.println("bye!");
38
+            if (commandLine.equalsIgnoreCase("exit")) {
39
+                System.out.println("Thank you for visiting!");
40 40
                 break;
41 41
             }
42 42
 

+ 82
- 1
Client/src/main/java/YouAreEll.java Прегледај датотеку

@@ -1,23 +1,104 @@
1
+import com.fasterxml.jackson.core.JsonProcessingException;
2
+import com.fasterxml.jackson.core.type.TypeReference;
3
+import com.fasterxml.jackson.databind.ObjectMapper;
4
+import com.mashape.unirest.http.Unirest;
5
+import com.mashape.unirest.http.exceptions.UnirestException;
6
+import com.mashape.unirest.request.GetRequest;
7
+import com.mashape.unirest.request.HttpRequestWithBody;
8
+
9
+import java.io.IOException;
10
+import java.util.List;
11
+
1 12
 public class YouAreEll {
2 13
 
14
+
3 15
     YouAreEll() {
4 16
     }
5 17
 
6
-    public static void main(String[] args) {
18
+    public static void main(String[] args) throws JsonProcessingException {
19
+
7 20
         YouAreEll urlhandler = new YouAreEll();
8 21
         System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
9 22
         System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
23
+        urlhandler.postId("Kay", "kfennimore");
24
+        urlhandler.postMsg("kfennimore", "bell7692", "hey Bo!");
25
+    }
26
+
27
+
28
+    public String postId(String name, String github) throws JsonProcessingException {
29
+
30
+        ObjectMapper objectMapper = new ObjectMapper();
31
+        id id = new id(name, github);
32
+        String payload = objectMapper.writeValueAsString((id));
33
+        MakeURLCall("/ids", "POST", payload);
34
+
35
+
36
+        return objectMapper.writeValueAsString(id);
10 37
     }
11 38
 
12 39
     public String get_ids() {
40
+
13 41
         return MakeURLCall("/ids", "GET", "");
14 42
     }
15 43
 
44
+    public void postMsg(String fromId, String toId, String message) throws JsonProcessingException {
45
+        ObjectMapper objectMapper = new ObjectMapper();
46
+        Message msg = new Message(fromId, toId, message);
47
+        String payload = objectMapper.writeValueAsString((msg));
48
+        String url = "/ids/" + toId + "/messages";
49
+        MakeURLCall(url, "POST", payload);
50
+
51
+    }
52
+
53
+    public String msgParse() throws IOException {
54
+        String string = MakeURLCall("/messages","GET" ,"" );
55
+        ObjectMapper objectMapper = new ObjectMapper();
56
+        List<Message> message = objectMapper.readValue(string, new TypeReference<List<Message>>(){});
57
+
58
+        StringBuilder sb = new StringBuilder();
59
+        for(int i = 0; i < message.size(); i++) {
60
+            sb.append("From Id: " + message.get(i).getFromId() + "\n");
61
+            sb.append("To Id: " + message.get(i).getToId() + "\n");
62
+            sb.append("Message: " + message.get(i).getMessage() + "\n");
63
+            sb.append("Timestamp: " + message.get(i).getTimestamp() + "\n");
64
+        }
65
+        return sb.toString();
66
+    }
67
+
16 68
     public String get_messages() {
69
+
17 70
         return MakeURLCall("/messages", "GET", "");
18 71
     }
19 72
 
73
+
74
+
20 75
     public String MakeURLCall(String mainurl, String method, String jpayload) {
76
+
77
+        String url ="http://zipcode.rocks:8085" + mainurl;
78
+        GetRequest request = Unirest.get(url);
79
+        HttpRequestWithBody request1 = Unirest.post(url);
80
+        HttpRequestWithBody request2 = Unirest.post(url);
81
+
82
+
83
+        if(method.equals("GET")) {
84
+            try {
85
+                return request.asJson().getBody().toString();
86
+            } catch (UnirestException e) {
87
+                e.printStackTrace();
88
+            }
89
+        } else if(method.equals("POST")) {
90
+            try {
91
+                return request1.body(jpayload).asJson().getBody().toString();
92
+            } catch (UnirestException e) {
93
+                e.printStackTrace();
94
+            }
95
+//        } else if(method.equals("PUT")) {
96
+//            try {
97
+//                return request2.asJson().getBody().toString();
98
+//            } catch (UnirestException e) {
99
+//                e.printStackTrace();
100
+//            }
101
+        }
21 102
         return "nada";
22 103
     }
23 104
 }

+ 51
- 0
Client/src/main/java/id.java Прегледај датотеку

@@ -0,0 +1,51 @@
1
+public class id {
2
+
3
+    private String userId;
4
+    private String name;
5
+    private String github;
6
+
7
+
8
+    public id(String userId, String name, String github) {
9
+        this.userId = userId;
10
+        this.name = name;
11
+        this.github = github;
12
+    }
13
+
14
+    public id(String name, String github) {
15
+        this.name = name;
16
+        this.github = github;
17
+    }
18
+
19
+    public String getUserId() {
20
+        return userId;
21
+    }
22
+
23
+    public void setUserId(String userId) {
24
+        this.userId = userId;
25
+    }
26
+
27
+    public String getName() {
28
+        return name;
29
+    }
30
+
31
+    public void setName(String name) {
32
+        this.name = name;
33
+    }
34
+
35
+    public String getGithub() {
36
+        return github;
37
+    }
38
+
39
+    public void setGithub(String github) {
40
+        this.github = github;
41
+    }
42
+
43
+
44
+    public String toString1() {
45
+        return "id {" +
46
+                "userId='" + userId + '\'' +
47
+                ", name='" + name + '\'' +
48
+                ", github='" + github + '\'' +
49
+                '}';
50
+    }
51
+}

+ 8
- 0
YouAreEll.iml Прегледај датотеку

@@ -11,5 +11,13 @@
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: org.apache.httpcomponents:httpclient:4.3.6" level="project" />
15
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.3.3" level="project" />
16
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.1.3" level="project" />
17
+    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.6" level="project" />
18
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpasyncclient:4.0.2" level="project" />
19
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore-nio:4.3.2" level="project" />
20
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpmime:4.3.6" level="project" />
21
+    <orderEntry type="library" name="Maven: org.json:json:20140107" level="project" />
14 22
   </component>
15 23
 </module>

+ 21
- 0
pom.xml Прегледај датотеку

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