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
40 lines (35 loc) · 1.1 KB
/
Copy pathStringServer.java
File metadata and controls
40 lines (35 loc) · 1.1 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
32
33
34
35
36
37
38
39
40
import java.io.IOException;
import java.net.URI;
import java.util.ArrayList;
class Handler implements URLHandler{
ArrayList<String> dataList= new ArrayList<>();
public String handleRequest(URI url){
if(url.getPath().equals("/")){
return "This is the homepage of Bernico's String Server!";
}
else{
if(url.getPath().contains("/add-message")){
String[] queries = url.getQuery().split("=");
if(queries[0].equals("s")){
String r = "";
dataList.add(queries[1]);
for(String strs: dataList){
r = r + strs + "\n";
}
return r;
}
}
}
return "ERROR! Page not found!";
}
}
public class StringServer{
public static void main(String[] args) throws IOException{
if(args.length == 0){
System.out.println("Missing port number!");
return;
}
int port = Integer.parseInt(args[0]);
Server.start(port, new Handler());
}
}