Search in sources :

Example 41 with HttpServer

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;
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HttpServer(com.sun.net.httpserver.HttpServer)

Example 42 with 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;
}
Also used : HttpServer(com.sun.net.httpserver.HttpServer)

Example 43 with 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);
    }
}
Also used : HttpServer(com.sun.net.httpserver.HttpServer)

Example 44 with HttpServer

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);
    }
}
Also used : FileOutputStream(java.io.FileOutputStream) HttpServer(com.sun.net.httpserver.HttpServer) File(java.io.File) URL(java.net.URL) LoginException(javax.security.auth.login.LoginException) UnsupportedCallbackException(javax.security.auth.callback.UnsupportedCallbackException) IOException(java.io.IOException)

Example 45 with HttpServer

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);
    }
}
Also used : InetSocketAddress(java.net.InetSocketAddress) HttpServer(com.sun.net.httpserver.HttpServer) URI(java.net.URI) CookieHandler(java.net.CookieHandler)

Aggregations

HttpServer (com.sun.net.httpserver.HttpServer)49 InetSocketAddress (java.net.InetSocketAddress)29 HttpHandler (com.sun.net.httpserver.HttpHandler)12 IOException (java.io.IOException)10 Test (org.junit.Test)8 HttpExchange (com.sun.net.httpserver.HttpExchange)7 File (java.io.File)7 HttpContext (com.sun.net.httpserver.HttpContext)6 JarFile (java.util.jar.JarFile)6 MockHttpServer (org.elasticsearch.mocksocket.MockHttpServer)6 URL (java.net.URL)5 BasicAuthenticator (com.sun.net.httpserver.BasicAuthenticator)3 HttpsServer (com.sun.net.httpserver.HttpsServer)3 InputStream (java.io.InputStream)3 ExecutorService (java.util.concurrent.ExecutorService)3 CompilerError (com.redhat.ceylon.compiler.java.test.CompilerError)2 HttpsConfigurator (com.sun.net.httpserver.HttpsConfigurator)2 FileNotFoundException (java.io.FileNotFoundException)2 OutputStream (java.io.OutputStream)2 InvocationTargetException (java.lang.reflect.InvocationTargetException)2