![JAR search and dependency download from the Maven repository](/logo.png)
com.unboundid.ldap.sdk.unboundidds.tools.ReportBindResultLDAPConnectionPoolHealthCheck Maven / Gradle / Ivy
Go to download
Show more of this group Show more artifacts with this name
Show all versions of unboundid-ldapsdk-commercial-edition Show documentation
Show all versions of unboundid-ldapsdk-commercial-edition Show documentation
The UnboundID LDAP SDK for Java is a fast, comprehensive, and easy-to-use
Java API for communicating with LDAP directory servers and performing
related tasks like reading and writing LDIF, encoding and decoding data
using base64 and ASN.1 BER, and performing secure communication. This
package contains the Commercial Edition of the LDAP SDK, which includes
all of the general-purpose functionality contained in the Standard
Edition, plus additional functionality specific to UnboundID server
products.
The newest version!
/*
* Copyright 2016-2017 UnboundID Corp.
* All Rights Reserved.
*/
/*
* Copyright (C) 2016-2017 UnboundID Corp.
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License (GPLv2 only)
* or the terms of the GNU Lesser General Public License (LGPLv2.1 only)
* as published by the Free Software Foundation.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, see .
*/
package com.unboundid.ldap.sdk.unboundidds.tools;
import java.util.ArrayList;
import com.unboundid.ldap.sdk.BindResult;
import com.unboundid.ldap.sdk.LDAPConnection;
import com.unboundid.ldap.sdk.LDAPConnectionPoolHealthCheck;
import com.unboundid.ldap.sdk.LDAPException;
import com.unboundid.ldap.sdk.ResultCode;
import com.unboundid.util.CommandLineTool;
import com.unboundid.util.StaticUtils;
import com.unboundid.util.ThreadSafety;
import com.unboundid.util.ThreadSafetyLevel;
import static com.unboundid.ldap.sdk.unboundidds.tools.ToolMessages.*;
/**
* This class provides an implementation of a connection pool health check that
* can display information about the result of a bind operation. It will always
* report information about an unsuccessful bind. It may optionally report
* information about a successful bind, and optionally only if the successful
* bind includes one or more response controls.
*
*
* NOTE: This class is part of the Commercial Edition of the UnboundID
* LDAP SDK for Java. It is not available for use in applications that
* include only the Standard Edition of the LDAP SDK, and is not supported for
* use in conjunction with non-UnboundID products.
*
*
* Note that this health check is only intended to generate output when
* appropriate and will never throw an exception to indicate that a connection
* is unusable. If additional health checking is required, then this health
* check may be combined with others via an aggregate health check in a manner
* that ensures this health check will be invoked before any others that may
* throw an exception.
*/
@ThreadSafety(level=ThreadSafetyLevel.COMPLETELY_THREADSAFE)
public final class ReportBindResultLDAPConnectionPoolHealthCheck
extends LDAPConnectionPoolHealthCheck
{
// Indicates whether to display result details for successful binds that
// include one or more response controls.
private final boolean displaySuccessResultWithControls;
// Indicates whether to display result details for successful binds that do
// not include any response controls.
private final boolean displaySuccessResultWithoutControls;
// The tool whose output and error streams will be used for displaying result
// details.
private final CommandLineTool tool;
// The column at which to wrap long lines.
private final int wrapColumn;
/**
* Creates a new instance of this health check with the provided information.
*
* @param tool The tool with which this
* health check is associated.
* Any success messages written
* will be sent to the tool's
* standard output stream. Any
* failure messages written will
* be sent to the tool's standard
* error stream.
* @param displaySuccessResultWithControls Indicates whether to display
* information about a bind
* result with a result code of
* {@code SUCCESS} that has one
* or more response controls.
* @param displaySuccessResultWithoutControls Indicates whether to display
* information about a bind
* result with a result code of
* {@code SUCCESS} that has no
* response controls.
*/
public ReportBindResultLDAPConnectionPoolHealthCheck(
final CommandLineTool tool,
final boolean displaySuccessResultWithControls,
final boolean displaySuccessResultWithoutControls)
{
this.tool = tool;
this.displaySuccessResultWithControls = displaySuccessResultWithControls;
this.displaySuccessResultWithoutControls =
displaySuccessResultWithoutControls;
wrapColumn = StaticUtils.TERMINAL_WIDTH_COLUMNS - 1;
}
/**
* {@inheritDoc}
*/
@Override()
public void ensureConnectionValidAfterAuthentication(
final LDAPConnection connection,
final BindResult bindResult)
throws LDAPException
{
if (bindResult.getResultCode() == ResultCode.SUCCESS)
{
final boolean displayResult;
if (bindResult.hasResponseControl())
{
displayResult = displaySuccessResultWithControls;
}
else
{
displayResult = displaySuccessResultWithoutControls;
}
if (displayResult)
{
final ArrayList lines = new ArrayList(10);
lines.add("# " + INFO_REPORT_BIND_RESULT_HEADER.get());
ResultUtils.formatResult(lines, bindResult, true, false, 5, wrapColumn);
for (final String line : lines)
{
tool.out(line);
}
tool.out();
}
}
else
{
final ArrayList lines = new ArrayList(10);
lines.add("# " + INFO_REPORT_BIND_RESULT_HEADER.get());
ResultUtils.formatResult(lines, bindResult, true, false, 0, wrapColumn);
for (final String line : lines)
{
tool.err(line);
}
tool.err();
}
}
/**
* {@inheritDoc}
*/
@Override()
public void toString(final StringBuilder buffer)
{
buffer.append("ReportBindResultLDAPConnectionPoolHealthCheck(" +
"displaySuccessResultWithControls=");
buffer.append(displaySuccessResultWithControls);
buffer.append(", displaySuccessResultWithoutControls=");
buffer.append(displaySuccessResultWithoutControls);
buffer.append(')');
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy