|
|
|
|
4
|
|
4
|
|
5
|
|
5
|
|
6
|
### The Point
|
6
|
### The Point
|
|
|
7
|
+* You are to write a command interpreter using the provided `SimpleShell` class.
|
|
|
8
|
+* You're going to create a way
|
|
|
9
|
+ * for commands to be typed into your shell,
|
|
|
10
|
+ * to read the typed commands and arguments,
|
|
|
11
|
+ * to send them off to the Under-A-Rock server using a REST API over the HTTP protocol,
|
|
|
12
|
+ * to read the JSON data returned from the URL call,
|
|
|
13
|
+ * to print it out nicely formatted for your user.
|
7
|
|
14
|
|
8
|
-You are to write a command interpreter using the provided SimpleShell class. You're going to create a way for
|
|
|
9
|
-commands to be typed into your shell, read the typed commands and arguments, send them off to the Under-A-Rock
|
|
|
10
|
-server using a REST API over the HTTP protocol, read the JSON data returned from the URL call, and print it out
|
|
|
11
|
-nicely formatted for your user. If you manage to get this all done in a reasonable time, attempt parts 2 and 3.
|
|
|
|
|
15
|
+* `Under-A-Rock` acts a little (very little) like a twitter server or chat server.
|
|
|
16
|
+ * You register your name and github id by creating an ID JSON payload (see below) and POSTing it to the server.
|
|
|
17
|
+ * You can GET all the ids registered by sending a GET request to the same URL.
|
|
|
18
|
+ * Once you've received all the ids, you can send messages to the world or to a specific `Github_id`.
|
12
|
|
19
|
|
13
|
-Under-A-Rock acts a little (very little) like a twitter server or chat server.
|
|
|
14
|
|
20
|
|
15
|
-You register your name and githubid by creating an ID JSON payload (see below) and POSTing it to the server. You can GET
|
|
|
16
|
-all the ids registered by sending a GET request to the same URL. Once you've received all the ids, you can send
|
|
|
17
|
-messages to the world or to a specific Github_id.
|
|
|
18
|
|
21
|
|
19
|
-You
|
|
|
20
|
-can send a message to the global timeline by POSTing a Message JSON object to the URL below.
|
|
|
21
|
-If you leave the "to id" field empty, the message is "to the world". If you fill out the the JSON template with
|
|
|
22
|
-a valid github_id in the "to id" field of the JSON payload, then that message is addressed to that friend. Yes, all
|
|
|
23
|
-messages can be seen by users of the system. There are JSON templates below for both Ids and Messages.
|
|
|
|
|
22
|
+* You can send a message to the global timeline by POSTing a Message JSON object to the URL below.
|
|
|
23
|
+ * If you leave the `to id` field empty, the message is `to the world`.
|
|
|
24
|
+ * If you fill out the the JSON template with a valid github_id in the `to id` field of the JSON payload, then that message is addressed to that friend.
|
|
|
25
|
+ * Yes, all messages can be seen by users of the system.
|
|
|
26
|
+ * There are JSON templates below for both Ids and Messages.
|
24
|
|
27
|
|
25
|
-When you send a new Message or Id JSON object to the server, it records it, and fills in one or two fields.
|
|
|
26
|
-A Message gets an assigned sequence number and a timestamp of when it was received by the server. An ID
|
|
|
27
|
-object gets a "user id" field assigned to it.
|
|
|
28
|
-Any sequence number, timestamp or userid you put into a JSON template
|
|
|
29
|
-gets overwritten by the server when you POST it.
|
|
|
30
|
|
28
|
|
31
|
-You're going to create a series of REST API handlers that will each perform a
|
|
|
32
|
-specific command. Each one of the command methods will then call a even lower-level method that makes a certain kind
|
|
|
33
|
-of HTTP request (GET, POST, PUT) to specific filled-in URL.
|
|
|
34
|
|
29
|
|
35
|
-The Under-A-Rock Server can be reached at `http://zipcode.rocks:8085` Everyone uses the same server.
|
|
|
|
|
30
|
+* When you send a new Message or Id JSON object to the server, it records it, and fills in one or two fields.
|
|
|
31
|
+ * A Message gets an assigned sequence number and a timestamp of when it was received by the server.
|
|
|
32
|
+ * An ID object gets a "user id" field assigned to it.
|
|
|
33
|
+ * Any sequence number, timestamp or userid you put into a JSON template gets overwritten by the server when you POST it.
|
36
|
|
34
|
|
37
|
-There are two segments to the API and two kinds of commands in the shell, the ID segment and the Messages segment.
|
|
|
38
|
|
35
|
|
39
|
|
36
|
|
40
|
-You can explore several ways of doing the HTTP URL calls to the server, using the one of these:
|
|
|
41
|
-* Core Java version
|
|
|
42
|
-URL https://docs.oracle.com/javase/8/docs/api/java/net/URL.html and
|
|
|
43
|
-HttpURLConnection https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html,
|
|
|
44
|
-* Apache HTTP Client Library http://hc.apache.org/httpcomponents-client-ga/index.html
|
|
|
45
|
-* Unirest for Java http://unirest.io/java.html
|
|
|
46
|
-* Square's OKHttp https://github.com/square/okhttp
|
|
|
|
|
37
|
+* You're going to create a series of REST API handlers that will each perform a
|
|
|
38
|
+specific command.
|
|
|
39
|
+ * Each one of the command methods will then call a even lower-level method that makes a certain kind of HTTP request (GET, POST, PUT) to specific filled-in URL.
|
47
|
|
40
|
|
48
|
-Be prepared to defend your choice if which HTTP client library you chose, with reasons why you chose it.
|
|
|
49
|
-You should also create some unit tests for your REST API handlers. You should look at how ItelliJ does management of
|
|
|
50
|
-dependencies. (You'll be modifying the `pom.xml` file.) Usually, you merely need to add a `dependency` clause to the `dependencies`
|
|
|
51
|
-clause in the pom.xml.
|
|
|
|
|
41
|
+* The Under-A-Rock Server can be reached at `http://zipcode.rocks:8085` Everyone uses the same server.
|
|
|
42
|
+ * There are two segments to the API and two kinds of commands in the shell, the ID segment and the Messages segment.
|
52
|
|
43
|
|
53
|
-It's possible you may also need to understand some of what the Jackson package does for you. `jackson` will also need to be inserted into the `pom.xml` file, with a dependency clause.
|
|
|
54
|
|
44
|
|
55
|
-* jackson json https://github.com/FasterXML/jackson
|
|
|
|
|
45
|
+* You can explore several ways of doing the HTTP URL calls to the server, using the one of these:
|
|
|
46
|
+ * [Apache HTTP Client Library](http://hc.apache.org/httpcomponents-client-ga/index.html)
|
|
|
47
|
+ * [Unirest for Java](http://unirest.io/java.html)
|
|
|
48
|
+ * [Square's OKHttp](https://github.com/square/okhttp)
|
|
|
49
|
+ * Core Java:
|
|
|
50
|
+ * [URL](https://docs.oracle.com/javase/8/docs/api/java/net/URL.html)
|
|
|
51
|
+ * [HttpURLConnection](https://docs.oracle.com/javase/8/docs/api/java/net/HttpURLConnection.html)
|
56
|
|
52
|
|
57
|
-And you may wish to create a couple classes `public class Message` and `public class Id` to make handling
|
|
|
58
|
-the abstractions implied by the API easier.
|
|
|
|
|
53
|
+* Be prepared to defend your choice if which HTTP client library you chose, with reasons why you chose it.
|
|
|
54
|
+ * You should also create some unit tests for your REST API handlers.
|
59
|
|
55
|
|
60
|
-Jackson can help you parse the json into objects,and objects back into JSON strings. Be sure to research how you can
|
|
|
61
|
-dependencies in the `pom.xml` so that Jackson, well, so that you can use Jackson in the project.
|
|
|
|
|
56
|
+* It's possible you may also need to understand some of what the [Jackson package](https://github.com/FasterXML/jackson) does.
|
62
|
|
57
|
|
63
|
## IDs
|
58
|
## IDs
|
64
|
|
59
|
|
65
|
#### ID commands in shell
|
60
|
#### ID commands in shell
|
66
|
-In the shell,
|
|
|
67
|
-`ids` should return a formatted list of the IDs available to you.
|
|
|
|
|
61
|
+* In the shell, `ids` should return a formatted list of the IDs available to you.
|
|
|
62
|
+* `ids your_name your_github_id` command should post your Name and your GithubId to the server.
|
|
|
63
|
+* If you do this twice with two different Names, but the name GithubId, the name on the server gets changed.
|
68
|
|
64
|
|
69
|
-`ids your_name your_github_id` command should post your Name and your GithubId to the server.
|
|
|
70
|
-If you do this twice with two different Names, but the name GithubId, the name on the server gets changed.
|
|
|
71
|
-
|
|
|
72
|
-the IDs API is:
|
|
|
|
|
65
|
+-
|
|
|
66
|
+### The IDs API is:
|
73
|
|
67
|
|
74
|
#### URL: /ids/
|
68
|
#### URL: /ids/
|
75
|
* `GET` : Get all github ids registered
|
69
|
* `GET` : Get all github ids registered
|
|
|
|
|
77
|
* `PUT` : change the name linked to your github id
|
71
|
* `PUT` : change the name linked to your github id
|
78
|
|
72
|
|
79
|
json payload for /ids/ - this is a sample
|
73
|
json payload for /ids/ - this is a sample
|
|
|
74
|
+
|
80
|
```json
|
75
|
```json
|
81
|
{
|
76
|
{
|
82
|
"userid": "-", // gets filled w id
|
77
|
"userid": "-", // gets filled w id
|
|
|
|
|
85
|
}
|
80
|
}
|
86
|
```
|
81
|
```
|
87
|
|
82
|
|
88
|
- #### Example:
|
|
|
89
|
-
|
|
|
90
|
- if I type
|
|
|
91
|
- ```aidl
|
|
|
92
|
-cmd?
|
|
|
93
|
- ids Kris xt0fer
|
|
|
94
|
-```
|
|
|
95
|
- into the shell, your command processor creates a JSON object which looks like:
|
|
|
|
|
83
|
+#### Example:
|
|
|
84
|
+If I type `cmd? ids Kris xt0fer` into the shell, your command processor creates a JSON object which looks like:
|
|
|
85
|
+
|
96
|
```json
|
86
|
```json
|
97
|
{
|
87
|
{
|
98
|
"userid": "-", // gets filled w id
|
88
|
"userid": "-", // gets filled w id
|
|
|
|
|
106
|
## Messages
|
96
|
## Messages
|
107
|
|
97
|
|
108
|
#### Message comands in shell
|
98
|
#### Message comands in shell
|
109
|
-
|
|
|
110
|
-in the shell,
|
|
|
|
|
99
|
+in the shell
|
111
|
* `messages` should return the last 20 messages, nicely formatted.
|
100
|
* `messages` should return the last 20 messages, nicely formatted.
|
112
|
* `messages your_github_id` should return the last 20 messages sent to you.
|
101
|
* `messages your_github_id` should return the last 20 messages sent to you.
|
113
|
* `send your_github_id 'Hello World' ` should post a new message in the timeline
|
102
|
* `send your_github_id 'Hello World' ` should post a new message in the timeline
|
|
|
|
|
129
|
* `GET` : Get last 20 msgs for myid from friendid
|
118
|
* `GET` : Get last 20 msgs for myid from friendid
|
130
|
|
119
|
|
131
|
json payload for /messages/ these are samples, one to a specific friend, one to the timeline.
|
120
|
json payload for /messages/ these are samples, one to a specific friend, one to the timeline.
|
|
|
121
|
+
|
132
|
```json
|
122
|
```json
|
133
|
[
|
123
|
[
|
134
|
{
|
124
|
{
|
|
|
|
|
151
|
|
141
|
|
152
|
#### Example:
|
142
|
#### Example:
|
153
|
|
143
|
|
154
|
- if I type
|
|
|
155
|
- ```aidl
|
|
|
156
|
-cmd?
|
|
|
|
|
144
|
+if I type
|
|
|
145
|
+``` cmd?
|
157
|
send xt0fer 'Hello old buddy!' to torvalds
|
146
|
send xt0fer 'Hello old buddy!' to torvalds
|
158
|
```
|
147
|
```
|
159
|
- into the shell, your command processor creates a JSON object which looks like:
|
|
|
|
|
148
|
+into the shell, your command processor creates a JSON object which looks like:
|
|
|
149
|
+
|
160
|
```json
|
150
|
```json
|
161
|
- {
|
|
|
162
|
- "sequence": "-",
|
|
|
163
|
- "timestamp": "_",
|
|
|
164
|
- "fromid": "xt0fer",
|
|
|
165
|
- "toid": "torvalds",
|
|
|
166
|
- "message": "Hello old buddy!"
|
|
|
167
|
- }
|
|
|
|
|
151
|
+{
|
|
|
152
|
+ "sequence": "-",
|
|
|
153
|
+ "timestamp": "_",
|
|
|
154
|
+ "fromid": "xt0fer",
|
|
|
155
|
+ "toid": "torvalds",
|
|
|
156
|
+ "message": "Hello old buddy!"
|
|
|
157
|
+}
|
168
|
```
|
158
|
```
|
169
|
and send it as the body of a POST request to `http://zipcode.rocks:8085/ids/xt0fer/messages/`
|
159
|
and send it as the body of a POST request to `http://zipcode.rocks:8085/ids/xt0fer/messages/`
|
170
|
|
160
|
|
|
|
161
|
+
|
|
|
162
|
+
|
171
|
## Part Two
|
163
|
## Part Two
|
172
|
|
164
|
|
173
|
What's that ProcessBuilder stuff about? In the SimpleShell class, take a look. How can that be used
|
165
|
What's that ProcessBuilder stuff about? In the SimpleShell class, take a look. How can that be used
|