本文整理了Java中io.vertx.ext.web.client.HttpResponse.statusCode()
方法的一些代码示例,展示了HttpResponse.statusCode()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpResponse.statusCode()
方法的具体详情如下:
包路径:io.vertx.ext.web.client.HttpResponse
类名称:HttpResponse
方法名:statusCode
暂无
代码示例来源: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: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
Buffer body = Buffer.buffer("Hello World");
client.put(8080, "localhost", "/").sendBuffer(body, ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Got HTTP response with status " + response.statusCode());
} else {
ar.cause().printStackTrace();
}
});
}
}
代码示例来源: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);
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: 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", "/")
.addQueryParam("firstName", "Dale")
.addQueryParam("lastName", "Cooper")
.addQueryParam("male", "true")
.send(ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Got HTTP response with status " + response.statusCode());
} else {
ar.cause().printStackTrace();
}
});
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
MultiMap form = MultiMap.caseInsensitiveMultiMap();
form.add("firstName", "Dale");
form.add("lastName", "Cooper");
form.add("male", "true");
client.post(8080, "localhost", "/").sendForm(form, ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Got HTTP response with status " + response.statusCode());
} else {
ar.cause().printStackTrace();
}
});
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
String filename = "upload.txt";
FileSystem fs = vertx.fileSystem();
WebClient client = WebClient.create(vertx);
fs.props(filename, ares -> {
FileProps props = ares.result();
System.out.println("props is " + props);
long size = props.size();
HttpRequest<Buffer> req = client.put(8080, "localhost", "/");
req.putHeader("content-length", "" + size);
fs.open(filename, new OpenOptions(), ares2 -> {
req.sendStream(ares2.result(), ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Got HTTP response with status " + response.statusCode());
} else {
ar.cause().printStackTrace();
}
});
});
});
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
MultiMap form = MultiMap.caseInsensitiveMultiMap();
form.add("firstName", "Dale");
form.add("lastName", "Cooper");
form.add("male", "true");
client
.post(8080, "localhost", "/")
.putHeader("content-type", "multipart/form-data")
.sendForm(form, ar -> {
if (ar.succeeded()) {
HttpResponse<Buffer> response = ar.result();
System.out.println("Got HTTP response with status " + response.statusCode());
} else {
ar.cause().printStackTrace();
}
});
}
}
代码示例来源:origin: vert-x3/vertx-examples
.send(authHandler -> {
if (authHandler.succeeded() && 200 == authHandler.result().statusCode()) {
JsonObject authJson = authHandler.result().body();
String accessToken = authJson.getString("access_token");
.putHeader("Authorization", header)
.send(handler -> {
if (handler.succeeded() && 200 == handler.result().statusCode()) {
System.out.println(handler.result().body());
} else {
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
// Create the web client and enable SSL/TLS with a trust store
WebClient client = WebClient.create(vertx,
new WebClientOptions()
.setSsl(true)
.setTrustStoreOptions(new JksOptions()
.setPath("client-truststore.jks")
.setPassword("wibble")
)
);
client.get(8443, "localhost", "/")
.send(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-rx-java
/**
* @return the status code of the response
*/
public int statusCode() {
if (cached_1 != null) {
return cached_1;
}
int ret = delegate.statusCode();
cached_1 = ret;
return ret;
}
代码示例来源:origin: vert-x3/vertx-rx
/**
* @return the status code of the response
*/
public int statusCode() {
if (cached_1 != null) {
return cached_1;
}
int ret = delegate.statusCode();
cached_1 = ret;
return ret;
}
代码示例来源: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: io.vertx/vertx-consul-client
@Override
public ConsulClient getKeysWithOptions(String keyPrefix, BlockingQueryOptions options, Handler<AsyncResult<List<String>>> resultHandler) {
Query query = Query.of("recurse", true).put("keys", true).put(options);
request(KV_VALID_CODES, HttpMethod.GET, "/v1/kv/" + urlEncode(keyPrefix), query, null, resultHandler, resp -> {
if (resp.statusCode() == HttpResponseStatus.NOT_FOUND.code()) {
return new ArrayList<>();
} else {
return resp.bodyAsJsonArray().stream().map(Object::toString).collect(Collectors.toList());
}
});
return this;
}
代码示例来源:origin: io.vertx/vertx-consul-client
@Override
public ConsulClient getValueWithOptions(String key, BlockingQueryOptions options, Handler<AsyncResult<KeyValue>> resultHandler) {
request(KV_VALID_CODES, HttpMethod.GET, "/v1/kv/" + urlEncode(key), new Query().put(options), null, resultHandler, resp -> {
if (resp.statusCode() == HttpResponseStatus.NOT_FOUND.code()) {
return new KeyValue();
} else {
return KVParser.parse(resp.bodyAsJsonArray().getJsonObject(0));
}
});
return this;
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testResponseUnknownContentTypeBodyAsJsonObject() 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.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(expected, resp.bodyAsJsonObject());
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testResponseUnknownContentTypeBodyAsJsonMapped() 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.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.bodyAsJson(WineAndCheese.class));
testComplete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testMutateResponseInterceptor() throws Exception {
server.requestHandler(req -> req.response().setStatusCode(500).end());
startServer();
client.addInterceptor(this::mutateResponseHandler);
HttpRequest<Buffer> builder = client.get("/somepath");
builder.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
complete();
}));
await();
}
代码示例来源:origin: io.vertx/vertx-web-client
@Test
public void testCacheInterceptor() throws Exception {
server.requestHandler(req -> fail());
startServer();
client.addInterceptor(this::cacheInterceptorHandler);
HttpRequest<Buffer> builder = client.get("/somepath").host("localhost").port(8080);
builder.send(onSuccess(resp -> {
assertEquals(200, resp.statusCode());
complete();
}));
await();
}
内容来源于网络,如有侵权,请联系作者删除!