o upgraded the webapp to 1.5.8-SNAPSHOT
authorKiran Ayyagari <kayyagari@apache.org>
Thu, 29 Jul 2010 20:43:23 +0000 (20:43 +0000)
committerKiran Ayyagari <kayyagari@apache.org>
Thu, 29 Jul 2010 20:43:23 +0000 (20:43 +0000)
o changed the log level to WARN

git-svn-id: https://svn.apache.org/repos/asf/directory/samples/trunk@980566 13f79535-47bb-0310-9956-ffa450edef68

apacheds-archetype-webapp/archetype-catalog.xml
apacheds-archetype-webapp/pom.xml
apacheds-archetype-webapp/src/main/resources/archetype-resources/pom.xml
apacheds-archetype-webapp/src/main/resources/archetype-resources/src/main/java/StartStopListener.java
apacheds-archetype-webapp/src/main/resources/archetype-resources/src/main/resources/log4j.properties

index bc03797..c0d4796 100644 (file)
@@ -26,7 +26,7 @@
     <archetype>
       <groupId>org.apache.directory.samples</groupId>
       <artifactId>apacheds-archetype-webapp</artifactId>
-      <version>1.5.5-SNAPSHOT</version>
+      <version>1.5.8-SNAPSHOT</version>
       <!-- FIX ME after the first release
       <version>RELEASE</version>
        -->
index 4a9c909..829de12 100644 (file)
@@ -32,7 +32,7 @@ under the License.
   <packaging>maven-archetype</packaging>
   <name>ApacheDS Archetype Web Application</name>
   <description>Archetype to embed ApacheDS as a Web Application</description>
-  <version>1.5.5-SNAPSHOT</version>
+  <version>1.5.8-SNAPSHOT</version>
 
   <prerequisites>
     <maven>2.0.9</maven>
index 7b3a44f..aed7e84 100644 (file)
@@ -63,8 +63,8 @@ under the License.
   <dependencies>
     <dependency>
       <groupId>org.apache.directory.server</groupId>
-      <artifactId>apacheds-protocol-ldap</artifactId>
-      <version>1.5.5</version>
+      <artifactId>apacheds-all</artifactId>
+      <version>1.5.8-SNAPSHOT</version>
     </dependency>
     <dependency>
       <groupId>org.slf4j</groupId>
index 0582767..1907c3f 100644 (file)
@@ -21,16 +21,30 @@ package ${package};
 
 
 import java.io.File;
+import java.util.List;
 
 import javax.servlet.ServletContext;
 import javax.servlet.ServletContextEvent;
 import javax.servlet.ServletContextListener;
 
+import org.apache.directory.server.constants.ServerDNConstants;
 import org.apache.directory.server.core.DefaultDirectoryService;
 import org.apache.directory.server.core.DirectoryService;
+import org.apache.directory.server.core.factory.JdbmPartitionFactory;
+import org.apache.directory.server.core.partition.Partition;
+import org.apache.directory.server.core.partition.ldif.LdifPartition;
+import org.apache.directory.server.core.schema.SchemaPartition;
+import org.apache.directory.server.i18n.I18n;
 import org.apache.directory.server.ldap.LdapServer;
 import org.apache.directory.server.protocol.shared.transport.TcpTransport;
-
+import org.apache.directory.shared.ldap.constants.SchemaConstants;
+import org.apache.directory.shared.ldap.schema.SchemaManager;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.SchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.ldif.extractor.impl.DefaultSchemaLdifExtractor;
+import org.apache.directory.shared.ldap.schema.loader.ldif.LdifSchemaLoader;
+import org.apache.directory.shared.ldap.schema.manager.impl.DefaultSchemaManager;
+import org.apache.directory.shared.ldap.schema.registries.SchemaLoader;
+import org.apache.directory.server.core.factory.JdbmPartitionFactory;
 
 /**
  * A Servlet context listener to start and stop ApacheDS.
@@ -67,8 +81,14 @@ public class StartStopListener implements ServletContextListener
             // Determine an appropriate working directory
             ServletContext servletContext = evt.getServletContext();
             File workingDir = ( File ) servletContext.getAttribute( "javax.servlet.context.tempdir" );
+            workingDir = new File( workingDir, "server-work" );
+            workingDir.mkdirs();
+            
             directoryService.setWorkingDirectory( workingDir );
 
+            initSchema();
+            initSystemPartition();
+            
             directoryService.startup();
             ldapServer.start();
 
@@ -97,4 +117,77 @@ public class StartStopListener implements ServletContextListener
             throw new RuntimeException( e );
         }
     }
+    
+    
+    /**
+     * Inits the schema and schema partition.
+     */
+    private void initSchema() throws Exception
+    {
+        SchemaPartition schemaPartition = directoryService.getSchemaService().getSchemaPartition();
+
+        // Init the LdifPartition
+        LdifPartition ldifPartition = new LdifPartition();
+        String workingDirectory = directoryService.getWorkingDirectory().getPath();
+        ldifPartition.setWorkingDirectory( workingDirectory + "/schema" );
+
+        // Extract the schema on disk (a brand new one) and load the registries
+        File serverWorkDirectory = new File( workingDirectory );
+        File schemaRepository = new File( serverWorkDirectory, "schema" );
+        SchemaLdifExtractor extractor = new DefaultSchemaLdifExtractor( serverWorkDirectory );
+        if( ! schemaRepository.exists() )
+        {
+            // extract only if the schema directory is not present
+            extractor.extractOrCopy();
+        }
+        else
+        {
+            System.out.println( "schema partition directory exists, skipping schema extraction" );
+        }
+
+        schemaPartition.setWrappedPartition( ldifPartition );
+
+        SchemaLoader loader = new LdifSchemaLoader( schemaRepository );
+        SchemaManager schemaManager = new DefaultSchemaManager( loader );
+        directoryService.setSchemaManager( schemaManager );
+
+        // We have to load the schema now, otherwise we won't be able
+        // to initialize the Partitions, as we won't be able to parse 
+        // and normalize their suffix DN
+        schemaManager.loadAllEnabled();
+
+        schemaPartition.setSchemaManager( schemaManager );
+
+        List<Throwable> errors = schemaManager.getErrors();
+
+        if ( errors.size() != 0 )
+        {
+            System.out.println( errors );
+            throw new RuntimeException( "there were errors while loading schema" );
+        }
+    }
+
+    
+    /**
+     * Inits the system partition.
+     * 
+     * @throws Exception the exception
+     */
+    private void initSystemPartition() throws Exception
+    {
+        // change the working directory to something that is unique
+        // on the system and somewhere either under target directory
+        // or somewhere in a temp area of the machine.
+        JdbmPartitionFactory partitionFactory = new JdbmPartitionFactory();
+
+        // Inject the System Partition
+        Partition systemPartition = partitionFactory.createPartition( "system", ServerDNConstants.SYSTEM_DN, 500,
+            new File( directoryService.getWorkingDirectory(), "system" ) );
+        systemPartition.setSchemaManager( directoryService.getSchemaManager() );
+
+        partitionFactory.addIndex( systemPartition, SchemaConstants.OBJECT_CLASS_AT, 100 );
+
+        directoryService.setSystemPartition( systemPartition );
+    }
+
 }
\ No newline at end of file
index ea0c377..f3d839f 100644 (file)
@@ -14,7 +14,7 @@
 #    See the License for the specific language governing permissions and
 #    limitations under the License.
 #############################################################################
-log4j.rootCategory=INFO, stdout, R
+log4j.rootCategory=WARN, stdout, R
 
 log4j.appender.stdout=org.apache.log4j.ConsoleAppender
 log4j.appender.stdout.layout=org.apache.log4j.PatternLayout