Explorar el Código

Have Message and Id Class written out

CWinarski hace 6 años
padre
commit
96d5924e4f

+ 7
- 3
Client/Client.iml Ver fichero

@@ -1,12 +1,10 @@
1 1
 <?xml version="1.0" encoding="UTF-8"?>
2 2
 <module org.jetbrains.idea.maven.project.MavenProjectsManager.isMavenModule="true" type="JAVA_MODULE" version="4">
3
-  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_5">
3
+  <component name="NewModuleRootManager" LANGUAGE_LEVEL="JDK_1_7">
4 4
     <output url="file://$MODULE_DIR$/target/classes" />
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,11 @@
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: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
16
+    <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
17
+    <orderEntry type="library" scope="TEST" name="Maven: com.squareup.okhttp3:mockwebserver:3.10.0" level="project" />
18
+    <orderEntry type="library" scope="TEST" name="Maven: org.bouncycastle:bcprov-jdk15on:1.50" level="project" />
19
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
20
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
17 21
   </component>
18 22
 </module>

+ 12
- 0
Client/pom.xml Ver fichero

@@ -10,6 +10,18 @@
10 10
     <modelVersion>4.0.0</modelVersion>
11 11
 
12 12
     <artifactId>Client</artifactId>
13
+    <build>
14
+        <plugins>
15
+            <plugin>
16
+                <groupId>org.apache.maven.plugins</groupId>
17
+                <artifactId>maven-compiler-plugin</artifactId>
18
+                <configuration>
19
+                    <source>1.7</source>
20
+                    <target>1.7</target>
21
+                </configuration>
22
+            </plugin>
23
+        </plugins>
24
+    </build>
13 25
 
14 26
 
15 27
 </project>

+ 67
- 0
Client/src/main/java/Message.java Ver fichero

@@ -0,0 +1,67 @@
1
+public class Message {
2
+
3
+    private String sequence;
4
+    private String timestamp = "2018-03-21T01:00:00.0Z";
5
+    private String fromid;
6
+    private String toid;
7
+    private String message;
8
+
9
+    public Message(String sequence, String timestamp, String fromid, String toid, String message) {
10
+        this.sequence = sequence;
11
+        this.timestamp = timestamp;
12
+        this.fromid = fromid;
13
+        this.toid = toid;
14
+        this.message = message;
15
+    }
16
+
17
+    public String getSequence() {
18
+        return sequence;
19
+    }
20
+
21
+    public void setSequence(String sequence) {
22
+        this.sequence = sequence;
23
+    }
24
+
25
+    public String getTimestamp() {
26
+        return timestamp;
27
+    }
28
+
29
+    public void setTimestamp(String timestamp) {
30
+        this.timestamp = timestamp;
31
+    }
32
+
33
+    public String getFromid() {
34
+        return fromid;
35
+    }
36
+
37
+    public void setFromid(String fromid) {
38
+        this.fromid = fromid;
39
+    }
40
+
41
+    public String getToid() {
42
+        return toid;
43
+    }
44
+
45
+    public void setToid(String toid) {
46
+        this.toid = toid;
47
+    }
48
+
49
+    public String getMessage() {
50
+        return message;
51
+    }
52
+
53
+    public void setMessage(String message) {
54
+        this.message = message;
55
+    }
56
+
57
+    @Override
58
+    public String toString() {
59
+        return "Message{" +
60
+                "sequence='" + sequence + '\'' +
61
+                ", timestamp='" + timestamp + '\'' +
62
+                ", fromid='" + fromid + '\'' +
63
+                ", toid='" + toid + '\'' +
64
+                ", message='" + message + '\'' +
65
+                '}';
66
+    }
67
+}

+ 7
- 0
Client/src/main/java/SimpleShell.java Ver fichero

@@ -1,3 +1,6 @@
1
+import okhttp3.Request;
2
+import okhttp3.Response;
3
+
1 4
 import java.io.BufferedReader;
2 5
 import java.io.IOException;
3 6
 import java.io.InputStream;
@@ -73,6 +76,10 @@ public class SimpleShell {
73 76
                 }
74 77
                 // you need to add a bunch more.
75 78
 
79
+                // create
80
+                // send message
81
+                //
82
+
76 83
                 //!! command returns the last command in history
77 84
                 if (list.get(list.size() - 1).equals("!!")) {
78 85
                     pb.command(history.get(history.size() - 2));

+ 55
- 0
Client/src/main/java/User.java Ver fichero

@@ -0,0 +1,55 @@
1
+import okhttp3.OkHttpClient;
2
+
3
+public class User {
4
+
5
+    private String userid;
6
+    private String name;
7
+    private String githubid;
8
+
9
+    OkHttpClient client = new OkHttpClient();
10
+
11
+    public User(String name, String githubid, String userid) {
12
+        this.name = name;
13
+        this.githubid = githubid;
14
+        this.userid = userid;
15
+    }
16
+
17
+    public User(String name, String githubid){
18
+        this.githubid = githubid;
19
+        this.name = name;
20
+    }
21
+
22
+    public String getUserid() {
23
+        return userid;
24
+    }
25
+
26
+    public void setUserid(String userid) {
27
+        this.userid = userid;
28
+    }
29
+
30
+    public String getName() {
31
+        return name;
32
+    }
33
+
34
+    public void setName(String name) {
35
+        this.name = name;
36
+    }
37
+
38
+    public String getGithub() {
39
+        return githubid;
40
+    }
41
+
42
+    public void setGithub(String github) {
43
+        this.githubid = github;
44
+    }
45
+
46
+    @Override
47
+    public String toString() {
48
+        return "User{" +
49
+                "userid='" + userid + '\'' +
50
+                ", name='" + name + '\'' +
51
+                ", githubid='" + githubid + '\'' +
52
+                ", client=" + client +
53
+                '}';
54
+    }
55
+}

+ 32
- 1
Client/src/main/java/YouAreEll.java Ver fichero

@@ -1,5 +1,10 @@
1
-public class YouAreEll {
1
+import okhttp3.*;
2
+
3
+import java.io.IOException;
2 4
 
5
+public class YouAreEll {
6
+    private static final MediaType JSON = MediaType.parse("application/json; charset=utf-8");
7
+    OkHttpClient client = new OkHttpClient();
3 8
     YouAreEll() {
4 9
     }
5 10
 
@@ -18,6 +23,32 @@ public class YouAreEll {
18 23
     }
19 24
 
20 25
     public String MakeURLCall(String mainurl, String method, String jpayload) {
26
+
27
+        String actualUrl = "http://zipcode.rocks:8085" + mainurl;
28
+
29
+        if (method.equals("GET")) {
30
+            Request request = new Request.Builder()
31
+                    .url(actualUrl)
32
+                    .build();
33
+
34
+            try (Response response = client.newCall(request).execute()) {
35
+                return response.body().string();
36
+            } catch (IOException ioe) {
37
+                ioe.printStackTrace();
38
+            }
39
+        } else if (method.equals("PUT")){
40
+                RequestBody body = RequestBody.create(JSON, jpayload);
41
+                Request request = new Request.Builder()
42
+                        .url(actualUrl)
43
+                        .post(body)
44
+                        .build();
45
+                try (Response response = client.newCall(request).execute()) {
46
+                    return response.body().string();
47
+                } catch (IOException e) {
48
+                    e.printStackTrace();
49
+                }
50
+        }
51
+
21 52
         return "nada";
22 53
     }
23 54
 }

+ 6
- 0
YouAreEll.iml Ver fichero

@@ -11,5 +11,11 @@
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: com.squareup.okhttp3:okhttp:3.10.0" level="project" />
15
+    <orderEntry type="library" name="Maven: com.squareup.okio:okio:1.14.0" level="project" />
16
+    <orderEntry type="library" scope="TEST" name="Maven: com.squareup.okhttp3:mockwebserver:3.10.0" level="project" />
17
+    <orderEntry type="library" scope="TEST" name="Maven: org.bouncycastle:bcprov-jdk15on:1.50" level="project" />
18
+    <orderEntry type="library" scope="TEST" name="Maven: junit:junit:4.12" level="project" />
19
+    <orderEntry type="library" scope="TEST" name="Maven: org.hamcrest:hamcrest-core:1.3" level="project" />
14 20
   </component>
15 21
 </module>

+ 11
- 0
pom.xml Ver fichero

@@ -18,5 +18,16 @@
18 18
             <artifactId>jackson-databind</artifactId>
19 19
             <version>2.8.6</version>
20 20
         </dependency>
21
+        <dependency>
22
+            <groupId>com.squareup.okhttp3</groupId>
23
+            <artifactId>okhttp</artifactId>
24
+            <version>3.10.0</version>
25
+        </dependency>
26
+        <dependency>
27
+            <groupId>com.squareup.okhttp3</groupId>
28
+            <artifactId>mockwebserver</artifactId>
29
+            <version>3.10.0</version>
30
+            <scope>test</scope>
31
+        </dependency>
21 32
     </dependencies>
22 33
 </project>