io.vertx.ext.web.client.HttpRequest.sendJsonObject()方法的使用及代码示例

x33g5p2x  于2022-01-20 转载在 其他  
字(7.9k)|赞(0)|评价(0)|浏览(127)

本文整理了Java中io.vertx.ext.web.client.HttpRequest.sendJsonObject()方法的一些代码示例,展示了HttpRequest.sendJsonObject()的具体用法。这些代码示例主要来源于Github/Stackoverflow/Maven等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.sendJsonObject()方法的具体详情如下:
包路径:io.vertx.ext.web.client.HttpRequest
类名称:HttpRequest
方法名:sendJsonObject

HttpRequest.sendJsonObject介绍

暂无

代码示例

代码示例来源:origin: io.vertx/vertx-rx-java

/**
 * Like {@link io.vertx.rxjava.ext.web.client.HttpRequest#send} but with an HTTP request <code>body</code> object encoded as json and the content type
 * set to <code>application/json</code>.
 * @param body the body
 * @param handler 
 */
public void sendJsonObject(JsonObject body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) { 
 delegate.sendJsonObject(body, new Handler<AsyncResult<io.vertx.ext.web.client.HttpResponse<T>>>() {
  public void handle(AsyncResult<io.vertx.ext.web.client.HttpResponse<T>> ar) {
   if (ar.succeeded()) {
    handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(ar.result(), __typeArg_0)));
   } else {
    handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
   }
  }
 });
}

代码示例来源:origin: vert-x3/vertx-rx

/**
 * Like {@link io.vertx.rxjava.ext.web.client.HttpRequest#send} but with an HTTP request <code>body</code> object encoded as json and the content type
 * set to <code>application/json</code>.
 * @param body the body
 * @param handler 
 */
public void sendJsonObject(JsonObject body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) { 
 delegate.sendJsonObject(body, new Handler<AsyncResult<io.vertx.ext.web.client.HttpResponse<T>>>() {
  public void handle(AsyncResult<io.vertx.ext.web.client.HttpResponse<T>> ar) {
   if (ar.succeeded()) {
    handler.handle(io.vertx.core.Future.succeededFuture(io.vertx.rxjava.ext.web.client.HttpResponse.newInstance(ar.result(), __typeArg_0)));
   } else {
    handler.handle(io.vertx.core.Future.failedFuture(ar.cause()));
   }
  }
 });
}

代码示例来源:origin: io.vertx/vertx-lang-groovy

public static void sendJsonObject(io.vertx.ext.web.client.HttpRequest<Object> j_receiver, java.util.Map<String, Object> body, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.web.client.HttpResponse<java.lang.Object>>> handler) {
 j_receiver.sendJsonObject(body != null ? io.vertx.core.impl.ConversionHelper.toJsonObject(body) : null,
  handler != null ? new io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.web.client.HttpResponse<java.lang.Object>>>() {
  public void handle(io.vertx.core.AsyncResult<io.vertx.ext.web.client.HttpResponse<java.lang.Object>> ar) {
   handler.handle(ar.map(event -> io.vertx.core.impl.ConversionHelper.fromObject(event)));
  }
 } : null);
}
public static void sendJson(io.vertx.ext.web.client.HttpRequest<Object> j_receiver, java.lang.Object body, io.vertx.core.Handler<io.vertx.core.AsyncResult<io.vertx.ext.web.client.HttpResponse<java.lang.Object>>> handler) {

代码示例来源:origin: vert-x3/vertx-config

/**
 * Logs in against the `userpass` backend.
 *
 * @param username      the username
 * @param password      the password
 * @param resultHandler the callback invoked with the result
 */
public void loginWithUserCredentials(String username, String password, Handler<AsyncResult<Auth>>
 resultHandler) {
 JsonObject payload = new JsonObject()
  .put("password", Objects.requireNonNull(password, "The password must not be null"));
 client.post("/v1/auth/userpass/login/" + Objects.requireNonNull(username, "The username must not be null"))
  .sendJsonObject(payload, ar -> {
   if (ar.failed()) {
    resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
    return;
   }
   manageAuthResult(resultHandler, ar.result());
  });
}

代码示例来源:origin: vert-x3/vertx-config

/**
 * Logs in against the `AppRole` backend.
 *
 * @param roleId        the role id
 * @param secretId      the secret id
 * @param resultHandler the callback invoked with the result
 */
public void loginWithAppRole(String roleId, String secretId, Handler<AsyncResult<Auth>>
 resultHandler) {
 JsonObject payload = new JsonObject()
  .put("role_id", Objects.requireNonNull(roleId, "The role must not be null"))
  .put("secret_id", Objects.requireNonNull(secretId, "The secret must not be null"));
 client.post("/v1/auth/approle/login")
  .sendJsonObject(payload, ar -> {
   if (ar.failed()) {
    resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
    return;
   }
   manageAuthResult(resultHandler, ar.result());
  });
}

代码示例来源:origin: vert-x3/vertx-config

/**
 * Renews the current token.
 *
 * @param leaseDurationInSecond the extension in second
 * @param resultHandler         the callback invoked with the result
 */
public void renewSelf(long leaseDurationInSecond, Handler<AsyncResult<Auth>> resultHandler) {
 JsonObject payload = null;
 if (leaseDurationInSecond > 0) {
  payload = new JsonObject().put("increment", leaseDurationInSecond);
 }
 HttpRequest<Buffer> request = client.post("/v1/auth/token/renew-self")
  .putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must not be null"));
 Handler<AsyncResult<HttpResponse<Buffer>>> handler = ar -> {
  if (ar.failed()) {
   resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
   return;
  }
  manageAuthResult(resultHandler, ar.result());
 };
 if (payload != null) {
  request.sendJsonObject(payload, handler);
 } else {
  request.send(handler);
 }
}

代码示例来源:origin: vert-x3/vertx-config

/**
 * Creates a new token.
 *
 * @param tokenRequest  the token request
 * @param resultHandler the callback invoked with the result.
 */
public void createToken(TokenRequest tokenRequest, Handler<AsyncResult<Auth>> resultHandler) {
 client.post("/v1/auth/token/create" + ((tokenRequest.getRole() == null) ? "" : "/" + tokenRequest.getRole()))
  .putHeader(TOKEN_HEADER, Objects.requireNonNull(getToken(), "The token must be set"))
  .sendJsonObject(tokenRequest.toPayload(), ar -> {
   if (ar.failed()) {
    resultHandler.handle(VaultException.toFailure("Unable to access the Vault", ar.cause()));
    return;
   }
   manageAuthResult(resultHandler, ar.result());
  });
}

代码示例来源: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: io.vertx/vertx-web-client

private void testSendBody(Object body, BiConsumer<String, Buffer> checker) throws Exception {
 waitFor(2);
 server.requestHandler(req -> req.bodyHandler(buff -> {
  checker.accept(req.getHeader("content-type"), buff);
  complete();
  req.response().end();
 }));
 startServer();
 HttpRequest<Buffer> post = client.post(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
 if (body instanceof Buffer) {
  post.sendBuffer((Buffer) body, onSuccess(resp -> complete()));
 } else if (body instanceof JsonObject) {
  post.sendJsonObject((JsonObject) body, onSuccess(resp -> complete()));
 } else {
  post.sendJson(body, onSuccess(resp -> complete()));
 }
 await();
}

代码示例来源:origin: io.vertx/vertx-web-client

req.sendForm(new CaseInsensitiveHeaders().add("a", "b"), handler);
req.sendJson("", handler);
req.sendJsonObject(new JsonObject(), handler);
req.sendMultipartForm(MultipartForm.create().attribute("a", "b"), handler);

相关文章