try {
server = HttpServer.create(addr, 0);
} catch (IOException ioe) { thrownew RuntimeException("Server could not be created");
}
executor = Executors.newFixedThreadPool(10);
server.setExecutor(executor);
server.createContext("/test/realm1/t1a", new AuthenticationHandlerT1a() );
server.createContext("/test/realm2/t1b", new AuthenticationHandlerT1b());
server.createContext("/test/realm1/t1c", new AuthenticationHandlerT1c());
server.createContext("/test/realm2/t1d", new AuthenticationHandlerT1d());
server.createContext("/test/realm3/t2a", new AuthenticationHandlerT2a());
server.createContext("/test/realm3/t2b", new AuthenticationHandlerT2b());
server.createContext("/test/realm4/t3a", new AuthenticationHandlerT3a());
server.createContext("/test/realm4/t3b", new AuthenticationHandlerT3bc());
server.createContext("/test/realm4/t3c", new AuthenticationHandlerT3bc());
t1Cond1 = new CyclicBarrier(3);
server.start();
}
/* T3 tests proxy and server authentication. three threads request same *resourceatsametime.Authenticatorshouldbecalledonceforserver *andonceforproxy
*/
class AuthenticationHandlerT3a implements HttpHandler
{ volatileint count = -1;
staticvoid doServerTests (String authority, Server server) throws Exception
{
System.out.println ("Doing Server tests");
System.out.println ("T1");
c1 = new Client (authority, "/test/realm1/t1a", false);
c2 = new Client (authority, "/test/realm2/t1b", false);
c3 = new Client (authority, "/test/realm1/t1c", false);
c4 = new Client (authority, "/test/realm2/t1d", false);
c1.start(); c2.start();
t1Cond1.await();
c3.start(); c4.start();
c1.join(); c2.join(); c3.join(); c4.join();
int f = auth.getCount(); if (f != 2) {
except ("Authenticator was called "+f+" times. Should be 2",
server);
} if (error) {
except ("error occurred", server);
}
auth.resetCount();
System.out.println ("T2");
c5 = new Client (authority, "/test/realm3/t2a", true);
c6 = new Client (authority, "/test/realm3/t2b", false);
t2condlatch = new CountDownLatch(1);
c5.start ();
t2condlatch.await();
c6.start ();
c5.join(); c6.join();
f = auth.getCount(); if (f != redirects+1) {
except ("Authenticator was called "+f+" times. Should be: "
+ redirects+1, server);
} if (error) {
except ("error occurred", server);
}
}
staticvoid doProxyTests (String authority, Server server) throws Exception
{
System.out.println ("Doing Proxy tests");
c7 = new Client (authority, "/test/realm4/t3a", false);
c8 = new Client (authority, "/test/realm4/t3b", false);
c9 = new Client (authority, "/test/realm4/t3c", false);
t3cond1 = new CountDownLatch(1);
c7.start ();
t3cond1.await();
c8.start ();
c9.start ();
c7.join(); c8.join(); c9.join();
int f = auth.getCount(); if (f != 2) {
except ("Authenticator was called "+f+" times. Should be: " + 2,
server);
} if (error) {
except ("error occurred", server);
}
}
publicstaticvoid main (String[] args) throws Exception { new B4769350().runTest(args[0].equals ("proxy"));
}
Die Informationen auf dieser Webseite wurden
nach bestem Wissen sorgfältig zusammengestellt. Es wird jedoch weder Vollständigkeit, noch Richtigkeit,
noch Qualität der bereit gestellten Informationen zugesichert.
Bemerkung:
Die farbliche Syntaxdarstellung und die Messung sind noch experimentell.