From e900aca2e02a5376f2c2e788e182c0ea9606cf64 Mon Sep 17 00:00:00 2001 From: FrozenCow Date: Tue, 15 Feb 2011 14:19:43 +0100 Subject: [PATCH] Added helper classes for HTTP. --- .../java/org/dynmap/web/HttpErrorHandler.java | 20 +++++++++++++++++++ src/main/java/org/dynmap/web/HttpMethods.java | 8 ++++++++ 2 files changed, 28 insertions(+) create mode 100644 src/main/java/org/dynmap/web/HttpErrorHandler.java create mode 100644 src/main/java/org/dynmap/web/HttpMethods.java diff --git a/src/main/java/org/dynmap/web/HttpErrorHandler.java b/src/main/java/org/dynmap/web/HttpErrorHandler.java new file mode 100644 index 00000000..f2476390 --- /dev/null +++ b/src/main/java/org/dynmap/web/HttpErrorHandler.java @@ -0,0 +1,20 @@ +package org.dynmap.web; + +import java.io.IOException; + +public class HttpErrorHandler { + public static void handle(HttpResponse response, int statusCode, String statusMessage) throws IOException { + response.statusCode = statusCode; + response.statusMessage = statusMessage; + response.fields.put("Content-Length", "0"); + response.getBody(); + } + + public static void handleNotFound(HttpResponse response) throws IOException { + handle(response, 404, "Not found"); + } + + public static void handleMethodNotAllowed(HttpResponse response) throws IOException { + handle(response, 405, "Method not allowed"); + } +} diff --git a/src/main/java/org/dynmap/web/HttpMethods.java b/src/main/java/org/dynmap/web/HttpMethods.java new file mode 100644 index 00000000..8c116519 --- /dev/null +++ b/src/main/java/org/dynmap/web/HttpMethods.java @@ -0,0 +1,8 @@ +package org.dynmap.web; + +public class HttpMethods { + public static final String Get = "GET"; + public static final String Post = "POST"; + public static final String Put = "PUT"; + public static final String Delete = "DELETE"; +}