static SSLContext ctx;
static boolean error = false;
public static void main (String[] args) throws Exception {
HttpServer s1 = null;
HttpsServer s2 = null;
ExecutorService executor=null;
try {
String root = System.getProperty ("test.src")+ "/docs";
System.out.print ("Test9: ");
InetSocketAddress addr = new InetSocketAddress (0);
s1 = HttpServer.create (addr, 0);
s2 = HttpsServer.create (addr, 0);
HttpHandler h = new FileServerHandler (root);
HttpContext c1 = s1.createContext ("/test1", h);
HttpContext c2 = s2.createContext ("/test1", h);
executor = Executors.newCachedThreadPool();
s1.setExecutor (executor);
s2.setExecutor (executor);
ctx = new SimpleSSLContext(System.getProperty("test.src")).get();
s2.setHttpsConfigurator(new HttpsConfigurator (ctx));
s1.start();
s2.start();
int p1 = s1.getAddress().getPort();
int p2 = s2.getAddress().getPort();
error = false;
Thread[] t = new Thread[100];
t[0] = test (true, "http", root+"/test1", p1, "smallfile.txt", 23);
t[1] = test (true, "http", root+"/test1", p1, "largefile.txt", 2730088);
t[2] = test (true, "https", root+"/test1", p2, "smallfile.txt", 23);
t[3] = test (true, "https", root+"/test1", p2, "largefile.txt", 2730088);
t[4] = test (false, "http", root+"/test1", p1, "smallfile.txt", 23);
t[5] = test (false, "http", root+"/test1", p1, "largefile.txt", 2730088);
t[6] = test (false, "https", root+"/test1", p2, "smallfile.txt", 23);
t[7] = test (false, "https", root+"/test1", p2, "largefile.txt", 2730088);
t[8] = test (true, "http", root+"/test1", p1, "smallfile.txt", 23);
t[9] = test (true, "http", root+"/test1", p1, "largefile.txt", 2730088);
t[10] = test (true, "https", root+"/test1", p2, "smallfile.txt", 23);
t[11] = test (true, "https", root+"/test1", p2, "largefile.txt", 2730088);
t[12] = test (false, "http", root+"/test1", p1, "smallfile.txt", 23);
t[13] = test (false, "http", root+"/test1", p1, "largefile.txt", 2730088);
t[14] = test (false, "https", root+"/test1", p2, "smallfile.txt", 23);
t[15] = test (false, "https", root+"/test1", p2, "largefile.txt", 2730088);
for (int i=0; i<16; i++) {
t[i].join();
}
if (error) {
throw new RuntimeException ("error");
}
System.out.println ("OK");
} finally {
delay();
if (s1 != null)
s1.stop(2);
if (s2 != null)
s2.stop(2);
if (executor != null)
executor.shutdown ();
}