本文整理汇总了Java中io.vertx.rxjava.ext.web.client.WebClient类的典型用法代码示例。如果您正苦于以下问题:Java WebClient类的具体用法?Java WebClient怎么用?Java WebClient使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
WebClient类属于io.vertx.rxjava.ext.web.client包,在下文中一共展示了WebClient类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: hello7
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Path("7")
@GET
public CompletionStage<String> hello7(@Context Vertx vertx){
io.vertx.rxjava.core.Vertx rxVertx = io.vertx.rxjava.core.Vertx.newInstance(vertx);
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
CompletableFuture<String> ret = new CompletableFuture<>();
responseHandler.subscribe(body -> {
System.err.println("Got body");
ret.complete(body.body().toString());
});
System.err.println("Created client");
return ret;
}
开发者ID:FroMage,项目名称:redpipe,代码行数:24,代码来源:MyResource.java
示例2: prepare
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Before
public void prepare(TestContext context) throws IOException {
Async async = context.async();
JsonObject config = new JsonObject().put("db_url", "jdbc:hsqldb:mem:testdb;shutdown=true")
.put("db_max_pool_size", 4)
.put("security_definitions", "classpath:wiki-users.properties")
.put("scan", new JsonArray().add(AppResource.class.getPackage().getName()))
.put("keystore", new JsonObject()
.put("path", "keystore.jceks")
.put("type", "jceks")
.put("password", "secret"));
server = new WikiServer();
server.start(config)
.subscribe(v -> {
webClient = WebClient.create(server.getVertx(),
new WebClientOptions().setDefaultHost("localhost").setDefaultPort(9000));
async.complete();
}, x -> {
x.printStackTrace();
context.fail(x);
async.complete();
});
}
开发者ID:FroMage,项目名称:redpipe,代码行数:26,代码来源:ApiTest.java
示例3: hello6
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Path("6")
@GET
public void hello6(@Suspended final AsyncResponse asyncResponse,
// Inject the Vertx instance
@Context Vertx vertx){
io.vertx.rxjava.core.Vertx rxVertx = io.vertx.rxjava.core.Vertx.newInstance(vertx);
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
responseHandler.subscribe(body -> {
System.err.println("Got body");
asyncResponse.resume(Response.ok(body.body().toString()).build());
});
System.err.println("Created client");
}
开发者ID:FroMage,项目名称:redpipe,代码行数:24,代码来源:MyResource.java
示例4: hello7Error
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Path("7error")
@GET
public CompletionStage<String> hello7Error(@Context Vertx vertx){
io.vertx.rxjava.core.Vertx rxVertx = io.vertx.rxjava.core.Vertx.newInstance(vertx);
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
CompletableFuture<String> ret = new CompletableFuture<>();
responseHandler.subscribe(body -> {
System.err.println("Got body");
ret.completeExceptionally(new MyException());
});
System.err.println("Created client");
return ret;
}
开发者ID:FroMage,项目名称:redpipe,代码行数:24,代码来源:MyResource.java
示例5: hello8
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Path("8")
@GET
public Single<String> hello8(@Context io.vertx.rxjava.core.Vertx rxVertx){
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
System.err.println("Created client");
return responseHandler.map(body -> {
System.err.println("Got body");
return body.body().toString();
});
}
开发者ID:FroMage,项目名称:redpipe,代码行数:20,代码来源:MyResource.java
示例6: hello8User
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Path("8user")
@Produces("text/json")
@GET
public Single<DataClass> hello8User(@Context io.vertx.rxjava.core.Vertx rxVertx){
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
System.err.println("Created client");
return responseHandler.map(body -> {
System.err.println("Got body");
return new DataClass(body.body().toString());
});
}
开发者ID:FroMage,项目名称:redpipe,代码行数:21,代码来源:MyResource.java
示例7: hello8Error
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Path("8error")
@GET
public Single<String> hello8Error(@Context io.vertx.rxjava.core.Vertx rxVertx){
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
System.err.println("Created client");
return responseHandler.map(body -> {
System.err.println("Got body");
throw new MyException();
});
}
开发者ID:FroMage,项目名称:redpipe,代码行数:20,代码来源:MyResource.java
示例8: helloAsync
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Path("coroutines/1")
@GET
public Single<Response> helloAsync(@Context io.vertx.rxjava.core.Vertx rxVertx){
return Fibers.fiber(() -> {
System.err.println("Creating client");
WebClientOptions options = new WebClientOptions();
options.setSsl(true);
options.setTrustAll(true);
options.setVerifyHost(false);
WebClient client = WebClient.create(rxVertx, options);
Single<HttpResponse<io.vertx.rxjava.core.buffer.Buffer>> responseHandler = client.get(443,
"www.google.com",
"/robots.txt").rxSend();
System.err.println("Got response");
HttpResponse<io.vertx.rxjava.core.buffer.Buffer> httpResponse = Fibers.await(responseHandler);
System.err.println("Got body");
return Response.ok(httpResponse.body().toString()).build();
});
}
开发者ID:FroMage,项目名称:redpipe,代码行数:23,代码来源:MyResource.java
示例9: testGet
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Test
public void testGet() {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.response().setChunked(true).end("some_content"));
try {
server.listen(ar -> {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Single<HttpResponse<Buffer>> single = client
.get(8080, "localhost", "/the_uri")
.as(BodyCodec.buffer())
.rxSend();
for (int i = 0; i < times; i++) {
single.subscribe(resp -> {
Buffer body = resp.body();
assertEquals("some_content", body.toString("UTF-8"));
complete();
}, this::fail);
}
});
await();
} finally {
server.close();
}
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:27,代码来源:RxTest.java
示例10: testPost
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Test
public void testPost() {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.bodyHandler(buff -> {
assertEquals("onetwothree", buff.toString());
req.response().end();
}));
try {
server.listen(ar -> {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Observable<Buffer> stream = Observable.just(Buffer.buffer("one"), Buffer.buffer("two"), Buffer.buffer("three"));
Single<HttpResponse<Buffer>> single = client
.post(8080, "localhost", "/the_uri")
.rxSendStream(stream);
for (int i = 0; i < times; i++) {
single.subscribe(resp -> complete(), this::fail);
}
});
await();
} finally {
server.close();
}
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:26,代码来源:RxTest.java
示例11: testResponseMissingBody
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Test
public void testResponseMissingBody() throws Exception {
int times = 5;
waitFor(times);
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.response().setStatusCode(403).end());
try {
server.listen(ar -> {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Single<HttpResponse<Buffer>> single = client
.get(8080, "localhost", "/the_uri")
.rxSend();
for (int i = 0; i < times; i++) {
single.subscribe(resp -> {
assertEquals(403, resp.statusCode());
assertNull(resp.body());
complete();
}, this::fail);
}
});
await();
} finally {
server.close();
}
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:26,代码来源:RxTest.java
示例12: testResponseBodyAsAsJsonMapped
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Test
public void testResponseBodyAsAsJsonMapped() throws Exception {
JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.response().end(expected.encode()));
try {
server.listen(ar -> {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Single<HttpResponse<WineAndCheese>> single = client
.get(8080, "localhost", "/the_uri")
.as(BodyCodec.json(WineAndCheese.class))
.rxSend();
single.subscribe(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.body());
testComplete();
}, this::fail);
});
await();
} finally {
server.close();
}
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:24,代码来源:RxTest.java
示例13: testErrorHandling
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Test
public void testErrorHandling() throws Exception {
try {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Single<HttpResponse<WineAndCheese>> single = client
.get(-1, "localhost", "/the_uri")
.as(BodyCodec.json(WineAndCheese.class))
.rxSend();
single.subscribe(resp -> fail(), error -> {
assertEquals(IllegalArgumentException.class, error.getClass());
testComplete();
});
await();
} catch (Throwable t) {
fail();
}
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:18,代码来源:RxTest.java
示例14: start
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Override
public void start(Future<Void> future) throws Exception {
Router router = Router.router(vertx);
circuit = CircuitBreaker.create("circuit-breaker", vertx, new CircuitBreakerOptions()
.setFallbackOnFailure(true)
.setMaxFailures(3)
.setResetTimeout(5000)
.setTimeout(1000)
);
router.get("/").handler(this::getShoppingList);
ServiceDiscovery.create(vertx, discovery -> {
Single<WebClient> s1 = HttpEndpoint.rxGetWebClient(discovery,
rec -> rec.getName().equals("shopping-backend"));
Single<WebClient> s2 = HttpEndpoint.rxGetWebClient(discovery,
rec -> rec.getName().equals("pricer-service"));
Single.zip(s1, s2, (x, y) -> {
shopping = x;
pricer = y;
return vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}).subscribe();
});
}
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:32,代码来源:MyShoppingList.java
示例15: retrievePrice
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
public static void retrievePrice(WebClient pricer, Map.Entry<String, Object> entry, Future<JsonObject> future) {
pricer.post("/prices")
.rxSendJson(new JsonObject()
.put("name", entry.getKey())
.put("quantity", entry.getValue())
).subscribe(
resp -> future.complete(resp.bodyAsJsonObject()),
future::fail
);
}
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:11,代码来源:Shopping.java
示例16: start
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Override
public void start() {
circuit = CircuitBreaker.create("circuit-breaker", vertx,
new CircuitBreakerOptions()
.setFallbackOnFailure(true)
.setMaxFailures(3)
.setResetTimeout(5000)
.setTimeout(1000)
);
Router router = Router.router(vertx);
router.route("/health").handler(rc ->
rc.response().end("OK"));
router.route("/").handler(this::getShoppingList);
ServiceDiscovery.create(vertx, discovery -> {
// Get pricer-service
Single<WebClient> s1 = HttpEndpoint.rxGetWebClient(discovery, svc -> svc.getName().equals("pricer-service"));
// Get shopping-backend
Single<WebClient> s2 = HttpEndpoint.rxGetWebClient(discovery, svc -> svc.getName().equals("shopping-backend"));
Single.zip(s1, s2, (p, s) -> {
pricer = p;
shopping = s;
return vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
}).subscribe();
// When both are done...
});
}
开发者ID:cescoffier,项目名称:vertx-chtijug-2017,代码行数:37,代码来源:MyShoppingList.java
示例17: start
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
@Override
public void start() {
circuit = CircuitBreaker.create("circuit-breaker", vertx,
new CircuitBreakerOptions()
.setFallbackOnFailure(true)
.setMaxFailures(3)
.setResetTimeout(5000)
.setTimeout(1000)
);
Router router = Router.router(vertx);
router.route("/health").handler(rc -> rc.response().end("OK"));
router.route("/").handler(this::getShoppingList);
ServiceDiscovery.create(vertx, discovery -> {
// Get pricer-service
Single<WebClient> s1 = HttpEndpoint.rxGetWebClient(discovery,
svc -> svc.getName().equals("pricer-service"));
// Get shopping-backend
Single<WebClient> s2 = HttpEndpoint.rxGetWebClient(discovery,
svc -> svc.getName().equals("shopping-backend"));
// When both are done...
Single.zip(s1, s2, (p, s) -> {
pricer = p;
shopping = s;
return vertx.createHttpServer()
.requestHandler(router::accept)
.listen(8080);
})
.subscribe();
});
}
开发者ID:cescoffier,项目名称:vertx-rhsummit-2017,代码行数:38,代码来源:MyShoppingList.java
示例18: main
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
public static void main(String[] args) {
Vertx vertx = Vertx.vertx();
Args cli = new Args();
JCommander commander = JCommander.newBuilder()
.addObject(cli)
.build();
commander.parse(args);
if (cli.help) {
commander.usage();
return;
}
WebClientOptions options = new WebClientOptions();
String host = cli.url.getHost();
int port = cli.url.getPort();
if (port <= 0) {
port = 80;
}
options.setDefaultHost(host);
options.setDefaultPort(port);
WebClient client = WebClient.create(vertx, options);
switch (cli.action.toLowerCase()) {
case "remove": remove(vertx, client, cli); break;
case "add": add(vertx, client, cli); break;
case "populate": populate(vertx, client); break;
case "get" : list(vertx, client); break;
default: System.out.println("Unknown action " + cli.action + ", supported actions are list, remove, add " +
"and populate");
}
}
开发者ID:cescoffier,项目名称:vertx-openshift-shopping-hol,代码行数:34,代码来源:ShoppingBackendClient.java
示例19: populate
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
private static void populate(Vertx vertx, WebClient client) {
JsonObject product1 = new JsonObject().put("name", "coffee").put("quantity", 2);
JsonObject product2 = new JsonObject().put("name", "bacon").put("quantity", 1);
JsonObject product3 = new JsonObject().put("name", "eggs").put("quantity", 3);
client.post("/shopping")
.rxSendJsonObject(product1)
.flatMap(x -> client.post("/shopping").rxSendJsonObject(product2))
.flatMap(x -> client.post("/shopping").rxSendJsonObject(product3))
.flatMap(x -> client.get("/shopping").as(BodyCodec.jsonObject()).rxSend())
.doAfterTerminate(vertx::close)
.subscribe(resp -> dump("GET /shopping", resp), ShoppingBackendClient::dump);
}
开发者ID:cescoffier,项目名称:vertx-openshift-shopping-hol,代码行数:14,代码来源:ShoppingBackendClient.java
示例20: list
import io.vertx.rxjava.ext.web.client.WebClient; //导入依赖的package包/类
private static void list(Vertx vertx, WebClient client) {
client.get("/shopping")
.as(BodyCodec.jsonObject())
.rxSend()
.doAfterTerminate(vertx::close)
.subscribe(
resp -> dump("GET /shopping", resp),
ShoppingBackendClient::dump
);
}
开发者ID:cescoffier,项目名称:vertx-openshift-shopping-hol,代码行数:11,代码来源:ShoppingBackendClient.java
注:本文中的io.vertx.rxjava.ext.web.client.WebClient类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论