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

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

Introduction

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

Prototype

public JsonObject put(String key, Object value) 

Source Link

Document

Put an Object into the JSON object with the specified key.

Usage

From source file:io.apiman.gateway.platforms.vertx3.io.VertxServiceRequestConverter.java

License:Apache License

public static void toJson(VertxServiceRequest obj, JsonObject json) {
    if (obj.getApiKey() != null) {
        json.put("apiKey", obj.getApiKey());
    }// w  ww  . jav a 2s.  c o m
    if (obj.getDestination() != null) {
        json.put("destination", obj.getDestination());
    }
    if (obj.getHeaders() != null) {
        JsonObject map = new JsonObject();
        obj.getHeaders().forEach((key, value) -> map.put(key, value));
        json.put("headers", map);
    }
    if (obj.getQueryParams() != null) {
        JsonObject map = new JsonObject();
        obj.getQueryParams().forEach((key, value) -> map.put(key, value));
        json.put("queryParams", map);
    }
    if (obj.getRawRequest() != null) {
        json.put("rawRequest", obj.getRawRequest());
    }
    if (obj.getRemoteAddr() != null) {
        json.put("remoteAddr", obj.getRemoteAddr());
    }
    if (obj.getServiceId() != null) {
        json.put("serviceId", obj.getServiceId());
    }
    if (obj.getServiceOrgId() != null) {
        json.put("serviceOrgId", obj.getServiceOrgId());
    }
    if (obj.getServiceVersion() != null) {
        json.put("serviceVersion", obj.getServiceVersion());
    }
    json.put("transportSecure", obj.isTransportSecure());
    if (obj.getType() != null) {
        json.put("type", obj.getType());
    }
}

From source file:io.apiman.gateway.platforms.vertx3.io.VertxServiceResponseConverter.java

License:Apache License

public static void toJson(VertxServiceResponse obj, JsonObject json) {
    if (obj.getAttributes() != null) {
        JsonObject map = new JsonObject();
        obj.getAttributes().forEach((key, value) -> map.put(key, value));
        json.put("attributes", map);
    }// ww w .  j av  a2s. c  om
    json.put("code", obj.getCode());
    if (obj.getHeaders() != null) {
        JsonObject map = new JsonObject();
        obj.getHeaders().forEach((key, value) -> map.put(key, value));
        json.put("headers", map);
    }
    if (obj.getMessage() != null) {
        json.put("message", obj.getMessage());
    }
}

From source file:io.apiman.gateway.platforms.vertx3.services.IngestorToPolicyServiceVertxEBProxy.java

License:Apache License

@Override
public void head(VertxApiRequest apiRequest, Handler<AsyncResult<Boolean>> readyHandler) {
    if (closed) {
        readyHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;/* ww w  .j  a  v  a 2  s  .co m*/
    }
    JsonObject _json = new JsonObject();
    _json.put("apiRequest", apiRequest == null ? null : apiRequest.toJson());
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "head");
    _vertx.eventBus().<Boolean>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            readyHandler.handle(Future.failedFuture(res.cause()));
        } else {
            readyHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:io.apiman.gateway.platforms.vertx3.services.IngestorToPolicyServiceVertxEBProxy.java

License:Apache License

@Override
public void write(String chunk) {
    if (closed) {
        throw new IllegalStateException("Proxy is closed");
    }/*from w  ww. j a  v  a 2 s.c  o  m*/
    JsonObject _json = new JsonObject();
    _json.put("chunk", chunk);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "write");
    _vertx.eventBus().send(_address, _json, _deliveryOptions);
}

From source file:io.apiman.gateway.platforms.vertx3.services.InitializeIngestorServiceVertxEBProxy.java

License:Apache License

@Override
public void createIngestor(String uuid, Handler<AsyncResult<IngestorToPolicyService>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//from w w w  .j  ava 2  s  .c  om
    }
    JsonObject _json = new JsonObject();
    _json.put("uuid", uuid);
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "createIngestor");
    _vertx.eventBus().<IngestorToPolicyService>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            resultHandler.handle(Future.failedFuture(res.cause()));
        } else {
            String addr = res.result().headers().get("proxyaddr");
            resultHandler.handle(Future
                    .succeededFuture(ProxyHelper.createProxy(IngestorToPolicyService.class, _vertx, addr)));
        }
    });
}

From source file:io.apiman.gateway.platforms.vertx3.services.PolicyToIngestorServiceVertxEBProxy.java

License:Apache License

@Override
public void head(VertxApiResponse apiResponse, Handler<AsyncResult<Void>> readyHandler) {
    if (closed) {
        readyHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//w ww  .j  a  va  2s  . c  o m
    }
    JsonObject _json = new JsonObject();
    _json.put("apiResponse", apiResponse == null ? null : apiResponse.toJson());
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "head");
    _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            readyHandler.handle(Future.failedFuture(res.cause()));
        } else {
            readyHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

From source file:io.apiman.gateway.platforms.vertx3.services.PolicyToIngestorServiceVertxEBProxy.java

License:Apache License

@Override
public void policyFailure(VertxPolicyFailure policyFailure) {
    if (closed) {
        throw new IllegalStateException("Proxy is closed");
    }//from w w w .j  ava  2  s.c  om
    JsonObject _json = new JsonObject();
    _json.put("policyFailure", policyFailure == null ? null : policyFailure.toJson());
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "policyFailure");
    _vertx.eventBus().send(_address, _json, _deliveryOptions);
}

From source file:io.engagingspaces.graphql.marshaller.schema.decorators.GraphQLSchemaDO.java

License:Open Source License

private void marshallTypes(JsonObject schemaJson) {
    JsonObject types = new JsonObject();
    JsonObject interfaces = new JsonObject();

    getAllTypesAsList().stream().filter(shouldIncludeIntrospectionTypes)
            .filter(type -> !(type instanceof GraphQLScalarType)).map(context::marshall).forEach(type -> {
                if (GraphQLInterfaceType.class.getName().equals(type.getString(MARSHALED_TYPE))) {
                    interfaces.put(type.getString(NAME), type);
                } else {
                    types.put(type.getString(NAME), type);
                }//from  w w w .  j  a v a 2  s.  c o  m
            });
    schemaJson.put(SCHEMA_TYPES, types);
    schemaJson.put(SCHEMA_INTERFACES, interfaces);
}

From source file:io.engagingspaces.graphql.marshaller.schema.decorators.GraphQLSchemaDO.java

License:Open Source License

private void marshallTypeResolvers(JsonObject schemaJson) {
    if (!context.getTypeResolvers().isEmpty()) {
        JsonObject resolvers = new JsonObject();
        context.getTypeResolvers().entrySet()
                .forEach(entry -> resolvers.put(entry.getKey(), context.marshall(entry.getValue())));
        schemaJson.put(TYPE_RESOLVERS, resolvers);
    }//from  ww  w  .j  a va  2  s.c  o m
}

From source file:io.engagingspaces.graphql.marshaller.schema.decorators.GraphQLSchemaDO.java

License:Open Source License

private void marshallDataFetchers(JsonObject schemaJson) {
    if (!context.getDataFetchers().isEmpty()) {
        JsonObject fetchers = new JsonObject();
        context.getDataFetchers().entrySet()
                .forEach(entry -> fetchers.put(entry.getKey(), context.marshall(entry.getValue())));
        schemaJson.put(DATA_FETCHERS, fetchers);
    }//from  w w  w .jav  a 2 s  . c om

}