Преглед на файлове

everything works, about to start prettyprint

Carolynn Vansant преди 6 години
родител
ревизия
7c11b5e7cc
променени са 7 файла, в които са добавени 47 реда и са изтрити 50 реда
  1. 0
    4
      Client/Client.iml
  2. 0
    6
      Client/pom.xml
  3. 7
    7
      Client/src/main/java/Id.java
  4. 2
    0
      Client/src/main/java/SimpleShell.java
  5. 28
    25
      Client/src/main/java/YouAreEll.java
  6. 2
    4
      YouAreEll.iml
  7. 8
    4
      pom.xml

+ 0
- 4
Client/Client.iml Целия файл

@@ -14,9 +14,5 @@
14 14
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.9.0" level="project" />
15 15
     <orderEntry type="library" name="Maven: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
16 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 17
   </component>
22 18
 </module>

+ 0
- 6
Client/pom.xml Целия файл

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

+ 7
- 7
Client/src/main/java/Id.java Целия файл

@@ -2,26 +2,26 @@
2 2
 
3 3
 public class Id {
4 4
 
5
-    private String id;
5
+    private String userid;
6 6
     private String name;
7 7
     private String github;
8 8
 
9 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 14
         this.name = name;
15 15
         this.github = github;
16 16
     }
17 17
 
18 18
 
19 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 27
     public void setName(String name) {
@@ -42,7 +42,7 @@ public class Id {
42 42
 
43 43
     @Override
44 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 Целия файл

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

+ 28
- 25
Client/src/main/java/YouAreEll.java Целия файл

@@ -1,11 +1,15 @@
1 1
 import com.fasterxml.jackson.core.JsonProcessingException;
2
-import org.apache.http.client.fluent.*;
3 2
 import com.fasterxml.jackson.databind.*;
3
+import okhttp3.*;
4
+import com.fasterxml.jackson.databind.ObjectMapper;
5
+
6
+
4 7
 import java.io.IOException;
5
-import javax.swing.*;
8
+
6 9
 
7 10
 
8 11
 public class YouAreEll {
12
+    private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
9 13
 
10 14
     YouAreEll() {
11 15
     }
@@ -14,9 +18,10 @@ public class YouAreEll {
14 18
         YouAreEll urlhandler = new YouAreEll();
15 19
         ObjectMapper objectMapper = new ObjectMapper();
16 20
         String payload = "";
17
-        Id id = new Id("-","Carolynn","me");
21
+        Id id = new Id("-", "Carolynn", "me");
18 22
         try {
19 23
             payload = objectMapper.writeValueAsString(id);
24
+            urlhandler.makeURLCall("/ids", "POST", payload);
20 25
         } catch (JsonProcessingException e) {
21 26
             e.printStackTrace();
22 27
         }
@@ -24,28 +29,26 @@ public class YouAreEll {
24 29
 //        System.out.println(urlhandler.makeURLCall("/messages", "GET", ""));
25 30
     }
26 31
 
32
+
27 33
     public String makeURLCall(String mainurl, String method, String jpayload) {
34
+        OkHttpClient okHttpClient = new OkHttpClient();
28 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 Целия файл

@@ -9,9 +9,7 @@
9 9
     <orderEntry type="inheritedJdk" />
10 10
     <orderEntry type="sourceFolder" forTests="false" />
11 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 14
   </component>
17 15
 </module>

+ 8
- 4
pom.xml Целия файл

@@ -19,11 +19,15 @@
19 19
             <artifactId>jackson-core</artifactId>
20 20
             <version>2.9.4</version>
21 21
         </dependency>
22
-
23 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 26
         </dependency>
27
+        <!--<dependency>-->
28
+            <!--<groupId>org.apache.httpcomponents</groupId>-->
29
+            <!--<artifactId>httpclient</artifactId>-->
30
+            <!--<version>4.5.5</version>-->
31
+        <!--</dependency>-->
28 32
     </dependencies>
29 33
 </project>