scala Suicide-Server
import java.net.{InetSocketAddress, URI}
import com.sun.net.httpserver._
import java.io.{PrintWriter, OutputStream}
 
object httpd {
  def main(args: Array[String]) {
    val port: Int = 8080
    val server = HttpServer.create(new InetSocketAddress(port),0)
    server.createContext("/", new info())
    val kill: HttpContext = server.createContext("/kill", new KILL(server))
    kill.setAuthenticator(new BasicAuthenticator("kill") {
      def checkCredentials(user: String , pwd: String): Boolean = {
        println (s"user==$user pwd==$pwd")
        user=="is10-99" && pwd=="alleskaput"
      }
    });
 
    server.setExecutor(null)
    server.start()
 
    java.awt.Desktop.getDesktop().browse(new URI(s"http://localhost:$port/"))
    println(s"\nSCALA httpdServer:$port startded.")
  }
 
  class info extends HttpHandler {
    def handle(exchange: HttpExchange){
      val out = new PrintWriter(exchange.getResponseBody())
      exchange.getResponseHeaders.set("Content-Type", "text/html; charset=UTF-8")
      exchange.sendResponseHeaders(200, 0)
      out.println ("""
<H2>SCALA httpdServer is ready!</H2>
<div style="font-size:34">
<a href='/kill'>kill me!</a>
</div>
""")
      out.close()
      exchange.close()
    }
  }
 
  class KILL(val serv : HttpServer) extends HttpHandler {
    def handle(exchange: HttpExchange) {
      val out = new PrintWriter(exchange.getResponseBody())
      exchange.getResponseHeaders.set("Content-Type", "text/html; charset=UTF-8")
      exchange.sendResponseHeaders(200, 0)
      val path = exchange.getRequestURI().getPath()
      println (s"\nkill::==> $path")
      if(path!="/kill") { exchange.close(); return }
      out.println ("<H2>SCALA httpdServer killed.</H2>")
      out.close()
      exchange.close()
      serv.stop(0)
      println ("\nSCALA httpdServer killed.\n-------------------------------")
    }
  }
 
}