import com.novell.ldap.*;
import java.io.UnsupportedEncodingException;
// register to listen for unsolicited notifications. It
// gets notified on unsolicited notifications.
public class UnsolicitedListener {
public class theListener implements LDAPUnsolicitedNotificationListener {
public theListener()
{
}
public void messageReceived(LDAPExtendedResponse msg)
{
System.out.println("Received notification of unsolicited notification");
System.out.println("The OID in the notification was ==>" +
((LDAPExtendedResponse)msg).getID());
byte [] data = msg.getValue();
if (data == null)
System.out.println("The DATA in the notification was <null>" );
else
System.out.println("The DATA in the notification was ==> " + data);
}
}
public static void main( String[] args ) {
UnsolicitedListener temp = new UnsolicitedListener();
temp.doWork(args);
}
public void doWork( String[] args ) {
int ldapVersion = LDAPConnection.LDAP_V3;
int ldapPort = LDAPConnection.DEFAULT_PORT;
LDAPConnection lc = new LDAPConnection();
if (args.length != 3) {
System.err.println("Usage: java UnsolicitedListener <host Name>"
+ " <login dn> <password>");
System.err.println("Example: java UnsolicitedListener Acme.com"
+ " \"cn=Admin,o=Acme\" secret");
System.exit(1);
}
String ldapHost = args[0];
String loginDN = args[1];
String passWord = args[2];
try {
lc.connect( ldapHost, ldapPort );
System.out.println("Connecting.......");
lc.bind( ldapVersion,loginDN, passWord.getBytes("UTF8") );
System.out.println("Authenticated to the server ");
theListener notifyMe = new theListener();
lc.addUnsolicitedNotificationListener(notifyMe);
System.out.println("Added listener for unsolicited messages");
System.out.println("Sleeping .ZZZZZZZZZZZZZZZZZZZZ");
try {
java.lang.Thread.sleep(100000);
} catch (InterruptedException e) {
System.out.println("Interrupted");
}
System.out.println("YAWN, I'M AWAKE NOW");
lc.removeUnsolicitedNotificationListener(notifyMe);
System.out.println("Removed listener");
lc.disconnect();
}
catch( LDAPException e ) {
System.out.println( "Error: " + e.toString() );
}
catch( UnsupportedEncodingException e ) {
System.out.println( "Error: " + e.toString() );
}
System.exit(0);
}
}