From 760b73261aa5f9256c33fd7eb0a5336cb4f5a6b1 Mon Sep 17 00:00:00 2001 From: adb Date: Tue, 26 Jan 2021 20:43:31 +0100 Subject: [PATCH] clean up debug RedditAPI --- build.gradle | 1 - .../CommunityHandler.java | 21 +++++++++++++++++++ .../RandomRedditMemesAPI/FallbackHandler.java | 21 +++++++++++++++++++ 3 files changed, 42 insertions(+), 1 deletion(-) create mode 100644 src/main/java/sh/adb/RandomRedditMemesAPI/CommunityHandler.java create mode 100644 src/main/java/sh/adb/RandomRedditMemesAPI/FallbackHandler.java diff --git a/build.gradle b/build.gradle index b39d00f..19269fe 100644 --- a/build.gradle +++ b/build.gradle @@ -17,7 +17,6 @@ sourceSets { repositories { mavenCentral() } -apply plugin: "java" dependencies { //jreddit 1.0.4 dependencies diff --git a/src/main/java/sh/adb/RandomRedditMemesAPI/CommunityHandler.java b/src/main/java/sh/adb/RandomRedditMemesAPI/CommunityHandler.java new file mode 100644 index 0000000..76d2da5 --- /dev/null +++ b/src/main/java/sh/adb/RandomRedditMemesAPI/CommunityHandler.java @@ -0,0 +1,21 @@ +package sh.adb.RandomRedditMemesAPI; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +class CommunityHandler implements HttpHandler { + @Override + public void handle(HttpExchange t) throws IOException { + InputStream is = t.getRequestBody(); + //is.read(); + String response = "This is the response"; + t.sendResponseHeaders(200, response.length()); + OutputStream os = t.getResponseBody(); + os.write(response.getBytes()); + os.close(); + } +} diff --git a/src/main/java/sh/adb/RandomRedditMemesAPI/FallbackHandler.java b/src/main/java/sh/adb/RandomRedditMemesAPI/FallbackHandler.java new file mode 100644 index 0000000..3db5897 --- /dev/null +++ b/src/main/java/sh/adb/RandomRedditMemesAPI/FallbackHandler.java @@ -0,0 +1,21 @@ +package sh.adb.RandomRedditMemesAPI; + +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; + +import java.io.IOException; +import java.io.InputStream; +import java.io.OutputStream; + +class FallbackHandler implements HttpHandler { + @Override + public void handle(HttpExchange t) throws IOException { + InputStream is = t.getRequestBody(); + //is.read(); + String response = "404"; + t.sendResponseHeaders(404, response.length()); + OutputStream os = t.getResponseBody(); + os.write(response.getBytes()); + os.close(); + } +} \ No newline at end of file