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

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

Introduction

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

Prototype

public JsonObject() 

Source Link

Document

Create a new, empty instance

Usage

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

License:Apache License

public JsonObject toJson() {
    JsonObject asJson = new JsonObject();
    VertxServiceResponseConverter.toJson(this, asJson);
    return asJson;
}

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);
    }/*from www .  j a  v  a 2s .co  m*/
    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;//from  w  w  w .j a va 2s .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  a2s .  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.IngestorToPolicyServiceVertxEBProxy.java

License:Apache License

@Override
public void end(Handler<AsyncResult<Void>> resultHandler) {
    if (closed) {
        resultHandler.handle(Future.failedFuture(new IllegalStateException("Proxy is closed")));
        return;//from  ww  w .  jav  a  2  s .c o  m
    }
    closed = true;
    JsonObject _json = new JsonObject();
    DeliveryOptions _deliveryOptions = new DeliveryOptions();
    _deliveryOptions.addHeader("action", "end");
    _vertx.eventBus().<Void>send(_address, _json, _deliveryOptions, res -> {
        if (res.failed()) {
            resultHandler.handle(Future.failedFuture(res.cause()));
        } else {
            resultHandler.handle(Future.succeededFuture(res.result().body()));
        }
    });
}

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  ww w  .j ava  2s .c  o  m
    }
    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  w  w.  j  a v  a2s.  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");
    }/* www  .  ja  va 2  s.  c  o m*/
    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.apiman.test.common.echo.EchoServerVertx.java

License:Apache License

private HttpServerOptions getHttpServerOptions(String name) {
    HttpServerOptions options = new HttpServerOptions();
    HttpServerOptionsConverter.fromJson(config().getJsonObject(name, new JsonObject()), options);
    if (JdkSSLEngineOptions.isAlpnAvailable()) {
        options.setUseAlpn(true);//  w ww. ja  va  2s .c  om
    }
    return options;
}

From source file:io.apiman.test.common.echo.EchoServerVertx.java

License:Apache License

private JksOptions getJksOptions(String key, String defaultResource) {
    JsonObject config = config().getJsonObject(key, new JsonObject());
    JksOptions jksOptions = new JksOptions().setPassword(config.getString("password", "secret"))
            .setValue(getResource(config.getString("resourceName", defaultResource)));
    return jksOptions;
}