use of org.apache.http.impl.nio.bootstrap.ServerBootstrap 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");
}
Aggregations