Modify attribute with multibyte data
I am an LDAP newbie. I am connecting to Active Directory and trying to modify "sn" attribute to an entry with chinese characters "槦樖檉", but i am getting an error at the line-
ctx.modifyAttributes(entry,modItem);
The error is-
javax.naming.directory.InvalidAttributeValueException: [LDAP: error code 19 - 00002082: AtrErr: DSID-03150979, #1:0: 00002082: DSID-03150979, problem 1005 (CONSTRAINT_ATT_TYPE), data 0, Att 4 (sn):len 200
Please suggest the reasons why i might be getting this error?
[523 byte] By [
neha_83a] at [2007-11-27 2:00:20]

# 1
Active Directory (and for that matter Windows) is Unicode enabled.
Active Directory stores most of it's stuff as Unicode, so creating users that use DBCS values such as Japanese or Chinese is supported.
The litmus test is whether you can create a user with Chinese characters using the Windows Active Directory Users & Computers snap-in. I definitely know it works for Japanese character sets.
Possibly the problem could be that either you are not using "real" Chinese characters (your sample doesn't look like Chinese characters I've seen, or is it just this web site is not rendering the characters correctly), or that your Java code containing the new surname attribute is not a Unicode file.
Alternatively you may be incorrectly modifying the attribute (doing an add rather a replace or vice-versa), and without seeing how you constructed the modItem variable I can't say for certain. One thing to try is whether your code can successfully modify the surname with non-Chinese single byte characters. (Is there a politically correct way to say "normal English characters" ?)
# 2
Thanks for the prompt reply. I am using Chinese characters. (Reading from SQL Server using JDBC APIs). These are not getting rendered correctly on the site here. Also, I am able to add users with Chinese characters using AD Users and Computers. I am able to replace this sn attribute if i give plain english characters as the value. But i receive this javax.naming.directory.InvalidAttributeValueException error using JNDI APIs when value contains Chinese characters.
ModificationItem modItem[] = new ModificationItem[1];
modItem[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE,
new BasicAttribute(attribute, data));
con.modifyAttributes(entry,modItem);
Please help.
# 3
If you can input the characters into the Active Directory Users & Computers snap-in, then there should be no reason why you can't modify a user using Java & JNDI.
I have tested this myself (to the best that I can find a way to type what looks to me like Chinese characters !)
Here are the steps I took.
Used some of the sample code (that you would find under my posts on this foum).
Used the Windows character mapper to copy some chinese characters into the code. It looks like this (note this web site does not render the characters correctly)// Now modify some attributes
ModificationItem[] mods = new ModificationItem[3];
//Replace the sn, giveName & displayName attributes
String sn = "涯涐涴";
String givenName = "浃浆浞";
String displayName = "浃浆浞涯涐涴";
//Replace surname
mods[0] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("sn",sn));
//Replace givenName
mods[1] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("givenName", givenName));
//Replace displayName
mods[2] = new ModificationItem(DirContext.REPLACE_ATTRIBUTE, new BasicAttribute("displayName", displayName));
// Perform the update
ctx.modifyAttributes(userName, mods);
As I was using my favourite editor, notepad, I just saved the file as Unicode and then compiled it using the appropriate encoding:c:\code\java\javac mod-chinese-user.java -encoding UNICODE
Running the resulting sample went OK, albeit the Windows command shell doesn't render the characters either. Viewing the modified user in the Active Directory snap-in showed tha the user had been modified correctly.