Просмотр исходного кода

registered with the chat server

Eric Barnaba 6 лет назад
Родитель
Сommit
9ebace58e2
4 измененных файлов: 94 добавлений и 24 удалений
  1. 7
    8
      Client/Client.iml
  2. 9
    9
      Client/pom.xml
  3. 24
    7
      Client/src/main/java/Id.java
  4. 54
    0
      Client/src/main/java/YouAreEll.java

+ 7
- 8
Client/Client.iml Просмотреть файл

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

+ 9
- 9
Client/pom.xml Просмотреть файл

@@ -15,17 +15,22 @@
15 15
     <dependency>
16 16
         <groupId>org.apache.httpcomponents</groupId>
17 17
         <artifactId>httpclient</artifactId>
18
-        <version>4.3.6</version>
18
+        <version>4.5.5</version>
19 19
     </dependency>
20 20
     <dependency>
21 21
         <groupId>org.apache.httpcomponents</groupId>
22
-        <artifactId>httpasyncclient</artifactId>
23
-        <version>4.0.2</version>
22
+        <artifactId>httpclient-cache</artifactId>
23
+        <version>4.5.5</version>
24 24
     </dependency>
25 25
     <dependency>
26 26
         <groupId>org.apache.httpcomponents</groupId>
27 27
         <artifactId>httpmime</artifactId>
28
-        <version>4.3.6</version>
28
+        <version>4.5.5</version>
29
+    </dependency>
30
+    <dependency>
31
+        <groupId>org.apache.httpcomponents</groupId>
32
+        <artifactId>fluent-hc</artifactId>
33
+        <version>4.5.5</version>
29 34
     </dependency>
30 35
     <dependency>
31 36
         <groupId>org.json</groupId>
@@ -33,11 +38,6 @@
33 38
         <version>20140107</version>
34 39
     </dependency>
35 40
     <dependency>
36
-        <groupId>com.mashape.unirest</groupId>
37
-        <artifactId>unirest-java</artifactId>
38
-        <version>1.4.9</version>
39
-    </dependency>
40
-    <dependency>
41 41
         <groupId>com.fasterxml.jackson.core</groupId>
42 42
         <artifactId>jackson-databind</artifactId>
43 43
         <version>2.8.6</version>

+ 24
- 7
Client/src/main/java/Id.java Просмотреть файл

@@ -1,18 +1,35 @@
1 1
 public class Id {
2
-    String userid;
3
-    String name;
4
-    String githubid;
2
+    private String userid;
3
+    private String name;
4
+    private String github;
5 5
 
6
-    public Id(String userid, String name, String githubid){
6
+    public Id(String userid, String name, String github){
7 7
         this.userid=userid;
8 8
         this.name=name;
9
-        this.githubid=githubid;
9
+        this.github=github;
10 10
     }
11 11
 
12
-    public Id(String name, String githubid){
12
+    public Id(String name, String github){
13 13
         this.userid="-";
14 14
         this.name=name;
15
-        this.githubid=githubid;
15
+        this.github=github;
16
+    }
17
+
18
+    public String getUserid() {
19
+        return userid;
20
+    }
21
+
22
+    public String getName() {
23
+        return name;
24
+    }
25
+
26
+    public String getGithub() {
27
+        return github;
28
+    }
29
+
30
+    @Override
31
+    public String toString(){
32
+        return "User ID: " + this.userid + "Name: " + this.name +  "GitHub: " + this.github;
16 33
     }
17 34
 
18 35
 

+ 54
- 0
Client/src/main/java/YouAreEll.java Просмотреть файл

@@ -1,10 +1,34 @@
1
+import com.fasterxml.jackson.core.JsonProcessingException;
2
+import com.fasterxml.jackson.databind.ObjectMapper;
3
+import org.apache.http.client.fluent.Form;
4
+import org.apache.http.client.fluent.Request;
5
+import org.apache.http.entity.ContentType;
6
+import org.apache.http.entity.StringEntity;
7
+
8
+import java.io.IOException;
9
+import java.io.UnsupportedEncodingException;
10
+
1 11
 public class YouAreEll {
2 12
 
13
+
14
+
3 15
     YouAreEll() {
16
+
4 17
     }
5 18
 
6 19
     public static void main(String[] args) {
20
+        ObjectMapper mapper = new ObjectMapper();
7 21
         YouAreEll urlhandler = new YouAreEll();
22
+//        Id ericB = new Id("EricB", "EricBarnaba");
23
+//        try {
24
+//            String json = mapper.writeValueAsString(ericB);
25
+//            urlhandler.MakeURLCall("/ids", "POST", json );
26
+//            //System.out.println(json);
27
+//        }
28
+//        catch(JsonProcessingException jpe){
29
+//            System.out.println(jpe.getMessage());
30
+//        }
31
+
8 32
         System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
9 33
         System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
10 34
     }
@@ -18,6 +42,36 @@ public class YouAreEll {
18 42
     }
19 43
 
20 44
     public String MakeURLCall(String mainurl, String method, String jpayload) {
45
+        String url = "http://zipcode.rocks:8085" + mainurl;
46
+
47
+        if(method.equals("GET")){
48
+            try{
49
+                System.out.println(Request.Get(url)
50
+                        .execute().returnContent());
51
+            }
52
+            catch(IOException ioe){
53
+                System.out.println(ioe.getMessage());
54
+            }
55
+
56
+        }
57
+        else if (method.equals("POST")){
58
+            try {
59
+                //StringEntity json = new StringEntity(jpayload);
60
+                System.out.println(jpayload);
61
+                Request.Post(url)
62
+                        .useExpectContinue().bodyString(jpayload, ContentType.DEFAULT_TEXT)
63
+                        .execute().returnContent();
64
+            }
65
+            catch(IOException ioe){
66
+                System.out.println(ioe.getMessage());
67
+            }
68
+
69
+
70
+        }
71
+        else if (method.equals("PUT")){
72
+
73
+        }
74
+
21 75
         return "nada";
22 76
     }
23 77
 }