Browse Source

I guess I've made progress....

Lauren Green 6 years ago
parent
commit
a59344fb72

+ 15
- 5
Client/Client.iml View File

@@ -5,14 +5,24 @@
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" />
14
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
15
-    <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" />
12
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.4" level="project" />
13
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
14
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.4" 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" />
24
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
25
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
26
+    <orderEntry type="library" scope="TEST" name="Maven: commons-io:commons-io:2.4" level="project" />
17 27
   </component>
18 28
 </module>

+ 1
- 0
Client/pom.xml View File

@@ -12,4 +12,5 @@
12 12
     <artifactId>Client</artifactId>
13 13
 
14 14
 
15
+
15 16
 </project>

+ 5
- 0
Client/src/main/java/Console.java View File

@@ -0,0 +1,5 @@
1
+public class Console {
2
+
3
+
4
+
5
+}

+ 43
- 0
Client/src/main/java/Id.java View File

@@ -0,0 +1,43 @@
1
+public class Id {
2
+
3
+    public String userId;
4
+    public String name;
5
+    public String github;
6
+
7
+    public Id(String name, String github) {
8
+        this.name = name;
9
+        this.github = github;
10
+    }
11
+
12
+    public String getUserId() {
13
+        return userId;
14
+    }
15
+
16
+    public void setUserId(String userId) {
17
+        this.userId = userId;
18
+    }
19
+
20
+    public String getName() {
21
+        return name;
22
+    }
23
+
24
+    public void setName(String name) {
25
+        this.name = name;
26
+    }
27
+
28
+    public String getGithub() {
29
+        return github;
30
+    }
31
+
32
+    public void setGithub(String github) {
33
+        this.github = github;
34
+    }
35
+
36
+    @Override
37
+    public String toString() {
38
+    return String.format("userid: " + userId + "\n" +
39
+            "name: " + name + "\n" +
40
+            "github: " +  github);
41
+    }
42
+
43
+}

+ 66
- 0
Client/src/main/java/Message.java View File

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

+ 6
- 0
Client/src/main/java/Messages.java View File

@@ -0,0 +1,6 @@
1
+import java.util.ArrayList;
2
+
3
+public class Messages {
4
+
5
+    ArrayList<Message> messages;
6
+}

+ 8
- 0
Client/src/main/java/SimpleShell.java View File

@@ -1,3 +1,8 @@
1
+import com.mashape.unirest.http.HttpResponse;
2
+import com.mashape.unirest.http.JsonNode;
3
+import com.mashape.unirest.http.Unirest;
4
+import com.mashape.unirest.http.exceptions.UnirestException;
5
+
1 6
 import java.io.BufferedReader;
2 7
 import java.io.IOException;
3 8
 import java.io.InputStream;
@@ -106,6 +111,8 @@ public class SimpleShell {
106 111
             //catch ioexception, output appropriate message, resume waiting for input
107 112
             catch (IOException e) {
108 113
                 System.out.println("Input Error, Please try again!");
114
+            } catch (UnirestException e) {
115
+                e.printStackTrace();
109 116
             }
110 117
             // So what, do you suppose, is the meaning of this comment?
111 118
             /** The steps are:
@@ -121,4 +128,5 @@ public class SimpleShell {
121 128
 
122 129
     }
123 130
 
131
+
124 132
 }

+ 57
- 7
Client/src/main/java/YouAreEll.java View File

@@ -1,23 +1,73 @@
1
+import com.mashape.unirest.http.HttpResponse;
2
+import com.mashape.unirest.http.JsonNode;
3
+import com.mashape.unirest.http.Unirest;
4
+import com.mashape.unirest.http.exceptions.UnirestException;
5
+
6
+import java.io.IOException;
7
+import java.net.HttpURLConnection;
8
+import java.net.ProtocolException;
9
+import java.net.URL;
10
+
1 11
 public class YouAreEll {
2 12
 
13
+    private String underARock = "http://zipcode.rocks:8085";
14
+
3 15
     YouAreEll() {
16
+
4 17
     }
5 18
 
6 19
     public static void main(String[] args) {
7 20
         YouAreEll urlhandler = new YouAreEll();
8
-        System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
9
-        System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
21
+//        System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
22
+//        System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
10 23
     }
11 24
 
12
-    public String get_ids() {
13
-        return MakeURLCall("/ids", "GET", "");
25
+    public String get_ids(){
26
+
27
+        try {
28
+            HttpResponse<JsonNode> jsonResponse = Unirest.get(underARock + "/ids")
29
+                    .header("accept", "application/json")
30
+                    .asJson();
31
+
32
+            String ids = jsonResponse.getBody().toString();
33
+            System.out.println(ids);
34
+            return ids;
35
+        } catch (UnirestException e) {
36
+            System.out.println("Error");
37
+        }
38
+
39
+        return null;
14 40
     }
15 41
 
16
-    public String get_messages() {
42
+    public String get_messages() throws UnirestException {
43
+        try {
17 44
         return MakeURLCall("/messages", "GET", "");
45
+        } catch (UnirestException e) {
46
+            System.out.println("Error");
47
+        }
48
+        return null;
18 49
     }
19 50
 
20
-    public String MakeURLCall(String mainurl, String method, String jpayload) {
21
-        return "nada";
51
+    public String MakeURLCall(String mainurl, String method, String jpayload) throws UnirestException {
52
+
53
+        String url = underARock + mainurl;
54
+        method = method.toUpperCase();
55
+        HttpResponse<com.mashape.unirest.http.JsonNode> jsonResponse;
56
+
57
+        if(method.equals("GET")) {
58
+            jsonResponse = Unirest.get("http://zipcode.rocks:8085/GET").routeParam("method", url).asJson();
59
+        }
60
+
61
+        if(method.equals("POST")) {
62
+
63
+        }
64
+
65
+        if(method.equals("PUT")) {
66
+
67
+        }
68
+
69
+            return "nada";
70
+
22 71
     }
72
+
23 73
 }

+ 1
- 1
README.md View File

@@ -40,7 +40,7 @@ specific command.
40 40
 
41 41
 * The Under-A-Rock Server can be reached at `http://zipcode.rocks:8085` Everyone uses the same server. 		
42 42
 	* There are two segments to the API and two kinds of commands in the shell, the ID segment and the Messages segment.
43
-
43
+Car car = objectMapper.readValue(json, Car.class);  
44 44
 
45 45
 * You can explore several ways of doing the HTTP URL calls to the server, using the one of these:
46 46
 	* [Apache HTTP Client Library](http://hc.apache.org/httpcomponents-client-ga/index.html)

+ 15
- 3
YouAreEll.iml View File

@@ -8,8 +8,20 @@
8 8
     </content>
9 9
     <orderEntry type="inheritedJdk" />
10 10
     <orderEntry type="sourceFolder" forTests="false" />
11
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
12
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
13
-    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
11
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.9.4" level="project" />
12
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
13
+    <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.4" 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" />
23
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.11" level="project" />
24
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
25
+    <orderEntry type="library" scope="TEST" name="Maven: commons-io:commons-io:2.4" level="project" />
14 26
   </component>
15 27
 </module>

+ 39
- 2
pom.xml View File

@@ -16,7 +16,44 @@
16 16
         <dependency>
17 17
             <groupId>com.fasterxml.jackson.core</groupId>
18 18
             <artifactId>jackson-databind</artifactId>
19
-            <version>2.8.6</version>
19
+            <version>2.9.4</version>
20 20
         </dependency>
21
-    </dependencies>
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>
46
+            <dependency>
47
+                <groupId>junit</groupId>
48
+                <artifactId>junit</artifactId>
49
+                <version>4.11</version>
50
+                <scope>test</scope>
51
+            </dependency>
52
+            <dependency>
53
+                <groupId>commons-io</groupId>
54
+                <artifactId>commons-io</artifactId>
55
+                <version>2.4</version>
56
+                <scope>test</scope>
57
+            </dependency>
58
+        </dependencies>
22 59
 </project>