You are viewing a plain text version of this content. The canonical link for it is here.
Posted to commits@directory.apache.org by ka...@apache.org on 2009/08/02 20:23:34 UTC
svn commit: r800123 - in /directory: apacheds/trunk/
apacheds/trunk/http-integration/ apacheds/trunk/http-integration/src/
apacheds/trunk/http-integration/src/main/
apacheds/trunk/http-integration/src/main/java/
apacheds/trunk/http-integration/src/main...
Author: kayyagari
Date: Sun Aug 2 18:23:33 2009
New Revision: 800123
URL: http://svn.apache.org/viewvc?rev=800123&view=rev
Log:
integrated jetty http server(DIRSERVER-1262)
Added:
directory/apacheds/trunk/http-integration/
directory/apacheds/trunk/http-integration/pom.xml
directory/apacheds/trunk/http-integration/src/
directory/apacheds/trunk/http-integration/src/main/
directory/apacheds/trunk/http-integration/src/main/java/
directory/apacheds/trunk/http-integration/src/main/java/org/
directory/apacheds/trunk/http-integration/src/main/java/org/apache/
directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/
directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/
directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/
directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/
directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/HttpServer.java
directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/WebApp.java
Modified:
directory/apacheds/trunk/pom.xml
directory/apacheds/trunk/server-xml/pom.xml
directory/apacheds/trunk/server-xml/src/main/resources/server.xml
directory/apacheds/trunk/xbean-spring/pom.xml
directory/installers/trunk/apacheds-noarch/src/main/java/org/apache/directory/server/Service.java
directory/installers/trunk/pom.xml
Added: directory/apacheds/trunk/http-integration/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/http-integration/pom.xml?rev=800123&view=auto
==============================================================================
--- directory/apacheds/trunk/http-integration/pom.xml (added)
+++ directory/apacheds/trunk/http-integration/pom.xml Sun Aug 2 18:23:33 2009
@@ -0,0 +1,74 @@
+<?xml version="1.0" encoding="UTF-8"?>
+
+<!--
+ Licensed to the Apache Software Foundation (ASF) under one
+ or more contributor license agreements. See the NOTICE file
+ distributed with this work for additional information
+ regarding copyright ownership. The ASF licenses this file
+ to you under the Apache License, Version 2.0 (the
+ "License"); you may not use this file except in compliance
+ with the License. You may obtain a copy of the License at
+
+ http://www.apache.org/licenses/LICENSE-2.0
+
+ Unless required by applicable law or agreed to in writing,
+ software distributed under the License is distributed on an
+ "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ KIND, either express or implied. See the License for the
+ specific language governing permissions and limitations
+ under the License.
+-->
+
+<project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd">
+ <parent>
+ <artifactId>apacheds-parent</artifactId>
+ <groupId>org.apache.directory.server</groupId>
+ <version>1.5.5-SNAPSHOT</version>
+ </parent>
+ <modelVersion>4.0.0</modelVersion>
+ <groupId>org.apache.directory.server.http</groupId>
+ <artifactId>apacheds-http-integration</artifactId>
+ <name>ApacheDS jetty http server integration</name>
+ <version>1.5.5-SNAPSHOT</version>
+
+ <properties>
+ <jetty.version>6.1.14</jetty.version>
+ </properties>
+
+ <dependencies>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty</artifactId>
+ <version>${jetty.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>servlet-api-2.5</artifactId>
+ <version>${jetty.version}</version>
+ </dependency>
+ <dependency>
+ <groupId>org.mortbay.jetty</groupId>
+ <artifactId>jetty-util</artifactId>
+ <version>${jetty.version}</version>
+ </dependency>
+ </dependencies>
+
+ <build>
+ <plugins>
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-source-plugin</artifactId>
+ <executions>
+ <execution>
+ <id>attach-sources</id>
+ <phase>verify</phase>
+ <goals>
+ <goal>jar</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+ </plugins>
+ </build>
+
+</project>
\ No newline at end of file
Added: directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/HttpServer.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/HttpServer.java?rev=800123&view=auto
==============================================================================
--- directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/HttpServer.java (added)
+++ directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/HttpServer.java Sun Aug 2 18:23:33 2009
@@ -0,0 +1,201 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.server.integration.http;
+
+
+import java.io.FileInputStream;
+import java.util.ArrayList;
+import java.util.List;
+import java.util.Set;
+
+import org.mortbay.jetty.Connector;
+import org.mortbay.jetty.Handler;
+import org.mortbay.jetty.Server;
+import org.mortbay.jetty.nio.SelectChannelConnector;
+import org.mortbay.jetty.webapp.WebAppContext;
+import org.mortbay.xml.XmlConfiguration;
+import org.slf4j.Logger;
+import org.slf4j.LoggerFactory;
+
+
+/**
+ * Class to start the jetty http server
+ *
+ * @org.apache.xbean.XBean
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class HttpServer
+{
+
+ /** the jetty http server instance */
+ private Server jetty;
+
+ /** jetty config file */
+ private String confFile;
+
+ /** a collection to hold the configured web applications */
+ private Set<WebApp> webApps;
+
+ private int port = 8080;
+
+ private boolean configured = false;
+
+ private static final Logger LOG = LoggerFactory.getLogger( HttpServer.class );
+
+
+ public HttpServer()
+ {
+ }
+
+
+ /**
+ * starts the jetty http server
+ *
+ * @throws Exception
+ */
+ public void start() throws Exception
+ {
+
+ if ( confFile == null && ( webApps == null || webApps.isEmpty() ) )
+ {
+ LOG.warn( "Neither configuration file nor web apps were configured for the http server, skipping initialization." );
+ return;
+ }
+
+ XmlConfiguration jettyConf = null;
+
+ if ( confFile != null )
+ {
+ jettyConf = new XmlConfiguration( new FileInputStream( confFile ) );
+
+ LOG.info( "configuring jetty http server from the configuration file {}", confFile );
+
+ try
+ {
+ jetty = new Server();
+ jettyConf.configure( jetty );
+ configured = true;
+ }
+ catch ( Exception e )
+ {
+ LOG.error( "Failed to configure the jetty http server" );
+ throw e;
+ }
+ }
+ else
+ {
+ LOG.info( "No configuration file set, looking for web apps" );
+ configureServerThroughCode();
+ }
+
+ if ( configured )
+ {
+ LOG.info( "starting jetty http server" );
+ jetty.start();
+ }
+ else
+ {
+ jetty = null;
+ LOG.warn( "Error while configuring the http server, skipping the http server startup" );
+ }
+ }
+
+
+ /*
+ * configure the jetty server programmatically without using any configuration file
+ */
+ private void configureServerThroughCode()
+ {
+ try
+ {
+ jetty = new Server();
+
+ Connector connector = new SelectChannelConnector();
+ connector.setPort( port );
+ jetty.setConnectors( new Connector[]{ connector } );
+
+ List<Handler> handlers = new ArrayList<Handler>();
+ for ( WebApp w : webApps )
+ {
+ WebAppContext webapp = new WebAppContext();
+ webapp.setWar( w.getWarFile() );
+ webapp.setContextPath( w.getContextPath() );
+ handlers.add( webapp );
+ }
+
+ jetty.setHandlers( handlers.toArray( new Handler[ handlers.size() ] ) );
+
+ configured = true;
+ }
+ catch ( Exception e )
+ {
+ LOG.error( "Failed to configure the web application(s)", e );
+ }
+
+ }
+
+
+ /**
+ * stops the jetty http server
+ *
+ * @throws Exception
+ */
+ public void stop() throws Exception
+ {
+ if ( jetty != null && jetty.isStarted() )
+ {
+ LOG.info( "stopping jetty http server" );
+ jetty.stop();
+ }
+ }
+
+
+ public void setConfFile( String confFile )
+ {
+ this.confFile = confFile;
+ }
+
+
+ public Set<WebApp> getWebApps()
+ {
+ return webApps;
+ }
+
+
+ public void setWebApps( Set<WebApp> webapps )
+ {
+ this.webApps = webapps;
+ }
+
+
+ public int getPort()
+ {
+ return port;
+ }
+
+
+ public void setPort( int port )
+ {
+ this.port = port;
+ }
+
+}
Added: directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/WebApp.java
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/WebApp.java?rev=800123&view=auto
==============================================================================
--- directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/WebApp.java (added)
+++ directory/apacheds/trunk/http-integration/src/main/java/org/apache/directory/server/integration/http/WebApp.java Sun Aug 2 18:23:33 2009
@@ -0,0 +1,73 @@
+/*
+ * Licensed to the Apache Software Foundation (ASF) under one
+ * or more contributor license agreements. See the NOTICE file
+ * distributed with this work for additional information
+ * regarding copyright ownership. The ASF licenses this file
+ * to you under the Apache License, Version 2.0 (the
+ * "License"); you may not use this file except in compliance
+ * with the License. You may obtain a copy of the License at
+ *
+ * http://www.apache.org/licenses/LICENSE-2.0
+ *
+ * Unless required by applicable law or agreed to in writing,
+ * software distributed under the License is distributed on an
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
+ * KIND, either express or implied. See the License for the
+ * specific language governing permissions and limitations
+ * under the License.
+ *
+ */
+
+package org.apache.directory.server.integration.http;
+
+import java.io.File;
+
+
+/**
+ * A class to configure a web application
+ *
+ * @org.apache.xbean.XBean
+ * @author <a href="mailto:dev@directory.apache.org">Apache Directory Project</a>
+ * @version $Rev$, $Date$
+ */
+public class WebApp
+{
+
+ /** complete path name of a war file */
+ private String warFile;
+
+ /** context path of this web application, defaults to the war file's name */
+ private String contextPath;
+
+
+ public String getWarFile()
+ {
+ return warFile;
+ }
+
+
+ public String getContextPath()
+ {
+ if( contextPath != null )
+ {
+ return contextPath;
+ }
+
+ String fileName = new File( warFile ).getName();
+
+ return fileName.substring( 0, fileName.lastIndexOf( '.' ) );
+ }
+
+
+ public void setWarFile( String warFile )
+ {
+ this.warFile = warFile;
+ }
+
+
+ public void setContextPath( String contextPath )
+ {
+ this.contextPath = contextPath;
+ }
+
+}
Modified: directory/apacheds/trunk/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/pom.xml?rev=800123&r1=800122&r2=800123&view=diff
==============================================================================
--- directory/apacheds/trunk/pom.xml (original)
+++ directory/apacheds/trunk/pom.xml Sun Aug 2 18:23:33 2009
@@ -380,6 +380,7 @@
<module>server-replication</module>
<module>xbean-spring</module>
<module>ldap-api-test</module>
+ <module>http-integration</module>
</modules>
<reporting>
Modified: directory/apacheds/trunk/server-xml/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-xml/pom.xml?rev=800123&r1=800122&r2=800123&view=diff
==============================================================================
--- directory/apacheds/trunk/server-xml/pom.xml (original)
+++ directory/apacheds/trunk/server-xml/pom.xml Sun Aug 2 18:23:33 2009
@@ -96,6 +96,13 @@
</dependency>
<dependency>
+ <groupId>org.apache.directory.server.http</groupId>
+ <artifactId>apacheds-http-integration</artifactId>
+ <version>${pom.version}</version>
+ <scope>test</scope>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.xbean</groupId>
<artifactId>xbean-spring</artifactId>
<version>3.4.3</version>
Modified: directory/apacheds/trunk/server-xml/src/main/resources/server.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/server-xml/src/main/resources/server.xml?rev=800123&r1=800122&r2=800123&view=diff
==============================================================================
--- directory/apacheds/trunk/server-xml/src/main/resources/server.xml (original)
+++ directory/apacheds/trunk/server-xml/src/main/resources/server.xml Sun Aug 2 18:23:33 2009
@@ -244,4 +244,16 @@
<apacheDS id="apacheDS">
<ldapServer>#ldapServer</ldapServer>
</apacheDS>
+
+ <!-- uncomment the below line to start the jetty(v6.1.14) http server
+ This can be used to provide access to the data present in DIT via http
+ using a web application
+ -->
+ <!--
+ <httpServer id="httpServer" port="7009" >
+ <webApps>
+ <webApp warFile="/path/to/war/file" contextPath="/myApp"/>
+ </webApps>
+ </httpServer>
+ -->
</spring:beans>
Modified: directory/apacheds/trunk/xbean-spring/pom.xml
URL: http://svn.apache.org/viewvc/directory/apacheds/trunk/xbean-spring/pom.xml?rev=800123&r1=800122&r2=800123&view=diff
==============================================================================
--- directory/apacheds/trunk/xbean-spring/pom.xml (original)
+++ directory/apacheds/trunk/xbean-spring/pom.xml Sun Aug 2 18:23:33 2009
@@ -132,6 +132,14 @@
</dependency>
<dependency>
+ <groupId>org.apache.directory.server.http</groupId>
+ <artifactId>apacheds-http-integration</artifactId>
+ <version>${pom.version}</version>
+ <classifier>sources</classifier>
+ <scope>provided</scope>
+ </dependency>
+
+ <dependency>
<groupId>xerces</groupId>
<artifactId>xercesImpl</artifactId>
</dependency>
Modified: directory/installers/trunk/apacheds-noarch/src/main/java/org/apache/directory/server/Service.java
URL: http://svn.apache.org/viewvc/directory/installers/trunk/apacheds-noarch/src/main/java/org/apache/directory/server/Service.java?rev=800123&r1=800122&r2=800123&view=diff
==============================================================================
--- directory/installers/trunk/apacheds-noarch/src/main/java/org/apache/directory/server/Service.java (original)
+++ directory/installers/trunk/apacheds-noarch/src/main/java/org/apache/directory/server/Service.java Sun Aug 2 18:23:33 2009
@@ -21,9 +21,6 @@
import java.io.File;
-import java.io.IOException;
-
-import javax.naming.NamingException;
import org.apache.directory.daemon.DaemonApplication;
import org.apache.directory.daemon.InstallationLayout;
@@ -32,6 +29,7 @@
import org.apache.directory.server.core.DefaultDirectoryService;
import org.apache.directory.server.core.DirectoryService;
import org.apache.directory.server.dns.DnsServer;
+import org.apache.directory.server.integration.http.HttpServer;
import org.apache.directory.server.kerberos.kdc.KdcServer;
import org.apache.directory.server.ldap.LdapServer;
import org.apache.directory.server.ntp.NtpServer;
@@ -69,6 +67,8 @@
private ApacheDS apacheDS;
+ private HttpServer httpServer;
+
private FileSystemXmlApplicationContext factory;
@@ -91,6 +91,9 @@
// Initialize the Kerberos server
initKerberos( install, args );
+
+ // initialize the jetty http server
+ initHttpServer();
}
@@ -282,7 +285,23 @@
}
}
+
+ private void initHttpServer() throws Exception
+ {
+ if( factory == null )
+ {
+ return;
+ }
+
+ httpServer = ( HttpServer ) factory.getBean( "httpServer" );
+
+ if( httpServer != null )
+ {
+ httpServer.start();
+ }
+ }
+
public DirectoryService getDirectoryService() {
return ldapServer.getDirectoryService();
}
Modified: directory/installers/trunk/pom.xml
URL: http://svn.apache.org/viewvc/directory/installers/trunk/pom.xml?rev=800123&r1=800122&r2=800123&view=diff
==============================================================================
--- directory/installers/trunk/pom.xml (original)
+++ directory/installers/trunk/pom.xml Sun Aug 2 18:23:33 2009
@@ -169,6 +169,12 @@
</dependency>
<dependency>
+ <groupId>org.apache.directory.server.http</groupId>
+ <artifactId>apacheds-http-integration</artifactId>
+ <version>${pom.version}</version>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.mina</groupId>
<artifactId>mina-core</artifactId>
<version>2.0.0-M6</version>
@@ -479,6 +485,11 @@
</dependency>
<dependency>
+ <groupId>org.apache.directory.server.http</groupId>
+ <artifactId>apacheds-http-integration</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.slf4j</groupId>
<artifactId>slf4j-api</artifactId>
</dependency>