Search in sources :

Example 1 with NoticeOfDisconnectionExtendedResult

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);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) NoticeOfDisconnectionExtendedResult(com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 2 with NoticeOfDisconnectionExtendedResult

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);
        }
    }
}
Also used : NoticeOfDisconnectionExtendedResult(com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult) ArrayList(java.util.ArrayList) IOException(java.io.IOException) SocketException(java.net.SocketException) LDAPException(com.unboundid.ldap.sdk.LDAPException)

Example 3 with NoticeOfDisconnectionExtendedResult

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);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) NoticeOfDisconnectionExtendedResult(com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 4 with NoticeOfDisconnectionExtendedResult

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);
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Control(com.unboundid.ldap.sdk.Control) NoticeOfDisconnectionExtendedResult(com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult) ByteArrayOutputStream(java.io.ByteArrayOutputStream) ASN1OctetString(com.unboundid.asn1.ASN1OctetString) Test(org.testng.annotations.Test)

Example 5 with NoticeOfDisconnectionExtendedResult

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);
    }
}
Also used : InMemoryDirectoryServer(com.unboundid.ldap.listener.InMemoryDirectoryServer) NoticeOfDisconnectionExtendedResult(com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult) LDAPConnection(com.unboundid.ldap.sdk.LDAPConnection) ByteArrayOutputStream(java.io.ByteArrayOutputStream) Test(org.testng.annotations.Test)

Aggregations

NoticeOfDisconnectionExtendedResult (com.unboundid.ldap.sdk.extensions.NoticeOfDisconnectionExtendedResult)18 Test (org.testng.annotations.Test)14 ByteArrayOutputStream (java.io.ByteArrayOutputStream)9 LDAPConnection (com.unboundid.ldap.sdk.LDAPConnection)8 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)7 Control (com.unboundid.ldap.sdk.Control)7 InMemoryDirectoryServer (com.unboundid.ldap.listener.InMemoryDirectoryServer)5 ASN1Exception (com.unboundid.asn1.ASN1Exception)2 LDAPResponse (com.unboundid.ldap.protocol.LDAPResponse)2 OperationPurposeRequestControl (com.unboundid.ldap.sdk.unboundidds.controls.OperationPurposeRequestControl)2 IOException (java.io.IOException)2 InterruptedIOException (java.io.InterruptedIOException)2 SocketTimeoutException (java.net.SocketTimeoutException)2 Level (java.util.logging.Level)2 ASN1StreamReader (com.unboundid.asn1.ASN1StreamReader)1 ExtendedResult (com.unboundid.ldap.sdk.ExtendedResult)1 LDAPException (com.unboundid.ldap.sdk.LDAPException)1 AuthorizationIdentityResponseControl (com.unboundid.ldap.sdk.controls.AuthorizationIdentityResponseControl)1 ContentSyncDoneControl (com.unboundid.ldap.sdk.controls.ContentSyncDoneControl)1 ContentSyncStateControl (com.unboundid.ldap.sdk.controls.ContentSyncStateControl)1