Search in sources :

Example 1 with LDAPRuntimeException

use of com.unboundid.ldap.sdk.LDAPRuntimeException in project ldapsdk by pingidentity.

the class LogFieldSyntax method sha256.

/**
 * Retrieves a SHA-256 digest of the contents of the provided buffer.
 *
 * @param  buffer  The buffer containing the data to digest.  It must not be
 *                 {@code null}.
 *
 * @return  The bytes that comprise the SHA-256 digest.
 */
@NotNull()
protected final byte[] sha256(@NotNull final ByteStringBuffer buffer) {
    MessageDigest digest = threadLocalDigests.get();
    if (digest == null) {
        try {
            digest = CryptoHelper.getMessageDigest(TOKEN_DIGEST_ALGORITHM);
        } catch (final Exception e) {
            Debug.debugException(e);
            throw new LDAPRuntimeException(new LDAPException(ResultCode.ENCODING_ERROR, ERR_LOG_SYNTAX_TOKENIZE_DIGEST_ERROR.get(TOKEN_DIGEST_ALGORITHM), e));
        }
    }
    digest.update(buffer.getBackingArray(), 0, buffer.length());
    return digest.digest();
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) MessageDigest(java.security.MessageDigest) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) LDAPException(com.unboundid.ldap.sdk.LDAPException) NotNull(com.unboundid.util.NotNull)

Example 2 with LDAPRuntimeException

use of com.unboundid.ldap.sdk.LDAPRuntimeException in project ldapsdk by pingidentity.

the class StreamFileValuePatternComponent method append.

/**
 * {@inheritDoc}
 */
@Override()
void append(@NotNull final StringBuilder buffer) {
    String line = lineQueue.poll();
    if (line != null) {
        buffer.append(line);
        return;
    }
    while (true) {
        try {
            StreamFileValuePatternReaderThread readerThread;
            synchronized (this) {
                readerThread = threadRef.get();
                if (readerThread == null) {
                    readerThread = new StreamFileValuePatternReaderThread(file, lineQueue, maxOfferBlockTimeMillis, nextReadPosition, threadRef);
                    threadRef.set(readerThread);
                    readerThread.start();
                }
            }
            line = lineQueue.poll(10L, TimeUnit.MILLISECONDS);
            if (line != null) {
                buffer.append(line);
                return;
            }
        } catch (final Exception e) {
            Debug.debugException(e);
            throw new LDAPRuntimeException(new LDAPException(ResultCode.LOCAL_ERROR, ERR_STREAM_FILE_VALUE_PATTERN_ERROR_GETTING_NEXT_VALUE.get(file.getAbsolutePath(), StaticUtils.getExceptionMessage(e)), e));
        }
    }
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) IOException(java.io.IOException) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException)

Example 3 with LDAPRuntimeException

use of com.unboundid.ldap.sdk.LDAPRuntimeException in project ldapsdk by pingidentity.

the class ValuesOnlyLDAPResultWriter method writeSearchResultEntry.

/**
 * {@inheritDoc}
 */
@Override()
public void writeSearchResultEntry(@NotNull final SearchResultEntry entry) {
    try {
        for (final Attribute a : entry.getAttributes()) {
            for (final byte[] value : a.getValueByteArrays()) {
                getPrintStream().write(value);
                getPrintStream().write(StaticUtils.EOL_BYTES);
            }
        }
    } catch (final Exception e) {
        Debug.debugException(e);
        throw new LDAPRuntimeException(new LDAPException(ResultCode.OTHER, ERR_VALUES_ONLY_OUTPUT_FORMAT_WRITE_ERROR.get(StaticUtils.getExceptionMessage(e)), e));
    }
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) Attribute(com.unboundid.ldap.sdk.Attribute) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 4 with LDAPRuntimeException

use of com.unboundid.ldap.sdk.LDAPRuntimeException in project ldapsdk by pingidentity.

the class JSONLDAPResultWriter method toJSON.

/**
 * Encodes the provided LDAP result as a JSON object.
 *
 * @param  result  The LDAP result to be encoded as a JSON object.  It must
 *                 not be {@code null}.
 *
 * @return  The JSON object containing the encoded representation of the
 *          LDAP result.
 */
@NotNull()
public static JSONObject toJSON(@NotNull final LDAPResult result) {
    try {
        final JSONBuffer jsonBuffer = new JSONBuffer();
        toJSON(result, jsonBuffer);
        return jsonBuffer.toJSONObject();
    } catch (final JSONException e) {
        // This should never happen.
        Debug.debugException(e);
        throw new LDAPRuntimeException(new LDAPException(ResultCode.ENCODING_ERROR, e.getMessage(), e));
    }
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) JSONBuffer(com.unboundid.util.json.JSONBuffer) JSONException(com.unboundid.util.json.JSONException) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) NotNull(com.unboundid.util.NotNull)

Example 5 with LDAPRuntimeException

use of com.unboundid.ldap.sdk.LDAPRuntimeException in project ldapsdk by pingidentity.

the class JSONLDAPResultWriter method toJSON.

/**
 * Encodes the provided entry as a JSON object.
 *
 * @param  entry  The entry to be encoded as a JSON object.  It must not be
 *                {@code null}.
 *
 * @return  The JSON object containing the encoded representation of the
 *          entry.
 */
@NotNull()
public static JSONObject toJSON(@NotNull final Entry entry) {
    try {
        final JSONBuffer jsonBuffer = new JSONBuffer();
        toJSON(entry, jsonBuffer);
        return jsonBuffer.toJSONObject();
    } catch (final JSONException e) {
        // This should never happen.
        Debug.debugException(e);
        throw new LDAPRuntimeException(new LDAPException(ResultCode.ENCODING_ERROR, e.getMessage(), e));
    }
}
Also used : LDAPException(com.unboundid.ldap.sdk.LDAPException) JSONBuffer(com.unboundid.util.json.JSONBuffer) JSONException(com.unboundid.util.json.JSONException) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) NotNull(com.unboundid.util.NotNull)

Aggregations

LDAPException (com.unboundid.ldap.sdk.LDAPException)8 LDAPRuntimeException (com.unboundid.ldap.sdk.LDAPRuntimeException)8 NotNull (com.unboundid.util.NotNull)6 JSONBuffer (com.unboundid.util.json.JSONBuffer)3 JSONException (com.unboundid.util.json.JSONException)3 ArrayList (java.util.ArrayList)2 ASN1Boolean (com.unboundid.asn1.ASN1Boolean)1 ASN1Element (com.unboundid.asn1.ASN1Element)1 ASN1Enumerated (com.unboundid.asn1.ASN1Enumerated)1 ASN1Integer (com.unboundid.asn1.ASN1Integer)1 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 ASN1Sequence (com.unboundid.asn1.ASN1Sequence)1 Attribute (com.unboundid.ldap.sdk.Attribute)1 DN (com.unboundid.ldap.sdk.DN)1 RDN (com.unboundid.ldap.sdk.RDN)1 CollectSupportDataSecurityLevel (com.unboundid.ldap.sdk.unboundidds.tasks.CollectSupportDataSecurityLevel)1 IOException (java.io.IOException)1 MessageDigest (java.security.MessageDigest)1