--- miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/web/BanListener.java 2012/05/28 14:32:53 1803 +++ miscJava/bukkit-minecraft-plugins/HoerupUtils/src/main/java/dk/thoerup/bukkit/hoeruputils/web/BanListener.java 2013/03/20 16:41:20 1940 @@ -1,26 +1,21 @@ package dk.thoerup.bukkit.hoeruputils.web; -import java.io.File; +import java.io.IOException; +import java.io.OutputStream; +import java.net.HttpURLConnection; import java.text.SimpleDateFormat; import java.util.Date; -import java.util.Set; -import java.util.Map; -import org.bukkit.Location; -import org.bukkit.Server; + import org.bukkit.OfflinePlayer; -import org.bukkit.entity.Player; +import org.bukkit.Server; import org.bukkit.plugin.Plugin; -import org.bukkit.configuration.Configuration; +import com.sun.net.httpserver.HttpExchange; +import com.sun.net.httpserver.HttpHandler; -/*import org.kokakiwi.apicraft.events.ApiEvent; -import org.kokakiwi.apicraft.events.ApiListener;*/ -import de.codeinfection.quickwango.ApiBukkit.ApiBukkit; -import de.codeinfection.quickwango.ApiBukkit.ApiServer.*; -@Controller( name = "bans", authenticate = false, serializer = "raw" ) -public class BanListener extends ApiController { +public class BanListener implements HttpHandler { SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss"); @@ -30,8 +25,6 @@ String cachedText = ""; public BanListener(Plugin plugin, Server server) { - super( new de.codeinfection.quickwango.Abstraction.Implementations.Bukkit.BukkitPlugin(plugin) ); - //super( new de.codeinfection.quickwango.ApiBukkit.Abstraction.Implementations.Bukkit.BukkitPlugin(plugin) ); this.server = server; } @@ -44,9 +37,11 @@ return format.format(d ); } + + @Override - public void defaultAction(ApiRequest request, ApiResponse response) { -/* if(!event.path[0].equalsIgnoreCase("webstatus")) { + public void handle(HttpExchange http) throws IOException { + /* if(!event.path[0].equalsIgnoreCase("webstatus")) { return; }*/ @@ -62,12 +57,14 @@ text = cachedText; } } - -/* event.setResponse(xml); - event.setActionTaken(true);*/ - - response.setContent( text ); + byte bytes[] = text.getBytes(); + http.sendResponseHeaders(HttpURLConnection.HTTP_OK, bytes.length ); + final OutputStream os = http.getResponseBody(); + os.write(bytes); + os.close(); + http.close(); + } private String buildText() { @@ -93,4 +90,6 @@ } + + }