本文整理了Java中io.vertx.ext.web.client.HttpRequest.sendJson()
方法的一些代码示例,展示了HttpRequest.sendJson()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.sendJson()
方法的具体详情如下:
包路径:io.vertx.ext.web.client.HttpRequest
类名称:HttpRequest
方法名:sendJson
暂无
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
JsonObject user = new JsonObject()
.put("firstName", "Dale")
.put("lastName", "Cooper")
.put("male", true);
client.put(8080, "localhost", "/").sendJson(user, ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Got HTTP response with status " + response.statusCode());
} else {
ar.cause().printStackTrace();
}
});
}
}
代码示例来源: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: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
User user = new User();
user.firstName = "Dale";
user.lastName = "Cooper";
user.male = true;
client.put(8080, "localhost", "/").sendJson(user, ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Got HTTP response with status " + response.statusCode());
} else {
ar.cause().printStackTrace();
}
});
}
}
代码示例来源:origin: io.vertx/vertx-web-client
req.sendBuffer(Buffer.buffer(), handler);
req.sendForm(new CaseInsensitiveHeaders().add("a", "b"), handler);
req.sendJson("", handler);
req.sendJsonObject(new JsonObject(), handler);
req.sendMultipartForm(MultipartForm.create().attribute("a", "b"), handler);
代码示例来源: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 sendJson(Object body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) {
delegate.sendJson(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 sendJson(Object body, Handler<AsyncResult<io.vertx.rxjava.ext.web.client.HttpResponse<T>>> handler) {
delegate.sendJson(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 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) {
j_receiver.sendJson(io.vertx.core.impl.ConversionHelper.toObject(body),
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);
}
}
代码示例来源:origin: EnMasseProject/enmasse
/**
* Get all info about messaging client (stdOut, stdErr, code, isRunning)
*
* @param uuid client id
* @return
* @throws InterruptedException
* @throws ExecutionException
* @throws TimeoutException
*/
public JsonObject getClientInfo(String uuid) throws InterruptedException, ExecutionException, TimeoutException {
CompletableFuture<JsonObject> responsePromise = new CompletableFuture<>();
JsonObject request = new JsonObject();
request.put("id", uuid);
client.get(endpoint.getPort(), endpoint.getHost(), "")
.as(BodyCodec.jsonObject())
.timeout(120000)
.sendJson(request,
ar -> responseHandler(ar, responsePromise, HttpURLConnection.HTTP_OK, "Error getting messaging clients info"));
return responsePromise.get(150000, TimeUnit.SECONDS);
}
代码示例来源:origin: EnMasseProject/enmasse
/**
* Stop messaging client and get all informations about them (stdOut, stdErr, code, isRunning)
*
* @param uuid client id
* @return
* @throws InterruptedException
* @throws ExecutionException
* @throws TimeoutException
*/
public JsonObject stopClient(String uuid) throws InterruptedException, ExecutionException, TimeoutException {
CompletableFuture<JsonObject> responsePromise = new CompletableFuture<>();
JsonObject request = new JsonObject();
request.put("id", uuid);
client.delete(endpoint.getPort(), endpoint.getHost(), "")
.as(BodyCodec.jsonObject())
.timeout(120000)
.sendJson(request,
ar -> responseHandler(ar, responsePromise, HttpURLConnection.HTTP_OK, "Error removing messaging clients"));
return responsePromise.get(150000, TimeUnit.SECONDS);
}
内容来源于网络,如有侵权,请联系作者删除!