Пример #1
0
  /**
   * Connects to a remote server.
   *
   * @param iUserName Server's user name
   * @param iUserPassword Server's password for the user name used
   * @return The instance itself. Useful to execute method in chain
   * @throws IOException
   */
  public synchronized OServerAdmin connect(final String iUserName, final String iUserPassword)
      throws IOException {
    networkAdminOperation(
        new OStorageRemoteOperation<Void>() {
          @Override
          public Void execute(OChannelBinaryAsynchClient network, OStorageRemoteSession session)
              throws IOException {
            OStorageRemoteNodeSession nodeSession =
                storage.getCurrentSession().getOrCreate(network.getServerURL());
            try {
              storage.beginRequest(network, OChannelBinaryProtocol.REQUEST_CONNECT, session);

              storage.sendClientInfo(network, clientType, false, collectStats);

              String username = iUserName;
              String password = iUserPassword;

              OCredentialInterceptor ci = OSecurityManager.instance().newCredentialInterceptor();

              if (ci != null) {
                ci.intercept(storage.getURL(), iUserName, iUserPassword);
                username = ci.getUsername();
                password = ci.getPassword();
              }

              network.writeString(username);
              network.writeString(password);
            } finally {
              storage.endRequest(network);
            }

            try {
              network.beginResponse(nodeSession.getSessionId(), false);
              int sessionId = network.readInt();
              byte[] sessionToken = network.readBytes();
              if (sessionToken.length == 0) {
                sessionToken = null;
              }
              nodeSession.setSession(sessionId, sessionToken);
            } finally {
              storage.endResponse(network);
            }

            return null;
          }
        },
        "Cannot connect to the remote server/database '" + storage.getURL() + "'");
    return this;
  }
Пример #2
0
 public synchronized String getURL() {
   return storage != null ? storage.getURL() : null;
 }