Package org.webbitserver

Examples of org.webbitserver.WebServer


    public static void main(String[] args) throws Exception {
        ExecutorService webThread = newSingleThreadExecutor();
        final Pusher pusher = new Pusher();

        WebServer webServer = createWebServer(webThread, 9876)
                .add("/events", new EventSourceHandler() {
                    @Override
                    public void onOpen(EventSourceConnection connection) throws Exception {
                        pusher.addConnection(connection);
                    }

                    @Override
                    public void onClose(EventSourceConnection connection) throws Exception {
                        pusher.removeConnection(connection);
                    }
                })
                .add(new EmbeddedResourceHandler("samples/eventsource/content"))
                .start()
                .get();

        System.out.println("EventSource demo running on: " + webServer.getUri());

        pusher.pushPeriodicallyOn(webThread);
    }
View Full Code Here


public class FlashPolicyFileTest {

    @Test
    public void returnsCrossDomainXML() throws IOException, InterruptedException, ExecutionException {
        WebServer webServer = createWebServer(59504).add(new StringHttpHandler("text/plain", "body")).start().get();

        try {
            Socket client = new Socket(InetAddress.getLocalHost(), 59504);
            OutputStream out = client.getOutputStream();
            out.write(("<policy-file-request/>\0").getBytes("ASCII"));
            out.flush();
            InputStream in = client.getInputStream();
            String result = convertStreamToString(in);
            client.close();

            assertEquals(getPolicyFile("59504"), result);

        } finally {
            webServer.stop().get();
        }
    }
View Full Code Here

        Executor executor = Executors.newSingleThreadScheduledExecutor();
        InetSocketAddress address = new InetSocketAddress(59504);
        URI publicUri = URI.create("http://localhost:800/");

        WebServer webServer = createWebServer(executor, address, publicUri).add(new StringHttpHandler("text/plain", "body")).start().get();
        try {

            Socket client = new Socket(InetAddress.getLocalHost(), 59504);
            OutputStream out = client.getOutputStream();
            out.write(("<policy-file-request/>\0").getBytes("ASCII"));
            out.flush();
            InputStream in = client.getInputStream();
            String result = convertStreamToString(in);
            client.close();

            assertEquals(getPolicyFile("800"), result);

        } finally {
            webServer.stop().get();
        }
    }
View Full Code Here

        Executor executor = Executors.newSingleThreadScheduledExecutor();
        InetSocketAddress address = new InetSocketAddress(59504);
        URI publicUri = URI.create("http://localhost/");

        WebServer webServer = createWebServer(executor, address, publicUri).add(new StringHttpHandler("text/plain", "body")).start().get();
        try {

            Socket client = new Socket(InetAddress.getLocalHost(), 59504);
            OutputStream out = client.getOutputStream();
            out.write(("<policy-file-request/>\0").getBytes("ASCII"));
            out.flush();
            InputStream in = client.getInputStream();
            String result = convertStreamToString(in);
            client.close();

            assertEquals(getPolicyFile("80"), result);

        } finally {
            webServer.stop().get();
        }
    }
View Full Code Here

        Executor executor = Executors.newSingleThreadScheduledExecutor();
        InetSocketAddress address = new InetSocketAddress(59504);
        URI publicUri = URI.create("https://localhost/");

        WebServer webServer = createWebServer(executor, address, publicUri).add(new StringHttpHandler("text/plain", "body")).start().get();
        try {

            Socket client = new Socket(InetAddress.getLocalHost(), 59504);
            OutputStream out = client.getOutputStream();
            out.write(("<policy-file-request/>\0").getBytes("ASCII"));
            out.flush();
            InputStream in = client.getInputStream();
            String result = convertStreamToString(in);
            client.close();

            assertEquals(getPolicyFile("443"), result);

        } finally {
            webServer.stop().get();
        }
    }
View Full Code Here

* With Chrome, the request for the audio file uses a Range header
*/
public class AudioTagUsesRangesExample {

    public static void main(String[] args) throws IOException, ExecutionException, InterruptedException {
        WebServer webServer = createWebServer(45453)
                .add(new StaticFileHandler("src/test/java/samples/ranges/content"))
                .start().get();

        System.out.println("Running on " + webServer.getUri());
    }
View Full Code Here

        writeFile("index.html", "Hello world");
        writeFile("foo.js", "some js");
        mkdir("some/dir");
        writeFile("some/dir/content1.txt", "some txt");

        WebServer webServer = createWebServer(59504)
                .add(handler)
                .start()
                .get();
        try {
            assertEquals("Hello world", contents(httpGet(webServer, "/index.html")));
            assertEquals("some js", contents(httpGet(webServer, "/foo.js?xx=y")));
            assertEquals("some txt", contents(httpGet(webServer, "/some/dir/content1.txt")));
        } finally {
            webServer.stop().get();
        }
    }
View Full Code Here

public class SslTest {

    @Test
    public void setsSecureHttpsServerHeader() throws Exception {
        InputStream keystore = getClass().getResourceAsStream("/ssl/keystore");
        WebServer webServer = createWebServer(10443)
                .setupSsl(keystore, "webbit")
                .add(new ServerHeaderHandler("My Server"))
                .add(new StringHttpHandler("text/plain", "body"));

        keystore.close();
        webServer.start();

        try {
            HttpsURLConnection urlConnection = httpsGet(webServer, "/");
            assertEquals("My Server", urlConnection.getHeaderField("Server"));
            assertEquals("body", contents(urlConnection));
        } finally {
            webServer.stop().get();
        }
    }
View Full Code Here

import static org.webbitserver.WebServers.createWebServer;

public class Main {

    public static void main(String[] args) throws Exception {
        WebServer webServer = createWebServer(9876)
                .add(new LoggingHandler(new SimpleLogSink(Chatroom.USERNAME_KEY)))
                .add("/chatsocket", new Chatroom())
                .add(new StaticFileHandler("./src/test/java/samples/chatroom/content"))
                .start().get();

        System.out.println("Chat room running on: " + webServer.getUri());
    }
View Full Code Here

public class AsyncPasswordsExample {

    static Executor backgroundAuthenticatorThread = Executors.newSingleThreadExecutor();

    public static void main(String[] args) throws ExecutionException, InterruptedException {
        WebServer webServer = createWebServer(45454)
                .add(new BasicAuthenticationHandler(new SlowPasswordAuthenticator()))
                .add("/whoami", new WhoAmIHttpHandler())
                .add("/whoami-ws", new WhoAmIWebSocketHandler())
                .add(new StaticFileHandler("src/test/java/samples/authentication/content"))
                .start()
                .get();

        System.out.println("Running on " + webServer.getUri());
    }
View Full Code Here

TOP

Related Classes of org.webbitserver.WebServer

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.