本文整理了Java中io.vertx.ext.web.client.HttpResponse.bodyAsString()
方法的一些代码示例,展示了HttpResponse.bodyAsString()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.bodyAsString()
方法的具体详情如下:
包路径:io.vertx.ext.web.client.HttpResponse
类名称:HttpResponse
方法名:bodyAsString
暂无
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* @return the response body decoded as a <code>String</code>, or <code>null</code> if a codec other than was used
*/
public String bodyAsString() {
if (cached_8 != null) {
return cached_8;
}
String ret = delegate.bodyAsString();
cached_8 = ret;
return ret;
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* @param encoding
* @return the response body decoded as a <code>String</code> given a specific <code>encoding</code>, or <code>null</code> if a codec other than was used
*/
public String bodyAsString(String encoding) {
String ret = delegate.bodyAsString(encoding);
return ret;
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* @return the response body decoded as a <code>String</code>, or <code>null</code> if a codec other than was used
*/
public String bodyAsString() {
if (cached_8 != null) {
return cached_8;
}
String ret = delegate.bodyAsString();
cached_8 = ret;
return ret;
}
代码示例来源:origin: io.vertx/vertx-rx-java
/**
* @param encoding
* @return the response body decoded as a <code>String</code> given a specific <code>encoding</code>, or <code>null</code> if a codec other than was used
*/
public String bodyAsString(String encoding) {
String ret = delegate.bodyAsString(encoding);
return ret;
}
代码示例来源:origin: io.vertx/vertx-consul-client
private <T> void requestString(HttpMethod method, String path, Query query, String body,
Handler<AsyncResult<T>> resultHandler,
BiFunction<String, MultiMap, T> mapper) {
request(DEFAULT_VALID_CODES, method, path, query, body, resultHandler, resp -> mapper.apply(resp.bodyAsString().trim(), resp.headers()));
}
代码示例来源:origin: EnMasseProject/enmasse
protected <T> void responseHandler(AsyncResult<HttpResponse<T>> ar, CompletableFuture<T> promise, int expectedCode,
String warnMessage) {
try {
if (ar.succeeded()) {
HttpResponse<T> response = ar.result();
T body = response.body();
if (response.statusCode() != expectedCode) {
log.error("expected-code: {}, response-code: {}, body: {}", expectedCode, response.statusCode(), response.body());
promise.completeExceptionally(new RuntimeException("Status " + response.statusCode() + " body: " + (body != null ? body.toString() : null)));
} else if (response.statusCode() < HTTP_OK || response.statusCode() >= HttpURLConnection.HTTP_MULT_CHOICE) {
promise.completeExceptionally(new RuntimeException(body.toString()));
} else {
promise.complete(ar.result().body());
}
} else {
log.warn(warnMessage);
promise.completeExceptionally(ar.cause());
}
} catch (io.vertx.core.json.DecodeException decEx) {
if (ar.result().bodyAsString().toLowerCase().contains("application is not available")) {
log.warn("'{}' is not available.", apiClientName(), ar.cause());
throw new IllegalStateException(String.format("'%s' is not available.", apiClientName()));
} else {
log.warn("Unexpected object received", ar.cause());
throw new IllegalStateException("JsonObject expected, but following object was received: " + ar.result().bodyAsString());
}
}
}
代码示例来源:origin: vert-x3/vertx-config
private void manageAuthResult(Handler<AsyncResult<Auth>> resultHandler, HttpResponse<Buffer> response) {
if (response.statusCode() != 200) {
resultHandler.handle(VaultException.toFailure(response.statusMessage(), response.statusCode(),
response.bodyAsString()));
} else {
JsonObject object = response.bodyAsJsonObject();
Auth auth = object.getJsonObject("auth").mapTo(Auth.class);
resultHandler.handle(Future.succeededFuture(auth));
}
}
代码示例来源:origin: vert-x3/vertx-config
/**
* Deletes a secret from `path`.
*
* @param path the path
* @param resultHandler the callback invoked with the result
*/
public void delete(String path, Handler<AsyncResult<Void>> resultHandler) {
Objects.requireNonNull(resultHandler);
client.delete("/v1/" + Objects.requireNonNull(path))
.putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must be set"))
.send(ar -> {
if (ar.failed()) {
resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
return;
}
HttpResponse<Buffer> response = ar.result();
if (response.statusCode() != 204) {
resultHandler.handle(VaultException.toFailure(response.statusMessage(), response.statusCode(),
response.bodyAsString()));
} else {
resultHandler.handle(Future.succeededFuture());
}
});
}
代码示例来源:origin: vert-x3/vertx-service-discovery
private Future<JsonArray> retrieveServices(String token) {
Future<JsonArray> future = Future.future();
String path = "/api/v1/namespaces/" + namespace + "/services";
client.get(path)
.putHeader("Authorization", "Bearer " + token)
.send(resp -> {
if (resp.failed()) {
future.fail(resp.cause());
} else if (resp.result().statusCode() != 200) {
future.fail("Unable to retrieve services from namespace " + namespace + ", status code: "
+ resp.result().statusCode() + ", content: " + resp.result().bodyAsString());
} else {
HttpResponse<Buffer> response = resp.result();
JsonArray items = response.bodyAsJsonObject().getJsonArray("items");
if (items == null) {
future.fail("Unable to retrieve services from namespace " + namespace + " - no items");
} else {
future.complete(items);
watch(client, token, response.bodyAsJsonObject().getJsonObject("metadata").getString("resourceVersion"));
}
}
});
return future;
}
代码示例来源:origin: vert-x3/vertx-config
/**
* Reads a secret from `path`.
*
* @param path the path
* @param responseHandler the callback invoked with the result
*/
public void read(String path, Handler<AsyncResult<Secret>> responseHandler) {
Objects.requireNonNull(responseHandler);
client.get("/v1/" + Objects.requireNonNull(path))
.putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "No token to access the vault"))
.send(response -> {
if (response.failed()) {
responseHandler.handle(VaultException.toFailure("Unable to access the Vault", response.cause()));
return;
}
HttpResponse<Buffer> result = response.result();
if (result.statusCode() != 200) {
responseHandler.handle(VaultException.toFailure(result.statusMessage(), result.statusCode(),
result.bodyAsString()));
} else {
Secret secret = result.bodyAsJson(Secret.class);
responseHandler.handle(Future.succeededFuture(secret));
}
});
}
代码示例来源:origin: vert-x3/vertx-config
/**
* Write a secret to `path`.
*
* @param path the path
* @param resultHandler the callback invoked with the result
*/
public void write(String path, JsonObject secrets, Handler<AsyncResult<Secret>> resultHandler) {
Objects.requireNonNull(resultHandler);
client.post("/v1/" + Objects.requireNonNull(path))
.putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must be set"))
.sendJsonObject(Objects.requireNonNull(secrets, "The secret must be set"),
ar -> {
if (ar.failed()) {
resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
return;
}
HttpResponse<Buffer> response = ar.result();
if (response.statusCode() == 200 || response.statusCode() == 204) {
resultHandler.handle(Future.succeededFuture(response.bodyAsJson(Secret.class)));
} else {
resultHandler.handle(VaultException.toFailure(response.statusMessage(), response.statusCode(),
response.bodyAsString()));
}
});
}
代码示例来源:origin: vert-x3/vertx-config
/**
* Looks up for the current token metadata.
*
* @param resultHandler the callback invoked with the result
*/
public void lookupSelf(Handler<AsyncResult<Lookup>> resultHandler) {
client.get("/v1/auth/token/lookup-self")
.putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must not be null"))
.send(ar -> {
if (ar.failed()) {
resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
return;
}
HttpResponse<Buffer> response = ar.result();
if (response.statusCode() != 200) {
resultHandler.handle(VaultException.toFailure(response.statusMessage(), response.statusCode(),
response.bodyAsString()));
} else {
JsonObject object = response.bodyAsJsonObject();
Lookup lookup = object.getJsonObject("data").mapTo(Lookup.class);
resultHandler.handle(Future.succeededFuture(lookup));
}
});
}
代码示例来源:origin: vert-x3/vertx-config
completionHandler.handle(Future.failedFuture("Cannot retrieve the configmap or secret in namespace "
+ namespace + ": " + name + ", status code: " + response.statusCode() + ", error: "
+ response.bodyAsString()));
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testStreamHttpServerRequest() throws Exception {
Buffer expected = TestUtils.randomBuffer(10000);
HttpServer server2 = vertx.createHttpServer(new HttpServerOptions().setPort(8081)).requestHandler(req -> req.bodyHandler(body -> {
assertEquals(body, expected);
req.response().end();
}));
startServer(server2);
WebClient webClient = WebClient.create(vertx);
try {
server.requestHandler(req -> webClient.postAbs("http://localhost:8081/")
.sendStream(req, onSuccess(resp -> req.response().end("ok"))));
startServer();
webClient.post(8080, "localhost", "/").sendBuffer(expected, onSuccess(resp -> {
assertEquals("ok", resp.bodyAsString());
complete();
}));
await();
} finally {
server2.close();
}
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testSessionHeaders(TestContext context) {
String headerName = "x-client-header";
String headerVal = "MY-HEADER";
prepareServer(context, req -> {
req.response().setChunked(true);
if (headerVal.equals(req.getHeader(headerName))) {
req.response().write("OK");
} else {
req.response().write("ERR");
}
});
Async async = context.async();
client.addHeader(headerName, headerVal);
client.get("/").send(ar -> {
context.assertTrue(ar.succeeded());
HttpResponse<Buffer> res = ar.result();
context.assertEquals(200, res.statusCode());
context.assertEquals("OK", res.bodyAsString());
async.complete();
});
}
代码示例来源:origin: io.vertx/vertx-web-client
HttpResponse<Buffer> res = ar.result();
context.assertEquals(200, res.statusCode());
context.assertEquals("OK", res.bodyAsString());
async.countDown();
});
代码示例来源:origin: io.vertx/vertx-web-client
HttpResponse<Buffer> res = ar.result();
context.assertEquals(200, res.statusCode());
context.assertEquals("OK", res.bodyAsString());
async.complete();
});
内容来源于网络,如有侵权,请联系作者删除!