本文整理了Java中io.vertx.ext.web.client.HttpResponse.body()
方法的一些代码示例,展示了HttpResponse.body()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.body()
方法的具体详情如下:
包路径:io.vertx.ext.web.client.HttpResponse
类名称:HttpResponse
方法名:body
暂无
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
client.get(8080, "localhost", "/").send(ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Got HTTP response with status " + response.statusCode() + " with data " +
response.body().toString("ISO-8859-1"));
} else {
ar.cause().printStackTrace();
}
});
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
client.get(8080, "localhost", "/")
.as(BodyCodec.json(User.class))
.send(ar -> {
if (ar.succeeded()) {
HttpResponse<User> response = ar.result();
System.out.println("Got HTTP response body");
User user = response.body();
System.out.println("FirstName " + user.firstName);
System.out.println("LastName " + user.lastName);
System.out.println("Male " + user.male);
} else {
ar.cause().printStackTrace();
}
});
}
}
代码示例来源:origin: vert-x3/vertx-examples
private void invoke(RoutingContext rc) {
client.get("/luke").as(BodyCodec.string()).send(ar -> {
if (ar.failed()) {
rc.response().end("Unable to call the greeting service: " + ar.cause().getMessage());
} else {
if (ar.result().statusCode() != 200) {
rc.response().end("Unable to call the greeting service - received status:" + ar.result().statusMessage());
} else {
rc.response().end("Greeting service invoked: '" + ar.result().body() + "'");
}
}
});
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
client.get(8080, "localhost", "/")
.as(BodyCodec.jsonObject())
.send(ar -> {
if (ar.succeeded()) {
HttpResponse<JsonObject> response = ar.result();
System.out.println("Got HTTP response body");
System.out.println(response.body().encodePrettily());
} else {
ar.cause().printStackTrace();
}
});
}
}
代码示例来源:origin: vert-x3/vertx-examples
JsonObject authJson = authHandler.result().body();
String accessToken = authJson.getString("access_token");
String header = "Bearer " + accessToken;
.send(handler -> {
if (handler.succeeded() && 200 == handler.result().statusCode()) {
System.out.println(handler.result().body());
} else {
System.out.println(handler.cause().getMessage());
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* @return the response body in the format it was decoded.
*/
public T body() {
if (cached_6 != null) {
return cached_6;
}
T ret = (T)__typeArg_0.wrap(delegate.body());
cached_6 = ret;
return ret;
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* @return the response body in the format it was decoded.
*/
public T body() {
if (cached_6 != null) {
return cached_6;
}
T ret = (T)__typeArg_0.wrap(delegate.body());
cached_6 = ret;
return ret;
}
代码示例来源:origin: io.vertx/vertx-lang-groovy
public static java.lang.Object body(io.vertx.ext.web.client.HttpResponse<Object> j_receiver) {
return io.vertx.core.impl.ConversionHelper.fromObject(j_receiver.body());
}
public static java.util.Map<String, Object> bodyAsJsonObject(io.vertx.ext.web.client.HttpResponse<Object> j_receiver) {
代码示例来源:origin: redhat-developer-demos/istio-tutorial
private void getNow(RoutingContext ctx) {
count++;
final WebClient client = WebClient.create(vertx);
client.get(80, HTTP_NOW, "/")
.timeout(5000)
.as(BodyCodec.jsonObject())
.send(ar -> {
if (ar.succeeded()) {
HttpResponse<JsonObject> response = ar.result();
JsonObject body = response.body();
String now = body.getJsonObject("now").getString("rfc2822");
ctx.response().end(now + " " + String.format(RESPONSE_STRING_FORMAT, HOSTNAME, count));
} else {
ctx.response().setStatusCode(503).end(ar.cause().getMessage());
}
});
}
代码示例来源:origin: cescoffier/vertx-microservices-workshop
private void callAuditService(RoutingContext context) {
if (client == null) {
context.response()
.putHeader("content-type", "application/json")
.setStatusCode(200)
.end(new JsonObject().put("message", "No audit service").encode());
} else {
client.get("/").send(ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
context.response()
.putHeader("content-type", "application/json")
.setStatusCode(200)
.end(response.body());
}
});
}
}
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testResponseBodyAsAsJsonObject() throws Exception {
JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
server.requestHandler(req -> req.response().end(expected.encode()));
startServer();
HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get
.as(BodyCodec.jsonObject())
.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(expected, resp.body());
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-junit5
@Test
@DisplayName("Start a HTTP server, then issue a HTTP client request and check the response")
void vertx_check_http_server_response() throws InterruptedException {
Vertx vertx = Vertx.vertx();
VertxTestContext testContext = new VertxTestContext();
vertx.deployVerticle(new HttpServerVerticle(), testContext.succeeding(id -> {
WebClient client = WebClient.create(vertx);
client.get(8080, "localhost", "/")
.as(BodyCodec.string())
.send(testContext.succeeding(response -> testContext.verify(() -> {
assertThat(response.body()).isEqualTo("Plop");
testContext.completeNow();
})));
}));
assertThat(testContext.awaitCompletion(5, TimeUnit.SECONDS)).isTrue();
closeVertx(vertx);
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testResponseBodyAsAsJsonMapped() throws Exception {
JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
server.requestHandler(req -> req.response().end(expected.encode()));
startServer();
HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get
.as(BodyCodec.json(WineAndCheese.class))
.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.body());
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testResponseBodyAsBuffer() throws Exception {
Buffer expected = TestUtils.randomBuffer(2000);
server.requestHandler(req -> req.response().end(expected));
startServer();
HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(expected, resp.body());
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-web-client
private <R> void testResponseMissingBody(BodyCodec<R> codec) throws Exception {
server.requestHandler(req -> req.response().setStatusCode(403).end());
startServer();
HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get
.as(codec)
.send(onSuccess(resp -> {
assertEquals(403, resp.statusCode());
assertNull(resp.body());
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testResponseBodyAsAsJsonArray() throws Exception {
JsonArray expected = new JsonArray().add("cheese").add("wine");
server.requestHandler(req -> req.response().end(expected.encode()));
startServer();
HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get
.as(BodyCodec.jsonArray())
.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(expected, resp.body());
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testResponseBodyDiscarded() throws Exception {
server.requestHandler(req -> req.response().end(TestUtils.randomAlphaString(1024)));
startServer();
HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get
.as(BodyCodec.none())
.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(null, resp.body());
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testResponseBodyAsAsJsonArrayMapped() throws Exception {
JsonArray expected = new JsonArray().add("cheese").add("wine");
server.requestHandler(req -> req.response().end(expected.encode()));
startServer();
HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get
.as(BodyCodec.json(List.class))
.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(expected.getList(), resp.body());
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testInvalidRedirection() throws Exception {
server.requestHandler(req -> {
assertEquals(HttpMethod.POST, req.method());
assertEquals("/redirect", req.path());
req.response().setStatusCode(302).putHeader("Location", "http://www.google.com").end();
});
startServer();
HttpRequest<Buffer> builder = client
.post("/redirect")
.followRedirects(true);
builder.send(onSuccess(resp -> {
assertEquals(302, resp.statusCode());
assertEquals("http://www.google.com", resp.getHeader("Location"));
assertNull(resp.body());
complete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testRedirectLimit() throws Exception {
String location = "http://" + DEFAULT_HTTP_HOST + ":" + DEFAULT_HTTP_PORT + "/redirect";
server.requestHandler(req -> {
assertEquals(HttpMethod.GET, req.method());
assertEquals("/redirect", req.path());
req.response().setStatusCode(302).putHeader("Location", location).end();
});
startServer();
HttpRequest<Buffer> builder = client
.get("/redirect")
.followRedirects(true);
builder.send(onSuccess(resp -> {
assertEquals(302, resp.statusCode());
assertEquals(location, resp.getHeader("Location"));
assertNull(resp.body());
complete();
}));
await();
}
内容来源于网络,如有侵权,请联系作者删除!