* @return Extended operation's response
* @throws LdapException If the DN is not valid or if the extended operation failed
*/
public ExtendedResponse extended( ExtendedRequest extendedRequest ) throws LdapException
{
ExtendedFuture extendedFuture = extendedAsync( extendedRequest );
// Get the result from the future
try
{
// Read the response, waiting for it if not available immediately
long timeout = getTimeout( extendedRequest.getTimeout() );
// Get the response, blocking
ExtendedResponse extendedResponse = ( ExtendedResponse ) extendedFuture.get( timeout, TimeUnit.MILLISECONDS );
if ( extendedResponse == null )
{
// We didn't received anything : this is an error
LOG.error( "Extended failed : timeout occured" );
throw new LdapException( TIME_OUT_ERROR );
}
if ( extendedResponse.getLdapResult().getResultCode() == ResultCodeEnum.SUCCESS )
{
// Everything is fine, return the response
LOG.debug( "Extended successful : {}", extendedResponse );
}
else
{
// We have had an error
LOG.debug( "Extended failed : {}", extendedResponse );
}
return extendedResponse;
}
catch ( TimeoutException te )
{
// Send an abandon request
if ( !extendedFuture.isCancelled() )
{
abandon( extendedRequest.getMessageId() );
}
// We didn't received anything : this is an error
LOG.error( "Extended failed : timeout occured" );
throw new LdapException( TIME_OUT_ERROR );
}
catch ( Exception ie )
{
// Catch all other exceptions
LOG.error( NO_RESPONSE_ERROR, ie );
LdapException ldapException = new LdapException( NO_RESPONSE_ERROR );
ldapException.initCause( ie );
// Send an abandon request
if ( !extendedFuture.isCancelled() )
{
abandon( extendedRequest.getMessageId() );
}
throw ldapException;