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

{Trying to push through leftovers}

Jacqueline Joson 5 лет назад
Родитель
Сommit
e0ba079754
4 измененных файлов: 60 добавлений и 8 удалений
  1. 4
    2
      Client/Client.iml
  2. 45
    6
      Client/src/main/java/YouAreEll.java
  3. 4
    0
      YouAreEll.iml
  4. 7
    0
      pom.xml

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

@@ -5,8 +5,6 @@
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" />
@@ -14,5 +12,9 @@
14 12
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-databind:2.8.6" level="project" />
15 13
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-annotations:2.8.0" level="project" />
16 14
     <orderEntry type="library" name="Maven: com.fasterxml.jackson.core:jackson-core:2.8.6" level="project" />
15
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpclient:4.5.6" level="project" />
16
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.10" level="project" />
17
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
18
+    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
17 19
   </component>
18 20
 </module>

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

@@ -1,3 +1,12 @@
1
+import org.apache.http.HttpEntity;
2
+import org.apache.http.client.methods.CloseableHttpResponse;
3
+import org.apache.http.client.methods.HttpGet;
4
+import org.apache.http.impl.client.CloseableHttpClient;
5
+import org.apache.http.impl.client.HttpClients;
6
+import org.apache.http.util.EntityUtils;
7
+
8
+import java.io.IOException;
9
+
1 10
 public class YouAreEll {
2 11
 
3 12
     YouAreEll() {
@@ -5,19 +14,49 @@ public class YouAreEll {
5 14
 
6 15
     public static void main(String[] args) {
7 16
         YouAreEll urlhandler = new YouAreEll();
8
-        System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
9
-        System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
17
+        try {
18
+            System.out.println(urlhandler.MakeURLCall("/ids", "GET", ""));
19
+            System.out.println(urlhandler.MakeURLCall("/messages", "GET", ""));
20
+        } catch (IOException e) {
21
+            e.printStackTrace();
22
+        }
10 23
     }
11 24
 
12 25
     public String get_ids() {
13
-        return MakeURLCall("/ids", "GET", "");
26
+        String temp = null;
27
+        try {
28
+            temp =  MakeURLCall("/ids", "GET", "");
29
+        } catch (IOException e) {
30
+            e.printStackTrace();
31
+        }
32
+        return temp;
14 33
     }
15 34
 
16 35
     public String get_messages() {
17
-        return MakeURLCall("/messages", "GET", "");
36
+        String temp = null;
37
+        try {
38
+            temp =  MakeURLCall("/messages", "GET", "");
39
+        } catch (IOException e) {
40
+            e.printStackTrace();
41
+        }
42
+        return temp;
18 43
     }
19 44
 
20
-    public String MakeURLCall(String mainurl, String method, String jpayload) {
21
-        return "nada";
45
+    public String MakeURLCall(String mainurl, String method, String jpayload) throws IOException {
46
+        String baseURL = "http://zipcode.rocks:8085";
47
+        String response;
48
+
49
+        CloseableHttpClient closeableHttpClient = HttpClients.createDefault();
50
+
51
+        HttpGet httpGet = new HttpGet(baseURL + mainurl);
52
+
53
+        CloseableHttpResponse response1 = closeableHttpClient.execute(httpGet);
54
+
55
+        HttpEntity httpEntity = response1.getEntity();
56
+
57
+        response = EntityUtils.toString(httpEntity);
58
+
59
+        return response;
60
+
22 61
     }
23 62
 }

+ 4
- 0
YouAreEll.iml Просмотреть файл

@@ -11,5 +11,9 @@
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.5.6" level="project" />
15
+    <orderEntry type="library" name="Maven: org.apache.httpcomponents:httpcore:4.4.10" level="project" />
16
+    <orderEntry type="library" name="Maven: commons-logging:commons-logging:1.2" level="project" />
17
+    <orderEntry type="library" name="Maven: commons-codec:commons-codec:1.10" level="project" />
14 18
   </component>
15 19
 </module>

+ 7
- 0
pom.xml Просмотреть файл

@@ -18,5 +18,12 @@
18 18
             <artifactId>jackson-databind</artifactId>
19 19
             <version>2.8.6</version>
20 20
         </dependency>
21
+
22
+        <dependency>
23
+            <groupId>org.apache.httpcomponents</groupId>
24
+            <artifactId>httpclient</artifactId>
25
+            <version>4.5.6</version>
26
+        </dependency>
27
+
21 28
     </dependencies>
22 29
 </project>