Search in sources :

Example 6 with HttpResponse

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();
}
Also used : HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) MalformedURLException(java.net.MalformedURLException) MosaicName(io.nem.sdk.model.mosaic.MosaicName) MosaicInfo(io.nem.sdk.model.mosaic.MosaicInfo) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) UInt64(io.nem.sdk.model.transaction.UInt64) List(java.util.List) PublicAccount(io.nem.sdk.model.account.PublicAccount) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) MosaicProperties(io.nem.sdk.model.mosaic.MosaicProperties) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Optional(java.util.Optional) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) MosaicId(io.nem.sdk.model.mosaic.MosaicId) MosaicId(io.nem.sdk.model.mosaic.MosaicId) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) MosaicName(io.nem.sdk.model.mosaic.MosaicName)

Example 7 with HttpResponse

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());
}
Also used : NamespaceInfo(io.nem.sdk.model.namespace.NamespaceInfo) NamespaceName(io.nem.sdk.model.namespace.NamespaceName) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) MalformedURLException(java.net.MalformedURLException) NamespaceType(io.nem.sdk.model.namespace.NamespaceType) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) UInt64(io.nem.sdk.model.transaction.UInt64) List(java.util.List) PublicAccount(io.nem.sdk.model.account.PublicAccount) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) Address(io.nem.sdk.model.account.Address) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Optional(java.util.Optional) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NetworkType(io.nem.sdk.model.blockchain.NetworkType) PublicAccount(io.nem.sdk.model.account.PublicAccount) JsonObject(io.vertx.core.json.JsonObject) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) ArrayList(java.util.ArrayList) List(java.util.List) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) NamespaceInfo(io.nem.sdk.model.namespace.NamespaceInfo)

Example 8 with HttpResponse

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();
}
Also used : NamespaceInfo(io.nem.sdk.model.namespace.NamespaceInfo) NamespaceName(io.nem.sdk.model.namespace.NamespaceName) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) MalformedURLException(java.net.MalformedURLException) NamespaceType(io.nem.sdk.model.namespace.NamespaceType) NetworkType(io.nem.sdk.model.blockchain.NetworkType) Collectors(java.util.stream.Collectors) ArrayList(java.util.ArrayList) UInt64(io.nem.sdk.model.transaction.UInt64) List(java.util.List) PublicAccount(io.nem.sdk.model.account.PublicAccount) BodyCodec(io.vertx.reactivex.ext.web.codec.BodyCodec) Address(io.nem.sdk.model.account.Address) NamespaceId(io.nem.sdk.model.namespace.NamespaceId) Optional(java.util.Optional) Observable(io.reactivex.Observable) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NamespaceName(io.nem.sdk.model.namespace.NamespaceName) JsonObject(io.vertx.core.json.JsonObject) TypeReference(com.fasterxml.jackson.core.type.TypeReference) NamespaceId(io.nem.sdk.model.namespace.NamespaceId)

Example 9 with HttpResponse

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()));
}
Also used : HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) WebClient(io.vertx.reactivex.ext.web.client.WebClient)

Example 10 with HttpResponse

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;
}
Also used : Buffer(io.vertx.reactivex.core.buffer.Buffer) HttpResponse(io.vertx.reactivex.ext.web.client.HttpResponse) ClientRequest(io.knotx.dataobjects.ClientRequest)

Aggregations

HttpResponse (io.vertx.reactivex.ext.web.client.HttpResponse)11 TypeReference (com.fasterxml.jackson.core.type.TypeReference)7 Observable (io.reactivex.Observable)7 JsonObject (io.vertx.core.json.JsonObject)7 BodyCodec (io.vertx.reactivex.ext.web.codec.BodyCodec)7 MalformedURLException (java.net.MalformedURLException)7 List (java.util.List)7 Collectors (java.util.stream.Collectors)7 NetworkType (io.nem.sdk.model.blockchain.NetworkType)5 Optional (java.util.Optional)5 PublicAccount (io.nem.sdk.model.account.PublicAccount)4 NamespaceId (io.nem.sdk.model.namespace.NamespaceId)4 UInt64 (io.nem.sdk.model.transaction.UInt64)4 MosaicId (io.nem.sdk.model.mosaic.MosaicId)3 JsonArray (io.vertx.core.json.JsonArray)3 Address (io.nem.sdk.model.account.Address)2 MosaicInfo (io.nem.sdk.model.mosaic.MosaicInfo)2 MosaicName (io.nem.sdk.model.mosaic.MosaicName)2 MosaicProperties (io.nem.sdk.model.mosaic.MosaicProperties)2 NamespaceInfo (io.nem.sdk.model.namespace.NamespaceInfo)2