[WebServer
strick**20120126081823
 Ignore-this: d33a154ec3c9875c26e88cb30cd7aee4
] addfile ./WebServer.java
hunk ./WebServer.java 1
+package net.yak.stalk;
+import java.io.IOException;
+import java.io.InputStream;
+import java.io.OutputStream;
+import java.net.InetSocketAddress;
+
+import com.sun.net.httpserver.*;
+
+public class WebServer {
+
+	public static class MyHandler implements HttpHandler {
+	       public void handle(HttpExchange t) throws IOException {
+	           InputStream is = t.getRequestBody();
+	           String x = readAll(is); // .. read the request body
+	           String response = "Content-Type: text/html\n\r\n\rThis is the response {" + x 
+	           + "}  <input name=xyz value=ABC>";
+	           t.sendResponseHeaders(200, response.length());
+	           OutputStream os = t.getResponseBody();
+	           os.write(response.getBytes());
+	           os.close();
+	       }
+	   	public String readAll(InputStream is) throws IOException {
+			StringBuffer b = new StringBuffer();
+			while (true) {
+				int c = is.read();
+				if (c < 0) break;
+				b.append((char)c);
+			}
+			return b.toString();
+		}
+
+	   }
+
+	public static void main(String[] args) throws IOException {
+		   HttpServer server = HttpServer.create(new InetSocketAddress(8000), 5);
+		   //server.createContext("/applications/myapp", new MyHandler());
+		   server.createContext("/", new MyHandler());
+		   server.setExecutor(null); // creates a default executor
+		   server.start();
+	}
+
+}