Example usage for io.vertx.core.json JsonObject toBuffer

List of usage examples for io.vertx.core.json JsonObject toBuffer

Introduction

In this page you can find the example usage for io.vertx.core.json JsonObject toBuffer.

Prototype

public Buffer toBuffer() 

Source Link

Document

Encode this JSON object as buffer.

Usage

From source file:org.eclipse.hono.client.impl.TenantClientImpl.java

License:Open Source License

/**
 * {@inheritDoc}/*ww  w  .  j  a  v  a2 s.  c o m*/
 */
@Override
public final Future<TenantObject> get(final String tenantId) {

    final TriTuple<TenantAction, String, Object> key = TriTuple.of(TenantAction.get, tenantId, null);

    return getResponseFromCache(key).recover(t -> {
        final Future<TenantResult<TenantObject>> tenantResult = Future.future();
        final JsonObject payload = new JsonObject().put(TenantConstants.FIELD_PAYLOAD_TENANT_ID, tenantId);
        createAndSendRequest(TenantConstants.TenantAction.get.toString(),
                customizeRequestApplicationProperties(), payload.toBuffer(), tenantResult.completer(), key);
        return tenantResult;
    }).map(tenantResult -> {
        switch (tenantResult.getStatus()) {
        case HttpURLConnection.HTTP_OK:
            return tenantResult.getPayload();
        default:
            throw StatusCodeMapper.from(tenantResult);
        }
    });
}

From source file:org.eclipse.hono.client.impl.TenantClientImpl.java

License:Open Source License

/**
 * {@inheritDoc}//www. j  a  va2  s  . co m
 */
@Override
public final Future<TenantObject> get(final X500Principal subjectDn) {

    final TriTuple<TenantAction, X500Principal, Object> key = TriTuple.of(TenantAction.get, subjectDn, null);

    return getResponseFromCache(key).recover(t -> {
        final Future<TenantResult<TenantObject>> tenantResult = Future.future();
        final JsonObject payload = new JsonObject().put(TenantConstants.FIELD_PAYLOAD_SUBJECT_DN,
                subjectDn.getName(X500Principal.RFC2253));
        createAndSendRequest(TenantConstants.TenantAction.get.toString(),
                customizeRequestApplicationProperties(), payload.toBuffer(), tenantResult.completer(), key);
        return tenantResult;
    }).map(tenantResult -> {
        switch (tenantResult.getStatus()) {
        case HttpURLConnection.HTTP_OK:
            return tenantResult.getPayload();
        default:
            throw StatusCodeMapper.from(tenantResult);
        }
    });
}