use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class HttpOnly method startHttpServer.
// HTTP Server
HttpServer startHttpServer() throws IOException {
HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
httpServer.createContext(URI_PATH, new SimpleHandler());
httpServer.start();
return httpServer;
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class HttpStreams method startHttpServer.
// HTTP Server
HttpServer startHttpServer() throws IOException {
HttpServer httpServer = HttpServer.create(new InetSocketAddress(0), 0);
httpServer.createContext("/chunked/", new ChunkedHandler());
httpServer.createContext("/fixed/", new FixedHandler());
httpServer.createContext("/error/", new ErrorHandler());
httpServer.createContext("/chunkedError/", new ChunkedErrorHandler());
httpServer.start();
return httpServer;
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class NoCache method main.
public static void main(String[] args) throws IOException {
ResponseCache.setDefault(new ThrowingCache());
HttpServer server = startHttpServer();
try {
URL url = new URL("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + server.getAddress().getPort() + "/NoCache/");
URLConnection uc = url.openConnection();
uc.setUseCaches(false);
uc.getInputStream().close();
} finally {
server.stop(0);
// clear the system-wide cache handler, samevm/agentvm mode
ResponseCache.setDefault(null);
}
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class SecurityPolicy method main.
public static void main(String[] args) throws Exception {
KDC kdcw = KDC.create(REALM_WEB);
kdcw.addPrincipal(WEB_USER, WEB_PASS);
kdcw.addPrincipalRandKey("krbtgt/" + REALM_WEB);
kdcw.addPrincipalRandKey("HTTP/" + WEB_HOST);
KDC kdcp = KDC.create(REALM_PROXY);
kdcp.addPrincipal(PROXY_USER, PROXY_PASS);
kdcp.addPrincipalRandKey("krbtgt/" + REALM_PROXY);
kdcp.addPrincipalRandKey("HTTP/" + PROXY_HOST);
KDC.saveConfig(KRB5_CONF, kdcw, kdcp, "default_keytab_name = " + KRB5_TAB, "[domain_realm]", "", ".web.domain=" + REALM_WEB, ".proxy.domain=" + REALM_PROXY);
System.setProperty("java.security.krb5.conf", KRB5_CONF);
Config.refresh();
KDC.writeMultiKtab(KRB5_TAB, kdcw, kdcp);
// Write a customized JAAS conf file, so that any kinit cache
// will be ignored.
System.setProperty("java.security.auth.login.config", OneKDC.JAAS_CONF);
File f = new File(OneKDC.JAAS_CONF);
FileOutputStream fos = new FileOutputStream(f);
fos.write(("com.sun.security.jgss.krb5.initiate {\n" + " com.sun.security.auth.module.Krb5LoginModule required;\n};\n").getBytes());
fos.close();
HttpServer h1 = httpd("Negotiate", false, "HTTP/" + WEB_HOST + "@" + REALM_WEB, KRB5_TAB);
webPort = h1.getAddress().getPort();
HttpServer h2 = httpd("Negotiate", true, "HTTP/" + PROXY_HOST + "@" + REALM_PROXY, KRB5_TAB);
proxyPort = h2.getAddress().getPort();
webUrl = new URL("http://" + WEB_HOST + ":" + webPort + "/a/b/c");
proxyUrl = new URL("http://nosuchplace/a/b/c");
try {
Exception e1 = null, e2 = null, e3 = null;
try {
test6578647();
} catch (Exception e) {
e1 = e;
e.printStackTrace();
}
try {
test6829283();
} catch (Exception e) {
e2 = e;
e.printStackTrace();
}
try {
test8077155();
} catch (Exception e) {
e3 = e;
e.printStackTrace();
}
if (e1 != null || e2 != null || e3 != null) {
throw new RuntimeException("Test error");
}
} finally {
// Must stop. Seems there's no HttpServer.startAsDaemon()
if (h1 != null)
h1.stop(0);
if (h2 != null)
h2.stop(0);
}
}
use of com.sun.net.httpserver.HttpServer in project jdk8u_jdk by JetBrains.
the class HttpOnly method test.
void test(String[] args) throws Exception {
HttpServer server = startHttpServer();
CookieHandler previousHandler = CookieHandler.getDefault();
try {
InetSocketAddress address = server.getAddress();
URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress() + ":" + address.getPort() + URI_PATH);
populateCookieStore(uri);
doClient(uri);
} finally {
CookieHandler.setDefault(previousHandler);
server.stop(0);
}
}
Aggregations