|
@@ -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
|
+}
|