Package org.jboss.com.sun.net.httpserver

Examples of org.jboss.com.sun.net.httpserver.HttpsServer


    static SSLContext ctx;

    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 ("Test1: ");
            InetSocketAddress addr = new InetSocketAddress (0);
            s1 = HttpServer.create (addr, 0);
            if (s1 instanceof HttpsServer) {
                throw new RuntimeException ("should not be httpsserver");
            }
            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 port = s1.getAddress().getPort();
            int httpsport = s2.getAddress().getPort();
            test (true, "http", root+"/test1", port, "smallfile.txt", 23);
            test (true, "http", root+"/test1", port, "largefile.txt", 2730088);
            test (true, "https", root+"/test1", httpsport, "smallfile.txt", 23);
            test (true, "https", root+"/test1", httpsport, "largefile.txt", 2730088);
            test (false, "http", root+"/test1", port, "smallfile.txt", 23);
            test (false, "http", root+"/test1", port, "largefile.txt", 2730088);
            test (false, "https", root+"/test1", httpsport, "smallfile.txt", 23);
            test (false, "https", root+"/test1", httpsport, "largefile.txt", 2730088);
            System.out.println ("OK");
        } finally {
            delay();
            if (s1 != null)
                s1.stop(2);
            if (s2 != null)
                s2.stop(2);
            if (executor != null)
                executor.shutdown ();
        }
    }
View Full Code Here


    static SSLContext serverCtx, clientCtx;
    static boolean error = false;

    public static void main (String[] args) throws Exception {
        HttpsServer server = null;
        ExecutorService executor=null;
        try {
            String root = System.getProperty ("test.src")+ "/docs";
            System.out.print ("Test9a: ");
            InetSocketAddress addr = new InetSocketAddress (0);
            server = HttpsServer.create (addr, 0);
            HttpHandler h = new FileServerHandler (root);
            HttpContext c1 = server.createContext ("/test1", h);
            executor = Executors.newCachedThreadPool();
            server.setExecutor (executor);
            serverCtx = new SimpleSSLContext(System.getProperty("test.src")).get();
            clientCtx = new SimpleSSLContext(System.getProperty("test.src")).get();
            server.setHttpsConfigurator(new HttpsConfigurator (serverCtx));
            server.start();

            int port = server.getAddress().getPort();
            error = false;
            Thread[] t = new Thread[100];

            t[0] = test (true, "https", root+"/test1", port, "smallfile.txt", 23);
            t[1] = test (true, "https", root+"/test1", port, "largefile.txt", 2730088);
            t[2] = test (true, "https", root+"/test1", port, "smallfile.txt", 23);
            t[3] = test (true, "https", root+"/test1", port, "largefile.txt", 2730088);
            t[4] = test (true, "https", root+"/test1", port, "smallfile.txt", 23);
            t[5] = test (true, "https", root+"/test1", port, "largefile.txt", 2730088);
            t[6] = test (true, "https", root+"/test1", port, "smallfile.txt", 23);
            t[7] = test (true, "https", root+"/test1", port, "largefile.txt", 2730088);
            t[8] = test (true, "https", root+"/test1", port, "smallfile.txt", 23);
            t[9] = test (true, "https", root+"/test1", port, "largefile.txt", 2730088);
            t[10] = test (true, "https", root+"/test1", port, "smallfile.txt", 23);
            t[11] = test (true, "https", root+"/test1", port, "largefile.txt", 2730088);
            t[12] = test (true, "https", root+"/test1", port, "smallfile.txt", 23);
            t[13] = test (true, "https", root+"/test1", port, "largefile.txt", 2730088);
            t[14] = test (true, "https", root+"/test1", port, "smallfile.txt", 23);
            t[15] = test (true, "https", root+"/test1", port, "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 (server != null)
                server.stop(2);
            if (executor != null)
                executor.shutdown();
        }
    }
View Full Code Here

    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 ();
        }
    }
View Full Code Here

    static boolean fail = false;

    public static void main (String[] args) throws Exception {
        HttpServer s1 = null;
        HttpsServer s2 = null;
        ExecutorService executor=null;
        Logger l = Logger.getLogger ("com.sun.net.httpserver");
        Handler ha = new ConsoleHandler();
        ha.setLevel(Level.ALL);
        l.setLevel(Level.ALL);
        l.addHandler(ha);
        try {
            String root = System.getProperty ("test.src")+ "/docs";
            System.out.print ("Test13: ");
            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 port = s1.getAddress().getPort();
            int httpsport = s2.getAddress().getPort();
            Runner r[] = new Runner[NUM*2];
            for (int i=0; i<NUM; i++) {
                r[i] = new Runner (true, "http", root+"/test1", port, "smallfile.txt", 23);
                r[i+NUM] = new Runner (true, "https", root+"/test1", httpsport, "smallfile.txt", 23);
            }
            start (r);
            join (r);
            System.out.println ("OK");
        } finally {
            delay();
            if (s1 != null)
                s1.stop(2);
            if (s2 != null)
                s2.stop(2);
            if (executor != null)
                executor.shutdown ();
        }
    }
View Full Code Here

        //Logger log = Logger.getLogger ("com.sun.net.httpserver");
        //ConsoleHandler h = new ConsoleHandler();
        //h.setLevel (Level.INFO);
        //log.addHandler (h);
        //log.setLevel (Level.INFO);
        HttpsServer server = null;
        ExecutorService executor = null;
        try {
            Handler handler = new Handler();
            InetSocketAddress addr = new InetSocketAddress (0);
            server = HttpsServer.create (addr, 0);
            HttpContext ctx = server.createContext ("/test", handler);
            executor = Executors.newCachedThreadPool();
            SSLContext ssl = new SimpleSSLContext(System.getProperty("test.src")).get();
            server.setHttpsConfigurator(new HttpsConfigurator (ssl));
            server.setExecutor (executor);
            server.start ();

            URL url = new URL ("https://localhost:"+server.getAddress().getPort()+"/test/foo.html");
            System.out.print ("Test8a: " );
            HttpsURLConnection urlc = (HttpsURLConnection)url.openConnection ();
            urlc.setDoOutput (true);
            urlc.setRequestMethod ("POST");
            urlc.setHostnameVerifier (new DummyVerifier());
            urlc.setSSLSocketFactory (ssl.getSocketFactory());
            OutputStream os = new BufferedOutputStream (urlc.getOutputStream(), 8000);
            for (int i=0; i<SIZE; i++) {
                os.write (i % 250);
            }
            os.close();
            int resp = urlc.getResponseCode();
            if (resp != 200) {
                throw new RuntimeException ("test failed response code");
            }
            InputStream is = urlc.getInputStream ();
            for (int i=0; i<SIZE; i++) {
                int f = is.read();
                if (f != (i % 250)) {
                    System.out.println ("Setting error(" +f +")("+i+")" );
                    error = true;
                    break;
                }
            }
            is.close();
        } finally {
            delay();
            if (server != null) server.stop(2);
            if (executor != null) executor.shutdown();
        }
        if (error) {
            throw new RuntimeException ("test failed error");
        }
View Full Code Here

TOP

Related Classes of org.jboss.com.sun.net.httpserver.HttpsServer

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.