-
Notifications
You must be signed in to change notification settings - Fork 2.1k
/
Client.java
36 lines (32 loc) · 1.06 KB
/
Client.java
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
package io.vertx.example.core.http.proxy;
import io.vertx.core.AbstractVerticle;
import io.vertx.core.Launcher;
import io.vertx.core.http.HttpClient;
import io.vertx.core.http.HttpMethod;
/*
* @author <a href="http://tfox.org">Tim Fox</a>
*/
public class Client extends AbstractVerticle {
public static void main(String[] args) {
Launcher.executeCommand("run", Client.class.getName());
}
@Override
public void start() throws Exception {
HttpClient client = vertx.createHttpClient();
client.request(HttpMethod.GET, 8080, "localhost", "/")
.compose(request -> {
request.setChunked(true);
for (int i = 0; i < 10; i++) {
request.write("client-chunk-" + i);
}
request.end();
return request.response().compose(resp -> {
System.out.println("Got response " + resp.statusCode());
return resp.body();
});
}
)
.onSuccess(body -> System.out.println("Got data " + body.toString("ISO-8859-1")))
.onFailure(Throwable::printStackTrace);
}
}