Example usage for org.apache.http.nio.protocol BasicAsyncRequestHandler BasicAsyncRequestHandler

List of usage examples for org.apache.http.nio.protocol BasicAsyncRequestHandler BasicAsyncRequestHandler

Introduction

In this page you can find the example usage for org.apache.http.nio.protocol BasicAsyncRequestHandler BasicAsyncRequestHandler.

Prototype

public BasicAsyncRequestHandler(final HttpRequestHandler handler) 

Source Link

Usage

From source file:com.aptana.webserver.internal.core.builtin.LocalWebServer.java

private void startServer(final InetAddress host, final int port) {
    updateState(State.STARTING);//from w  w  w.  j  a v a2s . c  o  m
    thread = new Thread() {
        @Override
        public void run() {
            runServer(new InetSocketAddress(host, port),
                    new BasicAsyncRequestHandler(new LocalWebServerHttpRequestHandler(LocalWebServer.this)));
        }
    };
    thread.setDaemon(true);
    thread.start();
    Thread.yield();
    long startTime = System.currentTimeMillis();
    while (thread.isAlive() && (System.currentTimeMillis() - startTime) < STARTUP_TIMEOUT) {
        if (reactor != null && reactor.getStatus() == IOReactorStatus.ACTIVE) {
            updateState(State.STARTED);
            break;
        }
        try {
            Thread.sleep(10);
        } catch (InterruptedException e) {
            updateState(State.UNKNOWN);
            break;
        }
    }
}

From source file:org.apache.http.nio.client.methods.TestZeroCopy.java

@Test
public void testTwoWayZeroCopy() throws Exception {
    this.serverBootstrap.registerHandler("*", new BasicAsyncRequestHandler(new TestHandler(false)));
    final HttpHost target = start();

    final File tmpdir = FileUtils.getTempDirectory();
    this.tmpfile = new File(tmpdir, "dst.test");
    final TestZeroCopyPost httppost = new TestZeroCopyPost(target.toURI() + "/bounce", false);
    final TestZeroCopyConsumer consumer = new TestZeroCopyConsumer(this.tmpfile);
    final Future<Integer> future = this.httpclient.execute(httppost, consumer, null);
    final Integer status = future.get();
    Assert.assertNotNull(status);//from w ww .j  a  va 2s  .  c o m
    Assert.assertEquals(HttpStatus.SC_OK, status.intValue());
    final InputStream instream = new FileInputStream(this.tmpfile);
    try {
        final LineIterator it = IOUtils.lineIterator(instream, ASCII.name());
        int count = 0;
        while (it.hasNext()) {
            final String line = it.next();
            final int i = count % TEXT.length;
            final String expected = TEXT[i];
            Assert.assertEquals(expected, line);
            count++;
        }
    } finally {
        instream.close();
    }
}

From source file:org.apache.http.nio.client.methods.TestZeroCopy.java

@Test
public void testZeroCopyFallback() throws Exception {
    this.serverBootstrap.registerHandler("*", new BasicAsyncRequestHandler(new TestHandler(true)));
    final HttpHost target = start();
    final File tmpdir = FileUtils.getTempDirectory();
    this.tmpfile = new File(tmpdir, "dst.test");
    final TestZeroCopyPost httppost = new TestZeroCopyPost(target.toURI() + "/bounce", true);
    final TestZeroCopyConsumer consumer = new TestZeroCopyConsumer(this.tmpfile);
    final Future<Integer> future = this.httpclient.execute(httppost, consumer, null);
    final Integer status = future.get();
    Assert.assertNotNull(status);/*from   www.  j a  v  a  2 s.  c o m*/
    Assert.assertEquals(HttpStatus.SC_OK, status.intValue());
    final InputStream instream = new FileInputStream(this.tmpfile);
    try {
        final LineIterator it = IOUtils.lineIterator(instream, ASCII.name());
        int count = 0;
        while (it.hasNext()) {
            final String line = it.next();
            final int i = count % TEXT.length;
            final String expected = TEXT[i];
            Assert.assertEquals(expected, line);
            count++;
        }
    } finally {
        instream.close();
    }
}