use of org.apache.directory.api.ldap.model.url.LdapUrl in project directory-ldap-api by apache.
the class LdapUrlTest method testLdapURLHostNoPortDN.
/**
* test a LdapUrl with a host, no port, and a Dn
*/
@Test
public void testLdapURLHostNoPortDN() throws LdapURLEncodingException {
LdapUrl url = new LdapUrl("ldap://localhost/ou=system");
assertEquals("ldap://localhost/ou=system", url.toString());
}
use of org.apache.directory.api.ldap.model.url.LdapUrl 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);
}
use of org.apache.directory.api.ldap.model.url.LdapUrl in project directory-ldap-api by apache.
the class AddReferral method action.
/**
* {@inheritDoc}
*/
public void action(LdapMessageContainer<MessageDecorator<? extends Message>> container) throws DecoderException {
TLV tlv = container.getCurrentTLV();
Message response = container.getMessage();
LdapResult ldapResult = ((ResultResponse) response).getLdapResult();
Referral referral = ldapResult.getReferral();
if (tlv.getLength() == 0) {
referral.addLdapUrl("");
} else {
if (ldapResult.getResultCode() == ResultCodeEnum.REFERRAL) {
try {
String url = Strings.utf8ToString(tlv.getValue().getData());
referral.addLdapUrl(new LdapUrl(url).toString());
} catch (LdapURLEncodingException luee) {
String badUrl = Strings.utf8ToString(tlv.getValue().getData());
LOG.error(I18n.err(I18n.ERR_04015, badUrl, luee.getMessage()));
throw new DecoderException(I18n.err(I18n.ERR_04016, luee.getMessage()), luee);
}
} else {
LOG.warn("The Referral error message is not allowed when havind an error code no equals to REFERRAL");
referral.addLdapUrl(LdapUrl.EMPTY_URL.toString());
}
}
if (IS_DEBUG) {
StringBuilder sb = new StringBuilder();
boolean isFirst = true;
for (String url : ldapResult.getReferral().getLdapUrls()) {
if (isFirst) {
isFirst = false;
} else {
sb.append(", ");
}
sb.append(url);
}
LOG.debug("The referral error message is set to " + sb.toString());
}
// We can have an END transition
container.setGrammarEndAllowed(true);
}
use of org.apache.directory.api.ldap.model.url.LdapUrl in project directory-ldap-api by apache.
the class LdapUrlTest method testLdapURLDNAttrsScopeBase.
/**
* test a LdapUrl with a Dn, some attributes an scope base
*/
@Test
public void testLdapURLDNAttrsScopeBase() throws LdapURLEncodingException {
LdapUrl url = new LdapUrl("ldap://localhost:123/ou=system?ou,cn?base");
assertEquals("ldap://localhost:123/ou=system?ou,cn", url.toString());
}
use of org.apache.directory.api.ldap.model.url.LdapUrl in project directory-ldap-api by apache.
the class LdapUrlTest method testLdapURLNoDNAttrsNoScopeFilter.
/**
* test a LdapUrl with no Dn, some attributes, no scope and filter
*/
@Test
public void testLdapURLNoDNAttrsNoScopeFilter() throws LdapURLEncodingException {
LdapUrl url = new LdapUrl("ldap://localhost:123/?cn,ou,dc??(cn=test)");
assertEquals("ldap://localhost:123/?cn,ou,dc??(cn=test)", url.toString());
}
Aggregations