Example usage for io.vertx.core Vertx createHttpClient

List of usage examples for io.vertx.core Vertx createHttpClient

Introduction

In this page you can find the example usage for io.vertx.core Vertx createHttpClient.

Prototype

HttpClient createHttpClient(HttpClientOptions options);

Source Link

Document

Create a HTTP/HTTPS client using the specified options

Usage

From source file:com.hubrick.vertx.rest.impl.DefaultRestClient.java

License:Apache License

public DefaultRestClient(Vertx vertx, final RestClientOptions clientOptions,
        List<HttpMessageConverter> httpMessageConverters) {
    this.vertx = vertx;
    this.httpMessageConverters = httpMessageConverters;
    this.httpClient = vertx.createHttpClient(clientOptions);
    this.options = new RestClientOptions(clientOptions);
}

From source file:com.hubrick.vertx.s3.client.S3Client.java

License:Apache License

public S3Client(Vertx vertx, S3ClientOptions s3ClientOptions, Clock clock) {
    checkNotNull(vertx, "vertx must not be null");
    checkNotNull(isNotBlank(s3ClientOptions.getAwsRegion()), "AWS region must be set");
    checkNotNull(isNotBlank(s3ClientOptions.getAwsServiceName()), "AWS service name must be set");
    checkNotNull(clock, "Clock must not be null");
    checkNotNull(s3ClientOptions.getGlobalTimeoutMs(), "global timeout must be null");
    checkArgument(s3ClientOptions.getGlobalTimeoutMs() > 0, "global timeout must be more than zero ms");

    this.jaxbMarshaller = createJaxbMarshaller();
    this.jaxbUnmarshaller = createJaxbUnmarshaller();

    this.vertx = vertx;
    this.clock = clock;
    this.awsServiceName = s3ClientOptions.getAwsServiceName();
    this.awsRegion = s3ClientOptions.getAwsRegion();
    this.awsAccessKey = s3ClientOptions.getAwsAccessKey();
    this.awsSecretKey = s3ClientOptions.getAwsSecretKey();
    this.globalTimeout = s3ClientOptions.getGlobalTimeoutMs();
    this.signPayload = s3ClientOptions.isSignPayload();

    final String hostnameOverride = s3ClientOptions.getHostnameOverride();
    if (!Strings.isNullOrEmpty(hostnameOverride)) {
        hostname = hostnameOverride;/*from   w w w .j  a  v a2 s  . c o  m*/
    } else {
        if (DEFAULT_REGION.equals(s3ClientOptions.getAwsRegion())) {
            hostname = DEFAULT_ENDPOINT;
        } else {
            hostname = MessageFormat.format(ENDPOINT_PATTERN, awsRegion);
        }
    }

    final S3ClientOptions options = new S3ClientOptions(s3ClientOptions);
    options.setDefaultHost(hostname);

    this.client = vertx.createHttpClient(options);
}

From source file:examples.HTTP2Examples.java

License:Open Source License

public void example7(Vertx vertx) {

    HttpClientOptions options = new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2).setSsl(true)
            .setUseAlpn(true).setTrustAll(true);

    HttpClient client = vertx.createHttpClient(options);
}

From source file:examples.HTTP2Examples.java

License:Open Source License

public void example8(Vertx vertx) {

    HttpClientOptions options = new HttpClientOptions().setProtocolVersion(HttpVersion.HTTP_2);

    HttpClient client = vertx.createHttpClient(options);
}

From source file:examples.HTTP2Examples.java

License:Open Source License

public void useMaxStreams(Vertx vertx) {

    HttpClientOptions clientOptions = new HttpClientOptions().setHttp2MultiplexingLimit(10)
            .setHttp2MaxPoolSize(3);/* www  . j  av  a  2  s  .c om*/

    // Uses up to 3 connections and up to 10 streams per connection
    HttpClient client = vertx.createHttpClient(clientOptions);
}

From source file:examples.HTTPExamples.java

License:Open Source License

public void example29(Vertx vertx) {
    HttpClientOptions options = new HttpClientOptions().setKeepAlive(false);
    HttpClient client = vertx.createHttpClient(options);
}

From source file:examples.HTTPExamples.java

License:Open Source License

public void exampleClientLogging(Vertx vertx) {
    HttpClientOptions options = new HttpClientOptions().setLogActivity(true);
    HttpClient client = vertx.createHttpClient(options);
}

From source file:examples.HTTPExamples.java

License:Open Source License

public void example30(Vertx vertx) {
    // Set the default host
    HttpClientOptions options = new HttpClientOptions().setDefaultHost("wibble.com");
    // Can also set default port if you want...
    HttpClient client = vertx.createHttpClient(options);
    client.getNow("/some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    });/*from   w ww  .j a  v a2 s .  co  m*/
}

From source file:examples.HTTPExamples.java

License:Open Source License

public void exampleFollowRedirect02(Vertx vertx) {

    HttpClient client = vertx.createHttpClient(new HttpClientOptions().setMaxRedirects(32));

    client.get("some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    }).setFollowRedirects(true).end();/*from  w w  w  .j  a  v a  2  s  .  c o  m*/
}

From source file:examples.HTTPExamples.java

License:Open Source License

public void example58(Vertx vertx) {

    HttpClientOptions options = new HttpClientOptions()
            .setProxyOptions(new ProxyOptions().setType(ProxyType.HTTP).setHost("localhost").setPort(3128)
                    .setUsername("username").setPassword("secret"));
    HttpClient client = vertx.createHttpClient(options);

}