Search in sources :

Example 1 with BasicAsyncRequestHandler

use of org.apache.http.nio.protocol.BasicAsyncRequestHandler in project metrics by dropwizard.

the class HttpClientTestBase method startServerWithGlobalRequestHandler.

/**
 * Start a local server that uses the {@code handler} to handle requests.
 * <p>
 * The server will be (if started) terminated in the {@link #tearDown()} {@link After} method.
 *
 * @param handler The request handler that will be used to respond to every request.
 * @return The {@link HttpHost} of the server
 * @throws IOException          in case it's not possible to start the server
 * @throws InterruptedException in case the server's main thread was interrupted
 */
public HttpHost startServerWithGlobalRequestHandler(HttpRequestHandler handler) throws IOException, InterruptedException {
    // If there is an existing instance, terminate it
    tearDown();
    ServerBootstrap serverBootstrap = ServerBootstrap.bootstrap();
    serverBootstrap.registerHandler("/*", new BasicAsyncRequestHandler(handler));
    server = serverBootstrap.create();
    server.start();
    ListenerEndpoint endpoint = server.getEndpoint();
    endpoint.waitFor();
    InetSocketAddress address = (InetSocketAddress) endpoint.getAddress();
    return new HttpHost("localhost", address.getPort(), "http");
}
Also used : ListenerEndpoint(org.apache.http.nio.reactor.ListenerEndpoint) InetSocketAddress(java.net.InetSocketAddress) HttpHost(org.apache.http.HttpHost) BasicAsyncRequestHandler(org.apache.http.nio.protocol.BasicAsyncRequestHandler) ServerBootstrap(org.apache.http.impl.nio.bootstrap.ServerBootstrap)

Aggregations

InetSocketAddress (java.net.InetSocketAddress)1 HttpHost (org.apache.http.HttpHost)1 ServerBootstrap (org.apache.http.impl.nio.bootstrap.ServerBootstrap)1 BasicAsyncRequestHandler (org.apache.http.nio.protocol.BasicAsyncRequestHandler)1 ListenerEndpoint (org.apache.http.nio.reactor.ListenerEndpoint)1