Package com.sun.net.httpserver

Examples of com.sun.net.httpserver.HttpExchange


    private HttpExchange prepareExchange(String pUri) throws URISyntaxException {
        return prepareExchange(pUri,"Origin",null);
    }

    private HttpExchange prepareExchange(String pUri,String ... pHeaders) throws URISyntaxException {
        HttpExchange exchange = EasyMock.createMock(HttpExchange.class);
        URI uri = new URI(pUri);
        expect(exchange.getRequestURI()).andReturn(uri);
        expect(exchange.getRemoteAddress()).andReturn(new InetSocketAddress(8080));
        Headers headers = new Headers();
        expect(exchange.getRequestHeaders()).andReturn(headers).anyTimes();
        for (int i = 0; i < pHeaders.length; i += 2) {
            headers.set(pHeaders[i], pHeaders[i + 1]);
        }
        return exchange;
    }
View Full Code Here


     * Test of handle method, of class HTTPHandler.
     */
    @Test
    public void testHandle() throws Exception {
        System.out.println("handle");
        HttpExchange he = null;
        HTTPHandler instance = new HTTPHandler();
        instance.handle(he);
    }
View Full Code Here

        // Let's watch out for pledges from the server.
        ObservableSet<LHProtos.Pledge> pledges = backend.mirrorOpenPledges(project1, gate);

        // HTTP request was made to server to learn about existing pledges.
        gate.waitAndRun();
        HttpExchange exchange = httpReqs.take();
        sendServerStatus(exchange, scrubbedPledge);

        // We got a pledge list update relayed into our thread.
        pledges.addListener((SetChangeListener<LHProtos.Pledge>) c -> {
            assertTrue(c.wasAdded());
View Full Code Here

        assertNotNull(statuses.get(project));
        assertTrue(statuses.get(project).inProgress);
        assertNull(statuses.get(project).error);
        // Doing request to server.
        gate.waitAndRun();
        HttpExchange exchange = httpReqs.take();
        exchange.sendResponseHeaders(404, -1);   // not found!
        gate.waitAndRun();
        // Error shows up in map.
        assertEquals(1, statuses.size());
        assertFalse(statuses.get(project).inProgress);
        final Throwable error = statuses.get(project).error;
View Full Code Here

        ObservableSet<LHProtos.Pledge> openPledges = backend.mirrorOpenPledges(project, gate);
        final LHProtos.Pledge scrubbedPledge = makeScrubbedPledge();
        writeProjectToDisk();
        gate.waitAndRun();
        // Is now loaded from disk and doing request to server.
        HttpExchange exchange = httpReqs.take();
        sendServerStatus(exchange, scrubbedPledge);
        gate.waitAndRun();
        assertEquals(1, openPledges.size());
        // Pledge gets revoked.
        backend.refreshProjectStatusFromServer(project);
View Full Code Here

TOP

Related Classes of com.sun.net.httpserver.HttpExchange

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.