Example usage for org.apache.http.localserver LocalTestServer stop

List of usage examples for org.apache.http.localserver LocalTestServer stop

Introduction

In this page you can find the example usage for org.apache.http.localserver LocalTestServer stop.

Prototype

public void stop() throws Exception 

Source Link

Document

Stops this test server.

Usage

From source file:com.flipkart.foxtrot.client.LocalServerTestRule.java

@Override
public Statement apply(final Statement base, Description description) {
    return new Statement() {
        @Override/*from w ww. ja v a2 s. c om*/
        public void evaluate() throws Throwable {
            LocalTestServer localTestServer = new LocalTestServer(null, null);
            for (Map.Entry<String, HttpRequestHandler> handler : handlers.entrySet()) {
                localTestServer.register(handler.getKey(), handler.getValue());
            }
            localTestServer.start();
            logger.info("Started test server");
            try {
                hostPort.setHostName(localTestServer.getServiceAddress().getHostName());
                hostPort.setPort(localTestServer.getServiceAddress().getPort());
                base.evaluate();
            } finally {
                localTestServer.stop();
                logger.info("Stopped test server");
            }
        }
    };
}