Skip to content
Permalink
Browse files
o upgraded the webapp to 1.5.8-SNAPSHOT
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
  • Loading branch information
kayyagari committed Jul 29, 2010
1 parent f6850e2 commit 767503216588fd15653d0d04a1d5481965ba808b
Showing 5 changed files with 99 additions and 6 deletions.
@@ -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>
-->
@@ -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>
@@ -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>
@@ -21,16 +21,30 @@


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 void contextInitialized( ServletContextEvent evt )
// 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 void contextDestroyed( ServletContextEvent evt )
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 );
}

}
@@ -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

0 comments on commit 7675032

Please sign in to comment.