@Override
  public void start() throws Exception {
    address = MQTTSession.ADDRESS;

    JsonObject conf = config();

    localBridgePort = conf.getInteger("local_bridge_port", 7007);
    idleTimeout = conf.getInteger("socket_idle_timeout", 120);
    ssl_cert_key = conf.getString("ssl_cert_key");
    ssl_cert = conf.getString("ssl_cert");
    ssl_trust = conf.getString("ssl_trust");

    // [WebSocket -> BUS] listen WebSocket publish to BUS
    HttpServerOptions opt =
        new HttpServerOptions()
            .setTcpKeepAlive(true)
            .setIdleTimeout(idleTimeout)
            .setPort(localBridgePort);

    if (ssl_cert_key != null && ssl_cert != null && ssl_trust != null) {
      opt.setSsl(true)
          .setClientAuth(ClientAuth.REQUIRED)
          .setPemKeyCertOptions(
              new PemKeyCertOptions().setKeyPath(ssl_cert_key).setCertPath(ssl_cert))
          .setPemTrustOptions(new PemTrustOptions().addCertPath(ssl_trust));
    }

    netServer = vertx.createHttpServer(opt);
    netServer
        .websocketHandler(
            sock -> {
              final EventBusWebsocketBridge ebnb =
                  new EventBusWebsocketBridge(sock, vertx.eventBus(), address);
              sock.closeHandler(
                  aVoid -> {
                    logger.info(
                        "Bridge Server - closed connection from client ip: "
                            + sock.remoteAddress());
                    ebnb.stop();
                  });
              sock.exceptionHandler(
                  throwable -> {
                    logger.error("Bridge Server - Exception: " + throwable.getMessage(), throwable);
                    ebnb.stop();
                  });

              logger.info("Bridge Server - new connection from client ip: " + sock.remoteAddress());

              RecordParser parser = ebnb.initialHandhakeProtocolParser();
              sock.handler(parser::handle);
            })
        .listen();
  }
Пример #2
0
  @Override
  public void onExecute(int what, JsonObject resultJO) {

    if (resultJO.containsKey("result_code") && resultJO.getInteger("result_code") == -1) {
      request.response().end(resultJO.toString());
      return;
    }
    JsonObject rs = new JsonObject();

    switch (what) {
      case WrapDAO.getSession:
        if (resultJO.getString("results").length() < 1) {
          rs.put("result_code", -1);
          rs.put("result_msg", "login please");
          request.response().end(rs.toString());
          break;
        }

        wrapDAO.getApp(this, Util.getUserId(params.getString("token")));
        break;

      case WrapDAO.getApp:
        rs.put("result_code", 0);
        rs.put("result_msg", "app list");
        rs.put("list_app", resultJO.getJsonArray("results"));
        request.response().end(rs.toString());
    }
  }
Пример #3
0
 VertxOptionsImpl(JsonObject json) {
   this.proxyOperationTimeout =
       json.getInteger("proxyOperationTimeout", DEFAULT_PROXYOPERATIONTIMEOUT);
   this.eventLoopPoolSize = json.getInteger("eventLoopPoolSize", DEFAULT_EVENTLOOPPOOLSIZE);
   this.workerPoolSize = json.getInteger("workerPoolSize", DEFAULT_WORKERPOOLSIZE);
   this.clustered = json.getBoolean("clustered", DEFAULT_CLUSTERED);
   this.clusterHost = json.getString("clusterHost", DEFAULT_CLUSTERHOST);
   this.clusterPort = json.getInteger("clusterPort", DEFAULT_CLUSTERPORT);
   this.internalBlockingPoolSize =
       json.getInteger("internalBlockingPoolSize", DEFAULT_INTERNALBLOCKINGPOOLSIZE);
   this.blockedThreadCheckPeriod =
       json.getLong("blockedThreadCheckPeriod", DEFAULT_BLOCKEDTHREADCHECKPERIOD);
   this.maxEventLoopExecuteTime =
       json.getLong("maxEventLoopExecuteTime", DEFAULT_MAXEVENTLOOPEXECUTETIME);
   this.maxWorkerExecuteTime = json.getLong("maxWorkerExecuteTime", DEFAULT_MAXWORKEREXECUTETIME);
   this.haEnabled = json.getBoolean("haEnabled", false);
   this.quorumSize = json.getInteger("quorumSize", DEFAULT_QUORUMSIZE);
   this.haGroup = json.getString("haGroup", null);
 }
Пример #4
0
  @Override
  public void onExecute(int what, JsonObject resultJO) {

    if (resultJO.containsKey("result_code") && resultJO.getInteger("result_code") == -1) {
      request.response().end(resultJO.toString());
      return;
    }
    JsonObject rs = new JsonObject();

    switch (what) {
      case Config.getSession:
        if (!resultJO.containsKey("result") || resultJO.getString("result") == null) {
          rs.put("result_code", -1);
          rs.put("result_msg", "로그인이 필요합니다.");
          request.response().end(rs.toString());
          break;
        }
        String user_info[] = resultJO.getString("result").split(",");
        String user_id = user_info[0];

        params.put("user_id", user_id);

        String query =
            String.format(
                "UPDATE app_user_list SET user_nick='%s' WHERE user_id='%s' and app_id='%s'",
                params.getString("user_nick"),
                params.getString("user_id"),
                params.getString("app_id"));
        insertCustomQuery(this, Config.setNickApp, query);

        break;

      case Config.setNickApp:
        String query2 =
            String.format(
                "UPDATE channel_user_list SET user_nick='%s' WHERE user_id='%s' and app_id='%s'",
                params.getString("user_nick"),
                params.getString("user_id"),
                params.getString("app_id"));
        insertCustomQuery(this, 100, query2);

        rs.put("result_code", 0);
        rs.put("result_msg", "닉네임을 변경하였습니다.");
        request.response().end(rs.toString());

        getRedis(this, Config.getRedis, "app:" + params.getString("user_id"));
        break;

      case Config.getRedis:
        JsonArray ja = new JsonArray(resultJO.getString("result"));
        for (int i = 0; i < ja.size(); i++) {
          if (params.getString("app_id").equals(ja.getJsonObject(i).getString("app_id"))) {
            JsonObject jo = ja.getJsonObject(i);
            jo.put("user_nick", params.getString("user_nick"));
            ja.remove(i);
            ja.add(jo);
          }
        }
        JsonObject table = new JsonObject();
        table.put("key", "app:" + Util.getUserId(params.getString("token")));
        table.put("value", ja.toString());
        setRedis(this, Config.setRedis, table);
        break;
    }
  }
Пример #5
0
 @CodeTranslate
 public void getIntegerFromIdentifier() throws Exception {
   JsonObject obj = new JsonObject().put("port", 8080);
   JsonTest.o = obj.getInteger("port");
 }