@@ -36,7 +36,7 @@ public class LDAPServer {
36
36
public LDAPServer () {
37
37
String dir = Utils .getFileFromClasspath ("benchmark.properties" , LDAPManager .class .getClassLoader ()).getParent ();
38
38
File workDir = new File (dir + "/../ldap" );
39
- System .out .println ("%%%%%%%%%%%%%%%%%%%%%%%%%%%% " + dir + "/../ldap" );
39
+ // System.out.println(dir + "/../ldap");
40
40
// File workDir = new File(System.getProperty("user.dir") +
41
41
workDir .mkdirs ();
42
42
@@ -56,7 +56,7 @@ public LDAPServer() {
56
56
}
57
57
58
58
// And print it if available
59
- System .out .println ("Found entry : " + result );
59
+ // System.out.println("Found entry : " + result);
60
60
61
61
// optionally we can start a server too
62
62
try {
@@ -97,17 +97,26 @@ public LDAPServer() {
97
97
* @throws Exception
98
98
* if there were some problems while initializing the system
99
99
*/
100
- private void initDirectoryService (File workDir ) throws Exception {
100
+ private void initDirectoryService (File workDir ){
101
101
// 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
+ }
103
107
service .setWorkingDirectory (workDir );
104
108
105
109
// first load the schema
106
110
initSchemaPartition ();
107
111
108
112
// then the system partition
109
113
// 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
+ }
111
120
service .setSystemPartition (systemPartition );
112
121
113
122
// Disable the ChangeLog system
@@ -116,51 +125,80 @@ private void initDirectoryService(File workDir) throws Exception {
116
125
117
126
// Now we can create as many partitions as we need
118
127
// 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
+ }
122
146
123
147
// Index some attributes on the apache partition
124
148
addIndex (apachePartition , "objectClass" , "ou" , "uid" );
125
149
try {
126
150
// And start the service
127
151
service .startup ();
128
152
} catch (Exception e ) {
129
- e .printStackTrace ();
130
- //System.out.println("%%%%%%%ERROR%%%%%%%%" + e.getMessage());
153
+ System .out .println ("Error at LDAP startup: " + e .getMessage ());
131
154
}
132
155
// Inject the foo root entry if it does not already exist
133
156
try {
134
157
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
+ }
141
168
}
142
169
143
170
// Inject the bar root entry
144
171
try {
145
172
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
+ }
152
183
}
153
184
154
185
// 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." );
161
200
}
162
201
163
- // We are all done !
164
202
}
165
203
166
204
/**
@@ -184,7 +222,7 @@ private void initSchemaPartition() {
184
222
SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor (wd );
185
223
try {
186
224
extractor .extractOrCopy ( true );
187
- System .out .println ("is Extracted: " + extractor .isExtracted ());
225
+ // System.out.println("is Extracted: " + extractor.isExtracted());
188
226
} catch (Exception e ) {
189
227
}
190
228
@@ -282,7 +320,8 @@ public void stopServer() throws Exception {
282
320
* @throws Exception
283
321
*/
284
322
public static void main (String [] args ) throws Exception {
285
- new LDAPServer ();
323
+ LDAPServer ldap = new LDAPServer ();
324
+ //ldap.stopServer();
286
325
}
287
326
288
327
}
0 commit comments