groovy Suicide-Server
import com.sun.net.httpserver.*
 
def port= this.args ? this.args[0].toInteger() : 8888
def server = HttpServer.create(new InetSocketAddress(port),0)
 
server.createContext("/", new info())
HttpContext kill = server.createContext("/kill", new Kill(server:server))
kill.setAuthenticator(new BasicAuthenticator("kill") {
  public boolean checkCredentials(String user, String pwd) {
    println "user==$user pwd==$pwd"
    user=="is10-99" && pwd=="alleskaput"
  }
});
 
server.setExecutor(null)
server.start()
 
println "\nGroovy Suicide-Server:$port startded."
 
class Kill implements HttpHandler {
  def server
  public void handle(HttpExchange exchange) {
    def path = exchange.getRequestURI().getPath()
    println "\nkill::==> ${path}"
    exchange.responseHeaders['Content-Type'] = 'text/html; charset=UTF-8'
    exchange.sendResponseHeaders(200, 0)
    if(path!="/kill") { exchange.close(); return }
    def out = new PrintWriter(exchange.getResponseBody())
    out.println "<H2>Groovy Suicide-Server killed.</H2>"
    out.close()
    exchange.close()
    server.stop(3)
    println "\nGroovy Suicide-Server killed.\n-------------------------------"
  }
}
 
class info implements HttpHandler {
  public void handle(HttpExchange exchange) {
    def path = exchange.getRequestURI().getPath()
    def out = new PrintWriter(exchange.getResponseBody())
    exchange.responseHeaders['Content-Type'] = 'text/html; charset=UTF-8'
    exchange.sendResponseHeaders(200, 0)
    println "\ninfo::==> ${path}"
    if(path =="/"){
      out.println """
<H2>Groovy Suicide-Server is ready!</H2>
<div style="font-size:34">
<a href='/kill'>kill me!</a>
</div>
"""
      println "Groovy Suicide-Server is ready!"
    }
    out.close()
    exchange.close()
  }
}
 
java.awt.Desktop.getDesktop().browse(new URI("http://localhost:${port}/"))