Browse Source

everything works, about to start prettyprint

Carolynn Vansant 6 years ago
parent
commit
7c11b5e7cc

+ 0
- 4
Client/Client.iml View File

14
     <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-annotations:2.9.0" level="project" />
15
     <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
15
     <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
16
     <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
16
     <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
17
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.5" level="project" />
18
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.9" level="project" />
19
-    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
20
-    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
21
   </component>
17
   </component>
22
 </module>
18
 </module>

+ 0
- 6
Client/pom.xml View File

25
             <artifactId>jackson-databind</artifactId>
25
             <artifactId>jackson-databind</artifactId>
26
             <version>2.9.4</version>
26
             <version>2.9.4</version>
27
         </dependency>
27
         </dependency>
28
-        <!--<dependency>-->
29
-            <!--<groupId>org.apache.httpcomponents</groupId>-->
30
-            <!--<artifactId>fluent-hc</artifactId>-->
31
-            <!--<version>4.5.5</version>-->
32
-        <!--</dependency>-->
33
         <dependency>
28
         <dependency>
34
             <groupId>com.squareup.okhttp3</groupId>
29
             <groupId>com.squareup.okhttp3</groupId>
35
             <artifactId>okhttp</artifactId>
30
             <artifactId>okhttp</artifactId>
36
             <version>3.10.0</version>
31
             <version>3.10.0</version>
37
         </dependency>
32
         </dependency>
38
-
39
     </dependencies>
33
     </dependencies>
40
 </project>
34
 </project>

+ 7
- 7
Client/src/main/java/Id.java View File

2
 
2
 
3
 public class Id {
3
 public class Id {
4
 
4
 
5
-    private String id;
5
+    private String userid;
6
     private String name;
6
     private String name;
7
     private String github;
7
     private String github;
8
 
8
 
9
     public Id(){
9
     public Id(){
10
     }
10
     }
11
 
11
 
12
-    public Id(String id, String name, String github){
13
-        this.id = id;
12
+    public Id(String userid, String name, String github){
13
+        this.userid = userid;
14
         this.name = name;
14
         this.name = name;
15
         this.github = github;
15
         this.github = github;
16
     }
16
     }
17
 
17
 
18
 
18
 
19
     public void setId(String id) {
19
     public void setId(String id) {
20
-        this.id = id;
20
+        this.userid = id;
21
     }
21
     }
22
 
22
 
23
-    public String getId() {
24
-        return id;
23
+    public String getuserid() {
24
+        return userid;
25
     }
25
     }
26
 
26
 
27
     public void setName(String name) {
27
     public void setName(String name) {
42
 
42
 
43
     @Override
43
     @Override
44
     public String toString(){
44
     public String toString(){
45
-        return "id: " + getId() + ", name: " + getName() + ", github: " + getGithub();
45
+        return "userid: " + getuserid() + ", name: " + getName() + ", github: " + getGithub();
46
     }
46
     }
47
 
47
 
48
 }
48
 }

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

53
                     String results = "";
53
                     String results = "";
54
                     System.out.println("To retrieve all registered github ids, press enter\n" +
54
                     System.out.println("To retrieve all registered github ids, press enter\n" +
55
                             "To register a new id or change the name associated, type your name");
55
                             "To register a new id or change the name associated, type your name");
56
+                    String first = console.readLine();
56
                     specificCommand = console.readLine();
57
                     specificCommand = console.readLine();
57
                     if(specificCommand.equals("")) {
58
                     if(specificCommand.equals("")) {
58
                         results = idCont.get_ids(commandList);
59
                         results = idCont.get_ids(commandList);
91
                         commandList.add(specificCommand);
92
                         commandList.add(specificCommand);
92
                     }
93
                     }
93
                     System.out.println(("Enter your github id"));
94
                     System.out.println(("Enter your github id"));
95
+                    specificCommand = console.readLine();
94
                     if(!specificCommand.equals("")) {
96
                     if(!specificCommand.equals("")) {
95
                         commandList.add(specificCommand);
97
                         commandList.add(specificCommand);
96
                         results = mesCont.post_world(commandList);
98
                         results = mesCont.post_world(commandList);

+ 28
- 25
Client/src/main/java/YouAreEll.java View File

1
 import com.fasterxml.jackson.core.JsonProcessingException;
1
 import com.fasterxml.jackson.core.JsonProcessingException;
2
-import org.apache.http.client.fluent.*;
3
 import com.fasterxml.jackson.databind.*;
2
 import com.fasterxml.jackson.databind.*;
3
+import okhttp3.*;
4
+import com.fasterxml.jackson.databind.ObjectMapper;
5
+
6
+
4
 import java.io.IOException;
7
 import java.io.IOException;
5
-import javax.swing.*;
8
+
6
 
9
 
7
 
10
 
8
 public class YouAreEll {
11
 public class YouAreEll {
12
+    private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
9
 
13
 
10
     YouAreEll() {
14
     YouAreEll() {
11
     }
15
     }
14
         YouAreEll urlhandler = new YouAreEll();
18
         YouAreEll urlhandler = new YouAreEll();
15
         ObjectMapper objectMapper = new ObjectMapper();
19
         ObjectMapper objectMapper = new ObjectMapper();
16
         String payload = "";
20
         String payload = "";
17
-        Id id = new Id("-","Carolynn","me");
21
+        Id id = new Id("-", "Carolynn", "me");
18
         try {
22
         try {
19
             payload = objectMapper.writeValueAsString(id);
23
             payload = objectMapper.writeValueAsString(id);
24
+            urlhandler.makeURLCall("/ids", "POST", payload);
20
         } catch (JsonProcessingException e) {
25
         } catch (JsonProcessingException e) {
21
             e.printStackTrace();
26
             e.printStackTrace();
22
         }
27
         }
24
 //        System.out.println(urlhandler.makeURLCall("/messages", "GET", ""));
29
 //        System.out.println(urlhandler.makeURLCall("/messages", "GET", ""));
25
     }
30
     }
26
 
31
 
32
+
27
     public String makeURLCall(String mainurl, String method, String jpayload) {
33
     public String makeURLCall(String mainurl, String method, String jpayload) {
34
+        OkHttpClient okHttpClient = new OkHttpClient();
28
         String fullUrl = "http://zipcode.rocks:8085" + mainurl;
35
         String fullUrl = "http://zipcode.rocks:8085" + mainurl;
29
-        String requestReturn = "";
30
-//        if(mainurl.equalsIgnoreCase("/ids") && method.equalsIgnoreCase("get")){
31
-//            try {
32
-//                requestReturn = Request.Get(fullUrl).execute().returnContent().asString();
33
-//
34
-//            } catch (IOException e) {
35
-//                e.printStackTrace();
36
-//            }
37
-//        }
38
-//        if(mainurl.equalsIgnoreCase("/ids") && method.equalsIgnoreCase("post")){
39
-//            requestReturn = Request.Post(jpayload).toString();
40
-//        }
41
-//        if(mainurl.equalsIgnoreCase("/messages")){
42
-//            try {
43
-//                Request.Get(fullUrl).execute().returnContent();
44
-//            } catch (IOException e) {
45
-//                e.printStackTrace();
46
-//            }
47
-//        }
48
-        return requestReturn;
49
-    }
36
+        Request request = null;
37
+        if (method.equalsIgnoreCase("get")) {
38
+            request = new Request.Builder().url(fullUrl).build();
39
+        }
40
+        if (method.equalsIgnoreCase("post")) {
41
+            RequestBody requestBody = RequestBody.create(JSON, jpayload);
42
+            request = new Request.Builder().url(fullUrl).post(requestBody).build();
43
+        }
50
 
44
 
51
-}
45
+        if (request != null) {
46
+            try (Response response = okHttpClient.newCall(request).execute()) {
47
+                return response.body().string();
48
+            } catch (IOException e) {
49
+                e.printStackTrace();
50
+            }
51
+        }
52
+        return "" + method;
53
+    }
54
+}

+ 2
- 4
YouAreEll.iml View File

9
     <orderEntry type="inheritedJdk" />
9
     <orderEntry type="inheritedJdk" />
10
     <orderEntry type="sourceFolder" forTests="false" />
10
     <orderEntry type="sourceFolder" forTests="false" />
11
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.4" level="project" />
11
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.9.4" level="project" />
12
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.5" level="project" />
13
-    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.9" level="project" />
14
-    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
15
-    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
12
+    <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
13
+    <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
16
   </component>
14
   </component>
17
 </module>
15
 </module>

+ 8
- 4
pom.xml View File

19
             <artifactId>jackson-core</artifactId>
19
             <artifactId>jackson-core</artifactId>
20
             <version>2.9.4</version>
20
             <version>2.9.4</version>
21
         </dependency>
21
         </dependency>
22
-
23
         <dependency>
22
         <dependency>
24
-            <groupId>org.apache.httpcomponents</groupId>
25
-            <artifactId>httpclient</artifactId>
26
-            <version>4.5.5</version>
23
+            <groupId>com.squareup.okhttp3</groupId>
24
+            <artifactId>okhttp</artifactId>
25
+            <version>3.10.0</version>
27
         </dependency>
26
         </dependency>
27
+        <!--<dependency>-->
28
+            <!--<groupId>org.apache.httpcomponents</groupId>-->
29
+            <!--<artifactId>httpclient</artifactId>-->
30
+            <!--<version>4.5.5</version>-->
31
+        <!--</dependency>-->
28
     </dependencies>
32
     </dependencies>
29
 </project>
33
 </project>