use of io.vertx.reactivex.ext.web.client.HttpResponse in project nem2-sdk-java by nemtech.
the class MosaicHttp method getMosaicNames.
@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(HttpResponse::body).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();
}
use of io.vertx.reactivex.ext.web.client.HttpResponse in project nem2-sdk-java by nemtech.
the class NamespaceHttp method getNamespacesFromAccounts.
private Observable<List<NamespaceInfo>> getNamespacesFromAccounts(List<Address> addresses, Optional<QueryParams> queryParams) {
JsonObject requestBody = new JsonObject();
requestBody.put("addresses", addresses.stream().map((address -> address.plain())).collect(Collectors.toList()));
Observable<NetworkType> networkTypeResolve = getNetworkTypeObservable();
return networkTypeResolve.flatMap(networkType -> this.client.postAbs(this.url + "/account/namespaces" + (queryParams.isPresent() ? queryParams.get().toUrl() : "")).as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<NamespaceInfoDTO>>readValue(json.toString(), new TypeReference<List<NamespaceInfoDTO>>() {
})).flatMapIterable(item -> item).map(namespaceInfoDTO -> new NamespaceInfo(namespaceInfoDTO.getMeta().isActive(), namespaceInfoDTO.getMeta().getIndex(), namespaceInfoDTO.getMeta().getId(), NamespaceType.rawValueOf(namespaceInfoDTO.getNamespace().getType()), namespaceInfoDTO.getNamespace().getDepth(), extractLevels(namespaceInfoDTO), new NamespaceId(namespaceInfoDTO.getNamespace().getParentId().extractIntArray()), new PublicAccount(namespaceInfoDTO.getNamespace().getOwner(), networkType), namespaceInfoDTO.getNamespace().getStartHeight().extractIntArray(), namespaceInfoDTO.getNamespace().getEndHeight().extractIntArray())).toList().toObservable());
}
use of io.vertx.reactivex.ext.web.client.HttpResponse in project nem2-sdk-java by nemtech.
the class NamespaceHttp method getNamespaceNames.
@Override
public Observable<List<NamespaceName>> getNamespaceNames(List<NamespaceId> namespaceIds) {
JsonObject requestBody = new JsonObject();
requestBody.put("namespaceIds", namespaceIds.stream().map(id -> UInt64.bigIntegerToHex(id.getId())).collect(Collectors.toList()));
return this.client.postAbs(this.url + "/namespace/names").as(BodyCodec.jsonArray()).rxSendJson(requestBody).toObservable().map(HttpResponse::body).map(json -> objectMapper.<List<NamespaceNameDTO>>readValue(json.toString(), new TypeReference<List<NamespaceNameDTO>>() {
})).flatMapIterable(item -> item).map(namespaceNameDTO -> {
if (namespaceNameDTO.getParentId() != null) {
return new NamespaceName(new NamespaceId(namespaceNameDTO.getNamespaceId().extractIntArray()), namespaceNameDTO.getName(), new NamespaceId(namespaceNameDTO.getParentId().extractIntArray()));
} else {
return new NamespaceName(new NamespaceId(namespaceNameDTO.getNamespaceId().extractIntArray()), namespaceNameDTO.getName());
}
}).toList().toObservable();
}
use of io.vertx.reactivex.ext.web.client.HttpResponse in project vertx-examples by vert-x3.
the class Client method start.
@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()));
}
use of io.vertx.reactivex.ext.web.client.HttpResponse in project knotx by Cognifide.
the class HttpClientFacade method callService.
private Single<HttpResponse<Buffer>> callService(Pair<ClientRequest, ServiceMetadata> serviceData, HttpMethod method) {
final Single<HttpResponse<Buffer>> httpResponse;
final ClientRequest serviceRequest = serviceData.getLeft();
final ServiceMetadata serviceMetadata = serviceData.getRight();
final HttpRequest<Buffer> request = webClient.request(method, serviceMetadata.getPort(), serviceMetadata.getDomain(), serviceRequest.getPath());
updateRequestQueryParams(request, serviceMetadata);
updateRequestHeaders(request, serviceRequest, serviceMetadata);
overrideRequestHeaders(request, serviceMetadata);
if (!serviceRequest.getFormAttributes().isEmpty()) {
httpResponse = request.rxSendForm(serviceRequest.getFormAttributes());
} else {
httpResponse = request.rxSend();
}
return httpResponse;
}
Aggregations