From a827b7219e1610971fa6578785a1d9f9ad8212d5 Mon Sep 17 00:00:00 2001 From: Juliet Raynovich Date: Thu, 6 Oct 2022 17:00:49 -0700 Subject: [PATCH 1/7] update --- NumberServer.java | 2 +- new | 40 ++++++++++++++++++++++++++++++++++++++++ 2 files changed, 41 insertions(+), 1 deletion(-) create mode 100644 new diff --git a/NumberServer.java b/NumberServer.java index a2842b9d..9943d872 100644 --- a/NumberServer.java +++ b/NumberServer.java @@ -4,7 +4,7 @@ class Handler implements URLHandler { // The one bit of state on the server: a number that will be manipulated by // various requests. - int num = 0; + int num = 7%5; public String handleRequest(URI url) { if (url.getPath().equals("/")) { diff --git a/new b/new new file mode 100644 index 00000000..031749c9 --- /dev/null +++ b/new @@ -0,0 +1,40 @@ +import java.io.IOException; +import java.net.URI; + +class Handler implements URLHandler { + // The one bit of state on the server: a number that will be manipulated by + // various requests. + int num = 7%5; + + public String handleRequest(URI url) { + if (url.getPath().equals("/")) { + return String.format("Number: %d", num); + } else if (url.getPath().equals("/increment")) { + num += 1; + return String.format("Number incremented!"); + } else { + System.out.println("Path: " + url.getPath()); + if (url.getPath().contains("/add")) { + String[] parameters = url.getQuery().split("="); + if (parameters[0].equals("count")) { + num += Integer.parseInt(parameters[1]); + return String.format("Number increased by %s! It's now %d", parameters[1], num); + } + } + return "404 Not Found!"; + } + } +} + +class NumberServer { + public static void main(String[] args) throws IOException { + if(args.length == 0){ + System.out.println("Missing port number! Try any number between 1024 to 49151"); + return; + } + + int port = Integer.parseInt(args[0]); + + Server.start(port, new Handler()); + } +} \ No newline at end of file From ae563392cfd487d0c37cd1ef896a5551814c6ea6 Mon Sep 17 00:00:00 2001 From: Juliet Raynovich Date: Thu, 6 Oct 2022 17:06:57 -0700 Subject: [PATCH 2/7] Update Server.java --- Server.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/Server.java b/Server.java index 20aab2a1..9a9ea815 100644 --- a/Server.java +++ b/Server.java @@ -46,7 +46,7 @@ public static void start(int port, URLHandler handler) throws IOException { //create request entrypoint server.createContext("/", new ServerHttpHandler(handler)); - //start the server + //start the server kk server.start(); System.out.println("Server Started! Visit http://localhost:" + port + " to visit."); } From fb03817577aad5dede9c9a62b60d71b7ad1f3c29 Mon Sep 17 00:00:00 2001 From: Juliet Raynovich Date: Thu, 6 Oct 2022 17:14:14 -0700 Subject: [PATCH 3/7] SearchEngine.java Update --- new => SearchEngine.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) rename new => SearchEngine.java (94%) diff --git a/new b/SearchEngine.java similarity index 94% rename from new rename to SearchEngine.java index 031749c9..aefb8767 100644 --- a/new +++ b/SearchEngine.java @@ -14,7 +14,7 @@ public String handleRequest(URI url) { return String.format("Number incremented!"); } else { System.out.println("Path: " + url.getPath()); - if (url.getPath().contains("/add")) { + if (url.getPath().contains("/add?=anewstringtoadd")) { String[] parameters = url.getQuery().split("="); if (parameters[0].equals("count")) { num += Integer.parseInt(parameters[1]); From e149efb4110444c470f7da5a966aa99d27820342 Mon Sep 17 00:00:00 2001 From: Juliet Raynovich Date: Thu, 6 Oct 2022 17:20:12 -0700 Subject: [PATCH 4/7] Update NumberServer.java --- NumberServer.java | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/NumberServer.java b/NumberServer.java index 9943d872..13ccc5c1 100644 --- a/NumberServer.java +++ b/NumberServer.java @@ -4,7 +4,7 @@ class Handler implements URLHandler { // The one bit of state on the server: a number that will be manipulated by // various requests. - int num = 7%5; + int num = 1000; public String handleRequest(URI url) { if (url.getPath().equals("/")) { From 41f1a7493ddb3052e6032fa61b79692fe15225da Mon Sep 17 00:00:00 2001 From: Juliet Raynovich Date: Fri, 14 Oct 2022 19:54:26 -0700 Subject: [PATCH 5/7] Update SearchEngine.java --- SearchEngine.java | 42 ++---------------------------------------- 1 file changed, 2 insertions(+), 40 deletions(-) diff --git a/SearchEngine.java b/SearchEngine.java index aefb8767..8cd36121 100644 --- a/SearchEngine.java +++ b/SearchEngine.java @@ -1,40 +1,2 @@ -import java.io.IOException; -import java.net.URI; - -class Handler implements URLHandler { - // The one bit of state on the server: a number that will be manipulated by - // various requests. - int num = 7%5; - - public String handleRequest(URI url) { - if (url.getPath().equals("/")) { - return String.format("Number: %d", num); - } else if (url.getPath().equals("/increment")) { - num += 1; - return String.format("Number incremented!"); - } else { - System.out.println("Path: " + url.getPath()); - if (url.getPath().contains("/add?=anewstringtoadd")) { - String[] parameters = url.getQuery().split("="); - if (parameters[0].equals("count")) { - num += Integer.parseInt(parameters[1]); - return String.format("Number increased by %s! It's now %d", parameters[1], num); - } - } - return "404 Not Found!"; - } - } -} - -class NumberServer { - public static void main(String[] args) throws IOException { - if(args.length == 0){ - System.out.println("Missing port number! Try any number between 1024 to 49151"); - return; - } - - int port = Integer.parseInt(args[0]); - - Server.start(port, new Handler()); - } -} \ No newline at end of file +class SearchEngine implements NumberServer { + \ No newline at end of file From f99c49608726a127bd2731eab74e724392990df6 Mon Sep 17 00:00:00 2001 From: Juliet Raynovich Date: Fri, 14 Oct 2022 20:03:13 -0700 Subject: [PATCH 6/7] searchengine --- .DS_Store | Bin 0 -> 6148 bytes SearchEngine.java | 5 +++-- 2 files changed, 3 insertions(+), 2 deletions(-) create mode 100644 .DS_Store diff --git a/.DS_Store b/.DS_Store new file mode 100644 index 0000000000000000000000000000000000000000..5008ddfcf53c02e82d7eee2e57c38e5672ef89f6 GIT binary patch literal 6148 zcmeH~Jr2S!425mzP>H1@V-^m;4Wg<&0T*E43hX&L&p$$qDprKhvt+--jT7}7np#A3 zem<@ulZcFPQ@L2!n>{z**++&mCkOWA81W14cNZlEfg7;MkzE(HCqgga^y>{tEnwC%0;vJ&^%eQ zLs35+`xjp>T0 Date: Fri, 14 Oct 2022 20:19:29 -0700 Subject: [PATCH 7/7] update --- HTTPServer.java | 4 ++++ SearchEngine.java | 2 +- 2 files changed, 5 insertions(+), 1 deletion(-) create mode 100644 HTTPServer.java diff --git a/HTTPServer.java b/HTTPServer.java new file mode 100644 index 00000000..1d5ba115 --- /dev/null +++ b/HTTPServer.java @@ -0,0 +1,4 @@ + +public interface HTTPServer { + +} diff --git a/SearchEngine.java b/SearchEngine.java index badf929f..f7e2bb44 100644 --- a/SearchEngine.java +++ b/SearchEngine.java @@ -1,3 +1,3 @@ -public class SearchEngine { +public class SearchEngine implements HTTPServer{ }