Search in sources :

Example 1 with HttpServer

use of org.apache.http.impl.bootstrap.HttpServer in project Manga by herrlock.

the class TestUtils method testExecuteHttpGet.

@Test
public void testExecuteHttpGet() throws ClientProtocolException, IOException {
    final String MAGIC_SUPER_SECRET_STRING = "somethingRandom";
    HttpRequestHandler requestHandler = new SetStringHttpRequestHandler(MAGIC_SUPER_SECRET_STRING);
    HttpServer server = ServerBootstrap.bootstrap().setListenerPort(1337).registerHandler("/", requestHandler).create();
    URL url = new URL("http", "localhost", 1337, "/");
    Properties p = new Properties();
    p.setProperty(Configuration.URL, url.toExternalForm());
    DownloadConfiguration conf = DownloadConfiguration.create(p);
    ResponseHandler<Boolean> responseHandler = new ResponseEqualsStringResponseHandler(MAGIC_SUPER_SECRET_STRING);
    server.start();
    Utils.getDataAndExecuteResponseHandler(url, conf, responseHandler);
    server.stop();
}
Also used : HttpRequestHandler(org.apache.http.protocol.HttpRequestHandler) HttpServer(org.apache.http.impl.bootstrap.HttpServer) Properties(java.util.Properties) URL(java.net.URL) DownloadConfiguration(de.herrlock.manga.util.configuration.DownloadConfiguration) Test(org.junit.Test)

Example 2 with HttpServer

use of org.apache.http.impl.bootstrap.HttpServer in project acceptance-test-harness by jenkinsci.

the class MockUpdateCenter method close.

@Override
public void close() throws IOException {
    if (original != null) {
        LOGGER.log(Level.INFO, () -> "stopping MockUpdateCenter on http://" + server.getInetAddress().getHostAddress() + ":" + server.getLocalPort() + "/update-center.json");
        HttpServer s = server;
        // make sure this.server holds a server that is guaranteed to be up
        server = null;
        s.shutdown(5, TimeUnit.SECONDS);
        /* TODO only if RemoteController etc.:
            injector.getInstance(Jenkins.class).runScript("DownloadService.signatureCheck = true; Jenkins.instance.updateCenter.sites.replaceBy([new UpdateSite(UpdateCenter.ID_DEFAULT, '%s')])", original);
            */
        original = null;
    }
}
Also used : HttpServer(org.apache.http.impl.bootstrap.HttpServer)

Aggregations

HttpServer (org.apache.http.impl.bootstrap.HttpServer)2 DownloadConfiguration (de.herrlock.manga.util.configuration.DownloadConfiguration)1 URL (java.net.URL)1 Properties (java.util.Properties)1 HttpRequestHandler (org.apache.http.protocol.HttpRequestHandler)1 Test (org.junit.Test)1