Package org.webbitserver

Examples of org.webbitserver.HttpHandler


    public void nextHandler(HttpRequest request, HttpResponse response, HttpControl control) {
        this.defaultRequest = request;
        this.defaultResponse = response;
        this.defaultControl = control;
        if (handlerIterator.hasNext()) {
            HttpHandler handler = handlerIterator.next();
            try {
                handler.handleHttpRequest(request, response, control);
            } catch (Throwable e) {
                response.error(e);
            }
        } else {
            response.status(404).end();
View Full Code Here


    @Test
    @Ignore
    public void stopsServerCleanlyAlsoWhenClientsAreConnected() throws Exception {
        final CountDownLatch stopper = new CountDownLatch(1);
        final WebServer server = new NettyWebServer(Executors.newSingleThreadScheduledExecutor(), 9080).start();
        server.add(new HttpHandler() {
            @Override
            public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
                System.out.println("We got here");
                server.stop().join();
                System.out.println("But never here");
View Full Code Here

        assertEquals("Your cookies: a=b c=\"d e=f", contents(urlConnection));
    }

    @Test
    public void behavesWellWhenThereAreNoInboundCookies() throws IOException {
        webServer.add(new HttpHandler() {
            @Override
            public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
                String body = "Cookie count:" + request.cookies().size();
                response.header("Content-Length", body.length())
                        .content(body)
View Full Code Here

import static org.mockito.Mockito.verifyZeroInteractions;

public class PathMatchHandlerTest {
    @Test
    public void matchesRequestWithFullUri() throws Exception {
        HttpHandler handler = mock(HttpHandler.class);
        PathMatchHandler pmh = new PathMatchHandler("/hello", handler);

        HttpRequest req = new StubHttpRequest("http://host.com:8080/hello");
        HttpResponse res = new StubHttpResponse();
        HttpControl ctl = new StubHttpControl();
View Full Code Here

        verify(handler).handleHttpRequest(req, res, ctl);
    }

    @Test
    public void matchesRequestWithPathOnly() throws Exception {
        HttpHandler handler = mock(HttpHandler.class);
        PathMatchHandler pmh = new PathMatchHandler("/hello", handler);

        HttpRequest req = new StubHttpRequest("/hello");
        HttpResponse res = new StubHttpResponse();
        HttpControl ctl = new StubHttpControl();
View Full Code Here

        verify(handler).handleHttpRequest(req, res, ctl);
    }

    @Test
    public void handsOffWhenNoMatch() throws Exception {
        HttpHandler handler = mock(HttpHandler.class);
        PathMatchHandler pmh = new PathMatchHandler("/hello", handler);

        HttpRequest req = new StubHttpRequest("http://hello.com:8080/wtf");
        HttpResponse res = new StubHttpResponse();
        HttpControl ctl = mock(HttpControl.class);
View Full Code Here

        webServer.stop().join();
    }

    @Test
    public void setsOneOutboundCookie() throws IOException, InterruptedException {
        webServer.add(new HttpHandler() {
            @Override
            public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
                response.cookie(new HttpCookie("a", "b")).end();
            }
        }).start();
View Full Code Here

        assertEquals("b", cookies.get(0).getValue());
    }

    @Test
    public void setsTwoOutboundCookies() throws IOException, InterruptedException {
        webServer.add(new HttpHandler() {
            @Override
            public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
                response.cookie(new HttpCookie("a", "b")).cookie(new HttpCookie("c", "d")).end();
            }
        }).start();
View Full Code Here

        assertEquals("d", cookies.get(1).getValue());
    }

    @Test
    public void parsesOneInboundCookie() throws IOException, InterruptedException {
        webServer.add(new HttpHandler() {
            @Override
            public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
                String body = "Your cookie value: " + request.cookieValue("someName");
                response.header("Content-Length", body.length())
                        .content(body)
View Full Code Here

        assertEquals("Your cookie value: someValue", contents(urlConnection));
    }

    @Test
    public void parsesThreeInboundCookiesInTwoHeaders() throws IOException, InterruptedException {
        webServer.add(new HttpHandler() {
            @Override
            public void handleHttpRequest(HttpRequest request, HttpResponse response, HttpControl control) throws Exception {
                String body = "Your cookies:";
                List<HttpCookie> cookies = sort(request.cookies());
                for (HttpCookie cookie : cookies) {
View Full Code Here

TOP

Related Classes of org.webbitserver.HttpHandler

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.