Search in sources :

Example 1 with IntermediateResponseProtocolOp

use of com.unboundid.ldap.protocol.IntermediateResponseProtocolOp in project ldapsdk by pingidentity.

the class LDAPListenerClientConnection method sendIntermediateResponse.

/**
 * Sends an intermediate response message to the client with the provided
 * information.
 *
 * @param  messageID   The message ID for the LDAP message to send to the
 *                     client.  It must match the message ID of the associated
 *                     search request.
 * @param  protocolOp  The intermediate response protocol op to include in the
 *                     LDAP message to send to the client.
 * @param  controls    The set of controls to include in the response message.
 *                     It may be empty or {@code null} if no controls should
 *                     be included.
 *
 * @throws  LDAPException  If a problem occurs while attempting to send the
 *                         provided response message.  If an exception is
 *                         thrown, then the client connection will have been
 *                         terminated.
 */
public void sendIntermediateResponse(final int messageID, @NotNull final IntermediateResponseProtocolOp protocolOp, @Nullable final Control... controls) throws LDAPException {
    if (intermediateResponseTransformers.isEmpty()) {
        sendMessage(new LDAPMessage(messageID, protocolOp, controls));
    } else {
        Control[] c;
        IntermediateResponseProtocolOp op = protocolOp;
        if (controls == null) {
            c = EMPTY_CONTROL_ARRAY;
        } else {
            c = controls;
        }
        for (final IntermediateResponseTransformer t : intermediateResponseTransformers) {
            try {
                final ObjectPair<IntermediateResponseProtocolOp, Control[]> p = t.transformIntermediateResponse(messageID, op, c);
                if (p == null) {
                    return;
                }
                op = p.getFirst();
                c = p.getSecond();
            } catch (final Exception e) {
                Debug.debugException(e);
                sendMessage(new LDAPMessage(messageID, protocolOp, c));
                throw new LDAPException(ResultCode.LOCAL_ERROR, ERR_CONN_INTERMEDIATE_RESPONSE_TRANSFORMER_EXCEPTION.get(t.getClass().getName(), String.valueOf(op), StaticUtils.getExceptionMessage(e)), e);
            }
        }
        sendMessage(new LDAPMessage(messageID, op, c));
    }
}
Also used : Control(com.unboundid.ldap.sdk.Control) LDAPException(com.unboundid.ldap.sdk.LDAPException) LDAPMessage(com.unboundid.ldap.protocol.LDAPMessage) IntermediateResponseProtocolOp(com.unboundid.ldap.protocol.IntermediateResponseProtocolOp) LDAPRuntimeException(com.unboundid.ldap.sdk.LDAPRuntimeException) LDAPException(com.unboundid.ldap.sdk.LDAPException) IOException(java.io.IOException)

Example 2 with IntermediateResponseProtocolOp

use of com.unboundid.ldap.protocol.IntermediateResponseProtocolOp in project ldapsdk by pingidentity.

the class InMemoryOperationInterceptorRequestHandler method transformIntermediateResponse.

/**
 * Transforms the provided intermediate response and/or set of controls to
 * alter what will be returned to the client.
 *
 * @param  messageID  The message ID for the associated search operation.
 * @param  response   The intermediate response to be processed.  It will not
 *                    be {@code null}.
 * @param  controls   The set of controls to be processed.  It will not be
 *                    {@code null} but may be empty if there are no controls.
 *
 * @return  An {@link ObjectPair} containing a possibly updated intermediate
 *          response and set of controls, or {@code null} to indicate that the
 *          response should not be returned to the client.
 */
@Override()
@Nullable()
public ObjectPair<IntermediateResponseProtocolOp, Control[]> transformIntermediateResponse(final int messageID, @NotNull final IntermediateResponseProtocolOp response, @NotNull final Control[] controls) {
    final InterceptedOperation op = activeOperations.get(messageID);
    if (op == null) {
        return new ObjectPair<>(response, controls);
    }
    final InterceptedIntermediateResponse r = new InterceptedIntermediateResponse(op, response, controls);
    for (final InMemoryOperationInterceptor i : interceptors) {
        try {
            i.processIntermediateResponse(r);
            if (r.getIntermediateResponse() == null) {
                return null;
            }
        } catch (final Exception ex) {
            Debug.debugException(ex);
            return null;
        }
    }
    return new ObjectPair<>(new IntermediateResponseProtocolOp(r.getIntermediateResponse()), r.getIntermediateResponse().getControls());
}
Also used : IntermediateResponseProtocolOp(com.unboundid.ldap.protocol.IntermediateResponseProtocolOp) LDAPException(com.unboundid.ldap.sdk.LDAPException) ObjectPair(com.unboundid.util.ObjectPair) Nullable(com.unboundid.util.Nullable)

Example 3 with IntermediateResponseProtocolOp

use of com.unboundid.ldap.protocol.IntermediateResponseProtocolOp in project ldapsdk by pingidentity.

the class InterceptedIntermediateResponseTestCase method testBasics.

/**
 * Provides basic test coverage for an intercepted intermediate response.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testBasics() throws Exception {
    // Create an intercepted intermediate response.  We'll use a null
    // connection, which shouldn't happen naturally but will be sufficient for
    // this test.
    final AddRequestProtocolOp requestOp = new AddRequestProtocolOp(new AddRequest("dn: dc=example,dc=com", "objectClass: top", "objectClass: domain", "dc: example"));
    final InterceptedAddOperation o = new InterceptedAddOperation(null, 1, requestOp);
    assertNotNull(o.toString());
    final IntermediateResponseProtocolOp responseOp = new IntermediateResponseProtocolOp(new IntermediateResponse("1.2.3.4", null));
    final InterceptedIntermediateResponse r = new InterceptedIntermediateResponse(o, responseOp);
    assertNotNull(r.toString());
    // Test methods for a generic intercepted operation.
    assertNull(r.getClientConnection());
    assertEquals(r.getConnectionID(), -1L);
    assertNull(r.getConnectedAddress());
    assertEquals(r.getConnectedPort(), -1);
    assertEquals(r.getMessageID(), 1);
    assertNull(r.getProperty("propX"));
    r.setProperty("propX", "valX");
    assertNotNull(r.getProperty("propX"));
    assertEquals(r.getProperty("propX"), "valX");
    assertNotNull(r.toString());
    r.setProperty("propX", null);
    assertNull(r.getProperty("propX"));
    // Test methods specific to an intercepted compare operation.
    assertNotNull(r.getRequest());
    assertNotNull(r.getIntermediateResponse());
    assertEquals(r.getIntermediateResponse().getOID(), "1.2.3.4");
    assertNotNull(r.toString());
    r.setIntermediateResponse(new IntermediateResponse("5.6.7.8", null));
    assertEquals(r.getIntermediateResponse().getOID(), "5.6.7.8");
    assertNotNull(r.toString());
    r.setIntermediateResponse(null);
    assertNull(r.getIntermediateResponse());
    assertNotNull(r.toString());
}
Also used : AddRequest(com.unboundid.ldap.sdk.AddRequest) IntermediateResponse(com.unboundid.ldap.sdk.IntermediateResponse) AddRequestProtocolOp(com.unboundid.ldap.protocol.AddRequestProtocolOp) IntermediateResponseProtocolOp(com.unboundid.ldap.protocol.IntermediateResponseProtocolOp) Test(org.testng.annotations.Test)

Example 4 with IntermediateResponseProtocolOp

use of com.unboundid.ldap.protocol.IntermediateResponseProtocolOp in project ldapsdk by pingidentity.

the class LDAPDebuggerTestCase method testFailedExtendedOperation.

/**
 * Provides test coverage for a failed extended operation.
 *
 * @throws  Exception  If an unexpected problem occurs.
 */
@Test()
public void testFailedExtendedOperation() throws Exception {
    TestRequestHandler.setReturnOp(new ExtendedResponseProtocolOp(32, "dc=example,dc=com", "msg", Arrays.asList("ldap://server1.example.com/dc=example,dc=com", "ldap://server2.example.com/dc=example,dc=com"), "1.2.3.5", new ASN1OctetString("baz")));
    TestRequestHandler.setReturnIntermediateResponses(new IntermediateResponseProtocolOp("5.6.7.8", new ASN1OctetString("a")), new IntermediateResponseProtocolOp("5.6.7.9", new ASN1OctetString("b")));
    try {
        conn.processExtendedOperation("1.2.3.4", new ASN1OctetString("bar"));
    } finally {
        TestRequestHandler.setReturnIntermediateResponses();
        TestRequestHandler.setControls();
    }
}
Also used : ASN1OctetString(com.unboundid.asn1.ASN1OctetString) ExtendedResponseProtocolOp(com.unboundid.ldap.protocol.ExtendedResponseProtocolOp) IntermediateResponseProtocolOp(com.unboundid.ldap.protocol.IntermediateResponseProtocolOp) Test(org.testng.annotations.Test)

Aggregations

IntermediateResponseProtocolOp (com.unboundid.ldap.protocol.IntermediateResponseProtocolOp)4 LDAPException (com.unboundid.ldap.sdk.LDAPException)2 Test (org.testng.annotations.Test)2 ASN1OctetString (com.unboundid.asn1.ASN1OctetString)1 AddRequestProtocolOp (com.unboundid.ldap.protocol.AddRequestProtocolOp)1 ExtendedResponseProtocolOp (com.unboundid.ldap.protocol.ExtendedResponseProtocolOp)1 LDAPMessage (com.unboundid.ldap.protocol.LDAPMessage)1 AddRequest (com.unboundid.ldap.sdk.AddRequest)1 Control (com.unboundid.ldap.sdk.Control)1 IntermediateResponse (com.unboundid.ldap.sdk.IntermediateResponse)1 LDAPRuntimeException (com.unboundid.ldap.sdk.LDAPRuntimeException)1 Nullable (com.unboundid.util.Nullable)1 ObjectPair (com.unboundid.util.ObjectPair)1 IOException (java.io.IOException)1