本文整理了Java中io.vertx.reactivex.ext.web.client.HttpRequest.as()
方法的一些代码示例,展示了HttpRequest.as()
的具体用法。这些代码示例主要来源于Github
/Stackoverflow
/Maven
等平台,是从一些精选项目中提取出来的代码,具有较强的参考意义,能在一定程度帮忙到你。HttpRequest.as()
方法的具体详情如下:
包路径:io.vertx.reactivex.ext.web.client.HttpRequest
类名称:HttpRequest
方法名:as
暂无
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
Single<HttpResponse<String>> request = client.get(8080, "localhost", "/")
.as(BodyCodec.string())
.rxSend();
// Fire the request
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
// Again
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
// And again
request.subscribe(resp -> System.out.println("Server content " + resp.body()));
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
WebClient client = WebClient.create(vertx);
Single<HttpResponse<Data>> request = client.get(8080, "localhost", "/")
.as(BodyCodec.json(Data.class))
.rxSend();
// Fire the request
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// Again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
// And again
request.subscribe(resp -> System.out.println("Server content " + resp.body().message));
}
}
代码示例来源:origin: vert-x3/vertx-examples
@Override
public void start() throws Exception {
// Create two requests
WebClient client = WebClient.create(vertx);
Single<JsonObject> request = client.get(8080, "localhost", "/")
.as(BodyCodec.jsonObject())
.rxSend()
.map(resp -> resp.body());
// Combine the responses with the zip into a single response
request
.zipWith(request, (b1, b2) -> new JsonObject().put("req1", b1).put("req2", b2))
.subscribe(json -> {
System.out.println("Got combined result " + json);
}, err -> {
err.printStackTrace();
});
}
}
代码示例来源:origin: nemtech/nem2-sdk-java
public Observable<NetworkType> getNetworkType() {
return this.client
.getAbs(this.url.toString())
.as(BodyCodec.jsonObject())
.rxSend()
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> json.getString("name"))
.map(name -> {
if (name.equalsIgnoreCase("mijinTest"))
return NetworkType.MIJIN_TEST;
else {
throw new IllegalArgumentException("network " + name + " is not supported yet by the sdk");
}
});
}
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<TransactionAnnounceResponse> announce(SignedTransaction signedTransaction) {
JsonObject requestBody = new JsonObject();
requestBody.put("payload", signedTransaction.getPayload());
return this.client
.putAbs(this.url.toString())
.as(BodyCodec.jsonObject())
.rxSendJson(requestBody)
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> new TransactionAnnounceResponse(new JsonObject(json.toString()).getString("message")));
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<TransactionAnnounceResponse> announceAggregateBonded(SignedTransaction signedTransaction) {
JsonObject requestBody = new JsonObject();
requestBody.put("payload", signedTransaction.getPayload());
return this.client
.putAbs(this.url + "/partial")
.as(BodyCodec.jsonObject())
.rxSendJson(requestBody)
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> new TransactionAnnounceResponse(new JsonObject(json.toString()).getString("message")));
}
代码示例来源:origin: nemtech/nem2-sdk-java
public Observable<BigInteger> getBlockchainScore() {
return this.client
.getAbs(this.url + "/chain/score")
.as(BodyCodec.jsonObject())
.rxSend()
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> objectMapper.readValue(json.toString(), BlockchainScoreDTO.class))
.map(blockchainScoreDTO -> blockchainScoreDTO.extractIntArray());
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<Transaction> getTransaction(String transactionHash) {
return this.client
.getAbs(this.url + transactionHash)
.as(BodyCodec.jsonObject())
.rxSend()
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> new JsonObject(json.toString()))
.map(new TransactionMapping());
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<TransactionAnnounceResponse> announceAggregateBondedCosignature(CosignatureSignedTransaction cosignatureSignedTransaction) {
JsonObject requestBody = new JsonObject();
requestBody.put("parentHash", cosignatureSignedTransaction.getParentHash());
requestBody.put("signature", cosignatureSignedTransaction.getSignature());
requestBody.put("signer", cosignatureSignedTransaction.getSigner());
return this.client
.putAbs(this.url + "/cosignature")
.as(BodyCodec.jsonObject())
.rxSendJson(requestBody)
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> new TransactionAnnounceResponse(new JsonObject(json.toString()).getString("message")));
}
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<BigInteger> getBlockchainHeight() {
return this.client
.getAbs(this.url + "/chain/height")
.as(BodyCodec.jsonObject())
.rxSend()
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> objectMapper.readValue(json.toString(), HeightDTO.class))
.map(blockchainHeight -> blockchainHeight.getHeight().extractIntArray());
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<List<Transaction>> getTransactions(List<String> transactionHashes) {
JsonObject requestBody = new JsonObject();
requestBody.put("transactionIds", transactionHashes);
return this.client
.postAbs(this.url.toString())
.as(BodyCodec.jsonArray())
.rxSendJson(requestBody)
.toObservable()
.map(Http::mapJsonArrayOrError)
.map(json -> new JsonArray(json.toString()).stream().map(s -> (JsonObject) s).collect(Collectors.toList()))
.flatMapIterable(item -> item)
.map(new TransactionMapping())
.toList()
.toObservable();
}
代码示例来源:origin: nemtech/nem2-sdk-java
private Observable<List<Transaction>> getBlockTransactions(BigInteger height, Optional<QueryParams> queryParams) {
return this.client
.getAbs(this.url + "/block/" + height + "/transactions" + (queryParams.isPresent() ? queryParams.get().toUrl() : ""))
.as(BodyCodec.jsonArray())
.rxSend()
.toObservable()
.map(Http::mapJsonArrayOrError)
.map(json -> new JsonArray(json.toString()).stream().map(s -> (JsonObject) s).collect(Collectors.toList()))
.flatMapIterable(item -> item)
.map(new TransactionMapping())
.toList()
.toObservable();
}
代码示例来源:origin: nemtech/nem2-sdk-java
private Observable<List<Transaction>> findTransactions(PublicAccount publicAccount, Optional<QueryParams> queryParams, String path) {
return this.client
.getAbs(this.url + publicAccount.getPublicKey() + path + (queryParams.isPresent() ? queryParams.get().toUrl() : ""))
.as(BodyCodec.jsonArray())
.rxSend()
.toObservable()
.map(Http::mapJsonArrayOrError)
.map(json -> new JsonArray(json.toString()).stream().map(s -> (JsonObject) s).collect(Collectors.toList()))
.flatMapIterable(item -> item)
.map(new TransactionMapping())
.toList()
.toObservable();
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<MultisigAccountInfo> getMultisigAccountInfo(Address address) {
Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable();
return networkTypeResolve
.flatMap(networkType -> this.client
.getAbs(this.url + address.plain() + "/multisig")
.as(BodyCodec.jsonObject())
.rxSend()
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> objectMapper.readValue(json.toString(), MultisigAccountInfoDTO.class))
.map(MultisigAccountInfoDTO::getMultisig)
.map(transfromMultisigAccountInfoDTO(networkType)));
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<BlockchainStorageInfo> getBlockchainStorage() {
return this.client
.getAbs(this.url + "/diagnostic/storage")
.as(BodyCodec.jsonObject())
.rxSend()
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> objectMapper.readValue(json.toString(), BlockchainStorageInfoDTO.class))
.map(blockchainStorageInfoDTO -> new BlockchainStorageInfo(blockchainStorageInfoDTO.getNumAccounts(),
blockchainStorageInfoDTO.getNumBlocks(),
blockchainStorageInfoDTO.getNumBlocks()));
}
}
代码示例来源:origin: tsegismont/vertx-musicstore
private Single<Buffer> sendGetRequest(String mbAlbumId) {
return webClient
.getAbs("http://coverartarchive.org")
.uri("/release/" + mbAlbumId + "/front")
.as(BodyCodec.buffer())
.rxSend()
.map(HttpResponse::body);
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<List<MosaicName>> getMosaicNames(List<MosaicId> mosaicIds) {
JsonObject requestBody = new JsonObject();
requestBody.put("mosaicIds", mosaicIds.stream().map(id -> UInt64.bigIntegerToHex(id.getId())).collect(Collectors.toList()));
return this.client
.postAbs(this.url + "/mosaic/names")
.as(BodyCodec.jsonArray())
.rxSendJson(requestBody)
.toObservable()
.map(Http::mapJsonArrayOrError)
.map(json -> objectMapper.<List<MosaicNameDTO>>readValue(json.toString(), new TypeReference<List<MosaicNameDTO>>() {
}))
.flatMapIterable(item -> item)
.map(mosaicNameDTO -> new MosaicName(new MosaicId(mosaicNameDTO.getMosaicId().extractIntArray()),
mosaicNameDTO.getName(),
new NamespaceId(mosaicNameDTO.getParentId().extractIntArray())))
.toList()
.toObservable();
}
代码示例来源:origin: nemtech/nem2-sdk-java
@Override
public Observable<TransactionStatus> getTransactionStatus(String transactionHash) {
return this.client
.getAbs(this.url + transactionHash + "/status")
.as(BodyCodec.jsonObject())
.rxSend()
.toObservable()
.map(Http::mapJsonObjectOrError)
.map(json -> objectMapper.readValue(json.toString(), TransactionStatusDTO.class))
.map(transactionStatusDTO -> new TransactionStatus(transactionStatusDTO.getGroup(),
transactionStatusDTO.getStatus(),
transactionStatusDTO.getHash(),
new Deadline(transactionStatusDTO.getDeadline().extractIntArray()),
transactionStatusDTO.getHeight().extractIntArray()));
}
代码示例来源:origin: io.vertx/vertx-rx-java2
@Test
public void testErrorHandling() throws Exception {
try {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Single<HttpResponse<WineAndCheese>> single = client
.get(-1, "localhost", "/the_uri")
.as(BodyCodec.json(WineAndCheese.class))
.rxSend();
single.subscribe(resp -> fail(), error -> {
assertEquals(IllegalArgumentException.class, error.getClass());
testComplete();
});
await();
} catch (Throwable t) {
fail();
}
}
}
代码示例来源:origin: io.vertx/vertx-rx-java2
@Test
public void testResponseBodyAsAsJsonMapped() throws Exception {
JsonObject expected = new JsonObject().put("cheese", "Goat Cheese").put("wine", "Condrieu");
HttpServer server = vertx.createHttpServer(new HttpServerOptions().setPort(8080));
server.requestStream().handler(req -> req.response().end(expected.encode()));
try {
server.listen(ar -> {
client = WebClient.wrap(vertx.createHttpClient(new HttpClientOptions()));
Single<HttpResponse<WineAndCheese>> single = client
.get(8080, "localhost", "/the_uri")
.as(BodyCodec.json(WineAndCheese.class))
.rxSend();
single.subscribe(resp -> {
assertEquals(200, resp.statusCode());
assertEquals(new WineAndCheese().setCheese("Goat Cheese").setWine("Condrieu"), resp.body());
testComplete();
}, this::fail);
});
await();
} finally {
server.close();
}
}
内容来源于网络,如有侵权,请联系作者删除!