Search in sources :

Example 11 with SearchResultReference

use of org.apache.directory.api.ldap.model.message.SearchResultReference in project directory-ldap-api by apache.

the class StoreReference method action.

/**
 * {@inheritDoc}
 */
public void action(LdapMessageContainer<SearchResultReferenceDecorator> container) throws DecoderException {
    SearchResultReference searchResultReference = container.getMessage();
    // Get the Value and store it in the BindRequest
    TLV tlv = container.getCurrentTLV();
    // Get the referral, or create it if not existing
    Referral referral = searchResultReference.getReferral();
    if (referral == null) {
        referral = new ReferralImpl();
        searchResultReference.setReferral(referral);
    }
    // We have to handle the special case of a 0 length list of referrals
    LdapUrl url = LdapUrl.EMPTY_URL;
    if (tlv.getLength() == 0) {
        referral.addLdapUrl("");
    } else {
        String urlStr = Strings.utf8ToString(tlv.getValue().getData());
        try {
            url = new LdapUrl(urlStr);
            referral.addLdapUrl(urlStr);
        } catch (LdapURLEncodingException luee) {
            LOG.error(I18n.err(I18n.ERR_04021, urlStr, luee.getMessage()));
            throw new DecoderException(I18n.err(I18n.ERR_04016, luee.getMessage()), luee);
        }
    }
    if (IS_DEBUG) {
        LOG.debug("Search reference URL found : {}", url);
    }
    // We can have an END transition
    container.setGrammarEndAllowed(true);
}
Also used : LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) DecoderException(org.apache.directory.api.asn1.DecoderException) Referral(org.apache.directory.api.ldap.model.message.Referral) ReferralImpl(org.apache.directory.api.ldap.model.message.ReferralImpl) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) TLV(org.apache.directory.api.asn1.ber.tlv.TLV)

Example 12 with SearchResultReference

use of org.apache.directory.api.ldap.model.message.SearchResultReference in project directory-ldap-api by apache.

the class EntryCursorImpl method next.

/**
 * {@inheritDoc}
 */
@Override
public boolean next() throws LdapException, CursorException {
    if (!searchCursor.next()) {
        return false;
    }
    try {
        do {
            response = searchCursor.get();
            if (response == null) {
                throw new LdapException(LdapNetworkConnection.TIME_OUT_ERROR);
            }
            messageId = response.getMessageId();
            if (response instanceof SearchResultEntry) {
                return true;
            }
            if (response instanceof SearchResultReference) {
                return true;
            }
        } while (!(response instanceof SearchResultDone));
        return false;
    } catch (Exception e) {
        LdapException ldapException = new LdapException(LdapNetworkConnection.NO_RESPONSE_ERROR);
        ldapException.initCause(e);
        // close the cursor
        try {
            close(ldapException);
        } catch (IOException ioe) {
            throw new LdapException(ioe.getMessage(), ioe);
        }
        throw ldapException;
    }
}
Also used : SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) SearchResultDone(org.apache.directory.api.ldap.model.message.SearchResultDone) IOException(java.io.IOException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) CursorLdapReferralException(org.apache.directory.api.ldap.model.cursor.CursorLdapReferralException) IOException(java.io.IOException) CursorException(org.apache.directory.api.ldap.model.cursor.CursorException) InvalidCursorPositionException(org.apache.directory.api.ldap.model.cursor.InvalidCursorPositionException) LdapReferralException(org.apache.directory.api.ldap.model.exception.LdapReferralException) LdapException(org.apache.directory.api.ldap.model.exception.LdapException) SearchResultEntry(org.apache.directory.api.ldap.model.message.SearchResultEntry)

Example 13 with SearchResultReference

use of org.apache.directory.api.ldap.model.message.SearchResultReference in project directory-ldap-api by apache.

the class SearchResultReferenceTest method testResponseWith1EmptyRef.

/**
 * Test parsing of a Response with 1 Ref
 */
@Test
public void testResponseWith1EmptyRef() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResultReferenceTest.class.getResource("response_with_1_empty_ref.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResultReference searchResultReference = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getCurrentSearchResultReference();
    Collection<String> references = searchResultReference.getReferral().getLdapUrls();
    assertEquals(0, references.size());
}
Also used : Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 14 with SearchResultReference

use of org.apache.directory.api.ldap.model.message.SearchResultReference in project directory-ldap-api by apache.

the class SearchResultReferenceTest method testResponseWith3ControlsWithoutValue.

/**
 * Test parsing of a response with 3 (optional) Control elements without value
 */
@Test
public void testResponseWith3ControlsWithoutValue() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResultReferenceTest.class.getResource("response_with_3_controls_without_value.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResultReference searchResultReference = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getCurrentSearchResultReference();
    Map<String, Control> controls = searchResultReference.getControls();
    assertEquals(3, searchResultReference.getControls().size());
    Control control = controls.get("1.2.840.113556.1.4.456");
    assertNotNull(control);
    assertTrue(control.isCritical());
    assertEquals("1.2.840.113556.1.4.456", control.getOid());
    assertFalse(((DsmlControl<?>) control).hasValue());
}
Also used : Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) DsmlControl(org.apache.directory.api.dsmlv2.DsmlControl) Control(org.apache.directory.api.ldap.model.message.Control) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Example 15 with SearchResultReference

use of org.apache.directory.api.ldap.model.message.SearchResultReference in project directory-ldap-api by apache.

the class SearchResultReferenceTest method testResponseWith1Ref.

/**
 * Test parsing of a Response with 1 Ref
 */
@Test
public void testResponseWith1Ref() {
    Dsmlv2ResponseParser parser = null;
    try {
        parser = new Dsmlv2ResponseParser(getCodec());
        parser.setInput(SearchResultReferenceTest.class.getResource("response_with_1_ref.xml").openStream(), "UTF-8");
        parser.parse();
    } catch (Exception e) {
        fail(e.getMessage());
    }
    SearchResultReference searchResultReference = ((SearchResponse) parser.getBatchResponse().getCurrentResponse().getDecorated()).getCurrentSearchResultReference();
    Collection<String> references = searchResultReference.getReferral().getLdapUrls();
    assertEquals(1, references.size());
    try {
        assertTrue(references.contains(new LdapUrl("ldap://localhost").toString()));
    } catch (LdapURLEncodingException e) {
        fail();
    }
}
Also used : LdapUrl(org.apache.directory.api.ldap.model.url.LdapUrl) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) Dsmlv2ResponseParser(org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser) SearchResultReference(org.apache.directory.api.ldap.model.message.SearchResultReference) LdapURLEncodingException(org.apache.directory.api.ldap.model.exception.LdapURLEncodingException) SearchResponse(org.apache.directory.api.dsmlv2.response.SearchResponse) Test(org.junit.Test) AbstractResponseTest(org.apache.directory.api.dsmlv2.AbstractResponseTest)

Aggregations

SearchResultReference (org.apache.directory.api.ldap.model.message.SearchResultReference)17 Test (org.junit.Test)11 LdapURLEncodingException (org.apache.directory.api.ldap.model.exception.LdapURLEncodingException)9 AbstractResponseTest (org.apache.directory.api.dsmlv2.AbstractResponseTest)8 Dsmlv2ResponseParser (org.apache.directory.api.dsmlv2.Dsmlv2ResponseParser)8 SearchResponse (org.apache.directory.api.dsmlv2.response.SearchResponse)8 Control (org.apache.directory.api.ldap.model.message.Control)6 DecoderException (org.apache.directory.api.asn1.DecoderException)4 EncoderException (org.apache.directory.api.asn1.EncoderException)4 DsmlControl (org.apache.directory.api.dsmlv2.DsmlControl)4 SearchResultReferenceDecorator (org.apache.directory.api.ldap.codec.decorators.SearchResultReferenceDecorator)4 Referral (org.apache.directory.api.ldap.model.message.Referral)4 SearchResultDone (org.apache.directory.api.ldap.model.message.SearchResultDone)4 SearchResultEntry (org.apache.directory.api.ldap.model.message.SearchResultEntry)4 ByteBuffer (java.nio.ByteBuffer)3 Asn1Decoder (org.apache.directory.api.asn1.ber.Asn1Decoder)3 LdapMessageContainer (org.apache.directory.api.ldap.codec.api.LdapMessageContainer)3 AbstractCodecServiceTest (org.apache.directory.api.ldap.codec.osgi.AbstractCodecServiceTest)3 LdapUrl (org.apache.directory.api.ldap.model.url.LdapUrl)3 HashSet (java.util.HashSet)2