Example usage for io.vertx.core.eventbus Message body

List of usage examples for io.vertx.core.eventbus Message body

Introduction

In this page you can find the example usage for io.vertx.core.eventbus Message body.

Prototype

@CacheReturn
T body();

Source Link

Document

The body of the message.

Usage

From source file:fr.wseduc.smsproxy.Sms.java

License:Apache License

@Override
public void handle(Message<JsonObject> message) {
    String action = message.body().getString("action", "");
    String providerName = message.body().getString("provider", "");

    SmsProvider provider = getService(providerName);
    if (provider == null) {
        sendError(message, "invalid.provider");
        return;/*from w  ww  .  ja v  a 2 s  .  c  o  m*/
    }

    switch (action) {
    case ("send-sms"):
        provider.sendSms(message);
        break;
    case ("get-info"):
        provider.getInfo(message);
        break;
    case ("ping"):
        sendOK(message);
    default:
        sendError(message, "invalid.action");
    }
}

From source file:fr.wseduc.webdav.WebDav.java

License:Apache License

@Override
public void handle(Message<JsonObject> message) {
    String action = message.body().getString("action", "");
    switch (action) {
    case "put":
        put(message);//from  ww  w.j ava 2  s .c o m
        break;
    default:
        sendError(message, "Invalid action.");
    }
}

From source file:fr.wseduc.webdav.WebDav.java

License:Apache License

private void put(Message<JsonObject> message) {
    String filePath = message.body().getString("file");
    if (filePath == null || filePath.trim().isEmpty()) {
        sendError(message, "Invalid file.");
        return;//from w w w.j  a  v a  2  s. co  m
    }
    FileInputStream fis;
    try {
        fis = new FileInputStream(filePath);
    } catch (FileNotFoundException e) {
        sendError(message, "Invalid file.", e);
        return;
    }
    String uri = message.body().getString("uri");
    Sardine sardine = getSardine(uri, message);
    if (sardine == null)
        return;
    try {
        sardine.put(uri, fis);
        sendOK(message);
    } catch (IOException e) {
        sendError(message, e.getMessage(), e);
    }
}

From source file:io.apiman.gateway.engine.vertxebinmemory.apis.EBRegistryProxyHandler.java

License:Apache License

@SuppressWarnings("nls")
default void listenProxyHandler() {
    System.out.println("Setting up a listener on " + address());

    vertx().eventBus().consumer(address(), (Message<JsonObject> message) -> {
        String uuid = message.body().getString("uuid");

        System.out.println("UUID == " + uuid + " vs " + uuid());

        if (shouldIgnore(uuid))
            return;

        String type = message.body().getString("type");
        String action = message.body().getString("action");
        String body = message.body().getString("body");

        switch (type) {
        case "client":
            Client app = Json.decodeValue(body, Client.class);

            if (action == "register") {
                registerClient(app);//from ww w  .j  a v a  2s. c om
            } else if (action == "unregister") {
                unregisterClient(app);
            }

            break;
        case "api":
            Api api = Json.decodeValue(body, Api.class);

            if (action == "publish") { //$NON-NLS-1$
                publishApi(api);
            } else if (action == "retire") {
                retireApi(api);
            }

            break;
        default:
            throw new IllegalStateException("Unknown type: " + type);
        }

    });
}

From source file:io.apiman.gateway.engine.vertxebinmemory.services.EBRegistryProxyHandler.java

License:Apache License

@SuppressWarnings("nls")
default void listenProxyHandler() {
    System.out.println("Setting up a listener on " + address());

    vertx().eventBus().consumer(address(), (Message<JsonObject> message) -> {
        String uuid = message.body().getString("uuid");

        System.out.println("UUID == " + uuid + " vs " + uuid());

        if (shouldIgnore(uuid))
            return;

        String type = message.body().getString("type");
        String action = message.body().getString("action");
        String body = message.body().getString("body");

        switch (type) {
        case "application":
            Application app = Json.decodeValue(body, Application.class);

            if (action == "register") {
                registerApplication(app);
            } else if (action == "unregister") {
                unregisterApplication(app);
            }/*from ww  w . j a v  a 2 s .c om*/

            break;
        case "service":
            Service svc = Json.decodeValue(body, Service.class);

            if (action == "publish") { //$NON-NLS-1$
                publishService(svc);
            } else if (action == "retire") {
                retireService(svc);
            }

            break;
        default:
            throw new IllegalStateException("Unknown type: " + type);
        }

    });
}

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

License:Apache License

@Override
public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }/*from  w w  w .  j  a v  a2s .c o m*/
    accessed();
    switch (action) {

    case "head": {
        service.head(json.getJsonObject("apiRequest") == null ? null
                : new io.apiman.gateway.platforms.vertx3.io.VertxApiRequest(json.getJsonObject("apiRequest")),
                createHandler(msg));
        break;
    }
    case "write": {
        service.write((java.lang.String) json.getValue("chunk"));
        break;
    }
    case "end": {
        service.end(createHandler(msg));
        close();
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

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

License:Apache License

@Override
public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }/*from   w  ww .j ava 2 s.com*/
    accessed();
    switch (action) {
    case "createIngestor": {
        service.createIngestor((java.lang.String) json.getValue("uuid"), res -> {
            if (res.failed()) {
                msg.fail(-1, res.cause().getMessage());
            } else {
                String proxyAddress = UUID.randomUUID().toString();
                ProxyHelper.registerService(IngestorToPolicyService.class, vertx, res.result(), proxyAddress,
                        false, timeoutSeconds);
                msg.reply(null, new DeliveryOptions().addHeader("proxyaddr", proxyAddress));
            }
        });
        break;
    }

    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

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

License:Apache License

@Override
public void handle(Message<JsonObject> msg) {
    JsonObject json = msg.body();
    String action = msg.headers().get("action");
    if (action == null) {
        throw new IllegalStateException("action not specified");
    }/*from  w  ww.  ja v  a 2  s.  c om*/
    accessed();
    switch (action) {

    case "head": {
        service.head(json.getJsonObject("apiResponse") == null ? null
                : new io.apiman.gateway.platforms.vertx3.io.VertxApiResponse(json.getJsonObject("apiResponse")),
                createHandler(msg));
        break;
    }
    case "write": {
        service.write((java.lang.String) json.getValue("chunk"));
        break;
    }
    case "end": {
        service.end(createHandler(msg));
        close();
        break;
    }
    case "policyFailure": {
        service.policyFailure(json.getJsonObject("policyFailure") == null ? null
                : new io.apiman.gateway.platforms.vertx3.io.VertxPolicyFailure(
                        json.getJsonObject("policyFailure")));
        break;
    }
    default: {
        throw new IllegalStateException("Invalid action: " + action);
    }
    }
}

From source file:io.engagingspaces.graphql.query.QueryableVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {/*from   ww  w  . j a  va 2  s  .  co  m*/
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {

        case "query": {
            service.query((java.lang.String) json.getValue("graphqlQuery"), res -> {
                if (res.failed()) {
                    if (res.cause() instanceof ServiceException) {
                        msg.reply(res.cause());
                    } else {
                        msg.reply(new ServiceException(-1, res.cause().getMessage()));
                    }
                } else {
                    msg.reply(res.result() == null ? null : res.result().toJson());
                }
            });
            break;
        }
        case "queryWithVariables": {
            service.queryWithVariables((java.lang.String) json.getValue("graphqlQuery"),
                    (io.vertx.core.json.JsonObject) json.getValue("variables"), res -> {
                        if (res.failed()) {
                            if (res.cause() instanceof ServiceException) {
                                msg.reply(res.cause());
                            } else {
                                msg.reply(new ServiceException(-1, res.cause().getMessage()));
                            }
                        } else {
                            msg.reply(res.result() == null ? null : res.result().toJson());
                        }
                    });
            break;
        }
        case "resolveType": {
            service.resolveType((java.lang.String) json.getValue("typeResolverId"),
                    (io.vertx.core.json.JsonObject) json.getValue("typeHolder"), createHandler(msg));
            break;
        }
        case "fetchData": {
            service.fetchData((java.lang.String) json.getValue("dataFetcherId"),
                    (io.vertx.core.json.JsonObject) json.getValue("dataFetchingEnvironment"),
                    createHandler(msg));
            break;
        }
        case "close": {
            service.close();
            close();
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}

From source file:io.github.pflima92.plyshare.common.configuration.ConfigurationProviderVertxProxyHandler.java

License:Apache License

public void handle(Message<JsonObject> msg) {
    try {//from  ww  w .ja v  a 2s  .c o m
        JsonObject json = msg.body();
        String action = msg.headers().get("action");
        if (action == null) {
            throw new IllegalStateException("action not specified");
        }
        accessed();
        switch (action) {
        case "getConfiguration": {
            service.getConfiguration((java.lang.String) json.getValue("name"), createHandler(msg));
            break;
        }
        default: {
            throw new IllegalStateException("Invalid action: " + action);
        }
        }
    } catch (Throwable t) {
        msg.reply(new ServiceException(500, t.getMessage()));
        throw t;
    }
}