*/
private void handleReferralEntryForSearch( LdapSession session, SearchRequest req, Entry entry )
throws Exception
{
LdapResult result = req.getResultResponse().getLdapResult();
ReferralImpl referral = new ReferralImpl();
result.setReferral( referral );
result.setResultCode( ResultCodeEnum.REFERRAL );
result.setDiagnosticMessage( "Encountered referral attempting to handle request." );
result.setMatchedDn( req.getBase() );
Attribute refAttr = ( ( ClonedServerEntry ) entry ).getOriginalEntry().get( SchemaConstants.REF_AT );
for ( Value<?> refval : refAttr )
{
String refstr = refval.getString();
// need to add non-ldap URLs as-is
if ( !refstr.startsWith( "ldap" ) )
{
referral.addLdapUrl( refstr );
continue;
}
// parse the ref value and normalize the Dn
LdapUrl ldapUrl = null;
try
{
ldapUrl = new LdapUrl( refstr );
}
catch ( LdapURLEncodingException e )
{
LOG.error( I18n.err( I18n.ERR_165, refstr, entry ) );
continue;
}
ldapUrl.setForceScopeRendering( true );
ldapUrl.setAttributes( req.getAttributes() );
ldapUrl.setScope( req.getScope().getScope() );
referral.addLdapUrl( ldapUrl.toString() );
}
session.getIoSession().write( req.getResultResponse() );
}