Search in sources :

Example 56 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class Debug method debugException.

/**
 * Writes debug information about the provided exception, if appropriate.
 *
 * @param  l  The log level that should be used for the debug information.
 * @param  t  The exception for which debug information should be written.
 */
public static void debugException(@NotNull final Level l, @NotNull final Throwable t) {
    if (debugEnabled && debugTypes.contains(DebugType.EXCEPTION)) {
        final JSONBuffer buffer = new JSONBuffer();
        addCommonHeader(buffer, l, DebugType.EXCEPTION);
        addCaughtException(buffer, "caught-exception", t);
        addCommonFooter(buffer);
        log(l, buffer, t);
    }
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer)

Example 57 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class Debug method debugConnectionPool.

/**
 * Writes debug information about interaction with a connection pool.
 *
 * @param  l  The log level that should be used for the debug information.
 * @param  p  The associated connection pool.
 * @param  c  The associated LDAP connection, if appropriate.
 * @param  m  A message with information about the pool interaction.
 * @param  e  An exception to include with the log message, if appropriate.
 */
public static void debugConnectionPool(@NotNull final Level l, @NotNull final AbstractConnectionPool p, @Nullable final LDAPConnection c, @Nullable final String m, @Nullable final Throwable e) {
    if (debugEnabled && debugTypes.contains(DebugType.CONNECTION_POOL)) {
        final JSONBuffer buffer = new JSONBuffer();
        addCommonHeader(buffer, l, DebugType.CONNECTION_POOL);
        final String poolName = p.getConnectionPoolName();
        if (poolName == null) {
            buffer.appendNull("connection-pool-name");
        } else {
            buffer.appendString("connection-pool-name", poolName);
        }
        if (c != null) {
            buffer.appendNumber("connection-id", c.getConnectionID());
            final String connectedAddress = c.getConnectedAddress();
            if (connectedAddress != null) {
                buffer.appendString("connected-to-address", connectedAddress);
                buffer.appendNumber("connected-to-port", c.getConnectedPort());
            }
        }
        final long currentAvailable = p.getCurrentAvailableConnections();
        if (currentAvailable >= 0) {
            buffer.appendNumber("current-available-connections", currentAvailable);
        }
        final long maxAvailable = p.getMaximumAvailableConnections();
        if (maxAvailable >= 0) {
            buffer.appendNumber("maximum-available-connections", maxAvailable);
        }
        if (m != null) {
            buffer.appendString("message", m);
        }
        if (e != null) {
            addCaughtException(buffer, "caught-exception", e);
        }
        addCommonFooter(buffer);
        log(l, buffer, e);
    }
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer)

Example 58 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class Debug method debugMonitor.

/**
 * Writes debug information about monitor entry parsing, if appropriate.
 *
 * @param  l  The log level that should be used for the debug information.
 * @param  e  The entry containing the monitor information being parsed.
 * @param  m  The message to be written to the debug logger.
 */
public static void debugMonitor(@NotNull final Level l, @Nullable final Entry e, @Nullable final String m) {
    if (debugEnabled && debugTypes.contains(DebugType.MONITOR)) {
        final JSONBuffer buffer = new JSONBuffer();
        addCommonHeader(buffer, l, DebugType.MONITOR);
        if (e != null) {
            buffer.appendString("monitor-entry-dn", e.getDN());
        }
        if (m != null) {
            buffer.appendString("message", m);
        }
        addCommonFooter(buffer);
        log(l, buffer);
    }
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer)

Example 59 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class JSONAccessLogRequestHandler method getConnectionHeader.

/**
 * Retrieves a {@code JSONBuffer} with header information for a connect log
 * message for the specified type of operation.
 *
 * @param  messageType  The type of operation being requested.
 *
 * @return  A {@code JSONBuffer} with header information appended for the
 *          connection;
 */
@NotNull()
private JSONBuffer getConnectionHeader(@NotNull final String messageType) {
    final JSONBuffer buffer = getBuffer();
    buffer.beginObject();
    addTimestamp(buffer);
    buffer.appendString("message-type", messageType);
    buffer.appendNumber("connection-id", clientConnection.getConnectionID());
    return buffer;
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) NotNull(com.unboundid.util.NotNull)

Example 60 with JSONBuffer

use of com.unboundid.util.json.JSONBuffer in project ldapsdk by pingidentity.

the class JSONAccessLogRequestHandler method getBuffer.

/**
 * Retrieves a JSON buffer that can be used to construct a log message.
 *
 * @return  A JSON buffer that can be used to construct a log message.
 */
@NotNull()
private JSONBuffer getBuffer() {
    JSONBuffer buffer = jsonBuffers.get();
    if (buffer == null) {
        buffer = new JSONBuffer();
        jsonBuffers.set(buffer);
    } else {
        buffer.clear();
    }
    return buffer;
}
Also used : JSONBuffer(com.unboundid.util.json.JSONBuffer) NotNull(com.unboundid.util.NotNull)

Aggregations

JSONBuffer (com.unboundid.util.json.JSONBuffer)73 Test (org.testng.annotations.Test)20 NotNull (com.unboundid.util.NotNull)16 LogRecord (java.util.logging.LogRecord)12 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)8 Date (java.util.Date)5 LDAPException (com.unboundid.ldap.sdk.LDAPException)3 LDAPRuntimeException (com.unboundid.ldap.sdk.LDAPRuntimeException)3 JSONException (com.unboundid.util.json.JSONException)3 DN (com.unboundid.ldap.sdk.DN)2 RDN (com.unboundid.ldap.sdk.RDN)2 JSONField (com.unboundid.util.json.JSONField)2 JSONObject (com.unboundid.util.json.JSONObject)2 JSONString (com.unboundid.util.json.JSONString)2 AddResponseProtocolOp (com.unboundid.ldap.protocol.AddResponseProtocolOp)1 BindResponseProtocolOp (com.unboundid.ldap.protocol.BindResponseProtocolOp)1 CompareResponseProtocolOp (com.unboundid.ldap.protocol.CompareResponseProtocolOp)1 DeleteResponseProtocolOp (com.unboundid.ldap.protocol.DeleteResponseProtocolOp)1 ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)1 ModifyDNResponseProtocolOp (com.unboundid.ldap.protocol.ModifyDNResponseProtocolOp)1