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();

Source Link

Document

Create a HTTP/HTTPS client using default options

Usage

From source file:examples.HTTPExamples.java

License:Open Source License

public void example28(Vertx vertx) {
    HttpClient client = vertx.createHttpClient();
}

From source file:examples.HTTPExamples.java

License:Open Source License

public void example31(Vertx vertx) {
    HttpClient client = vertx.createHttpClient();

    // Specify both port and host name
    client.getNow(8080, "myserver.mycompany.com", "/some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    });/*w ww . j  a va2s  . c  o  m*/

    // This time use the default port 80 but specify the host name
    client.getNow("foo.othercompany.com", "/other-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    });
}

From source file:examples.HTTPExamples.java

License:Open Source License

public void example32(Vertx vertx) {
    HttpClient client = vertx.createHttpClient();

    // Send a GET request
    client.getNow("/some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    });/*from   www  .j ava 2 s .c o m*/

    // Send a GET request
    client.headNow("/other-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    });

}

From source file:examples.HTTPExamples.java

License:Open Source License

public void example33(Vertx vertx) {
    HttpClient client = vertx.createHttpClient();

    client.request(HttpMethod.GET, "some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    }).end();//  w  w  w.  ja  v  a2s.  c o m

    client.request(HttpMethod.POST, "foo-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    }).end("some-data");
}

From source file:examples.HTTPExamples.java

License:Open Source License

public void example34(Vertx vertx, String body) {
    HttpClient client = vertx.createHttpClient();

    HttpClientRequest request = client.post("some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    });/*  www  . j  a  va 2  s . c  om*/

    // Now do stuff with the request
    request.putHeader("content-length", "1000");
    request.putHeader("content-type", "text/plain");
    request.write(body);

    // Make sure the request is ended when you're done with it
    request.end();

    // Or fluently:

    client.post("some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    }).putHeader("content-length", "1000").putHeader("content-type", "text/plain").write(body).end();

    // Or event more simply:

    client.post("some-uri", response -> {
        System.out.println("Received response with status code " + response.statusCode());
    }).putHeader("content-type", "text/plain").end(body);

}

From source file:examples.HTTPExamples.java

License:Open Source License

public void serversharingclient(Vertx vertx) {
    vertx.setPeriodic(100, (l) -> {/*  w ww . ja va  2  s . c  o  m*/
        vertx.createHttpClient().getNow(8080, "localhost", "/", resp -> {
            resp.bodyHandler(body -> {
                System.out.println(body.toString("ISO-8859-1"));
            });
        });
    });
}

From source file:io.apiman.gateway.platforms.vertx3.engine.VertxPluginRegistry.java

License:Apache License

/**
 * Constructor./*from   w  w  w  .j  av  a 2s. c o  m*/
 *
 * @param vertx the vertx
 * @param vxEngineConfig the engine config
 * @param config the plugin config
 */
public VertxPluginRegistry(Vertx vertx, VertxEngineConfig vxEngineConfig, Map<String, String> config) {
    super(getTempPluginsDir(), PluginUtils.getDefaultMavenRepositories());
    this.client = vertx.createHttpClient();
}

From source file:io.knotx.repository.impl.RepositoryConnectorProxyImpl.java

License:Apache License

private HttpClient createHttpClient(Vertx vertx) {
    io.vertx.core.http.HttpClient vertxHttpClient = clientOptions.isEmpty() ? vertx.createHttpClient()
            : vertx.createHttpClient(new HttpClientOptions(clientOptions));

    return HttpClient.newInstance(vertxHttpClient);
}