Author: norman
Date: Mon Apr 26 18:09:59 2010
New Revision: 938163
URL: http://svn.apache.org/viewvc?rev=938163&view=rev
Log:
Add war deployment. The only missing piece is to make it configurable where to
put the var, conf folder at. (JAMES-JAMES-834)
Added:
james/server/trunk/spring-deployment/src/main/config/war/
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/AbstractJamesResourceLoader.java
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/FileSystemRepositoryConfigFactory.java
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerWebApplicationContext.java
james/server/trunk/spring-deployment/src/main/webapp/
james/server/trunk/spring-deployment/src/main/webapp/WEB-INF/
james/server/trunk/spring-deployment/src/main/webapp/WEB-INF/web.xml
Modified:
james/server/trunk/core-api/src/main/java/org/apache/james/services/FileSystem.java
james/server/trunk/imapserver/src/main/java/org/apache/james/user/impl/file/FileUserMetaDataRepository.java
james/server/trunk/imapserver/src/test/java/org/apache/james/user/impl/file/FileUserMetaDataRepositoryTest.java
james/server/trunk/pom.xml
james/server/trunk/spoolmanager/src/main/java/org/apache/james/FileSpoolMessageStore.java
james/server/trunk/spring-deployment/pom.xml
james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesResourceLoader.java
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerApplicationContext.java
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/SpringFileSystem.java
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/SpringMailStore.java
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java
Modified:
james/server/trunk/core-api/src/main/java/org/apache/james/services/FileSystem.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/core-api/src/main/java/org/apache/james/services/FileSystem.java?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
---
james/server/trunk/core-api/src/main/java/org/apache/james/services/FileSystem.java
(original)
+++
james/server/trunk/core-api/src/main/java/org/apache/james/services/FileSystem.java
Mon Apr 26 18:09:59 2010
@@ -34,6 +34,32 @@ public interface FileSystem {
String ROLE = "org.apache.james.services.FileSystem";
+
+ /**
+ * Prefix for loading of a filesystem based on the current directory
+ */
+ public static final String FILE_PROTOCOL = "file://";
+
+ /**
+ * Prefix for loading of a filesystem using the absolute path
+ */
+ public static final String FILE_PROTOCOL_ABSOLUTE = "file:///";
+
+ /**
+ * Prefix for loading of the config directory
+ */
+ public static final String FILE_PROTOCOL_AND_CONF = "file://conf/";
+
+ /**
+ * Prefix for loading of the var directory
+ */
+ public static final String FILE_PROTOCOL_AND_VAR = "file://var/";
+
+ /**
+ * Prefix for loading of the classpath
+ */
+ public static final String CLASSPATH_PROTOCOL = "classpath:";
+
/**
* to retrieve a resource. this is typically a file resource,
* but depending on the implementation, this could also be from classpath
or
Modified:
james/server/trunk/imapserver/src/main/java/org/apache/james/user/impl/file/FileUserMetaDataRepository.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/main/java/org/apache/james/user/impl/file/FileUserMetaDataRepository.java?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
---
james/server/trunk/imapserver/src/main/java/org/apache/james/user/impl/file/FileUserMetaDataRepository.java
(original)
+++
james/server/trunk/imapserver/src/main/java/org/apache/james/user/impl/file/FileUserMetaDataRepository.java
Mon Apr 26 18:09:59 2010
@@ -29,10 +29,14 @@ import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
+
import org.apache.commons.io.FileUtils;
import org.apache.commons.io.IOUtils;
import org.apache.james.api.user.UserMetaDataRespository;
import org.apache.james.api.user.UserRepositoryException;
+import org.apache.james.services.FileSystem;
/**
* Stores user meta-data in the file system.
@@ -49,13 +53,39 @@ public class FileUserMetaDataRepository
'4','5','6','7','8','9'
};
- private final String baseDirectory;
+ private File baseDirectory;
+
+ private FileSystem fs;
+
+ private String baseDirUrl;
- public FileUserMetaDataRepository(final String baseDirectory) {
+ public FileUserMetaDataRepository() {
super();
- this.baseDirectory = baseDirectory;
}
+ @Resource(name="filesystem")
+ public void setFileSystem(FileSystem fs) {
+ this.fs = fs;
+ }
+
+ public void setBaseDirectory(String baseDirUrl) {
+ this.baseDirUrl = baseDirUrl;
+ }
+
+
+
+ @PostConstruct
+ public void init() throws Exception{
+ baseDirectory = fs.getFile(baseDirUrl);
+ if (!baseDirectory.exists()) {
+ if (!baseDirectory.mkdirs()) {
+ throw new Exception("Cannot create directory: " +
baseDirectory);
+ }
+ }
+ }
+
+
+
/*
* (non-Javadoc)
* @see
org.apache.james.api.user.UserMetaDataRespository#clear(java.lang.String)
@@ -125,11 +155,9 @@ public class FileUserMetaDataRepository
return valueFile;
}
- private File userDirectory(String username) throws UserRepositoryException
{
- final File baseDir = getBaseDirectory();
-
+ private File userDirectory(String username) throws UserRepositoryException
{
final String userDirectoryName = fileSystemSafeName(username);
- final File userDir = new File(baseDir, userDirectoryName);
+ final File userDir = new File(baseDirectory, userDirectoryName);
if (!userDir.exists()) {
if (!userDir.mkdir()) {
throw new UserRepositoryException("Cannot create directory: "
+ userDir.getAbsolutePath());
@@ -138,15 +166,7 @@ public class FileUserMetaDataRepository
return userDir;
}
- private File getBaseDirectory() throws UserRepositoryException {
- final File baseDir = new File(baseDirectory);
- if (!baseDir.exists()) {
- if (!baseDir.mkdirs()) {
- throw new UserRepositoryException("Cannot create directory: "
+ baseDirectory);
- }
- }
- return baseDir;
- }
+
/**
* Maps a value to a file-system safe name.
Modified:
james/server/trunk/imapserver/src/test/java/org/apache/james/user/impl/file/FileUserMetaDataRepositoryTest.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/imapserver/src/test/java/org/apache/james/user/impl/file/FileUserMetaDataRepositoryTest.java?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
---
james/server/trunk/imapserver/src/test/java/org/apache/james/user/impl/file/FileUserMetaDataRepositoryTest.java
(original)
+++
james/server/trunk/imapserver/src/test/java/org/apache/james/user/impl/file/FileUserMetaDataRepositoryTest.java
Mon Apr 26 18:09:59 2010
@@ -20,10 +20,14 @@
package org.apache.james.user.impl.file;
import java.io.File;
+import java.io.FileNotFoundException;
+import java.io.IOException;
+import java.io.InputStream;
import junit.framework.TestCase;
import org.apache.commons.io.FileUtils;
+import org.apache.james.services.FileSystem;
public class FileUserMetaDataRepositoryTest extends TestCase {
@@ -36,7 +40,22 @@ public class FileUserMetaDataRepositoryT
private static final String TEST_DIRECTORY = "target/testusermetadata";
- FileUserMetaDataRepository repository;
+ private FileUserMetaDataRepository repository;
+ private FileSystem fs = new FileSystem() {
+
+ public InputStream getResource(String url) throws IOException {
+ throw new UnsupportedOperationException();
+ }
+
+ public File getFile(String fileURL) throws FileNotFoundException {
+ fileURL = fileURL.substring("file://".length());
+ return new File(fileURL);
+ }
+
+ public File getBasedir() throws FileNotFoundException {
+ throw new UnsupportedOperationException();
+ }
+ };
protected void setUp() throws Exception {
super.setUp();
@@ -44,7 +63,10 @@ public class FileUserMetaDataRepositoryT
if (directory.exists()) {
FileUtils.deleteDirectory(directory);
}
- repository = new FileUserMetaDataRepository(TEST_DIRECTORY);
+ repository = new FileUserMetaDataRepository();
+ repository.setFileSystem(fs);
+ repository.setBaseDirectory("file://"+TEST_DIRECTORY);
+ repository.init();
}
public void testClear() throws Exception {
Modified: james/server/trunk/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/pom.xml?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
--- james/server/trunk/pom.xml (original)
+++ james/server/trunk/pom.xml Mon Apr 26 18:09:59 2010
@@ -912,6 +912,12 @@
</dependency>
<dependency>
<groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ <version>3.0.0.RELEASE</version>
+ </dependency>
+
+ <dependency>
+ <groupId>org.springframework</groupId>
<artifactId>spring-beans</artifactId>
<version>3.0.0.RELEASE</version>
</dependency>
Modified:
james/server/trunk/spoolmanager/src/main/java/org/apache/james/FileSpoolMessageStore.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spoolmanager/src/main/java/org/apache/james/FileSpoolMessageStore.java?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
---
james/server/trunk/spoolmanager/src/main/java/org/apache/james/FileSpoolMessageStore.java
(original)
+++
james/server/trunk/spoolmanager/src/main/java/org/apache/james/FileSpoolMessageStore.java
Mon Apr 26 18:09:59 2010
@@ -26,10 +26,13 @@ import java.io.OutputStream;
import java.util.ArrayList;
import java.util.List;
+import javax.annotation.PostConstruct;
+import javax.annotation.Resource;
import javax.mail.util.SharedFileInputStream;
import org.apache.james.core.MimeMessageSource;
import org.apache.james.lifecycle.Disposable;
+import org.apache.james.services.FileSystem;
/**
* Use the filesystem as storage for the Email message while spooling
@@ -41,12 +44,26 @@ public class FileSpoolMessageStore imple
private final String PROCESSING_SUFFIX =".processing";
private File spooldir;
+
+ private FileSystem fs;
+
+ private String spoolDir = "file://var/mail/spool";
+
+ @Resource(name="filesystem")
+ public void setFileSystem(FileSystem fs) {
+ this.fs = fs;
+ }
+
+ public void setSpoolDirectory(String spoolDir) {
+ this.spoolDir = spoolDir;
+ }
- public FileSpoolMessageStore(String storageDir) {
- spooldir = new File(storageDir);
+ @PostConstruct
+ public void init() throws Exception {
+ spooldir = fs.getFile(spoolDir);
if (spooldir.exists()) {
if (spooldir.isFile()) {
- throw new RuntimeException("Spooldirectory " + storageDir + "
already exists and is a file!");
+ throw new RuntimeException("Spooldirectory " + spoolDir + "
already exists and is a file!");
}
} else {
if (spooldir.mkdirs() == false) {
Modified: james/server/trunk/spring-deployment/pom.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/pom.xml?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/pom.xml (original)
+++ james/server/trunk/spring-deployment/pom.xml Mon Apr 26 18:09:59 2010
@@ -172,6 +172,51 @@
</execution>
</executions>
</plugin>
+
+ <plugin>
+ <groupId>org.apache.maven.plugins</groupId>
+ <artifactId>maven-war-plugin</artifactId>
+ <configuration>
+ <webResources>
+ <resource>
+ <directory>src/main/config/james</directory>
+ <!-- override the destination directory for this resource -->
+ <targetPath>WEB-INF/conf/</targetPath>
+ <excludes>
+ <exclude>log4j.properties</exclude>
+ <exclude>META-INF/persistence.xml</exclude>
+ </excludes>
+ </resource>
+ <resource>
+ <directory>src/main/config/james</directory>
+ <!-- override the destination directory for this resource -->
+ <targetPath>WEB-INF/classes/</targetPath>
+ <includes>
+ <include>log4j.properties</include>
+ <include>META-INF/persistence.xml</include>
+ </includes>
+ </resource>
+ <resource>
+ <directory>src/main/config/war</directory>
+ <!-- override the destination directory for this resource -->
+ <targetPath>WEB-INF/conf/</targetPath>
+
+ </resource>
+
+ </webResources>
+ </configuration>
+ <executions>
+ <execution>
+ <id>make-war</id>
+ <phase>package</phase>
+ <goals>
+ <goal>war</goal>
+ </goals>
+ </execution>
+ </executions>
+ </plugin>
+
+
<!-- be sure to start up james before run it -->
<!--
<plugin>
@@ -248,6 +293,11 @@
<artifactId>spring-context</artifactId>
</dependency>
<dependency>
+ <groupId>org.springframework</groupId>
+ <artifactId>spring-web</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>commons-configuration</groupId>
<artifactId>commons-configuration</artifactId>
</dependency>
@@ -401,10 +451,13 @@
<dependency>
<groupId>org.apache.jackrabbit</groupId>
<artifactId>jackrabbit-core</artifactId>
- <scope>runtime</scope>
</dependency>
-
- <dependency>
+ <dependency>
+ <groupId>javax.jcr</groupId>
+ <artifactId>jcr</artifactId>
+ </dependency>
+
+ <dependency>
<groupId>org.apache.derby</groupId>
<artifactId>derby</artifactId>
<scope>runtime</scope>
@@ -472,7 +525,6 @@
<dependency>
<groupId>org.apache.james</groupId>
<artifactId>james-server-smtpserver</artifactId>
- <version>3.0-SNAPSHOT</version>
<type>test-jar</type>
<scope>test</scope>
</dependency>
Modified:
james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
--- james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
(original)
+++ james/server/trunk/spring-deployment/src/main/config/james/spring-beans.xml
Mon Apr 26 18:09:59 2010
@@ -87,7 +87,7 @@
</bean>
<bean
class="org.springframework.beans.factory.config.PropertyPlaceholderConfigurer">
- <property name = "location" value="classpath:database.properties"/>
+ <property name = "location" value="file://conf/database.properties"/>
</bean>
<bean
class="org.apache.james.container.spring.lifecycle.LogEnabledBeanPostProcessor">
@@ -155,13 +155,14 @@
</bean>
<bean id="broker" class="org.apache.activemq.xbean.BrokerFactoryBean">
- <property name="config" value="classpath:activemq.xml" />
+ <property name="config" value="file://conf/activemq.xml" />
<property name="start" value="true" />
</bean>
<bean id ="spoolMessageStore"
class="org.apache.james.FileSpoolMessageStore">
- <constructor-arg index="0" value="../var/mail/spool"/>
+ <property name="spoolDirectory" value="file://var/mail/spool"/>
</bean>
+
<bean id ="mailClaimCheck"
class="org.apache.james.transport.camel.MailClaimCheck"/>
<bean id ="mailEnricher"
class="org.apache.james.transport.camel.MailEnricher"/>
@@ -308,7 +309,7 @@
<bean id="subscriper"
class="org.apache.james.imapserver.UserMetaDataRepositorySubscripter"/>
<bean id="userMetaDataRepository"
class="org.apache.james.user.impl.file.FileUserMetaDataRepository">
- <constructor-arg index="0" value="var/users"/>
+ <property name="baseDirectory" value="file://var/users"/>
</bean>
@@ -404,9 +405,12 @@
<bean id="jcrRepository" class="org.apache.jackrabbit.core.RepositoryImpl">
<constructor-arg index="0" ref="config" />
</bean>
- <bean id="config"
class="org.apache.jackrabbit.core.config.RepositoryConfig"
factory-method="create">
- <constructor-arg index="0" value="../conf/jcr-repository.xml"/>
- <constructor-arg index="1" value="../var/jackrabbit" />
+
+ <!-- Jackrabbit config -->
+ <bean id="config"
class="org.apache.james.container.spring.FileSystemRepositoryConfigFactory"
factory-method="create">
+ <constructor-arg index="0" value="file://conf/jcr-repository.xml"/>
+ <constructor-arg index="1" value="file://var/jackrabbit" />
+ <constructor-arg index="2" ref="filesystem"/>
</bean>
<!-- ####################################################################
-->
Added:
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/AbstractJamesResourceLoader.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/AbstractJamesResourceLoader.java?rev=938163&view=auto
==============================================================================
---
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/AbstractJamesResourceLoader.java
(added)
+++
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/AbstractJamesResourceLoader.java
Mon Apr 26 18:09:59 2010
@@ -0,0 +1,70 @@
+/****************************************************************
+ * 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.james.container.spring;
+
+import java.io.File;
+
+import org.apache.james.services.FileSystem;
+import org.springframework.context.ApplicationContext;
+import org.springframework.core.io.ClassPathResource;
+import org.springframework.core.io.DefaultResourceLoader;
+import org.springframework.core.io.FileSystemResource;
+import org.springframework.core.io.Resource;
+
+/**
+ * Abstract base class which load JAMES files based on the prefix. This can be
used in different
+ * {...@link ApplicationContext} implementations
+ *
+ *
+ */
+public abstract class AbstractJamesResourceLoader extends
DefaultResourceLoader implements JamesResourceLoader{
+
+
+
+ /**
+ * Return the {...@link Resource} for the given url. If the resource can
not be found null get returned
+ *
+ * @see
org.springframework.core.io.ResourceLoader#getResource(java.lang.String)
+ */
+ public Resource getResource(String fileURL) {
+ Resource r = null;
+ if (fileURL.startsWith(FileSystem.CLASSPATH_PROTOCOL)) {
+ String resourceName =
fileURL.substring(FileSystem.CLASSPATH_PROTOCOL.length());
+ r = new ClassPathResource(resourceName);
+ } else if (fileURL.startsWith(FileSystem.FILE_PROTOCOL)) {
+ File file = null;
+ if (fileURL.startsWith(FileSystem.FILE_PROTOCOL_AND_CONF)) {
+ file = new File(getConfDirectory() + "/" +
fileURL.substring(FileSystem.FILE_PROTOCOL_AND_CONF.length()));
+ } else if (fileURL.startsWith(FileSystem.FILE_PROTOCOL_AND_VAR)) {
+ file = new File(getVarDirectory() + "/" +
fileURL.substring(FileSystem.FILE_PROTOCOL_AND_VAR.length()));
+ } else if (fileURL.startsWith(FileSystem.FILE_PROTOCOL_ABSOLUTE)) {
+ file = new File(getAbsoluteDirectory() +
fileURL.substring(FileSystem.FILE_PROTOCOL_ABSOLUTE.length()));
+ } else {
+ // move to the root folder of the spring deployment
+ file = new File(getRootDirectory() + "/" +
fileURL.substring(FileSystem.FILE_PROTOCOL.length()));
+ }
+ r = new FileSystemResource(file);
+ } else {
+ return null;
+ }
+ return r;
+ }
+
+}
+
Added:
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/FileSystemRepositoryConfigFactory.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/FileSystemRepositoryConfigFactory.java?rev=938163&view=auto
==============================================================================
---
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/FileSystemRepositoryConfigFactory.java
(added)
+++
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/FileSystemRepositoryConfigFactory.java
Mon Apr 26 18:09:59 2010
@@ -0,0 +1,63 @@
+/****************************************************************
+ * 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.james.container.spring;
+
+import java.io.File;
+import java.io.FileNotFoundException;
+
+import org.apache.jackrabbit.core.config.ConfigurationException;
+import org.apache.jackrabbit.core.config.RepositoryConfig;
+import org.apache.james.services.FileSystem;
+
+/**
+ * Factory which use the {...@link FileSystem} to lookup the configuration
file and root directory to build a
+ * {...@link RepositoryConfig}
+ *
+ *
+ */
+public class FileSystemRepositoryConfigFactory{
+
+ /**
+ * Create a new {...@link RepositoryConfig}
+ *
+ * @param config
+ * @param root
+ * @param fs
+ * @return repositoryConfig
+ * @throws ConfigurationException
+ */
+ public static RepositoryConfig create(String config, String root,
FileSystem fs) throws ConfigurationException {
+ try {
+ File configFile = fs.getFile(config);
+ File rootDir = fs.getFile(root);
+
+ // create the rootDir if it not exist already
+ if (rootDir.exists() == false) {
+ rootDir.mkdirs();
+ }
+
+ return RepositoryConfig.create(configFile, rootDir);
+
+ } catch (FileNotFoundException e) {
+ throw new ConfigurationException("Unable to load configurationFile
", e);
+ }
+
+
+ }
+}
Modified:
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesResourceLoader.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesResourceLoader.java?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
---
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesResourceLoader.java
(original)
+++
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesResourceLoader.java
Mon Apr 26 18:09:59 2010
@@ -18,62 +18,42 @@
****************************************************************/
package org.apache.james.container.spring;
-import java.io.File;
-
-import org.springframework.context.ApplicationContext;
-import org.springframework.core.io.ClassPathResource;
-import org.springframework.core.io.FileSystemResource;
-import org.springframework.core.io.Resource;
import org.springframework.core.io.ResourceLoader;
/**
- * Abstract base class which load JAMES files based on the prefix. This can be
used in different
- * {...@link ApplicationContext} implementations
- *
+ * {...@link ResourceLoader} which offer extra methods to retrieve the Path to
all important
+ * Directories, which are in use by JAMES.
*
*/
-public abstract class JamesResourceLoader implements ResourceLoader{
+public interface JamesResourceLoader extends ResourceLoader{
- private static final String FILE_PROTOCOL = "file://";
- private static final String FILE_PROTOCOL_ABSOLUTE = "file:///";
+ /**
+ * Return the configuration directory of the application
+ *
+ * @return confDir
+ */
+ public String getAbsoluteDirectory();
- private static final String FILE_PROTOCOL_AND_CONF = "file://conf/";
- private static final String FILE_PROTOCOL_AND_VAR = "file://var/";
-
/**
- * Return the {...@link Resource} for the given url. If the resource can
not be found null get returned
+ * Return the var directory of the application
*
- * @see
org.springframework.core.io.ResourceLoader#getResource(java.lang.String)
+ * @return var
*/
- public Resource getResource(String fileURL) {
- Resource r = null;
- if (fileURL.startsWith("classpath:")) {
- String resourceName = fileURL.substring("classpath:".length());
- r = new ClassPathResource(resourceName);
- } else if (fileURL.startsWith(FILE_PROTOCOL)) {
- File file = null;
- if (fileURL.startsWith(FILE_PROTOCOL_AND_CONF)) {
- file = new File(getRootPath() + "/conf/" +
fileURL.substring(FILE_PROTOCOL_AND_CONF.length()));
- } else if (fileURL.startsWith(FILE_PROTOCOL_AND_VAR)) {
- file = new File(getRootPath() + "/var/" +
fileURL.substring(FILE_PROTOCOL_AND_VAR.length()));
- } else if (fileURL.startsWith(FILE_PROTOCOL_ABSOLUTE)) {
- file = new File("/" +
fileURL.substring(FILE_PROTOCOL_ABSOLUTE.length()));
- } else {
- // move to the root folder of the spring deployment
- file = new File(getRootPath() + "/" +
fileURL.substring(FILE_PROTOCOL.length()));
- }
- r = new FileSystemResource(file);
- } else {
- return null;
- }
- return r;
- }
+ public String getConfDirectory();
+
/**
- * Return the root path of the application
+ * Return the absolute directory of the application
+ *
+ * @return absolute
+ */
+ public String getVarDirectory();
+
+ /**
+ * Return the root directory of the application
*
- * @return rootPath
+ * @return rootDir
*/
- protected abstract String getRootPath();
+ public String getRootDirectory();
}
Modified:
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerApplicationContext.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerApplicationContext.java?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
---
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerApplicationContext.java
(original)
+++
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerApplicationContext.java
Mon Apr 26 18:09:59 2010
@@ -26,22 +26,45 @@ import org.springframework.core.io.Resou
* {...@link ApplicationContext} which loads all needed beans for JAMES
*
*/
-public class JamesServerApplicationContext extends
ClassPathXmlApplicationContext{
+public class JamesServerApplicationContext extends
ClassPathXmlApplicationContext implements JamesResourceLoader{
/**
- * The resourceloader to use
+ * The resourceloader to use. This must be defined as static, otherwise it
will fail to startup..
*/
- private final static JamesResourceLoader resourceLoader = new
JamesResourceLoader() {
+ private final static JamesResourceLoader resourceLoader = new
AbstractJamesResourceLoader() {
- @Override
- protected String getRootPath() {
- return "..";
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getAbsoluteDirectory()
+ */
+ public String getAbsoluteDirectory() {
+ return "/";
}
- public ClassLoader getClassLoader() {
- return this.getClassLoader();
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getConfDirectory()
+ */
+ public String getConfDirectory() {
+ return getRootDirectory() + "/conf/";
}
-
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getVarDirectory()
+ */
+ public String getVarDirectory() {
+ return getRootDirectory() + "/var/";
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getRootDirectory()
+ */
+ public String getRootDirectory() {
+ return "../";
+ }
+
};
@@ -62,4 +85,36 @@ public class JamesServerApplicationConte
return r;
}
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getAbsoluteDirectory()
+ */
+ public String getAbsoluteDirectory() {
+ return resourceLoader.getAbsoluteDirectory();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getConfDirectory()
+ */
+ public String getConfDirectory() {
+ return resourceLoader.getConfDirectory();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getVarDirectory()
+ */
+ public String getVarDirectory() {
+ return resourceLoader.getVarDirectory();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getRootDirectory()
+ */
+ public String getRootDirectory() {
+ return resourceLoader.getRootDirectory();
+ }
+
}
Added:
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerWebApplicationContext.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerWebApplicationContext.java?rev=938163&view=auto
==============================================================================
---
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerWebApplicationContext.java
(added)
+++
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/JamesServerWebApplicationContext.java
Mon Apr 26 18:09:59 2010
@@ -0,0 +1,154 @@
+/****************************************************************
+ * 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.james.container.spring;
+
+import org.springframework.core.io.Resource;
+import org.springframework.web.context.support.XmlWebApplicationContext;
+
+/**
+ * {...@link XmlWebApplicationContext} which is used to startup james in a
servlet
+ * container
+ *
+ */
+public class JamesServerWebApplicationContext extends XmlWebApplicationContext
implements JamesResourceLoader{
+
+ /**
+ * The resourceloader to use
+ */
+ private final JamesResourceLoader resourceLoader = new
AbstractJamesResourceLoader() {
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getAbsoluteDirectory()
+ */
+ public String getAbsoluteDirectory() {
+ if (absoluteDirectory == null) {
+ return getRootDirectory();
+ } else {
+ return absoluteDirectory;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getConfDirectory()
+ */
+ public String getConfDirectory() {
+ if (confDirectory == null) {
+ return getRootDirectory() + "/WEB-INF/conf/";
+ } else {
+ return confDirectory;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getRootDirectory()
+ */
+ public String getRootDirectory() {
+ if (rootDirectory == null) {
+ // the root dir is the same as the servlets path
+ return
JamesServerWebApplicationContext.this.getServletContext().getRealPath("/");
+ } else {
+ return rootDirectory;
+ }
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getVarDirectory()
+ */
+ public String getVarDirectory() {
+ if (varDirectory == null) {
+ return getRootDirectory() + "/var/";
+ } else {
+ return varDirectory;
+ }
+ }
+
+ };
+ private String rootDirectory;
+ private String absoluteDirectory;
+ private String varDirectory;
+ private String confDirectory;
+
+ /*
+ * (non-Javadoc)
+ *
+ * @see
+ * org.springframework.core.io.DefaultResourceLoader#getResource(java.lang
+ * .String)
+ */
+ public Resource getResource(String fileURL) {
+ // delegate the loading to the resourceloader
+ Resource r = resourceLoader.getResource(fileURL);
+ if (r == null) {
+ r = super.getResource(fileURL);
+ }
+ return r;
+ }
+
+ public void setRootDirectory(String rootDirectory) {
+ this.rootDirectory = rootDirectory;
+ }
+
+ public void setAbsoluteDirectory(String absoluteDirectory) {
+ this.absoluteDirectory = absoluteDirectory;
+ }
+
+
+ public void setVarDirectory(String varDirectory) {
+ this.varDirectory = varDirectory;
+ }
+
+ public void setConfDirectory(String confDirectory) {
+ this.confDirectory = confDirectory;
+ }
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getAbsoluteDirectory()
+ */
+ public String getAbsoluteDirectory() {
+ return resourceLoader.getAbsoluteDirectory();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getConfDirectory()
+ */
+ public String getConfDirectory() {
+ return resourceLoader.getConfDirectory();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getVarDirectory()
+ */
+ public String getVarDirectory() {
+ return resourceLoader.getVarDirectory();
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.container.spring.JamesResourceLoader#getRootDirectory()
+ */
+ public String getRootDirectory() {
+ return resourceLoader.getRootDirectory();
+ }
+}
Modified:
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/SpringFileSystem.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/SpringFileSystem.java?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
---
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/SpringFileSystem.java
(original)
+++
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/SpringFileSystem.java
Mon Apr 26 18:09:59 2010
@@ -19,31 +19,44 @@
package org.apache.james.container.spring;
import org.apache.james.services.FileSystem;
-import org.springframework.context.ResourceLoaderAware;
-import org.springframework.core.io.ResourceLoader;
+import org.springframework.beans.BeansException;
+import org.springframework.context.ApplicationContext;
+import org.springframework.context.ApplicationContextAware;
import java.io.File;
import java.io.FileNotFoundException;
import java.io.IOException;
import java.io.InputStream;
-public class SpringFileSystem implements FileSystem, ResourceLoaderAware {
-
+/**
+ * {...@link FileSystem} implementation which use the {...@link
JamesResourceLoader} to load all needed
+ * resources
+ *
+ */
+public class SpringFileSystem implements FileSystem, ApplicationContextAware {
+
+ private JamesResourceLoader resourceLoader = null;
+
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.services.FileSystem#getBasedir()
+ */
public File getBasedir() throws FileNotFoundException {
- return new File("./../");
+ return new File(resourceLoader.getRootDirectory());
}
- private ResourceLoader resourceLoader = null;
- /**
- * loads resources from classpath or file system
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.services.FileSystem#getResource(java.lang.String)
*/
public InputStream getResource(String url) throws IOException {
return resourceLoader.getResource(url).getInputStream();
}
- /**
- * @see org.apache.james.services.FileSystem#getFile(String filURL)
+ /*
+ * (non-Javadoc)
+ * @see org.apache.james.services.FileSystem#getFile(java.lang.String)
*/
public File getFile(String fileURL) throws FileNotFoundException {
try {
@@ -53,12 +66,14 @@ public class SpringFileSystem implements
}
}
- protected synchronized ResourceLoader getResourceLoader() {
- return resourceLoader;
- }
- public synchronized void setResourceLoader(ResourceLoader provider) {
- this.resourceLoader = provider;
+ /*
+ * (non-Javadoc)
+ * @see
org.springframework.context.ApplicationContextAware#setApplicationContext(org.springframework.context.ApplicationContext)
+ */
+ public void setApplicationContext(ApplicationContext context) throws
BeansException {
+ this.resourceLoader = (JamesResourceLoader)context;
}
+
}
Modified:
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/SpringMailStore.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/SpringMailStore.java?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
---
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/SpringMailStore.java
(original)
+++
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/SpringMailStore.java
Mon Apr 26 18:09:59 2010
@@ -1,51 +1,77 @@
-package org.apache.james.container.spring;
-
-import javax.annotation.Resource;
-
-import org.apache.commons.configuration.HierarchicalConfiguration;
-import org.apache.commons.logging.Log;
-import org.apache.james.mailrepository.AbstractMailStore;
-import org.springframework.beans.BeansException;
-import org.springframework.beans.factory.BeanFactory;
-import org.springframework.beans.factory.BeanFactoryAware;
-import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
-
-public class SpringMailStore extends AbstractMailStore implements
BeanFactoryAware{
-
- private Registry<HierarchicalConfiguration> confRegistry;
- private Registry<Log> logRegistry;
-
- @Resource(name="configurationRegistry")
- public void setConfigurationRegistry(Registry<HierarchicalConfiguration>
confRegistry) {
- this.confRegistry = confRegistry;
- }
-
- @Resource(name="logRegistry")
- public void setLogRegistry(Registry<Log> logRegistry) {
- this.logRegistry = logRegistry;
- }
-
- private ConfigurableListableBeanFactory factory;
-
- /*
- * (non-Javadoc)
- * @see
org.apache.james.mailrepository.AbstractMailStore#load(java.lang.String,
org.apache.commons.configuration.HierarchicalConfiguration,
org.apache.commons.logging.Log)
- */
- protected Object load(String className, HierarchicalConfiguration config,
Log log) throws Exception{
-
- // just register it with the classname as key. The createBean method
will use the classname as BeanDefinitation name anyway
- confRegistry.registerForComponent(className, config);
- logRegistry.registerForComponent(className, log);
-
- return
factory.createBean(factory.getBeanClassLoader().loadClass(className));
- }
-
- /*
- * (non-Javadoc)
- * @see
org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
- */
- public void setBeanFactory(BeanFactory factory) throws BeansException {
- this.factory = (ConfigurableListableBeanFactory) factory;
- }
-
-}
+/****************************************************************
+ * 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.james.container.spring;
+
+import javax.annotation.Resource;
+
+import org.apache.commons.configuration.HierarchicalConfiguration;
+import org.apache.commons.logging.Log;
+import org.apache.james.mailrepository.AbstractMailStore;
+import org.apache.james.services.MailRepository;
+import org.apache.james.services.store.Store;
+import org.springframework.beans.BeansException;
+import org.springframework.beans.factory.BeanFactory;
+import org.springframework.beans.factory.BeanFactoryAware;
+import
org.springframework.beans.factory.config.ConfigurableListableBeanFactory;
+
+/**
+ * {...@link Store} implementation which load {...@link MailRepository}
implementation on demand
+ *
+ *
+ */
+public class SpringMailStore extends AbstractMailStore implements
BeanFactoryAware{
+
+ private Registry<HierarchicalConfiguration> confRegistry;
+ private Registry<Log> logRegistry;
+
+ @Resource(name="configurationRegistry")
+ public void setConfigurationRegistry(Registry<HierarchicalConfiguration>
confRegistry) {
+ this.confRegistry = confRegistry;
+ }
+
+ @Resource(name="logRegistry")
+ public void setLogRegistry(Registry<Log> logRegistry) {
+ this.logRegistry = logRegistry;
+ }
+
+ private ConfigurableListableBeanFactory factory;
+
+ /*
+ * (non-Javadoc)
+ * @see
org.apache.james.mailrepository.AbstractMailStore#load(java.lang.String,
org.apache.commons.configuration.HierarchicalConfiguration,
org.apache.commons.logging.Log)
+ */
+ protected Object load(String className, HierarchicalConfiguration config,
Log log) throws Exception{
+
+ // just register it with the classname as key. The createBean method
will use the classname as BeanDefinitation name anyway
+ confRegistry.registerForComponent(className, config);
+ logRegistry.registerForComponent(className, log);
+
+ return
factory.createBean(factory.getBeanClassLoader().loadClass(className));
+ }
+
+ /*
+ * (non-Javadoc)
+ * @see
org.springframework.beans.factory.BeanFactoryAware#setBeanFactory(org.springframework.beans.factory.BeanFactory)
+ */
+ public void setBeanFactory(BeanFactory factory) throws BeansException {
+ this.factory = (ConfigurableListableBeanFactory) factory;
+ }
+
+}
Modified:
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java?rev=938163&r1=938162&r2=938163&view=diff
==============================================================================
---
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java
(original)
+++
james/server/trunk/spring-deployment/src/main/java/org/apache/james/container/spring/lifecycle/SpringConfigurationRegistry.java
Mon Apr 26 18:09:59 2010
@@ -53,7 +53,7 @@ public class SpringConfigurationRegistry
if (conf != null) {
return conf;
} else {
- Resource r = loader.getResource("classpath:" + name + ".xml");
+ Resource r = loader.getResource("file://conf/" + name + ".xml");
if (r.exists()) {
try {
return getConfig(r);
Added: james/server/trunk/spring-deployment/src/main/webapp/WEB-INF/web.xml
URL:
http://svn.apache.org/viewvc/james/server/trunk/spring-deployment/src/main/webapp/WEB-INF/web.xml?rev=938163&view=auto
==============================================================================
--- james/server/trunk/spring-deployment/src/main/webapp/WEB-INF/web.xml (added)
+++ james/server/trunk/spring-deployment/src/main/webapp/WEB-INF/web.xml Mon
Apr 26 18:09:59 2010
@@ -0,0 +1,34 @@
+<!DOCTYPE web-app PUBLIC '-//Sun Microsystems, Inc.//DTD Web Application
2.3//EN' 'http://java.sun.com/dtd/web-app_2_3.dtd'>
+ <!--
+ ! 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. !
+ -->
+
+<web-app>
+ <context-param>
+ <param-name>contextConfigLocation</param-name>
+ <param-value>
+ /WEB-INF/conf/spring-beans.xml
+ /WEB-INF/conf/spring-war-beans.xml
+ </param-value>
+ </context-param>
+ <context-param>
+ <param-name>contextClass</param-name>
+
<param-value>org.apache.james.container.spring.JamesServerWebApplicationContext</param-value>
+ </context-param>
+ <listener>
+
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
+ </listener>
+
+
+</web-app>
\ No newline at end of file
---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]