Beispiel #1
0
 public void testWrongPassword() throws IOException {
   try {
     database.open("reader", "swdsds");
   } catch (OException e) {
     Assert.assertTrue(
         e instanceof OSecurityAccessException
             || e.getCause() != null
                 && e.getCause()
                         .toString()
                         .indexOf(
                             "com.orientechnologies.orient.core.exception.OSecurityAccessException")
                     > -1);
   }
 }
Beispiel #2
0
  protected <T> T networkAdminOperation(
      final OStorageRemoteOperation<T> operation, final String errorMessage) {

    OChannelBinaryAsynchClient network = null;
    try {
      // TODO:replace this api with one that get connection for only the specified url.
      String serverUrl = storage.getNextAvailableServerURL(false, session);
      do {
        try {
          network = storage.getNetwork(serverUrl);
        } catch (OException e) {
          serverUrl = storage.useNewServerURL(serverUrl);
          if (serverUrl == null) throw e;
        }
      } while (network == null);

      T res = operation.execute(network, storage.getCurrentSession());
      storage.connectionManager.release(network);
      return res;
    } catch (Exception e) {
      if (network != null) storage.connectionManager.release(network);
      storage.close(true, false);
      throw OException.wrapException(new OStorageException(errorMessage), e);
    }
  }
Beispiel #3
0
  public OChannelBinary writeBytes(final byte[] iContent, final int iLength) throws IOException {
    if (debug)
      OLogManager.instance()
          .info(
              this,
              "%s - Writing bytes (4+%d=%d bytes): %s",
              socket.getRemoteSocketAddress(),
              iLength,
              iLength + 4,
              Arrays.toString(iContent));

    if (iContent == null) {
      out.writeInt(-1);
      updateMetricTransmittedBytes(OBinaryProtocol.SIZE_INT);
    } else {
      if (iLength > maxChunkSize) {
        throw OException.wrapException(
            new OIOException(
                "Impossible to write a chunk of length:"
                    + iLength
                    + " max allowed chunk length:"
                    + maxChunkSize
                    + " see NETWORK_BINARY_MAX_CONTENT_LENGTH settings "),
            null);
      }

      out.writeInt(iLength);
      out.write(iContent, 0, iLength);
      updateMetricTransmittedBytes(OBinaryProtocol.SIZE_INT + iLength);
    }
    return this;
  }
 @Override
 public ORawBuffer readRecord(long clusterPosition) throws IOException {
   throw OException.wrapException(
       new ORecordNotFoundException(
           new ORecordId(id, clusterPosition),
           "Record with rid #" + id + ":" + clusterPosition + " was not found in database"),
       new OOfflineClusterException(
           "Cannot read a record from the offline cluster '" + name + "'"));
 }
Beispiel #5
0
  public byte[] readBytes() throws IOException {
    if (debug)
      OLogManager.instance()
          .info(
              this,
              "%s - Reading chunk of bytes. Reading chunk length as int (4 bytes)...",
              socket.getRemoteSocketAddress());

    final int len = in.readInt();
    if (len > maxChunkSize) {
      throw OException.wrapException(
          new OIOException(
              "Impossible to read a chunk of length:"
                  + len
                  + " max allowed chunk length:"
                  + maxChunkSize
                  + " see NETWORK_BINARY_MAX_CONTENT_LENGTH settings "),
          null);
    }
    updateMetricReceivedBytes(OBinaryProtocol.SIZE_INT + len);

    if (debug)
      OLogManager.instance()
          .info(this, "%s - Read chunk lenght: %d", socket.getRemoteSocketAddress(), len);

    if (len < 0) return null;

    if (debug)
      OLogManager.instance()
          .info(this, "%s - Reading %d bytes...", socket.getRemoteSocketAddress(), len);

    // REUSE STATIC BUFFER?
    final byte[] tmp = new byte[len];
    in.readFully(tmp);

    if (debug)
      OLogManager.instance()
          .info(
              this,
              "%s - Read %d bytes: %s",
              socket.getRemoteSocketAddress(),
              len,
              new String(tmp));

    return tmp;
  }
  public synchronized <T> T getResource(final String iName, final Callable<T> iCallback) {
    T value = (T) sharedResources.get(iName);
    if (value == null) {
      // CREATE IT
      try {
        value = iCallback.call();
      } catch (Exception e) {
        throw OException.wrapException(
            new ODatabaseException("Error on creation of shared resource"), e);
      }

      if (value instanceof OSharedResource) ((OSharedResource) value).acquireExclusiveLock();

      sharedResources.put(iName, value);
    }

    return value;
  }