Search in sources :

Example 81 with HttpClientOptions

use of io.vertx.core.http.HttpClientOptions in project georocket by georocket.

the class ElasticsearchInstaller method doDownload.

/**
 * Download a file
 * @param downloadUrl the URL to download from
 * @param dest the destination file
 * @return a single emitting exactly one item once the file has been
 * downloaded
 */
private Single<Void> doDownload(String downloadUrl, AsyncFile dest) {
    ObservableFuture<Void> observable = RxHelper.observableFuture();
    Handler<AsyncResult<Void>> handler = observable.toHandler();
    HttpClientOptions options = new HttpClientOptions();
    if (downloadUrl.startsWith("https")) {
        options.setSsl(true);
    }
    HttpClient client = vertx.createHttpClient(options);
    HttpClientRequest req = client.getAbs(downloadUrl);
    req.exceptionHandler(t -> handler.handle(Future.failedFuture(t)));
    req.handler(res -> {
        if (res.statusCode() != 200) {
            handler.handle(Future.failedFuture(new HttpException(res.statusCode(), res.statusMessage())));
            return;
        }
        // get content-length
        int length;
        int[] read = { 0 };
        int[] lastOutput = { 0 };
        String contentLength = res.getHeader("Content-Length");
        if (contentLength != null) {
            length = Integer.parseInt(contentLength);
        } else {
            length = 0;
        }
        res.exceptionHandler(t -> handler.handle(Future.failedFuture(t)));
        // download file contents, log progress
        res.handler(buf -> {
            read[0] += buf.length();
            if (lastOutput[0] == 0 || read[0] - lastOutput[0] > 1024 * 2048) {
                logProgress(length, read[0]);
                lastOutput[0] = read[0];
            }
            dest.write(buf);
        });
        res.endHandler(v -> {
            logProgress(length, read[0]);
            handler.handle(Future.succeededFuture());
        });
    });
    req.end();
    return observable.toSingle();
}
Also used : HttpClientRequest(io.vertx.rxjava.core.http.HttpClientRequest) HttpClient(io.vertx.rxjava.core.http.HttpClient) HttpException(io.georocket.util.HttpException) AsyncResult(io.vertx.core.AsyncResult) HttpClientOptions(io.vertx.core.http.HttpClientOptions)

Example 82 with HttpClientOptions

use of io.vertx.core.http.HttpClientOptions in project incubator-servicecomb-java-chassis by apache.

the class TestVertxTLSBuilder method testbuildHttpClientOptions_ssl_withFactory.

@Test
public void testbuildHttpClientOptions_ssl_withFactory() {
    ArchaiusUtils.setProperty("ssl.exist.sslOptionFactory", SSLOptionFactoryForTest.class.getName());
    HttpClientOptions clientOptions = new HttpClientOptions();
    VertxTLSBuilder.buildHttpClientOptions("exist", clientOptions);
    Assert.assertTrue(clientOptions.isSsl());
    Assert.assertTrue(clientOptions.isVerifyHost());
}
Also used : HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 83 with HttpClientOptions

use of io.vertx.core.http.HttpClientOptions in project incubator-servicecomb-java-chassis by apache.

the class TestVertxTLSBuilder method testbuildHttpClientOptions.

@Test
public void testbuildHttpClientOptions() {
    SSLOption option = SSLOption.buildFromYaml("rest.consumer");
    SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
    HttpClientOptions serverOptions = new HttpClientOptions();
    VertxTLSBuilder.buildHttpClientOptions(option, custom, serverOptions);
    Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1);
    Assert.assertEquals(serverOptions.isTrustAll(), true);
}
Also used : SSLOption(org.apache.servicecomb.foundation.ssl.SSLOption) SSLCustom(org.apache.servicecomb.foundation.ssl.SSLCustom) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 84 with HttpClientOptions

use of io.vertx.core.http.HttpClientOptions in project incubator-servicecomb-java-chassis by apache.

the class TestVertxTLSBuilder method testbuildClientOptionsBase.

@Test
public void testbuildClientOptionsBase() {
    SSLOption option = SSLOption.buildFromYaml("rest.consumer");
    SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
    HttpClientOptions serverOptions = new HttpClientOptions();
    VertxTLSBuilder.buildClientOptionsBase(option, custom, serverOptions);
    Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1);
    Assert.assertEquals(serverOptions.isTrustAll(), true);
}
Also used : SSLOption(org.apache.servicecomb.foundation.ssl.SSLOption) SSLCustom(org.apache.servicecomb.foundation.ssl.SSLCustom) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Example 85 with HttpClientOptions

use of io.vertx.core.http.HttpClientOptions in project incubator-servicecomb-java-chassis by apache.

the class TestVertxTLSBuilder method testbuildClientOptionsBaseFileNull.

@Test
public void testbuildClientOptionsBaseFileNull() {
    SSLOption option = SSLOption.buildFromYaml("rest.consumer");
    option.setKeyStore(null);
    option.setTrustStore(null);
    option.setCrl(null);
    SSLCustom custom = SSLCustom.createSSLCustom(option.getSslCustomClass());
    HttpClientOptions serverOptions = new HttpClientOptions();
    VertxTLSBuilder.buildClientOptionsBase(option, custom, serverOptions);
    Assert.assertEquals(serverOptions.getEnabledSecureTransportProtocols().toArray().length, 1);
    Assert.assertEquals(serverOptions.isTrustAll(), true);
}
Also used : SSLOption(org.apache.servicecomb.foundation.ssl.SSLOption) SSLCustom(org.apache.servicecomb.foundation.ssl.SSLCustom) HttpClientOptions(io.vertx.core.http.HttpClientOptions) Test(org.junit.Test)

Aggregations

HttpClientOptions (io.vertx.core.http.HttpClientOptions)101 Test (org.junit.Test)51 HttpClient (io.vertx.core.http.HttpClient)27 HttpClientRequest (io.vertx.core.http.HttpClientRequest)23 HttpServerOptions (io.vertx.core.http.HttpServerOptions)19 CountDownLatch (java.util.concurrent.CountDownLatch)15 HttpMethod (io.vertx.core.http.HttpMethod)14 SSLCustom (org.apache.servicecomb.foundation.ssl.SSLCustom)14 SSLOption (org.apache.servicecomb.foundation.ssl.SSLOption)14 HttpVersion (io.vertx.core.http.HttpVersion)13 AtomicReference (java.util.concurrent.atomic.AtomicReference)13 Vertx (io.vertx.core.Vertx)11 MockUp (mockit.MockUp)11 DeploymentOptions (io.vertx.core.DeploymentOptions)10 AtomicInteger (java.util.concurrent.atomic.AtomicInteger)10 Buffer (io.vertx.core.buffer.Buffer)9 HttpServer (io.vertx.core.http.HttpServer)8 HttpServerResponse (io.vertx.core.http.HttpServerResponse)8 VertxOptions (io.vertx.core.VertxOptions)7 VertxInternal (io.vertx.core.impl.VertxInternal)7