JAMES-1842: Add jpa-guice module
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/d65e484a Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/d65e484a Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/d65e484a Branch: refs/heads/master Commit: d65e484a701c04efd570fc8fbc6050a5f273ed33 Parents: 4bc564d Author: Quynh Nguyen <qngu...@linagora.com> Authored: Fri Oct 28 12:24:15 2016 +0700 Committer: Quynh Nguyen <qngu...@linagora.com> Committed: Fri Nov 18 09:25:34 2016 +0700 ---------------------------------------------------------------------- .../james-database.properties | 40 +++ .../MailetProcessingWithoutCamelModule.java | 34 ++ .../modules/ProtocolsModuleWithoutJMAP.java | 25 ++ server/container/guice/jpa-guice/README.adoc | 40 +++ server/container/guice/jpa-guice/pom.xml | 336 +++++++++++++++++++ .../java/org/apache/james/JPAConfiguration.java | 63 ++++ .../org/apache/james/JPAJamesServerMain.java | 61 ++++ .../james/modules/data/JPADataJmapModule.java | 22 ++ .../james/modules/data/JPADomainListModule.java | 77 +++++ .../data/JPARecipientRewriteTableModule.java | 78 +++++ .../modules/data/JPAUsersRepositoryModule.java | 79 +++++ .../james/modules/mailbox/JPAMailboxModule.java | 134 ++++++++ .../mailbox/LuceneSearchMailboxModule.java | 55 +++ .../ScheduledExecutorServiceProvider.java | 49 +++ .../jpa-guice/src/main/resources/logback.xml | 22 ++ .../org/apache/james/JPAJamesServerTest.java | 44 +++ .../james/JamesCapabilitiesServerTest.java | 75 +++++ .../james/TestJPAConfigurationModule.java | 49 +++ .../jpa-guice/src/test/resources/dnsservice.xml | 29 ++ .../test/resources/fakemailrepositorystore.xml | 31 ++ .../jpa-guice/src/test/resources/imapserver.xml | 54 +++ .../guice/jpa-guice/src/test/resources/keystore | Bin 0 -> 2245 bytes .../jpa-guice/src/test/resources/lmtpserver.xml | 41 +++ .../src/test/resources/mailetcontainer.xml | 113 +++++++ .../src/test/resources/mailrepositorystore.xml | 31 ++ .../src/test/resources/managesieveserver.xml | 65 ++++ .../jpa-guice/src/test/resources/pop3server.xml | 42 +++ .../jpa-guice/src/test/resources/smtpserver.xml | 105 ++++++ server/container/guice/pom.xml | 1 + 29 files changed, 1795 insertions(+) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/guice-common/sample-configuration/james-database.properties ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/sample-configuration/james-database.properties b/server/container/guice/guice-common/sample-configuration/james-database.properties new file mode 100644 index 0000000..b3ac7eb --- /dev/null +++ b/server/container/guice/guice-common/sample-configuration/james-database.properties @@ -0,0 +1,40 @@ +# 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. + +# This template file can be used as example for James Server configuration +# DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS + +# See http://james.apache.org/server/3/config.html for usage + +# Use derby as default +database.driverClassName=org.apache.derby.jdbc.EmbeddedDriver +database.url=jdbc:derby:../var/store/derby;create=true +database.username=app +database.password=app + +# Supported adapters are: +# DB2, DERBY, H2, HSQL, INFORMIX, MYSQL, ORACLE, POSTGRESQL, SQL_SERVER, SYBASE +vendorAdapter.database=DERBY + +# Use streaming for Blobs +# This is only supported on a limited set of databases atm. You should check if its supported by your DB before enable +# it. +# +# See: +# http://openjpa.apache.org/builds/latest/docs/manual/ref_guide_mapping_jpa.html #7.11. LOB Streaming +# +openjpa.streaming=false \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/MailetProcessingWithoutCamelModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/MailetProcessingWithoutCamelModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/MailetProcessingWithoutCamelModule.java new file mode 100644 index 0000000..78fbc98 --- /dev/null +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/MailetProcessingWithoutCamelModule.java @@ -0,0 +1,34 @@ +/**************************************************************** + * 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.modules; + +import org.apache.james.modules.server.MailStoreRepositoryModule; +import org.apache.james.modules.server.SieveModule; + +import com.google.inject.AbstractModule; + +public class MailetProcessingWithoutCamelModule extends AbstractModule { + + @Override + protected void configure() { + install(new SieveModule()); + install(new MailStoreRepositoryModule()); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/ProtocolsModuleWithoutJMAP.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/ProtocolsModuleWithoutJMAP.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/ProtocolsModuleWithoutJMAP.java new file mode 100644 index 0000000..9c05696 --- /dev/null +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/ProtocolsModuleWithoutJMAP.java @@ -0,0 +1,25 @@ +package org.apache.james.modules; + +import org.apache.james.modules.protocols.IMAPServerModule; +import org.apache.james.modules.protocols.LMTPServerModule; +import org.apache.james.modules.protocols.ManageSieveServerModule; +import org.apache.james.modules.protocols.POP3ServerModule; +import org.apache.james.modules.protocols.ProtocolHandlerModule; +import org.apache.james.modules.protocols.SMTPServerModule; +import org.apache.james.modules.server.WebAdminServerModule; + +import com.google.inject.AbstractModule; + +public class ProtocolsModuleWithoutJMAP extends AbstractModule { + @Override + protected void configure() { + install(new IMAPServerModule()); + install(new ProtocolHandlerModule()); + install(new POP3ServerModule()); + install(new SMTPServerModule()); + install(new LMTPServerModule()); + install(new ManageSieveServerModule()); + install(new WebAdminServerModule()); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/README.adoc ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/README.adoc b/server/container/guice/jpa-guice/README.adoc new file mode 100644 index 0000000..8f47705 --- /dev/null +++ b/server/container/guice/jpa-guice/README.adoc @@ -0,0 +1,40 @@ += Guice-JPA Module How-to + +== Building + +=== Requirements + + * Java 8 SDK + * Docker + * Maven + +=== Building the artifacts + +An usual compilation using maven will produce two artifacts into target directory : + + * james-server-jpa-guice-${version}.jar + * james-server-jpa-guice-${version}.lib + +== Running + +=== Requirements + +=== James Launch + +To run james, you have to create a directory containing required configuration files. + +A sample directory (appropriately named sample-directory) is provided with some +default value you may need to replace. + +You also need to generate a keystore with the following command : +[source] +---- +$ keytool -genkey -alias james -keyalg RSA -keystore conf/keystore +---- + +Once everything is set up, you just have to run the jar with : + +[source] +---- +$ java -Dworking.directory=sample-configuration -jar target/james-server-jpa-guice-${version}.jar +---- http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/pom.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/pom.xml b/server/container/guice/jpa-guice/pom.xml new file mode 100644 index 0000000..b707871 --- /dev/null +++ b/server/container/guice/jpa-guice/pom.xml @@ -0,0 +1,336 @@ +<?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"> + + <modelVersion>4.0.0</modelVersion> + + <parent> + <groupId>org.apache.james</groupId> + <artifactId>james-server-guice</artifactId> + <version>3.0.0-beta5-SNAPSHOT</version> + <relativePath>../pom.xml</relativePath> + </parent> + + <artifactId>james-server-jpa-guice</artifactId> + <packaging>jar</packaging> + + <name>Apache James :: Server :: JPA - guice injection</name> + <description>An advanced email server - JPA backend with guice injection</description> + + <properties> + <jpa.includes>empty</jpa.includes> + </properties> + + <profiles> + <profile> + <id>disable-build-for-older-jdk</id> + <activation> + <jdk>(,1.8)</jdk> + </activation> + <build> + <plugins> + <plugin> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <id>default-jar</id> + <phase>none</phase> + </execution> + <execution> + <id>jar</id> + <phase>none</phase> + </execution> + <execution> + <id>test-jar</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-compiler-plugin</artifactId> + <executions> + <execution> + <id>default-compile</id> + <phase>none</phase> + </execution> + <execution> + <id>default-testCompile</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-surefire-plugin</artifactId> + <executions> + <execution> + <id>default-test</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-source-plugin</artifactId> + <executions> + <execution> + <id>attach-sources</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-install-plugin</artifactId> + <executions> + <execution> + <id>default-install</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-resources-plugin</artifactId> + <executions> + <execution> + <id>default-resources</id> + <phase>none</phase> + </execution> + <execution> + <id>default-testResources</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + <plugin> + <artifactId>maven-site-plugin</artifactId> + <executions> + <execution> + <id>attach-descriptor</id> + <phase>none</phase> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + <profile> + <id>build-for-jdk-8</id> + <activation> + <jdk>[1.8,)</jdk> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-dependency-plugin</artifactId> + <executions> + <execution> + <id>copy-dependencies</id> + <phase>package</phase> + <goals> + <goal>copy-dependencies</goal> + </goals> + <configuration> + <outputDirectory>${project.build.directory}/${project.build.finalName}.lib</outputDirectory> + </configuration> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-jar-plugin</artifactId> + <executions> + <execution> + <id>default-jar</id> + <goals> + <goal>jar</goal> + </goals> + <configuration> + <archive> + <manifest> + <addClasspath>true</addClasspath> + <classpathPrefix>${project.build.finalName}.lib/</classpathPrefix> + <mainClass>org.apache.james.JPAJamesServerMain</mainClass> + <useUniqueVersions>false</useUniqueVersions> + </manifest> + </archive> + </configuration> + </execution> + <execution> + <id>test-jar</id> + <goals> + <goal>test-jar</goal> + </goals> + </execution> + </executions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-compiler-plugin</artifactId> + <configuration> + <source>1.8</source> + <target>1.8</target> + </configuration> + </plugin> + </plugins> + </build> + <dependencies> +<!-- <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>apache-james-backends-cassandra</artifactId> + <type>test-jar</type> + </dependency>--> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-jpa</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-jpa</artifactId> + <scope>test</scope> + <type>test-jar</type> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-lucene</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-lucene</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>apache-james-mailbox-tika</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-data-jpa</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-guice-common</artifactId> + </dependency> + <dependency> + <groupId>${project.groupId}</groupId> + <artifactId>james-server-guice-common</artifactId> + <type>test-jar</type> + <scope>test</scope> + </dependency> + <dependency> + <groupId>ch.qos.logback</groupId> + <artifactId>logback-classic</artifactId> + <version>1.1.7</version> + </dependency> + <dependency> + <groupId>com.jayway.awaitility</groupId> + <artifactId>awaitility</artifactId> + </dependency> + <dependency> + <groupId>com.jayway.restassured</groupId> + <artifactId>rest-assured</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>com.nurkiewicz.asyncretry</groupId> + <artifactId>asyncretry</artifactId> + </dependency> + <dependency> + <groupId>org.assertj</groupId> + <artifactId>assertj-core</artifactId> + <version>${assertj-3.version}</version> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.mockito</groupId> + <artifactId>mockito-core</artifactId> + <scope>test</scope> + </dependency> + <dependency> + <groupId>org.apache.openjpa</groupId> + <artifactId>openjpa</artifactId> + </dependency> + <dependency> + <groupId>org.apache.geronimo.specs</groupId> + <artifactId>geronimo-jpa_2.0_spec</artifactId> + </dependency> + </dependencies> + </profile> + <profile> + <id>jpa</id> + <properties> + <jpa.includes>**/*.java</jpa.includes> + </properties> + </profile> + <profile> + <id>animal-sniffer-java-8</id> + <activation> + <jdk>[1.8,)</jdk> + </activation> + <build> + <plugins> + <plugin> + <groupId>org.codehaus.mojo</groupId> + <artifactId>animal-sniffer-maven-plugin</artifactId> + <configuration> + <signature> + <groupId>org.codehaus.mojo.signature</groupId> + <artifactId>java18</artifactId> + <version>1.0</version> + </signature> + </configuration> + <executions> + <execution> + <id>check_java_8</id> + <phase>test</phase> + <goals> + <goal>check</goal> + </goals> + </execution> + </executions> + </plugin> + </plugins> + </build> + </profile> + </profiles> + + <build> + <plugins> + <plugin> + <groupId>org.apache.felix</groupId> + <artifactId>maven-bundle-plugin</artifactId> + <extensions>true</extensions> + </plugin> + <plugin> + <groupId>org.apache.maven.plugins</groupId> + <artifactId>maven-surefire-plugin</artifactId> + <configuration> + <excludes> + <exclude>**/suite/*.java</exclude> + <exclude>**/suite/**/*.java</exclude> + </excludes> + <includes> + <include>${jpa.includes}</include> + </includes> + </configuration> + </plugin> + </plugins> + </build> +</project> http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAConfiguration.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAConfiguration.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAConfiguration.java new file mode 100644 index 0000000..8041205 --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAConfiguration.java @@ -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; + +import com.google.common.annotations.VisibleForTesting; + +public class JPAConfiguration { + public static Builder builder() { + return new Builder(); + } + + public static class Builder { + private String driverName; + private String driverURL; + + public Builder driverName(String driverName) { + this.driverName = driverName; + return this; + } + + public Builder driverURL(String driverURL) { + this.driverURL = driverURL; + return this; + } + + public JPAConfiguration build() { + return new JPAConfiguration(driverName, driverURL); + } + } + + private final String driverName; + private final String driverURL; + + @VisibleForTesting JPAConfiguration(String driverName, String driverURL) { + this.driverName = driverName; + this.driverURL = driverURL; + } + + public String getDriverName() { + return driverName; + } + + public String getDriverURL() { + return driverURL; + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java new file mode 100644 index 0000000..090965d --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/JPAJamesServerMain.java @@ -0,0 +1,61 @@ +/**************************************************************** + * 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; + +import org.apache.james.modules.CommonServicesModule; +import org.apache.james.modules.MailetProcessingWithoutCamelModule; +import org.apache.james.modules.ProtocolsModuleWithoutJMAP; +import org.apache.james.modules.data.JPADataJmapModule; +import org.apache.james.modules.data.JPADomainListModule; +import org.apache.james.modules.data.JPARecipientRewriteTableModule; +import org.apache.james.modules.data.JPAUsersRepositoryModule; +import org.apache.james.modules.mailbox.JPAMailboxModule; +import org.apache.james.modules.mailbox.LuceneSearchMailboxModule; +import org.apache.james.modules.server.ActiveMQQueueModule; +import org.apache.james.modules.server.JMXServerModule; +import org.apache.james.modules.server.QuotaModule; + +import com.google.inject.Module; +import com.google.inject.util.Modules; + +public class JPAJamesServerMain { + public static final Module mainServerModule = Modules.combine( + new CommonServicesModule(), + new ProtocolsModuleWithoutJMAP(), + new MailetProcessingWithoutCamelModule()); + + public static final Module jpaServerModule = Modules.combine( + new JPAMailboxModule(), + new JPAUsersRepositoryModule(), + new JPADomainListModule(), + new JPARecipientRewriteTableModule(), + new JPADataJmapModule(), + new LuceneSearchMailboxModule(), + new QuotaModule(), + new ActiveMQQueueModule()); + + + public static void main(String[] args) throws Exception { + GuiceJamesServer server = new GuiceJamesServer(mainServerModule) + .combineWith(jpaServerModule, new JMXServerModule()); + server.start(); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADataJmapModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADataJmapModule.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADataJmapModule.java new file mode 100644 index 0000000..84eda74 --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADataJmapModule.java @@ -0,0 +1,22 @@ +package org.apache.james.modules.data; + +import org.apache.james.jmap.api.vacation.VacationRepository; +import org.apache.james.jmap.vacation.NoneVacationRepository; +import org.apache.james.sieverepository.api.SieveRepository; +import org.apache.james.sieverepository.file.SieveFileRepository; + +import com.google.inject.AbstractModule; +import com.google.inject.Scopes; + +public class JPADataJmapModule extends AbstractModule { + + @Override + protected void configure() { + bind(NoneVacationRepository.class).in(Scopes.SINGLETON); + bind(VacationRepository.class).to(NoneVacationRepository.class); + + bind(SieveFileRepository.class).in(Scopes.SINGLETON); + bind(SieveRepository.class).to(SieveFileRepository.class); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADomainListModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADomainListModule.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADomainListModule.java new file mode 100644 index 0000000..4bb0030 --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADomainListModule.java @@ -0,0 +1,77 @@ +/**************************************************************** + * 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.modules.data; + +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableList; +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Scopes; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.james.domainlist.api.DomainList; +import org.apache.james.domainlist.jpa.JPADomainList; +import org.apache.james.lifecycle.api.Configurable; +import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.ConfigurationProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +public class JPADomainListModule extends AbstractModule { + + private static final Logger LOGGER = LoggerFactory.getLogger(DomainList.class); + + @Override + public void configure() { + bind(JPADomainList.class).in(Scopes.SINGLETON); + bind(DomainList.class).to(JPADomainList.class); + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(JPADomainListConfigurationPerformer.class); + } + + @Singleton + public static class JPADomainListConfigurationPerformer implements ConfigurationPerformer { + + private final ConfigurationProvider configurationProvider; + private final JPADomainList jpaDomainList; + + @Inject + public JPADomainListConfigurationPerformer(ConfigurationProvider configurationProvider, JPADomainList jpaDomainList) { + this.configurationProvider = configurationProvider; + this.jpaDomainList = jpaDomainList; + } + + @Override + public void initModule() { + try { + jpaDomainList.setLog(LOGGER); + jpaDomainList.configure(configurationProvider.getConfiguration("domainlist")); + } catch (ConfigurationException e) { + Throwables.propagate(e); + } + } + + @Override + public List<Class<? extends Configurable>> forClasses() { + return ImmutableList.of(JPADomainList.class); + } + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPARecipientRewriteTableModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPARecipientRewriteTableModule.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPARecipientRewriteTableModule.java new file mode 100644 index 0000000..a1f55b3 --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPARecipientRewriteTableModule.java @@ -0,0 +1,78 @@ +/**************************************************************** + * 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.modules.data; + +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableList; +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Scopes; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.james.lifecycle.api.Configurable; +import org.apache.james.rrt.api.RecipientRewriteTable; +import org.apache.james.rrt.jpa.JPARecipientRewriteTable; +import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.ConfigurationProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +public class JPARecipientRewriteTableModule extends AbstractModule { + + private static final Logger LOGGER = LoggerFactory.getLogger(RecipientRewriteTable.class); + + @Override + public void configure() { + bind(JPARecipientRewriteTable.class).in(Scopes.SINGLETON); + bind(RecipientRewriteTable.class).to(JPARecipientRewriteTable.class); + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(JPARecipientRewriteTablePerformer.class); + } + + @Singleton + public static class JPARecipientRewriteTablePerformer implements ConfigurationPerformer { + + private final ConfigurationProvider configurationProvider; + private final JPARecipientRewriteTable recipientRewriteTable; + + @Inject + public JPARecipientRewriteTablePerformer(ConfigurationProvider configurationProvider, JPARecipientRewriteTable recipientRewriteTable) { + this.configurationProvider = configurationProvider; + this.recipientRewriteTable = recipientRewriteTable; + } + + @Override + public void initModule() { + try { + recipientRewriteTable.setLog(LOGGER); + recipientRewriteTable.configure(configurationProvider.getConfiguration("recipientrewritetable")); + } catch (ConfigurationException e) { + Throwables.propagate(e); + } + } + + @Override + public List<Class<? extends Configurable>> forClasses() { + return ImmutableList.of(JPARecipientRewriteTable.class); + } + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPAUsersRepositoryModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPAUsersRepositoryModule.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPAUsersRepositoryModule.java new file mode 100644 index 0000000..ca26073 --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPAUsersRepositoryModule.java @@ -0,0 +1,79 @@ +/**************************************************************** + * 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.modules.data; + +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableList; +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Scopes; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.james.lifecycle.api.Configurable; +import org.apache.james.user.api.UsersRepository; +import org.apache.james.user.jpa.JPAUsersRepository; +import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.ConfigurationProvider; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import java.util.List; + +public class JPAUsersRepositoryModule extends AbstractModule { + + private static final Logger LOGGER = LoggerFactory.getLogger(JPAUsersRepositoryModule.class); + + @Override + public void configure() { + bind(JPAUsersRepository.class).in(Scopes.SINGLETON); + bind(UsersRepository.class).to(JPAUsersRepository.class); + + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(JPAUsersRepositoryConfigurationPerformer.class); + } + + @Singleton + public static class JPAUsersRepositoryConfigurationPerformer implements ConfigurationPerformer { + + private final ConfigurationProvider configurationProvider; + private final JPAUsersRepository usersRepository; + + @Inject + public JPAUsersRepositoryConfigurationPerformer(ConfigurationProvider configurationProvider, JPAUsersRepository usersRepository) { + this.configurationProvider = configurationProvider; + this.usersRepository = usersRepository; + } + + @Override + public void initModule() { + try { + usersRepository.setLog(LOGGER); + usersRepository.configure(configurationProvider.getConfiguration("usersrepository")); + } catch (ConfigurationException e) { + Throwables.propagate(e); + } + } + + @Override + public List<Class<? extends Configurable>> forClasses() { + return ImmutableList.of(JPAUsersRepository.class); + } + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java new file mode 100644 index 0000000..7f5f6eb --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/JPAMailboxModule.java @@ -0,0 +1,134 @@ +/**************************************************************** + * 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.modules.mailbox; + +import java.io.FileNotFoundException; +import java.util.HashMap; + +import javax.inject.Singleton; +import javax.persistence.EntityManagerFactory; +import javax.persistence.Persistence; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.james.JPAConfiguration; +import org.apache.james.adapter.mailbox.store.UserRepositoryAuthenticator; +import org.apache.james.mailbox.MailboxManager; +import org.apache.james.mailbox.MailboxPathLocker; +import org.apache.james.mailbox.SubscriptionManager; +import org.apache.james.mailbox.acl.GroupMembershipResolver; +import org.apache.james.mailbox.acl.MailboxACLResolver; +import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver; +import org.apache.james.mailbox.acl.UnionMailboxACLResolver; +import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.jpa.JPAId; +import org.apache.james.mailbox.jpa.JPAMailboxSessionMapperFactory; +import org.apache.james.mailbox.jpa.JPASubscriptionManager; +import org.apache.james.mailbox.jpa.mail.JPAModSeqProvider; +import org.apache.james.mailbox.jpa.mail.JPAUidProvider; +import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager; +import org.apache.james.mailbox.model.MailboxId; +import org.apache.james.mailbox.store.Authenticator; +import org.apache.james.mailbox.store.MailboxSessionMapperFactory; +import org.apache.james.mailbox.store.NoMailboxPathLocker; +import org.apache.james.mailbox.store.mail.AttachmentMapperFactory; +import org.apache.james.mailbox.store.mail.MailboxMapperFactory; +import org.apache.james.mailbox.store.mail.MessageMapperFactory; +import org.apache.james.mailbox.store.mail.ModSeqProvider; +import org.apache.james.mailbox.store.mail.UidProvider; +import org.apache.james.modules.Names; +import org.apache.james.utils.MailboxManagerDefinition; +import org.apache.james.utils.PropertiesProvider; + +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Provides; +import com.google.inject.Scopes; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.name.Named; + +public class JPAMailboxModule extends AbstractModule { + + @Override + protected void configure() { + bind(JPAMailboxSessionMapperFactory.class).in(Scopes.SINGLETON); + bind(OpenJPAMailboxManager.class).in(Scopes.SINGLETON); + bind(NoMailboxPathLocker.class).in(Scopes.SINGLETON); + bind(JPASubscriptionManager.class).in(Scopes.SINGLETON); + bind(JPAModSeqProvider.class).in(Scopes.SINGLETON); + bind(JPAUidProvider.class).in(Scopes.SINGLETON); + bind(UserRepositoryAuthenticator.class).in(Scopes.SINGLETON); + bind(JPAId.Factory.class).in(Scopes.SINGLETON); + bind(SimpleGroupMembershipResolver.class).in(Scopes.SINGLETON); + bind(UnionMailboxACLResolver.class).in(Scopes.SINGLETON); + + bind(MessageMapperFactory.class).to(JPAMailboxSessionMapperFactory.class); + bind(MailboxMapperFactory.class).to(JPAMailboxSessionMapperFactory.class); + bind(AttachmentMapperFactory.class).to(JPAMailboxSessionMapperFactory.class); + bind(MailboxSessionMapperFactory.class).to(JPAMailboxSessionMapperFactory.class); + + bind(ModSeqProvider.class).to(JPAModSeqProvider.class); + bind(UidProvider.class).to(JPAUidProvider.class); + bind(SubscriptionManager.class).to(JPASubscriptionManager.class); + bind(MailboxPathLocker.class).to(NoMailboxPathLocker.class); + bind(Authenticator.class).to(UserRepositoryAuthenticator.class); + bind(MailboxManager.class).to(OpenJPAMailboxManager.class); + bind(MailboxId.Factory.class).to(JPAId.Factory.class); + bind(GroupMembershipResolver.class).to(SimpleGroupMembershipResolver.class); + bind(MailboxACLResolver.class).to(UnionMailboxACLResolver.class); + + Multibinder.newSetBinder(binder(), MailboxManagerDefinition.class).addBinding().to(JPAMailboxManagerDefinition.class); + } + + @Provides @Named(Names.MAILBOXMANAGER_NAME) @Singleton + public MailboxManager provideMailboxManager(OpenJPAMailboxManager jpaMailboxManager) throws MailboxException { + jpaMailboxManager.init(); + return jpaMailboxManager; + } + + @Singleton + private static class JPAMailboxManagerDefinition extends MailboxManagerDefinition { + @Inject + private JPAMailboxManagerDefinition(OpenJPAMailboxManager manager) { + super("jpa-mailboxmanager", manager); + } + } + + @Provides + @Singleton + public EntityManagerFactory provideEntityManagerFactory(JPAConfiguration jpaConfiguration) { + HashMap<String, String> properties = new HashMap<String, String>(); + + properties.put("openjpa.ConnectionDriverName", jpaConfiguration.getDriverName()); + properties.put("openjpa.ConnectionURL", jpaConfiguration.getDriverURL()); + + return Persistence.createEntityManagerFactory("James", properties); + + } + + @Provides + @Singleton + JPAConfiguration provideConfiguration(PropertiesProvider propertiesProvider) throws FileNotFoundException, ConfigurationException{ + PropertiesConfiguration dataSource = propertiesProvider.getConfiguration("james-database"); + return JPAConfiguration.builder() + .driverName(dataSource.getString("database.driverClassName")) + .driverURL(dataSource.getString("database.url")) + .build(); + } +} \ No newline at end of file http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/LuceneSearchMailboxModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/LuceneSearchMailboxModule.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/LuceneSearchMailboxModule.java new file mode 100644 index 0000000..fa46463 --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/LuceneSearchMailboxModule.java @@ -0,0 +1,55 @@ +/**************************************************************** + * 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.modules.mailbox; + +import java.io.File; +import java.io.IOException; + +import org.apache.james.mailbox.extractor.TextExtractor; +import org.apache.james.mailbox.lucene.search.LuceneMessageSearchIndex; +import org.apache.james.mailbox.store.search.ListeningMessageSearchIndex; +import org.apache.james.mailbox.store.search.MessageSearchIndex; +import org.apache.james.mailbox.tika.extractor.TikaTextExtractor; +import org.apache.lucene.store.Directory; +import org.apache.lucene.store.FSDirectory; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; +import com.google.inject.Scopes; +import com.google.inject.Singleton; + +public class LuceneSearchMailboxModule extends AbstractModule { + + @Override + protected void configure() { + bind(LuceneMessageSearchIndex.class).in(Scopes.SINGLETON); + bind(MessageSearchIndex.class).to(LuceneMessageSearchIndex.class); + bind(ListeningMessageSearchIndex.class).to(LuceneMessageSearchIndex.class); + + bind(TikaTextExtractor.class).in(Scopes.SINGLETON); + bind(TextExtractor.class).to(TikaTextExtractor.class); + } + + @Provides + @Singleton + Directory provideDirectory() throws IOException { + return FSDirectory.open(new File("Lucene")); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/ScheduledExecutorServiceProvider.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/ScheduledExecutorServiceProvider.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/ScheduledExecutorServiceProvider.java new file mode 100644 index 0000000..48fe3f1 --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/ScheduledExecutorServiceProvider.java @@ -0,0 +1,49 @@ +/**************************************************************** + * 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.modules.mailbox; + +import java.util.concurrent.Executors; +import java.util.concurrent.ScheduledExecutorService; + +import javax.annotation.PreDestroy; + +import com.google.common.annotations.VisibleForTesting; +import com.google.inject.Provider; + +@VisibleForTesting +class ScheduledExecutorServiceProvider implements Provider<ScheduledExecutorService> { + + private final ScheduledExecutorService scheduler; + + @VisibleForTesting + ScheduledExecutorServiceProvider() { + scheduler = Executors.newSingleThreadScheduledExecutor(); + } + + @Override + public ScheduledExecutorService get() { + return scheduler; + } + + @PreDestroy + private void stop() { + scheduler.shutdown(); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/main/resources/logback.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/resources/logback.xml b/server/container/guice/jpa-guice/src/main/resources/logback.xml new file mode 100644 index 0000000..0e1ff22 --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/resources/logback.xml @@ -0,0 +1,22 @@ +<?xml version="1.0" encoding="UTF-8"?> +<configuration> + + <contextListener class="ch.qos.logback.classic.jul.LevelChangePropagator"> + <resetJUL>true</resetJUL> + </contextListener> + + <appender name="CONSOLE" class="ch.qos.logback.core.ConsoleAppender"> + <encoder> + <pattern>%d{HH:mm:ss.SSS} [%-5level] %logger{15} - %msg%n%rEx</pattern> + <immediateFlush>false</immediateFlush> + </encoder> + </appender> + + <root level="WARN"> + <appender-ref ref="CONSOLE" /> + </root> + + <logger name="org.apache.james" level="INFO"/> + + +</configuration> http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java new file mode 100644 index 0000000..23ac61c --- /dev/null +++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JPAJamesServerTest.java @@ -0,0 +1,44 @@ +/**************************************************************** + * 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; + +import org.apache.james.modules.TestFilesystemModule; +import org.junit.Rule; +import org.junit.rules.TemporaryFolder; + +public class JPAJamesServerTest extends AbstractJamesServerTest { + + @Rule + public TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Override + protected GuiceJamesServer createJamesServer() { + return new GuiceJamesServer(JPAJamesServerMain.mainServerModule) + .combineWith(JPAJamesServerMain.jpaServerModule) + .overrideWith(new TestFilesystemModule(temporaryFolder), + new TestJPAConfigurationModule()); + } + + @Override + protected void clean() { + } + + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java new file mode 100644 index 0000000..82e728a --- /dev/null +++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/JamesCapabilitiesServerTest.java @@ -0,0 +1,75 @@ +/**************************************************************** + * 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; + +import static org.mockito.Mockito.mock; +import static org.mockito.Mockito.when; + +import java.util.EnumSet; + +import org.apache.james.mailbox.MailboxManager; +import org.apache.james.modules.TestFilesystemModule; +import org.junit.After; +import org.junit.Rule; +import org.junit.Test; +import org.junit.rules.RuleChain; +import org.junit.rules.TemporaryFolder; + +import com.google.inject.Module; + +public class JamesCapabilitiesServerTest { + + private GuiceJamesServer server; + private TemporaryFolder temporaryFolder = new TemporaryFolder(); + + @Rule + public RuleChain chain = RuleChain.outerRule(temporaryFolder); + + @After + public void teardown() { + server.stop(); + } + + private GuiceJamesServer createJPAJamesServer(final MailboxManager mailboxManager) { + Module mockMailboxManager = (binder) -> binder.bind(MailboxManager.class).toInstance(mailboxManager); + + return new GuiceJamesServer() + .combineWith(JPAJamesServerMain.jpaServerModule) + .overrideWith( + new TestFilesystemModule(temporaryFolder), + new TestJPAConfigurationModule(), + mockMailboxManager); + } + + @Test + public void startShouldSucceedWhenRequiredCapabilities() throws Exception { + MailboxManager mailboxManager = mock(MailboxManager.class); + when(mailboxManager.getSupportedMailboxCapabilities()) + .thenReturn(EnumSet.noneOf(MailboxManager.MailboxCapabilities.class)); + when(mailboxManager.getSupportedMessageCapabilities()) + .thenReturn(EnumSet.noneOf(MailboxManager.MessageCapabilities.class)); + when(mailboxManager.getSupportedSearchCapabilities()) + .thenReturn(EnumSet.noneOf(MailboxManager.SearchCapabilities.class)); + + server = createJPAJamesServer(mailboxManager); + + server.start(); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/test/java/org/apache/james/TestJPAConfigurationModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/java/org/apache/james/TestJPAConfigurationModule.java b/server/container/guice/jpa-guice/src/test/java/org/apache/james/TestJPAConfigurationModule.java new file mode 100644 index 0000000..e1847cc --- /dev/null +++ b/server/container/guice/jpa-guice/src/test/java/org/apache/james/TestJPAConfigurationModule.java @@ -0,0 +1,49 @@ +/**************************************************************** + * 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; + +import java.io.FileNotFoundException; + +import javax.inject.Singleton; + +import org.apache.commons.configuration.ConfigurationException; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +public class TestJPAConfigurationModule extends AbstractModule { + + private static final String JDBC_EMBEDDED_URL = "jdbc:derby:../var/store/derby;create=true"; + private static final String JDBC_EMBEDDED_DRIVER = "org.apache.derby.jdbc.EmbeddedDriver"; + + @Override + protected void configure() { + } + + @Provides + @Singleton + JPAConfiguration provideConfiguration() throws FileNotFoundException, ConfigurationException{ + return JPAConfiguration.builder() + .driverName(JDBC_EMBEDDED_DRIVER) + .driverURL(JDBC_EMBEDDED_URL) + .build(); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/test/resources/dnsservice.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/resources/dnsservice.xml b/server/container/guice/jpa-guice/src/test/resources/dnsservice.xml new file mode 100644 index 0000000..0978a00 --- /dev/null +++ b/server/container/guice/jpa-guice/src/test/resources/dnsservice.xml @@ -0,0 +1,29 @@ +<?xml version="1.0"?> +<!-- + 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. + --> + +<dnsservice> + <servers> + <server>8.8.8.8</server> + <server>62.210.16.6</server> + </servers> + <autodiscover>false</autodiscover> + <authoritative>false</authoritative> + <maxcachesize>50000</maxcachesize> +</dnsservice> http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/test/resources/fakemailrepositorystore.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/resources/fakemailrepositorystore.xml b/server/container/guice/jpa-guice/src/test/resources/fakemailrepositorystore.xml new file mode 100644 index 0000000..2d19a80 --- /dev/null +++ b/server/container/guice/jpa-guice/src/test/resources/fakemailrepositorystore.xml @@ -0,0 +1,31 @@ +<?xml version="1.0"?> + +<!-- + 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. + --> + +<mailrepositorystore> + <mailrepositories> + <mailrepository class="org.apache.james.mailrepository.None"> + <protocols> + <protocol>file</protocol> + </protocols> + <config FIFO="false" CACHEKEYS="true"/> + </mailrepository> + </mailrepositories> +</mailrepositorystore> http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/test/resources/imapserver.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/resources/imapserver.xml b/server/container/guice/jpa-guice/src/test/resources/imapserver.xml new file mode 100644 index 0000000..ff478a9 --- /dev/null +++ b/server/container/guice/jpa-guice/src/test/resources/imapserver.xml @@ -0,0 +1,54 @@ +<?xml version="1.0"?> + +<!-- +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. +--> + + +<imapservers> + <imapserver enabled="true"> + <jmxName>imapserver</jmxName> + <bind>0.0.0.0:1143</bind> + <connectionBacklog>200</connectionBacklog> + <tls socketTLS="false" startTLS="false"> + <!-- To create a new keystore execute: + keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore + --> + <keystore>file://conf/keystore</keystore> + <secret>james72laBalle</secret> + <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider> + </tls> + <connectionLimit>0</connectionLimit> + <connectionLimitPerIP>0</connectionLimitPerIP> + </imapserver> + <imapserver enabled="true"> + <jmxName>imapserver-ssl</jmxName> + <bind>0.0.0.0:1993</bind> + <connectionBacklog>200</connectionBacklog> + <tls socketTLS="false" startTLS="false"> + <!-- To create a new keystore execute: + keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore + --> + <keystore>file://conf/keystore</keystore> + <secret>james72laBalle</secret> + <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider> + </tls> + <connectionLimit>0</connectionLimit> + <connectionLimitPerIP>0</connectionLimitPerIP> + </imapserver> +</imapservers> http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/test/resources/keystore ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/resources/keystore b/server/container/guice/jpa-guice/src/test/resources/keystore new file mode 100644 index 0000000..536a6c7 Binary files /dev/null and b/server/container/guice/jpa-guice/src/test/resources/keystore differ http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/test/resources/lmtpserver.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/resources/lmtpserver.xml b/server/container/guice/jpa-guice/src/test/resources/lmtpserver.xml new file mode 100644 index 0000000..5c4a9c7 --- /dev/null +++ b/server/container/guice/jpa-guice/src/test/resources/lmtpserver.xml @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<!-- + 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. + --> + +<lmtpservers> + + <lmtpserver enabled="true"> + <jmxName>lmtpserver</jmxName> + <!-- LMTP should not be reachable from outside your network so bind it to loopback--> + <bind>127.0.0.1:1024</bind> + <connectionBacklog>200</connectionBacklog> + <connectiontimeout>1200</connectiontimeout> + <!-- Set the maximum simultaneous incoming connections for this service --> + <connectionLimit>0</connectionLimit> + <!-- Set the maximum simultaneous incoming connections per IP for this service --> + <connectionLimitPerIP>0</connectionLimitPerIP> + <!-- This sets the maximum allowed message size (in kilobytes) for this --> + <!-- LMTP service. If unspecified, the value defaults to 0, which means no limit. --> + <maxmessagesize>0</maxmessagesize> + <handlerchain> + <handler class="org.apache.james.lmtpserver.CoreCmdHandlerLoader"/> + </handlerchain> + </lmtpserver> + +</lmtpservers> http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/test/resources/mailetcontainer.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/resources/mailetcontainer.xml b/server/container/guice/jpa-guice/src/test/resources/mailetcontainer.xml new file mode 100644 index 0000000..b265f93 --- /dev/null +++ b/server/container/guice/jpa-guice/src/test/resources/mailetcontainer.xml @@ -0,0 +1,113 @@ +<?xml version="1.0"?> + +<!-- + 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. + --> + +<mailetcontainer enableJmx="false"> + + <context> + <postmaster>postmas...@james.minet.net</postmaster> + </context> + + <spooler> + <threads>20</threads> + </spooler> + + <processors> + <processor state="root" enableJmx="false"> + <mailet match="All" class="PostmasterAlias"/> + <mailet match="RelayLimit=30" class="Null"/> + <mailet match="All" class="ToProcessor"> + <processor>transport</processor> + </mailet> + </processor> + + <processor state="error" enableJmx="false"> + <mailet match="All" class="Bounce"/> + <mailet match="All" class="ToRepository"> + <repositoryPath>file://var/mail/error/</repositoryPath> + </mailet> + </processor> + + + <processor state="transport" enableJmx="false"> + <mailet match="SMTPAuthSuccessful" class="SetMimeHeader"> + <name>X-UserIsAuth</name> + <value>true</value> + </mailet> + <mailet match="All" class="RemoveMimeHeader"> + <name>bcc</name> + </mailet> + <mailet match="All" class="RecipientRewriteTable" /> + <mailet match="RecipientIsLocal" class="org.apache.james.jmap.mailet.VacationMailet"/> + <mailet match="RecipientIsLocal" class="LocalDelivery"/> + <mailet match="HostIsLocal" class="ToProcessor"> + <processor>local-address-error</processor> + <notice>550 - Requested action not taken: no such user here</notice> + </mailet> + <mailet match="SMTPAuthSuccessful" class="RemoteDelivery"> + <outgoingQueue>outgoing</outgoingQueue> + <delayTime>5000, 100000, 500000</delayTime> + <maxRetries>25</maxRetries> + <maxDnsProblemRetries>0</maxDnsProblemRetries> + <deliveryThreads>10</deliveryThreads> + <sendpartial>true</sendpartial> + <bounceProcessor>bounces</bounceProcessor> + </mailet> + <mailet match="All" class="ToProcessor"> + <processor>relay-denied</processor> + </mailet> + </processor> + + <processor state="spam" enableJmx="false"> + <mailet match="All" class="ToRepository"> + <repositoryPath>file://var/mail/spam/</repositoryPath> + </mailet> + </processor> + + <processor state="local-address-error" enableJmx="false"> + <mailet match="All" class="Bounce"> + <attachment>none</attachment> + </mailet> + <mailet match="All" class="ToRepository"> + <repositoryPath>file://var/mail/address-error/</repositoryPath> + </mailet> + </processor> + + <processor state="relay-denied" enableJmx="false"> + <mailet match="All" class="Bounce"> + <attachment>none</attachment> + </mailet> + <mailet match="All" class="ToRepository"> + <repositoryPath>file://var/mail/relay-denied/</repositoryPath> + <notice>Warning: You are sending an e-mail to a remote server. You must be authentified to perform such an operation</notice> + </mailet> + </processor> + + <processor state="bounces" enableJmx="false"> + <mailet match="All" class="DSNBounce"> + <passThrough>false</passThrough> + </mailet> + </processor> + + </processors> + +</mailetcontainer> + + http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/test/resources/mailrepositorystore.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/resources/mailrepositorystore.xml b/server/container/guice/jpa-guice/src/test/resources/mailrepositorystore.xml new file mode 100644 index 0000000..3ca4a1d --- /dev/null +++ b/server/container/guice/jpa-guice/src/test/resources/mailrepositorystore.xml @@ -0,0 +1,31 @@ +<?xml version="1.0"?> + +<!-- + 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. + --> + +<mailrepositorystore> + <mailrepositories> + <mailrepository class="org.apache.james.mailrepository.file.FileMailRepository"> + <protocols> + <protocol>file</protocol> + </protocols> + <config FIFO="false" CACHEKEYS="true"/> + </mailrepository> + </mailrepositories> +</mailrepositorystore> http://git-wip-us.apache.org/repos/asf/james-project/blob/d65e484a/server/container/guice/jpa-guice/src/test/resources/managesieveserver.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/test/resources/managesieveserver.xml b/server/container/guice/jpa-guice/src/test/resources/managesieveserver.xml new file mode 100644 index 0000000..ec57e09 --- /dev/null +++ b/server/container/guice/jpa-guice/src/test/resources/managesieveserver.xml @@ -0,0 +1,65 @@ +<?xml version="1.0"?> +<!-- + 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. + --> + +<!-- + This template file can be used as example for James Server configuration + DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS +--> + +<!-- See http://james.apache.org/server/3/config.html for usage --> + +<managesieveservers> + + <managesieveserver enabled="true"> + + <jmxName>managesieveserver</jmxName> + + <bind>0.0.0.0:4190</bind> + + <connectionBacklog>200</connectionBacklog> + + <tls socketTLS="false" startTLS="false"> + <!-- To create a new keystore execute: + keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore + --> + <keystore>file://conf/keystore</keystore> + <secret>james72laBalle</secret> + <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider> + <!-- The algorithm is optional and only needs to be specified when using something other + than the Sun JCE provider - You could use IbmX509 with IBM Java runtime. --> + <algorithm>SunX509</algorithm> + </tls> + + <!-- connection timeout in secconds --> + <connectiontimeout>360</connectiontimeout> + + <!-- Set the maximum simultaneous incoming connections for this service --> + <connectionLimit>0</connectionLimit> + + <!-- Set the maximum simultaneous incoming connections per IP for this service --> + <connectionLimitPerIP>0</connectionLimitPerIP> + <maxmessagesize>0</maxmessagesize> + <addressBracketsEnforcement>true</addressBracketsEnforcement> + + </managesieveserver> + +</managesieveservers> + + --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org