Exemplo n.º 1
0
  private void checkAndSend(
      boolean send,
      final String address,
      Object body,
      final SockJSSocket sock,
      final String replyAddress) {
    final Handler<Message> replyHandler;
    if (replyAddress != null) {

      replyHandler =
          new Handler<Message>() {
            public void handle(Message message) {
              // Note we don't check outbound matches for replies
              // Replies are always let through if the original message
              // was approved
              checkAddAccceptedReplyAddress(message.replyAddress);
              deliverMessage(sock, replyAddress, message);
            }
          };
    } else {
      replyHandler = null;
    }
    if (log.isDebugEnabled()) {
      log.debug("Forwarding message to address " + address + " on event bus");
    }
    if (send) {
      eb.send(address, body, replyHandler);
    } else {
      eb.publish(address, body);
    }
  }
Exemplo n.º 2
0
 private void doSendOrPub(
     final boolean send, final SockJSSocket sock, final String address, final JsonObject message) {
   final Object body = getMandatoryValue(message, "body");
   final String replyAddress = message.getString("replyAddress");
   if (log.isDebugEnabled()) {
     log.debug("Received msg from client in bridge. address:" + address + " message:" + body);
   }
   Match curMatch = checkMatches(true, address, body);
   if (curMatch.doesMatch) {
     if (curMatch.requiresAuth) {
       final String sessionID = message.getString("sessionID");
       if (sessionID != null) {
         authorise(
             message,
             sessionID,
             new AsyncResultHandler<Boolean>() {
               public void handle(AsyncResult<Boolean> res) {
                 if (res.succeeded()) {
                   if (res.result) {
                     cacheAuthorisation(sessionID, sock);
                     checkAndSend(send, address, body, sock, replyAddress);
                   } else {
                     log.debug(
                         "Inbound message for address "
                             + address
                             + " rejected because sessionID is not authorised");
                   }
                 } else {
                   log.error("Error in performing authorisation", res.exception);
                 }
               }
             });
       } else {
         log.debug(
             "Inbound message for address "
                 + address
                 + " rejected because it requires auth and sessionID is missing");
       }
     } else {
       checkAndSend(send, address, body, sock, replyAddress);
     }
   } else {
     log.debug("Inbound message for address " + address + " rejected because there is no match");
   }
 }
Exemplo n.º 3
0
        @Override
        public void handle(Message<JsonObject> message) {
          if (log.isDebugEnabled()) {
            log.debug(
                String.format(
                    "%s - Received message %s", DefaultGroupManager.this, message.body().encode()));
          }

          String action = message.body().getString("action");
          if (action != null) {
            switch (action) {
              case "ping":
                doPing(message);
                break;
              case "find":
                doFind(message);
                break;
              case "list":
                doList(message);
                break;
              case "select":
                doSelect(message);
                break;
              case "deploy":
                doDeploy(message);
                break;
              case "undeploy":
                doUndeploy(message);
                break;
              default:
                message.reply(
                    new JsonObject()
                        .putString("status", "error")
                        .putString("message", "Invalid action " + action));
                break;
            }
          } else {
            message.reply(
                new JsonObject()
                    .putString("status", "error")
                    .putString("message", "Must specify an action"));
          }
        }