| | |
| | | described, if you have a directory server running import sample data, |
| | | and test your configuration with a sample client application.</para> |
| | | |
| | | <programlisting language="java">// Test.java: |
| | | <programlisting language="java">import org.forgerock.opendj.ldap.Connection; |
| | | import org.forgerock.opendj.ldap.LDAPConnectionFactory; |
| | | import org.forgerock.opendj.ldap.SearchScope; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultEntry; |
| | | import org.forgerock.opendj.ldap.responses.SearchResultReference; |
| | | import org.forgerock.opendj.ldif.ConnectionEntryReader; |
| | | import org.forgerock.opendj.ldif.LDIFEntryWriter; |
| | | |
| | | //Test.java: |
| | | // Kick the SDK tires, reading Babs Jensen's entry and displaying LDIF. |
| | | // If your LDAP server is not listening on localhost:1389, or if your |
| | | // data are different change the appropriate lines below. |
| | | |
| | | import org.forgerock.opendj.sdk.*; |
| | | import org.forgerock.opendj.sdk.ldif.*; |
| | | import org.forgerock.opendj.sdk.responses.*; |
| | | |
| | | class Test |
| | | { |
| | | public static void main(String [] args) |
| | | { |
| | | class Test { |
| | | public static void main(String[] args) { |
| | | |
| | | // Create an LDIF writer which will write the search results to stdout. |
| | | |
| | | final LDIFEntryWriter writer = new LDIFEntryWriter(System.out); |
| | | Connection connection = null; |
| | | |
| | | try |
| | | { |
| | | try { |
| | | // Connect and bind to the server. |
| | | // CHANGE THIS IF SERVER IS NOT AT localhost:1389. |
| | | final LDAPConnectionFactory factory = |
| | |
| | | // Read the entries and output them as LDIF. |
| | | // CHANGE THIS IF NO uid=bjensen,ou=people,dc=example,dc=com EXISTS. |
| | | final ConnectionEntryReader reader = |
| | | connection.search( |
| | | "dc=example,dc=com", SearchScope.WHOLE_SUBTREE, "(uid=bjensen)", "*"); |
| | | while (reader.hasNext()) |
| | | { |
| | | if (reader.isEntry()) |
| | | { |
| | | connection.search("dc=example,dc=com", |
| | | SearchScope.WHOLE_SUBTREE, "(uid=bjensen)", "*"); |
| | | while (reader.hasNext()) { |
| | | if (reader.isEntry()) { |
| | | // Got an entry. |
| | | final SearchResultEntry entry = reader.readEntry(); |
| | | writer.writeComment( |
| | | "Search result entry: " + entry.getName().toString()); |
| | | writer.writeComment("Search result entry: " |
| | | + entry.getName().toString()); |
| | | writer.writeEntry(entry); |
| | | } |
| | | else |
| | | { |
| | | } else { |
| | | // Got a continuation reference. |
| | | final SearchResultReference ref = reader.readReference(); |
| | | writer.writeComment( |
| | | "Search result reference: " + ref.getURIs().toString()); |
| | | writer.writeComment("Search result reference: " |
| | | + ref.getURIs().toString()); |
| | | } |
| | | } |
| | | writer.flush(); |
| | | } |
| | | catch (final Exception e) |
| | | { |
| | | } catch (final Exception e) { |
| | | // Handle exceptions... |
| | | System.err.println(e.getMessage()); |
| | | } |
| | | finally |
| | | { |
| | | if (connection != null) |
| | | { |
| | | } finally { |
| | | if (connection != null) { |
| | | connection.close(); |
| | | } |
| | | } |
| | | } |
| | | }</programlisting> |
| | | } |
| | | </programlisting> |
| | | |
| | | <para>If all goes well, <filename>Test.java</filename> compiles without |
| | | errors. The test program displays Babs Jensen's entry in LDIF.</para> |