forked from ucsd-cse15l-f22/wavelet
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathStringServer.java
More file actions
31 lines (29 loc) · 1.04 KB
/
StringServer.java
File metadata and controls
31 lines (29 loc) · 1.04 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
import java.io.IOException;
import java.net.URI;
class Handler implements URLHandler {
String message = "";
public String handleRequest(URI url){
if (url.getPath().equals("/")) {
return String.format("Your messages: %s", message);
}
else if(url.getPath().contains("/add-message")){
String[] param = url.getQuery().split("=");
//String template = param + "\n";
System.out.println("Added " + param[1] + " to your messages!");
System.out.println(param[1]);
message = message + "\n" + param[1];
return String.format("Added %s to your messages!", param[1]);
}
return "404 Not Found!";
}
}
public class StringServer{
public static void main(String[] arr) throws IOException{
if(arr.length == 0){
System.out.println("Missing port number! Try any number between 1024 to 49151");
return;
}
int port = Integer.parseInt(arr[0]);
Server.start(port, new Handler());
}
}