Le 11/12/14 04:57, Kiran Ayyagari a écrit : > On Thu, Dec 11, 2014 at 7:50 AM, Emmanuel Lécharny <[email protected]> > wrote: > >> Le 11/12/14 00:06, Dunn-Roberts, Richard R (N-LEIDOS, INC.) a écrit : >>> I am trying to add a document to an ou programatically. I am using >> ApacheDS v 2.0.0-M17. I am also using Apache Directory Studio >> 2.0.0.v20130628. >>> I am able to connect to the server localhost, at port 10389, and am >> working in partition dc=test,dc=com (for this example). >>> The following organizational units exist in the partition - persistent >> (ou=persistent,dc=test,dc=com), and under persistent, >> documentStore(ou=documentStore,ou=persistent,dc=test,dc=com). >>> If I import a document into the documentStore ou using an ldif import, >> it works. The ldif file contains only the following lines: >>> 1. dn: >> documentIdentifier=D1,ou=documentStore,ou=persistent,dc=test,dc=com >>> 2. objectClass: document >>> 3. documentIdentifier: D1 >>> I can also create the document by right clicking on the ou node in the >> LDAP browser, selecting New->New Entry (or New->New Context Entry; both >> seem to open the same dialog). In the dialog, I select Create entry from >> scratch, click Next, and select document from the Available object classes. >> This addsdocument and top to the Selected object classes. I then click >> Next. For RDN, I enter documentIdentifier and D2 to the entry fields, and >> click (yep, you guessed it!) Next. This shows three attributes ... two >> objectClass values (document and top), and one documentIdentifier value >> (D2), as expected. The dialog indicates that these are must attributes. I >> then click Finish, and the document node is displayed in the LDAP Browser >> in AD Studio. >>> Next, I try to create a document entry from a short java< >> http://www.javaranch.com/> program. I can successfully create an ou using >> the program, by creating an InitialDirContext< >> http://docs.oracle.com/javase/8/docs/api/javax/naming/directory/InitialDirContext.html> >> (let's call it idc. I can then create an ou using the following code: >>> 1. // The InitialDirContext is created using dn: >> ou=documentStore,ou=persistent,dc=test,dc=com >>> 2. // The argument ouName is set to the value ou=anotherOu >>> 3. public void createOu( String ouName ) >>> 4. { >>> 5. try >>> 6. { >>> 7. // CreateOu attributes to be associated with the new context >>> 8. Attributes attrs = new BasicAttributes(true); // case-ignore >>> 9. Attribute objclass = new BasicAttribute("objectclass"); >>> 10. objclass.add("top"); >>> 11. objclass.add("organizationalUnit"); >>> 12. attrs.put(objclass); >>> 13. >>> 14. // CreateOu the context >>> 15. Context result = idc.createSubcontext(ouName, attrs); >>> 16. >>> 17. // Close the context when we're done >>> 18. result.close(); >>> 19. } >>> 20. catch ( NamingException e ) >>> 21. { >>> 22. System.err.println( "LdapTest::createOu(): " + e.getMessage() >> ); >>> 23. e.printStackTrace(); >>> 24. } >>> 25. } >>> This code completes successfully, and the new ou, anotherOu, is visible >> in the LDAP Browser, when I reload the directoryStore ou. >>> Finally, I modify the code above to attempt to programatically add a >> document to the documentStore ou. The modified code is as follows: >>> 1. // The InitialDirContext is created using dn: >> ou=documentStore,ou=persistent,dc=test,dc=com >>> 2. // The argument docName is set to the value documentIdentifier=D3 >>> 3. public void createDocument( String docName ) >>> 4. { >>> 5. try >>> 6. { >>> 7. // CreateOu attributes to be associated with the new context >>> 8. Attributes attrs = new BasicAttributes(true); // case-ignore >>> 9. Attribute objclass = new BasicAttribute("objectclass"); >>> 10. objclass.add("top"); >>> 11. objclass.add("document"); >>> 12. attrs.put(objclass); >>> 13. >>> 14. // CreateOu the context >>> 15. Context result = idc.createSubcontext(docName, attrs); >>> 16. >>> 17. // Close the context when we're done >>> 18. result.close(); >>> 19. } >>> 20. catch ( NamingException e ) >>> 21. { >>> 22. System.err.println( "LdapTest::createDocument(): " + >> e.getMessage() ); >>> 23. e.printStackTrace(); >>> 24. } >>> 25. } >>> When I run this code, I get the following exception message and stack >> trace: >>> 1. LdapTest::createDocument(): [LDAP: error code 16 - >> NO_SUCH_ATTRIBUTE: failed for MessageType : ADD_REQUEST >>> 2. Message ID : 2 >>> 3. Add Request : >>> 4. Entry >>> 5. dn[n]: >> documentIdentifer=D3,ou=documentStore,ou=persistent,dc=test,dc=com >>> 6. >>> 7. documentIdentifer: D3 >>> 8. ManageDsaITImpl Control >>> 9. Type OID : '2.16.840.1.113730.3.4.2' >>> 10. Criticality : 'false' >>> 11. ' >>> 12. : ERR_04269 ATTRIBUTE_TYPE for OID documentidentifer does not exist!] >>> 13. javax.naming.directory.NoSuchAttributeException: [LDAP: error code >> 16 - NO_SUCH_ATTRIBUTE: failed for MessageType : ADD_REQUEST >>> 14. Message ID : 2 >>> 15. Add Request : >>> 16. Entry >>> 17. dn[n]: >> documentIdentifer=D3,ou=documentStore,ou=persistent,dc=test,dc=com >>> 18. >>> 19. documentIdentifer: D3 >>> 20. ManageDsaITImpl Control >>> 21. Type OID : '2.16.840.1.113730.3.4.2' >>> 22. Criticality : 'false' >>> 23. ' >>> 24. : ERR_04269 ATTRIBUTE_TYPE for OID documentidentifer does not >> exist!]; remaining name 'documentIdentifer=D3' >>> 25. at com.sun.jndi.ldap.LdapCtx.mapErrorCode(LdapCtx.java:3108) >>> 26. at >> com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:3033) >>> 27. at >> com.sun.jndi.ldap.LdapCtx.processReturnCode(LdapCtx.java:2840) >>> 28. at >> com.sun.jndi.ldap.LdapCtx.c_createSubcontext(LdapCtx.java:811) >>> 29. at >> com.sun.jndi.toolkit.ctx.ComponentDirContext.p_createSubcontext(ComponentDirContext.java:337) >>> 30. at >> com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(PartialCompositeDirContext.java:266) >>> 31. at >> com.sun.jndi.toolkit.ctx.PartialCompositeDirContext.createSubcontext(PartialCompositeDirContext.java:254) >>> 32. at >> javax.naming.directory.InitialDirContext.createSubcontext(InitialDirContext.java:197) >>> 33. at >> com.warsim.aui.ldaptest.CreateContext.createDocument(CreateContext.java:43) >>> 34. at >> com.warsim.aui.ldaptest.CreateContext.main(CreateContext.java:75) >>> I am a novice LDAP user, and freely admit I don't understand it very >> well. Any assistance in identifying my error, or identifying a solution, >> would be greatly appreciated. >> >> The documentIdentifier AttributeType is unknown to the server. You have >> to add it into the schema for the server to be able to create an entry >> containing such an entry. >> >> he already has it, but he is passing wrong attribute name while creating > the entry programmatically
Right, right ! I didn't made the connection with the very first entry added, and missed the typo... Thanks Kiran.
