本文整理汇总了Java中io.vertx.ext.web.codec.BodyCodec类的典型用法代码示例。如果您正苦于以下问题:Java BodyCodec类的具体用法?Java BodyCodec怎么用?Java BodyCodec使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
BodyCodec类属于io.vertx.ext.web.codec包,在下文中一共展示了BodyCodec类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: buildRequest
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
private HttpRequest<JsonObject> buildRequest(String requestURI, RequestParameters parameters) {
HttpRequest<JsonObject> request = client.post(requestURI)
.as(BodyCodec.jsonObject())
.putHeader("Content-Type", "application/x-www-form-urlencoded;charset=UTF-8")
.setQueryParam("properties", parameters.getProperties().toString())
.setQueryParam("pipelineLanguage", parameters.getLanguage().name());
if (options.getUsername() != null && options.getPassword() != null) {
request.putHeader("Authorization",
"Basic " + Base64.getEncoder().encodeToString(String.join(":", options.getUsername(), options.getPassword()).getBytes()));
}
if (parameters.getPattern() != null) {
request.setQueryParam("pattern", parameters.getPattern())
.setQueryParam("filter", String.valueOf(parameters.isFilter()));
}
return request;
}
开发者ID:shikeio,项目名称:vertx-corenlp-client,代码行数:17,代码来源:CoreNLPClientImpl.java
示例2: getAddressSpace
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
/**
* get address space by address space name vie rest api
*
* @param name name of address space
* @return
* @throws InterruptedException
*/
public JsonObject getAddressSpace(String name) throws Exception {
CompletableFuture<JsonObject> responsePromise = new CompletableFuture<>();
return doRequestNTimes(initRetry, () -> {
client.get(endpoint.getPort(), endpoint.getHost(), addressSpacesPath + "/" + name)
.as(BodyCodec.jsonObject())
.putHeader(HttpHeaders.AUTHORIZATION.toString(), authzString)
.send(ar -> {
if (ar.succeeded()) {
responsePromise.complete(responseHandler(ar));
} else {
Logging.log.warn("Error when getting address space {}", name);
responsePromise.completeExceptionally(ar.cause());
}
});
return responsePromise.get(30, TimeUnit.SECONDS);
});
}
开发者ID:EnMasseProject,项目名称:enmasse,代码行数:25,代码来源:AddressApiClient.java
示例3: getValueForCompany
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
private Future<Double> getValueForCompany(WebClient client, String company, int numberOfShares) {
// Create the future object that will get the value once the value have been retrieved
Future<Double> future = Future.future();
//----
client.get("/?name=" + encode(company))
.as(BodyCodec.jsonObject())
.send(ar -> {
if (ar.succeeded()) {
HttpResponse<JsonObject> response = ar.result();
if (response.statusCode() == 200) {
double v = numberOfShares * response.body().getDouble("bid");
future.complete(v);
} else {
future.complete(0.0);
}
} else {
future.fail(ar.cause());
}
});
// ---
return future;
}
开发者ID:cescoffier,项目名称:vertx-microservices-workshop,代码行数:25,代码来源:PortfolioServiceImpl.java
示例4: testInsertion
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
@Test
public void testInsertion(TestContext tc) {
Async async = tc.async();
vertx.eventBus().publish("portfolio", createBuyOperation());
WebClient.create(vertx).get(8081, "localhost", "/")
.as(BodyCodec.jsonArray())
.send(tc.asyncAssertSuccess(response -> {
tc.assertEquals(response.statusCode(), 200);
tc.assertEquals(response.body().size(), 1);
async.complete();
}));
}
开发者ID:cescoffier,项目名称:vertx-microservices-workshop,代码行数:17,代码来源:AuditVerticleTest.java
示例5: receiveResponseAsJsonObject
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
public void receiveResponseAsJsonObject(WebClient client) {
client
.get(8080, "myserver.mycompany.com", "/some-uri")
.as(BodyCodec.jsonObject())
.send(ar -> {
if (ar.succeeded()) {
HttpResponse<JsonObject> response = ar.result();
JsonObject body = response.body();
System.out.println("Received response with status code" + response.statusCode() + " with body " + body);
} else {
System.out.println("Something went wrong " + ar.cause().getMessage());
}
});
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:17,代码来源:WebClientExamples.java
示例6: receiveResponseAsJsonPOJO
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
public void receiveResponseAsJsonPOJO(WebClient client) {
client
.get(8080, "myserver.mycompany.com", "/some-uri")
.as(BodyCodec.json(User.class))
.send(ar -> {
if (ar.succeeded()) {
HttpResponse<User> response = ar.result();
User user = response.body();
System.out.println("Received response with status code" + response.statusCode() + " with body " +
user.getFirstName() + " " + user.getLastName());
} else {
System.out.println("Something went wrong " + ar.cause().getMessage());
}
});
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:18,代码来源:WebClientExamples.java
示例7: HttpRequestImpl
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
HttpRequestImpl(WebClientImpl client, HttpMethod method, String protocol, boolean ssl, int port, String host, String
uri, BodyCodec<T> codec, WebClientOptions options) {
this.client = client;
this.method = method;
this.protocol = protocol;
this.codec = codec;
this.port = port;
this.host = host;
this.uri = uri;
this.ssl = ssl;
this.followRedirects = options.isFollowRedirects();
this.options = options;
if (options.isUserAgentEnabled()) {
headers = new CaseInsensitiveHeaders().add(HttpHeaders.USER_AGENT, options.getUserAgent());
}
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:17,代码来源:HttpRequestImpl.java
示例8: subscriptionFetch
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
private void subscriptionFetch() {
if (this.shuttingDown || this.shutdownCompleted) {
this.shutdownCompleted = true;
return;
}
this.logger.info("Fetch " + Utils.getDateString(new Date()));
final JsonArray body = this.getConnectBody();
final HttpRequest<Buffer> request = this.initWebPostRequest(Constants.URL_CONNECT);
request.as(BodyCodec.jsonArray()).sendJson(body, this::subscriptionResult);
}
开发者ID:Stwissel,项目名称:vertx-sfdc-platformevents,代码行数:12,代码来源:CometD.java
示例9: shouldFindAll
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
@Test
public void shouldFindAll(TestContext context) {
Async async = context.async();
webClient.get("/api/dependencies").as(BodyCodec.jsonArray()).send(response -> {
if (response.succeeded()) {
assertThat(response.result().statusCode(), is(200));
JsonArray payload = response.result().body();
assertThat(payload.size(), is(2));
async.complete();
} else {
context.fail(response.cause());
async.complete();
}
});
}
开发者ID:vert-x3,项目名称:vertx-starter,代码行数:16,代码来源:DependencyResourceIntTest.java
示例10: shouldFindAll
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
@Test
public void shouldFindAll(TestContext context) {
Async async = context.async();
webClient.get("/api/versions").as(BodyCodec.jsonArray()).send(response -> {
if (response.succeeded()) {
assertThat(response.result().statusCode(), is(200));
JsonArray payload = response.result().body();
assertThat(payload.size(), is(4));
async.complete();
} else {
context.fail(response.cause());
async.complete();
}
});
}
开发者ID:vert-x3,项目名称:vertx-starter,代码行数:16,代码来源:VersionResourceIntTest.java
示例11: testRecordCreation
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
@Test
public void testRecordCreation(TestContext testContext) {
Record record = HttpEndpoint.createRecord("some-name", "123.456.789.111", 80, null);
assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://123.456.789.111:80/");
record = HttpEndpoint.createRecord("some-name", "123.456.789.111", 80, "foo");
assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://123.456.789.111:80/foo");
record = HttpEndpoint.createRecord("some-name", "123.456.789.111", 80, "foo", new JsonObject().put("language", "en"));
assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://123.456.789.111:80/foo");
assertThat(record.getMetadata().getString("language")).isEqualTo("en");
record = HttpEndpoint.createRecord("some-name", "acme.org");
assertThat(record.getLocation().getString(Record.ENDPOINT)).isEqualTo("http://acme.org:80/");
SelfSignedCertificate selfSignedCertificate = SelfSignedCertificate.create();
vertx.createHttpServer(new HttpServerOptions()
.setHost("127.0.0.1")
.setSsl(true)
.setKeyCertOptions(selfSignedCertificate.keyCertOptions())
).requestHandler(request -> {
request.response().end(new JsonObject().put("url", request.absoluteURI()).encode());
}).listen(0, testContext.asyncAssertSuccess(server -> {
Record sslRecord = HttpEndpoint.createRecord("http-bin", true, "127.0.0.1", server.actualPort(), "/get", null);
ServiceReference reference = discovery.getReferenceWithConfiguration(sslRecord, new HttpClientOptions()
.setSsl(true)
.setTrustAll(true)
.setVerifyHost(false)
.toJson());
WebClient webClient = WebClient.wrap(reference.get());
webClient.get("/get").as(BodyCodec.jsonObject()).send(testContext.asyncAssertSuccess(resp -> {
assertEquals("https://127.0.0.1:" + server.actualPort() + "/get", resp.body().getString("url"));
}));
}));
}
开发者ID:vert-x3,项目名称:vertx-service-discovery,代码行数:38,代码来源:HttpEndpointTest.java
示例12: receiveResponseAsWriteStream
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
public void receiveResponseAsWriteStream(WebClient client, WriteStream<Buffer> writeStream) {
client
.get(8080, "myserver.mycompany.com", "/some-uri")
.as(BodyCodec.pipe(writeStream))
.send(ar -> {
if (ar.succeeded()) {
HttpResponse<Void> response = ar.result();
System.out.println("Received response with status code" + response.statusCode());
} else {
System.out.println("Something went wrong " + ar.cause().getMessage());
}
});
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:16,代码来源:WebClientExamples.java
示例13: receiveResponseAndDiscard
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
public void receiveResponseAndDiscard(WebClient client) {
client
.get(8080, "myserver.mycompany.com", "/some-uri")
.as(BodyCodec.none())
.send(ar -> {
if (ar.succeeded()) {
HttpResponse<Void> response = ar.result();
System.out.println("Received response with status code" + response.statusCode());
} else {
System.out.println("Something went wrong " + ar.cause().getMessage());
}
});
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:16,代码来源:WebClientExamples.java
示例14: testResponseBodyAsAsJsonObject
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
@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();
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:16,代码来源:WebClientTest.java
示例15: testResponseBodyAsAsJsonMapped
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
@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();
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:16,代码来源:WebClientTest.java
示例16: testResponseBodyAsAsJsonArray
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
@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();
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:16,代码来源:WebClientTest.java
示例17: testResponseBodyAsAsJsonArrayMapped
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
@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();
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:16,代码来源:WebClientTest.java
示例18: testResponseBodyDiscarded
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
@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();
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:15,代码来源:WebClientTest.java
示例19: testResponseBodyUnmarshallingError
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
@Test
public void testResponseBodyUnmarshallingError() throws Exception {
server.requestHandler(req -> req.response().end("not-json-object"));
startServer();
HttpRequest<Buffer> get = client.get(DEFAULT_HTTP_PORT, DEFAULT_HTTP_HOST, "/somepath");
get
.as(BodyCodec.jsonObject())
.send(onFailure(err -> {
assertTrue(err instanceof DecodeException);
testComplete();
}));
await();
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:14,代码来源:WebClientTest.java
示例20: testResponseMissingBody
import io.vertx.ext.web.codec.BodyCodec; //导入依赖的package包/类
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();
}
开发者ID:vert-x3,项目名称:vertx-web,代码行数:14,代码来源:WebClientTest.java
注:本文中的io.vertx.ext.web.codec.BodyCodec类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论