Novell Home

TID102191 (xspjav01) How to refresh LDAP server using NCP

From Developer Community

ABSTRACT:

After making changes to LDAP properties, how do you refresh the server?

DETAILED DESCRIPTION

To refresh the LDAP server, an NCP is called. Below is the code to accomplish this.

/***************************************************************************
* Method: notifyNldapServerToRefresh
*
* Input:
* String treeName; // i.e., NOVELL_INC
* String hostServerDN; // Could be null or empty
*
* Output:
* 0 = success, -1 = failure
**************************************************************************/
public static int notifyNldapServerToRefresh(JFrame parentFrame, String 
treeName, String hostServerDN) {
if (hostServerDN == null || hostServerDN.length() == 0) {
return -1;
}
String ncpServer = treeName + "/" + hostServerDN;

try {
Hashtable hash = new Hashtable();
hash.put("java.naming.factory.initial", 
"com.novell.service.nds.naming.NdsInitialContextFactory");
hash.put("java.naming.provider.url", ncpServer);

Context ctx = new InitialContext(hash);
Context ncpServerCtx = (Context)ctx.lookup("/");

Context ctx2;
try {
ctx2 = 
(Context)ncpServerCtx.lookup("NCPExtensions");
}
catch (javax.naming.NameNotFoundException exp1) {
// send error message here
return -1;
}

NCPExtensionDirContext ctx3;
try {
ctx3 = 
(NCPExtensionDirContext)ctx2.lookup("NLDAP");
}
catch (javax.naming.NameNotFoundException exp2) {
// Cannot find NLDAP
// send error message here
return -1;
}
byte[] data = new byte[0];
byte[] response = ctx3.send(data, 200); // 200: 
maximum reply length
}
catch (Exception exp) {
// send error message here
}
return 0;
} // notifyNldapServerToRefresh

--devsup

Novell® Making IT Work As One

© 2009 Novell, Inc. All Rights Reserved.