use of com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult in project ldapsdk by pingidentity.
the class TabDelimitedLDAPResultWriterTestCase method testFormatUnsolicitedNotificationWithoutValue.
/**
* Tests the behavior of the {@code formatUnsolicitedNotification} method with
* a notification that does not have a value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testFormatUnsolicitedNotificationWithoutValue() throws Exception {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final List<String> requestedAttributes = Arrays.asList("uid", "givenName", "sn", "undefined", "mail");
final ColumnBasedLDAPResultWriter writer = new ColumnBasedLDAPResultWriter(outputStream, OutputFormat.TAB_DELIMITED_TEXT, requestedAttributes, Integer.MAX_VALUE, false);
final String[] referralURLs = { "ldap://ds1.example.com:389/dc=example,dc=com", "ldap://ds2.example.com:389/dc=example,dc=com" };
final Control[] controls = { new Control("1.2.3.4"), new Control("1.2.3.5", true, new ASN1OctetString("foo")) };
writer.writeUnsolicitedNotification(null, new NoticeOfDisconnectionExtendedResult(0, ResultCode.OTHER, "Connection terminated", "dc=example,dc=com", referralURLs, controls));
assertTrue(outputStream.size() > 0);
}
use of com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult in project ldapsdk by pingidentity.
the class LDAPListener method closeAllConnections.
/**
* Closes all connections that are currently established to this listener.
* This has no effect on the ability to accept new connections.
*
* @param sendNoticeOfDisconnection Indicates whether to send the client a
* notice of disconnection unsolicited
* notification before closing the
* connection.
*/
public void closeAllConnections(final boolean sendNoticeOfDisconnection) {
final NoticeOfDisconnectionExtendedResult noticeOfDisconnection = new NoticeOfDisconnectionExtendedResult(ResultCode.OTHER, null);
final ArrayList<LDAPListenerClientConnection> connList = new ArrayList<>(establishedConnections.values());
for (final LDAPListenerClientConnection c : connList) {
if (sendNoticeOfDisconnection) {
try {
c.sendUnsolicitedNotification(noticeOfDisconnection);
} catch (final Exception e) {
Debug.debugException(e);
}
}
try {
c.close();
} catch (final Exception e) {
Debug.debugException(e);
}
}
}
use of com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult in project ldapsdk by pingidentity.
the class CSVLDAPResultWriterTestCase method testFormatUnsolicitedNotificationWithoutValue.
/**
* Tests the behavior of the {@code formatUnsolicitedNotification} method with
* a notification that does not have a value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testFormatUnsolicitedNotificationWithoutValue() throws Exception {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final List<String> requestedAttributes = Arrays.asList("uid", "givenName", "sn", "undefined", "mail");
final ColumnBasedLDAPResultWriter writer = new ColumnBasedLDAPResultWriter(outputStream, OutputFormat.CSV, requestedAttributes, Integer.MAX_VALUE, false);
final String[] referralURLs = { "ldap://ds1.example.com:389/dc=example,dc=com", "ldap://ds2.example.com:389/dc=example,dc=com" };
final Control[] controls = { new Control("1.2.3.4"), new Control("1.2.3.5", true, new ASN1OctetString("foo")) };
writer.writeUnsolicitedNotification(null, new NoticeOfDisconnectionExtendedResult(0, ResultCode.OTHER, "Connection terminated", "dc=example,dc=com", referralURLs, controls));
assertTrue(outputStream.size() > 0);
}
use of com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult in project ldapsdk by pingidentity.
the class JSONLDAPResultWriterTestCase method testFormatUnsolicitedNotificationWithoutValue.
/**
* Tests the behavior of the {@code formatUnsolicitedNotification} method with
* a notification that does not have a value.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testFormatUnsolicitedNotificationWithoutValue() throws Exception {
final ByteArrayOutputStream outputStream = new ByteArrayOutputStream();
final JSONLDAPResultWriter writer = new JSONLDAPResultWriter(outputStream);
final String[] referralURLs = { "ldap://ds1.example.com:389/dc=example,dc=com", "ldap://ds2.example.com:389/dc=example,dc=com" };
final Control[] controls = { new Control("1.2.3.4"), new Control("1.2.3.5", true, new ASN1OctetString("foo")) };
writer.writeUnsolicitedNotification(null, new NoticeOfDisconnectionExtendedResult(0, ResultCode.OTHER, "Connection terminated", "dc=example,dc=com", referralURLs, controls));
assertValidJSONObject(outputStream);
}
use of com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult in project ldapsdk by pingidentity.
the class LDAPCompareTestCase method testUnsolicitedNotification.
/**
* Tests the behavior for the {@code handleUnsolicitedNotification} method.
*
* @throws Exception If an unexpected problem occurs.
*/
@Test()
public void testUnsolicitedNotification() throws Exception {
final InMemoryDirectoryServer ds = getTestDS(true, true);
try (LDAPConnection conn = ds.getConnection()) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ByteArrayOutputStream err = new ByteArrayOutputStream();
final LDAPCompare tool = new LDAPCompare(out, err);
tool.runTool("--hostname", "localhost", "--port", String.valueOf(ds.getListenPort()), "objectClass:top", "ou=missing,dc=example,dc=com");
out.reset();
err.reset();
tool.handleUnsolicitedNotification(conn, new NoticeOfDisconnectionExtendedResult(ResultCode.OTHER, "The connection will be closed"));
assertEquals(out.toByteArray().length, 0);
assertTrue(err.toByteArray().length > 0);
}
try (LDAPConnection conn = ds.getConnection()) {
final ByteArrayOutputStream out = new ByteArrayOutputStream();
final ByteArrayOutputStream err = new ByteArrayOutputStream();
final LDAPCompare tool = new LDAPCompare(out, err);
tool.runTool("--hostname", "localhost", "--port", String.valueOf(ds.getListenPort()), "--terse", "objectClass:top", "ou=missing,dc=example,dc=com");
out.reset();
err.reset();
tool.handleUnsolicitedNotification(conn, new NoticeOfDisconnectionExtendedResult(ResultCode.OTHER, "The connection will be closed"));
assertEquals(out.toByteArray().length, 0);
assertEquals(err.toByteArray().length, 0);
}
}
Aggregations