[Date Prev][Date Next]
[Chronological]
[Thread]
[Top]
Client Side message support in JLDAP's DSML Library
Hi,
I have completed an implementation in JLdap where you will be able
to Write Any of the LDAP messages using DSMLWriter class.
Earlier it use to have just server side message support and it
understands only LDAPSearch Results and Add Response, Modify Response,
ModifyDN Response, Delete Response, Compare Response and extended
operation Response.
After this Implementation DSMLWriter will also be able to write
LDAPSearch Request, LDAPAddRequest, LDAPModifyRequest,
LDAPModifyDNRequest, LDAPDeleteRequest and LDAPExtended Operation. I
guess this is what requested by Marc a few days ago in this List. Let me
know if your comments about it. I have checked in the changes in the
Openldap CVS Repository.
Also find a Sample code below to Test this functionality:-
import com.novell.ldap.*;
import com.novell.ldap.rfc2251.*;
import com.novell.ldap.util.*;
import com.novell.ldap.extensions.*;
import java.util.ArrayList;
import java.util.Enumeration;
import java.util.Iterator;
import java.io.FileOutputStream;
import java.io.IOException;
import java.io.UnsupportedEncodingException;
public class Filter
{
public static void main( String[] args ) throws Exception
{
String fileName = args[0];
LDAPSearchRequest request = new
LDAPSearchRequest("dc=octetstring,dc=com",1,new
RfcFilter("(|(cn=sun*)(sn>=kumar))"),new String[]
{"objectClass","cn","sn","uid"},0,100,100,false,null);
LDAPAttributeSet attributeSet = new LDAPAttributeSet();
ArrayList modList = new ArrayList();
/* To Add an entry to the directory,
* - Create the attributes of the entry and add them to an
attribute set
* - Specify the DN of the entry to be created
* - Create an LDAPEntry object with the DN and the attribute
set
* - Call the LDAPConnection add method to add it to the
directory
*/
attributeSet.add( new LDAPAttribute(
"objectclass", new
String("inetOrgPerson")));
attributeSet.add( new LDAPAttribute("cn",
new String[]{"James Smith", "Jim Smith", "Jimmy
Smith"}));
attributeSet.add( new LDAPAttribute("givenname",
new String[]{"James", "Jim", "Jimmy"
}));
attributeSet.add( new LDAPAttribute("sn", new
String("Smith")));
attributeSet.add( new LDAPAttribute("telephonenumber",
new String("1 801 555
1212")));
attributeSet.add( new LDAPAttribute("mail",
new
String("JSmith@Acme.com")));
String dn = "cn=JSmith,o=novell";
LDAPEntry newEntry = new LDAPEntry( dn, attributeSet );
LDAPAddRequest arequest = new LDAPAddRequest(newEntry,null);
String email = "James_Smith@Acme.com";
LDAPAttribute attribute = new LDAPAttribute( "mail", email);
modList.add( new LDAPModification(LDAPModification.REPLACE,
attribute));
// Change the phone number
// First we delete the old phone number
String phone1= "1 801 555 1212";
attribute= new LDAPAttribute( "telephoneNumber", phone1);
modList.add( new LDAPModification(LDAPModification.DELETE,
attribute));
// Now we add the new phone number
String phone2 = "1 423 555 1212";
attribute= new LDAPAttribute( "telephoneNumber", phone2);
modList.add( new LDAPModification(LDAPModification.ADD,
attribute));
LDAPModification[] mods = new LDAPModification[modList.size()];
mods = (LDAPModification[])modList.toArray(mods);
LDAPModifyRequest mrequest= new
LDAPModifyRequest(dn,mods,null);
LDAPDeleteRequest drequest = new LDAPDeleteRequest(dn,null);
LDAPModifyDNRequest mdrequest = new
LDAPModifyDNRequest(dn,"cn=sunilk","o=novell",true,null);
LDAPExtendedOperation oper = new
GetReplicaInfoRequest("cn=sunilk,o=novell", "o=novell");
// LDAPExtendedOperation oper = new
RefreshLDAPServerRequest();
LDAPExtendedRequest erequest = new
LDAPExtendedRequest(oper,null);
DSMLWriter out;
FileOutputStream outFileStream = null;
if (fileName == null){
out = new DSMLWriter(System.out);
} else {
outFileStream = new FileOutputStream(fileName);
out = new DSMLWriter(outFileStream);
}
out.useIndent(true);
out.setIndent(4);
out.writeMessage( request );
out.writeMessage( erequest );
out.writeMessage( arequest );
out.writeMessage( mrequest );
out.writeMessage( mdrequest );
out.writeMessage( drequest );
out.finish();
}
}
Regards,
Sunil Kumar