public BaseVO testConnection()

in backend/src/main/java/org/apache/iotdb/admin/controller/ConnectionController.java [94:126]


  public BaseVO testConnection(@RequestBody ConnectionDTO conn) throws BaseException {
    Socket socket = null;
    try {
      socket = new Socket();
      socket.connect(new InetSocketAddress(conn.getHost(), conn.getPort()), 5000);
    } catch (Exception e) {
      throw new BaseException(ErrorCode.TEST_CONN_FAIL, ErrorCode.TEST_CONN_FAIL_MSG);
    } finally {
      try {
        if (socket != null) {
          socket.close();
        }
      } catch (Exception e) {
        throw new BaseException(ErrorCode.TEST_CONN_FAIL, ErrorCode.TEST_CONN_FAIL_MSG);
      }
    }
    Session session = null;
    try {
      session = new Session(conn.getHost(), conn.getPort(), conn.getUsername(), conn.getPassword());
      session.open();
    } catch (Exception e) {
      throw new BaseException(ErrorCode.TEST_CONN_FAIL_PWD, ErrorCode.TEST_CONN_FAIL_PWD_MSG);
    } finally {
      try {
        if (session != null) {
          session.close();
        }
      } catch (Exception e) {
        throw new BaseException(ErrorCode.TEST_CONN_FAIL_PWD, ErrorCode.TEST_CONN_FAIL_PWD_MSG);
      }
    }
    return BaseVO.success("Connection successfully", null);
  }