package examples;
import java.io.BufferedReader;
import java.io.InputStreamReader;
import java.util.HashMap;
import java.util.Map;
import net.sourceforge.kitteh.DocumentProducer;
import net.sourceforge.kitteh.Redirection;
import net.sourceforge.kitteh.Request;
import net.sourceforge.kitteh.Response;
import net.sourceforge.kitteh.WebServer;
import net.sourceforge.kitteh.producers.AuthenticationProducer;
import net.sourceforge.kitteh.producers.DispatcherProducer;
import net.sourceforge.kitteh.producers.FileProducer;
import examples.pages.Another;
import examples.pages.Welcome;
/**
* An example showing some features of Kitteh
*
*/
public class Main
{
public static void main(String[] args) throws Exception
{
Map<String, Object> rules = new HashMap<String, Object>();
rules.put("", new Welcome());
rules.put("another\\.html", "examples.pages.Another");
rules.put("slow\\.html", "examples.pages.Slow");
rules.put("pages/(.*)", "examples.pages.dispatch.$1");
rules.put("secret/(.*)", new AuthenticationProducer(new Another(), "myuser", "mypass", "Top Secret Area"));
rules.put("breakme", new DocumentProducer()
{
public void produceDocument(Request request, Response response) throws Exception, Redirection
{
throw new Exception("You broke Kitteh!");
}
});
DocumentProducer f = new FileProducer("www");
DocumentProducer d = new DispatcherProducer(rules, f);
WebServer w = new WebServer(d,8080);
w.runAsThread();
System.out.println("Server started!");
System.out.println("Press ENTER to quit.");
BufferedReader r = new BufferedReader(new InputStreamReader( System.in ));
r.readLine();
w.close();
System.out.println("Quitting");
}
}