Java Code Examples for com.sun.net.httpserver.HttpServer#getAddress()

The following examples show how to use com.sun.net.httpserver.HttpServer#getAddress() . You can vote up the ones you like or vote down the ones you don't like, and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: HttpOnly.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 2
Source File: InfiniteLoop.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
    server.createContext("/test/InfiniteLoop", new RespHandler());
    server.start();
    try {
        InetSocketAddress address = server.getAddress();
        URL url = new URL("http://localhost:" + address.getPort()
                          + "/test/InfiniteLoop");
        final Phaser phaser = new Phaser(2);
        for (int i=0; i<10; i++) {
            HttpURLConnection uc = (HttpURLConnection)url.openConnection();
            final InputStream is = uc.getInputStream();
            final Thread thread = new Thread() {
                public void run() {
                    try {
                        phaser.arriveAndAwaitAdvance();
                        while (is.read() != -1)
                            Thread.sleep(50);
                    } catch (Exception x) { x.printStackTrace(); }
                }};
            thread.start();
            phaser.arriveAndAwaitAdvance();
            is.close();
            System.out.println("returned from close");
            thread.join();
        }
    } finally {
        server.stop(0);
    }
}
 
Example 3
Source File: InfiniteLoop.java    From openjdk-jdk9 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
    server.createContext("/test/InfiniteLoop", new RespHandler());
    server.start();
    try {
        InetSocketAddress address = server.getAddress();
        URL url = new URL("http://localhost:" + address.getPort()
                          + "/test/InfiniteLoop");
        final Phaser phaser = new Phaser(2);
        for (int i=0; i<10; i++) {
            HttpURLConnection uc = (HttpURLConnection)url.openConnection();
            final InputStream is = uc.getInputStream();
            final Thread thread = new Thread() {
                public void run() {
                    try {
                        phaser.arriveAndAwaitAdvance();
                        while (is.read() != -1)
                            Thread.sleep(50);
                    } catch (Exception x) { x.printStackTrace(); }
                }};
            thread.start();
            phaser.arriveAndAwaitAdvance();
            is.close();
            System.out.println("returned from close");
            thread.join();
        }
    } finally {
        server.stop(0);
    }
}
 
Example 4
Source File: HttpOnly.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 5
Source File: InfiniteLoop.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
    server.createContext("/test/InfiniteLoop", new RespHandler());
    server.start();
    try {
        InetSocketAddress address = server.getAddress();
        URL url = new URL("http://localhost:" + address.getPort()
                          + "/test/InfiniteLoop");
        final Phaser phaser = new Phaser(2);
        for (int i=0; i<10; i++) {
            HttpURLConnection uc = (HttpURLConnection)url.openConnection();
            final InputStream is = uc.getInputStream();
            final Thread thread = new Thread() {
                public void run() {
                    try {
                        phaser.arriveAndAwaitAdvance();
                        while (is.read() != -1)
                            Thread.sleep(50);
                    } catch (Exception x) { x.printStackTrace(); }
                }};
            thread.start();
            phaser.arriveAndAwaitAdvance();
            is.close();
            System.out.println("returned from close");
            thread.join();
        }
    } finally {
        server.stop(0);
    }
}
 
Example 6
Source File: UnmodifiableMaps.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void test(String[] args) throws Exception {
    HttpServer server = startHttpServer();
    try {
        InetSocketAddress address = server.getAddress();
        URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress()
                          + ":" + address.getPort() + "/foo");
        doClient(uri);
    } finally {
        server.stop(0);
    }
}
 
Example 7
Source File: HttpOnly.java    From hottub with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 8
Source File: HttpOnly.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 9
Source File: UnmodifiableMaps.java    From openjdk-jdk8u-backup with GNU General Public License v2.0 5 votes vote down vote up
void test(String[] args) throws Exception {
    HttpServer server = startHttpServer();
    try {
        InetSocketAddress address = server.getAddress();
        URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress()
                          + ":" + address.getPort() + "/foo");
        doClient(uri);
    } finally {
        server.stop(0);
    }
}
 
Example 10
Source File: HttpOnly.java    From jdk8u_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 11
Source File: UnmodifiableMaps.java    From jdk8u-jdk with GNU General Public License v2.0 5 votes vote down vote up
void test(String[] args) throws Exception {
    HttpServer server = startHttpServer();
    try {
        InetSocketAddress address = server.getAddress();
        URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress()
                          + ":" + address.getPort() + "/foo");
        doClient(uri);
    } finally {
        server.stop(0);
    }
}
 
Example 12
Source File: UnmodifiableMaps.java    From openjdk-jdk8u with GNU General Public License v2.0 5 votes vote down vote up
void test(String[] args) throws Exception {
    HttpServer server = startHttpServer();
    try {
        InetSocketAddress address = server.getAddress();
        URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress()
                          + ":" + address.getPort() + "/foo");
        doClient(uri);
    } finally {
        server.stop(0);
    }
}
 
Example 13
Source File: InfiniteLoop.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
    server.createContext("/test/InfiniteLoop", new RespHandler());
    server.start();
    try {
        InetSocketAddress address = server.getAddress();
        URL url = new URL("http://localhost:" + address.getPort()
                          + "/test/InfiniteLoop");
        final Phaser phaser = new Phaser(2);
        for (int i=0; i<10; i++) {
            HttpURLConnection uc = (HttpURLConnection)url.openConnection();
            final InputStream is = uc.getInputStream();
            final Thread thread = new Thread() {
                public void run() {
                    try {
                        phaser.arriveAndAwaitAdvance();
                        while (is.read() != -1)
                            Thread.sleep(50);
                    } catch (Exception x) { x.printStackTrace(); }
                }};
            thread.start();
            phaser.arriveAndAwaitAdvance();
            is.close();
            System.out.println("returned from close");
            thread.join();
        }
    } finally {
        server.stop(0);
    }
}
 
Example 14
Source File: HttpOnly.java    From jdk8u60 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 15
Source File: InfiniteLoop.java    From openjdk-8 with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
    server.createContext("/test/InfiniteLoop", new RespHandler());
    server.start();
    try {
        InetSocketAddress address = server.getAddress();
        URL url = new URL("http://localhost:" + address.getPort()
                          + "/test/InfiniteLoop");
        final Phaser phaser = new Phaser(2);
        for (int i=0; i<10; i++) {
            HttpURLConnection uc = (HttpURLConnection)url.openConnection();
            final InputStream is = uc.getInputStream();
            final Thread thread = new Thread() {
                public void run() {
                    try {
                        phaser.arriveAndAwaitAdvance();
                        while (is.read() != -1)
                            Thread.sleep(50);
                    } catch (Exception x) { x.printStackTrace(); }
                }};
            thread.start();
            phaser.arriveAndAwaitAdvance();
            is.close();
            System.out.println("returned from close");
            thread.join();
        }
    } finally {
        server.stop(0);
    }
}
 
Example 16
Source File: InfiniteLoop.java    From openjdk-8-source with GNU General Public License v2.0 5 votes vote down vote up
public static void main(String[] args) throws Exception {
    HttpServer server = HttpServer.create(new InetSocketAddress(0), 0);
    server.createContext("/test/InfiniteLoop", new RespHandler());
    server.start();
    try {
        InetSocketAddress address = server.getAddress();
        URL url = new URL("http://localhost:" + address.getPort()
                          + "/test/InfiniteLoop");
        final Phaser phaser = new Phaser(2);
        for (int i=0; i<10; i++) {
            HttpURLConnection uc = (HttpURLConnection)url.openConnection();
            final InputStream is = uc.getInputStream();
            final Thread thread = new Thread() {
                public void run() {
                    try {
                        phaser.arriveAndAwaitAdvance();
                        while (is.read() != -1)
                            Thread.sleep(50);
                    } catch (Exception x) { x.printStackTrace(); }
                }};
            thread.start();
            phaser.arriveAndAwaitAdvance();
            is.close();
            System.out.println("returned from close");
            thread.join();
        }
    } finally {
        server.stop(0);
    }
}
 
Example 17
Source File: HttpOnly.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 18
Source File: UnmodifiableMaps.java    From TencentKona-8 with GNU General Public License v2.0 5 votes vote down vote up
void test(String[] args) throws Exception {
    HttpServer server = startHttpServer();
    try {
        InetSocketAddress address = server.getAddress();
        URI uri = new URI("http://" + InetAddress.getLocalHost().getHostAddress()
                          + ":" + address.getPort() + "/foo");
        doClient(uri);
    } finally {
        server.stop(0);
    }
}
 
Example 19
Source File: HttpOnly.java    From jdk8u-dev-jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}
 
Example 20
Source File: HttpOnly.java    From dragonwell8_jdk with GNU General Public License v2.0 5 votes vote down vote up
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);
    }
}