@@ -36,7 +36,7 @@ public class LDAPServer {
3636 public LDAPServer () {
3737 String dir = Utils .getFileFromClasspath ("benchmark.properties" , LDAPManager .class .getClassLoader ()).getParent ();
3838 File workDir = new File (dir + "/../ldap" );
39- System .out .println ("%%%%%%%%%%%%%%%%%%%%%%%%%%%% " + dir + "/../ldap" );
39+ // System.out.println(dir + "/../ldap");
4040 // File workDir = new File(System.getProperty("user.dir") +
4141 workDir .mkdirs ();
4242
@@ -56,7 +56,7 @@ public LDAPServer() {
5656 }
5757
5858 // And print it if available
59- System .out .println ("Found entry : " + result );
59+ // System.out.println("Found entry : " + result);
6060
6161 // optionally we can start a server too
6262 try {
@@ -97,17 +97,26 @@ public LDAPServer() {
9797 * @throws Exception
9898 * if there were some problems while initializing the system
9999 */
100- private void initDirectoryService (File workDir ) throws Exception {
100+ private void initDirectoryService (File workDir ){
101101 // Initialize the LDAP service
102- service = new DefaultDirectoryService ();
102+ try {
103+ service = new DefaultDirectoryService ();
104+ } catch (Exception e1 ) {
105+ System .out .println ("Error creating DefaultDirectoryService. " + e1 .getMessage ());
106+ }
103107 service .setWorkingDirectory (workDir );
104108
105109 // first load the schema
106110 initSchemaPartition ();
107111
108112 // then the system partition
109113 // this is a MANDATORY partition
110- Partition systemPartition = addPartition ("system" , ServerDNConstants .SYSTEM_DN );
114+ Partition systemPartition = null ;
115+ try {
116+ systemPartition = addPartition ("system" , ServerDNConstants .SYSTEM_DN );
117+ } catch (Exception e1 ) {
118+ System .out .println ("Error addPartition system. " + e1 .getMessage ());
119+ }
111120 service .setSystemPartition (systemPartition );
112121
113122 // Disable the ChangeLog system
@@ -116,51 +125,80 @@ private void initDirectoryService(File workDir) throws Exception {
116125
117126 // Now we can create as many partitions as we need
118127 // Create some new partitions named 'foo', 'bar' and 'apache'.
119- Partition fooPartition = addPartition ("foo" , "dc=foo,dc=com" );
120- Partition barPartition = addPartition ("bar" , "dc=bar,dc=com" );
121- Partition apachePartition = addPartition ("apache" , "dc=apache,dc=org" );
128+ Partition fooPartition = null ;
129+ try {
130+ fooPartition = addPartition ("foo" , "dc=foo,dc=com" );
131+ } catch (Exception e1 ) {
132+ System .out .println ("Error addPartition foo. " + e1 .getMessage ());
133+ }
134+ Partition barPartition = null ;
135+ try {
136+ barPartition = addPartition ("bar" , "dc=bar,dc=com" );
137+ } catch (Exception e1 ) {
138+ System .out .println ("Error addPartition bar. " + e1 .getMessage ());
139+ }
140+ Partition apachePartition = null ;
141+ try {
142+ apachePartition = addPartition ("apache" , "dc=apache,dc=org" );
143+ } catch (Exception e1 ) {
144+ System .out .println ("Error addPartition apache. " + e1 .getMessage ());
145+ }
122146
123147 // Index some attributes on the apache partition
124148 addIndex (apachePartition , "objectClass" , "ou" , "uid" );
125149 try {
126150 // And start the service
127151 service .startup ();
128152 } catch (Exception e ) {
129- e .printStackTrace ();
130- //System.out.println("%%%%%%%ERROR%%%%%%%%" + e.getMessage());
153+ System .out .println ("Error at LDAP startup: " + e .getMessage ());
131154 }
132155 // Inject the foo root entry if it does not already exist
133156 try {
134157 service .getAdminSession ().lookup (fooPartition .getSuffixDn ());
135- } catch (LdapException lnnfe ) {
136- DN dnFoo = new DN ("dc=foo,dc=com" );
137- ServerEntry entryFoo = service .newEntry (dnFoo );
138- entryFoo .add ("objectClass" , "top" , "domain" , "extensibleObject" );
139- entryFoo .add ("dc" , "foo" );
140- service .getAdminSession ().add (entryFoo );
158+ } catch (Exception lnnfe ) {
159+ try {
160+ DN dnFoo = new DN ("dc=foo,dc=com" );
161+ ServerEntry entryFoo = service .newEntry (dnFoo );
162+ entryFoo .add ("objectClass" , "top" , "domain" , "extensibleObject" );
163+ entryFoo .add ("dc" , "foo" );
164+ service .getAdminSession ().add (entryFoo );
165+ } catch (Exception e ) {
166+ System .out .println ("Error creating new DN." );
167+ }
141168 }
142169
143170 // Inject the bar root entry
144171 try {
145172 service .getAdminSession ().lookup (barPartition .getSuffixDn ());
146- } catch (LdapException lnnfe ) {
147- DN dnBar = new DN ("dc=bar,dc=com" );
148- ServerEntry entryBar = service .newEntry (dnBar );
149- entryBar .add ("objectClass" , "top" , "domain" , "extensibleObject" );
150- entryBar .add ("dc" , "bar" );
151- service .getAdminSession ().add (entryBar );
173+ } catch (Exception lnnfe ) {
174+ try {
175+ DN dnBar = new DN ("dc=bar,dc=com" );
176+ ServerEntry entryBar = service .newEntry (dnBar );
177+ entryBar .add ("objectClass" , "top" , "domain" , "extensibleObject" );
178+ entryBar .add ("dc" , "bar" );
179+ service .getAdminSession ().add (entryBar );
180+ } catch (Exception e ) {
181+ System .out .println ("Error creating new DN." );
182+ }
152183 }
153184
154185 // Inject the apache root entry
155- if (!service .getAdminSession ().exists (apachePartition .getSuffixDn ())) {
156- DN dnApache = new DN ("dc=Apache,dc=Org" );
157- ServerEntry entryApache = service .newEntry (dnApache );
158- entryApache .add ("objectClass" , "top" , "domain" , "extensibleObject" );
159- entryApache .add ("dc" , "Apache" );
160- service .getAdminSession ().add (entryApache );
186+ try {
187+ if (!service .getAdminSession ().exists (apachePartition .getSuffixDn ())) {
188+ try {
189+ DN dnApache = new DN ("dc=Apache,dc=Org" );
190+ ServerEntry entryApache = service .newEntry (dnApache );
191+ entryApache .add ("objectClass" , "top" , "domain" , "extensibleObject" );
192+ entryApache .add ("dc" , "Apache" );
193+ service .getAdminSession ().add (entryApache );
194+ } catch (Exception e ) {
195+ System .out .println ("Error creating new DN." );
196+ }
197+ }
198+ } catch (Exception e ) {
199+ System .out .println ("Error when checking if partition exists." );
161200 }
162201
163- // We are all done !
164202 }
165203
166204 /**
@@ -184,7 +222,7 @@ private void initSchemaPartition() {
184222 SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor (wd );
185223 try {
186224 extractor .extractOrCopy ( true );
187- System .out .println ("is Extracted: " + extractor .isExtracted ());
225+ // System.out.println("is Extracted: " + extractor.isExtracted());
188226 } catch (Exception e ) {
189227 }
190228
@@ -282,7 +320,8 @@ public void stopServer() throws Exception {
282320 * @throws Exception
283321 */
284322 public static void main (String [] args ) throws Exception {
285- new LDAPServer ();
323+ LDAPServer ldap = new LDAPServer ();
324+ //ldap.stopServer();
286325 }
287326
288327}
0 commit comments