JAMES-1842: Rename GuiceJamesServer to GuiceJmapJamesServer, AbstractJamesServerTest to AbstractJmapJamesServerTest, add more GuiceJamesServer
Project: http://git-wip-us.apache.org/repos/asf/james-project/repo Commit: http://git-wip-us.apache.org/repos/asf/james-project/commit/11771d03 Tree: http://git-wip-us.apache.org/repos/asf/james-project/tree/11771d03 Diff: http://git-wip-us.apache.org/repos/asf/james-project/diff/11771d03 Branch: refs/heads/master Commit: 11771d03677b7f4ee7de9f41ae5295b8cfdeaf70 Parents: b9a9402 Author: Quynh Nguyen <qngu...@linagora.com> Authored: Mon Oct 31 11:24:21 2016 +0700 Committer: Quynh Nguyen <qngu...@linagora.com> Committed: Fri Nov 18 09:25:34 2016 +0700 ---------------------------------------------------------------------- .../org/apache/james/mailbox/jpa/JPAId.java | 2 +- .../src/main/resources/META-INF/persistence.xml | 3 - .../apache/james/CassandraJamesServerTest.java | 2 +- .../java/org/apache/james/GuiceJamesServer.java | 99 ++++++ .../org/apache/james/GuiceJmapJamesServer.java | 2 +- .../java/org/apache/james/jmap/JMAPModule.java | 15 - .../james/modules/CommonServicesModule.java | 2 - .../apache/james/modules/ProtocolsModule.java | 4 + .../modules/ProtocolsModuleWithoutJMAP.java | 5 + .../server/CamelMailetContainerModule.java | 20 ++ .../apache/james/utils/GuiceServerProbe.java | 352 +++++++++++++++++++ .../apache/james/AbstractJamesServerTest.java | 33 +- .../james/AbstractJmapJamesServerTest.java | 140 ++++++++ .../james/jmap/MailetPreconditionTest.java | 5 +- server/container/guice/jpa-guice/pom.xml | 16 +- .../java/org/apache/james/JPAConfiguration.java | 3 + .../org/apache/james/JPAJamesServerMain.java | 27 +- .../james/modules/data/JPADataJmapModule.java | 22 -- .../james/modules/data/JPADataModule.java | 32 ++ .../modules/data/JPASieveRepositoryModule.java | 18 + .../james/modules/mailbox/JPAMailboxModule.java | 8 +- .../mailbox/LuceneSearchMailboxModule.java | 5 - .../ScheduledExecutorServiceProvider.java | 49 --- .../src/main/resources/META-INF/persistence.xml | 45 +++ .../org/apache/james/JPAJamesServerTest.java | 2 +- .../james/TestJPAConfigurationModule.java | 5 +- .../src/test/resources/mailetcontainer.xml | 1 - .../org/apache/james/MemoryJamesServerTest.java | 2 +- .../src/main/resources/META-INF/persistence.xml | 6 - server/pom.xml | 7 +- 30 files changed, 748 insertions(+), 184 deletions(-) ---------------------------------------------------------------------- http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAId.java ---------------------------------------------------------------------- diff --git a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAId.java b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAId.java index 343476f..2992725 100644 --- a/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAId.java +++ b/mailbox/jpa/src/main/java/org/apache/james/mailbox/jpa/JPAId.java @@ -25,7 +25,7 @@ public class JPAId implements MailboxId { public static class Factory implements MailboxId.Factory { @Override public JPAId fromString(String serialized) { - return of(Long.parseLong(serialized)); + return of(Long.valueOf(serialized)); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/mailbox/jpa/src/main/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/mailbox/jpa/src/main/resources/META-INF/persistence.xml b/mailbox/jpa/src/main/resources/META-INF/persistence.xml index a9cbc68..3ec5f22 100644 --- a/mailbox/jpa/src/main/resources/META-INF/persistence.xml +++ b/mailbox/jpa/src/main/resources/META-INF/persistence.xml @@ -30,9 +30,6 @@ <class>org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage</class> <class>org.apache.james.mailbox.jpa.mail.model.JPAProperty</class> <class>org.apache.james.mailbox.jpa.user.model.JPASubscription</class> - <class>org.apache.james.domainlist.jpa.model.JPADomain</class> - <class>org.apache.james.user.jpa.model.JPAUser</class> - <class>org.apache.james.rrt.jpa.model.JPARecipientRewrite</class> <properties> <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> <property name="openjpa.jdbc.MappingDefaults" value="ForeignKeyDeleteAction=cascade, JoinForeignKeyDeleteAction=cascade"/> http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java index 41187a1..2f53657 100644 --- a/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java +++ b/server/container/guice/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java @@ -35,7 +35,7 @@ import com.google.inject.AbstractModule; import com.google.inject.Provides; import com.google.inject.Singleton; -public class CassandraJamesServerTest extends AbstractJamesServerTest { +public class CassandraJamesServerTest extends AbstractJmapJamesServerTest { private TemporaryFolder temporaryFolder = new TemporaryFolder(); private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder); http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java new file mode 100644 index 0000000..d847783 --- /dev/null +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJamesServer.java @@ -0,0 +1,99 @@ +/**************************************************************** + * 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.util.Arrays; +import java.util.Optional; + +import javax.annotation.PreDestroy; + +import org.apache.james.modules.CommonServicesModule; +import org.apache.james.modules.MailetProcessingModule; +import org.apache.james.modules.ProtocolsModuleWithoutJMAP; +import org.apache.james.onami.lifecycle.Stager; +import org.apache.james.utils.ConfigurationsPerformer; +import org.apache.james.utils.ExtendedServerProbe; +import org.apache.james.utils.GuiceServerProbe; +import org.apache.james.webadmin.Port; +import org.apache.james.webadmin.WebAdminServer; + +import com.google.common.collect.Iterables; +import com.google.inject.Guice; +import com.google.inject.Injector; +import com.google.inject.Key; +import com.google.inject.Module; +import com.google.inject.TypeLiteral; +import com.google.inject.util.Modules; + +public class GuiceJamesServer { + private final Module module; + private Stager<PreDestroy> preDestroy; + private GuiceServerProbe serverProbe; + private Optional<Port> webadminPort; + + public GuiceJamesServer() { + this(Modules.combine( + new CommonServicesModule(), + new ProtocolsModuleWithoutJMAP(), + new MailetProcessingModule())); + } + + private GuiceJamesServer(Module module) { + this.module = module; + } + + public GuiceJamesServer combineWith(Module... modules) { + return new GuiceJamesServer(Modules.combine(Iterables.concat(Arrays.asList(module), Arrays.asList(modules)))); + } + + public GuiceJamesServer overrideWith(Module... overrides) { + return new GuiceJamesServer(Modules.override(module).with(overrides)); + } + + public void start() throws Exception { + Injector injector = Guice.createInjector(module); + preDestroy = injector.getInstance(Key.get(new TypeLiteral<Stager<PreDestroy>>() {})); + injector.getInstance(ConfigurationsPerformer.class).initModules(); + serverProbe = injector.getInstance(GuiceServerProbe.class); + webadminPort =locateWebAdminPort(injector); + } + + private Optional<Port> locateWebAdminPort(Injector injector) { + try { + return Optional.of(injector.getInstance(WebAdminServer.class).getPort()); + } catch(Exception e) { + return Optional.empty(); + } + } + + public void stop() { + if (preDestroy != null) { + preDestroy.stage(); + } + } + + public ExtendedServerProbe serverProbe() { + return serverProbe; + } + + public Optional<Port> getWebadminPort() { + return webadminPort; + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJmapJamesServer.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJmapJamesServer.java b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJmapJamesServer.java index d137fdf..8a85b81 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJmapJamesServer.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/GuiceJmapJamesServer.java @@ -57,7 +57,7 @@ public class GuiceJmapJamesServer { new MailetProcessingModule())); } - public GuiceJmapJamesServer(Module module) { + private GuiceJmapJamesServer(Module module) { this.module = module; } http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java index 286cead..c38ea17 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/jmap/JMAPModule.java @@ -38,8 +38,6 @@ import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxManager.SearchCapabilities; import org.apache.james.mailetcontainer.impl.MatcherMailetPair; import org.apache.james.modules.server.CamelMailetContainerModule; -import org.apache.james.transport.mailets.RemoveMimeHeader; -import org.apache.james.transport.matchers.All; import org.apache.james.transport.matchers.RecipientIsLocal; import org.apache.james.utils.ConfigurationPerformer; import org.apache.james.utils.PropertiesProvider; @@ -71,7 +69,6 @@ public class JMAPModule extends AbstractModule { Multibinder<CamelMailetContainerModule.TransportProcessorCheck> transportProcessorChecks = Multibinder.newSetBinder(binder(), CamelMailetContainerModule.TransportProcessorCheck.class); transportProcessorChecks.addBinding().to(VacationMailetCheck.class); - transportProcessorChecks.addBinding().to(BccMailetCheck.class); bind(SystemMailboxesProvider.class).to(SystemMailboxesProviderImpl.class); } @@ -134,16 +131,4 @@ public class JMAPModule extends AbstractModule { } } - public static class BccMailetCheck implements CamelMailetContainerModule.TransportProcessorCheck { - @Override - public void check(List<MatcherMailetPair> pairs) throws ConfigurationException { - Preconditions.checkNotNull(pairs); - pairs.stream() - .filter(pair -> pair.getMailet().getClass().equals(RemoveMimeHeader.class)) - .filter(pair -> pair.getMatcher().getClass().equals(All.class)) - .filter(pair -> pair.getMailet().getMailetConfig().getInitParameter("name").equals("bcc")) - .findAny() - .orElseThrow(() -> new ConfigurationException("Missing RemoveMimeHeader in mailets configuration (mailetcontainer -> processors -> transport). Should be configured to remove Bcc header")); - } - } } http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java index 10af893..dfbbb8a 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/CommonServicesModule.java @@ -33,7 +33,6 @@ import org.apache.james.modules.server.AsyncTasksExecutorModule; import org.apache.james.modules.server.ConfigurationProviderModule; import org.apache.james.modules.server.DNSServiceModule; import org.apache.james.onami.lifecycle.PreDestroyModule; -import org.apache.james.utils.JmapGuiceServerProbe; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -55,7 +54,6 @@ public class CommonServicesModule extends AbstractModule { install(new AsyncTasksExecutorModule()); bind(FileSystemImpl.class).in(Scopes.SINGLETON); - bind(JmapGuiceServerProbe.class).in(Scopes.SINGLETON); bind(FileSystem.class).to(FileSystemImpl.class); } http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/guice-common/src/main/java/org/apache/james/modules/ProtocolsModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/ProtocolsModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/ProtocolsModule.java index c21391d..28554b2 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/ProtocolsModule.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/ProtocolsModule.java @@ -26,8 +26,10 @@ 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 org.apache.james.utils.JmapGuiceServerProbe; import com.google.inject.AbstractModule; +import com.google.inject.Scopes; public class ProtocolsModule extends AbstractModule { @@ -41,6 +43,8 @@ public class ProtocolsModule extends AbstractModule { install(new LMTPServerModule()); install(new ManageSieveServerModule()); install(new WebAdminServerModule()); + + bind(JmapGuiceServerProbe.class).in(Scopes.SINGLETON); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/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 index 9c05696..a945651 100644 --- 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 @@ -7,8 +7,10 @@ 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 org.apache.james.utils.GuiceServerProbe; import com.google.inject.AbstractModule; +import com.google.inject.Scopes; public class ProtocolsModuleWithoutJMAP extends AbstractModule { @Override @@ -20,6 +22,9 @@ public class ProtocolsModuleWithoutJMAP extends AbstractModule { install(new LMTPServerModule()); install(new ManageSieveServerModule()); install(new WebAdminServerModule()); + + bind(GuiceServerProbe.class).in(Scopes.SINGLETON); + } } http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java index 1decdd6..34a64a5 100644 --- a/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java @@ -39,6 +39,8 @@ import org.apache.james.mailetcontainer.impl.MatcherMailetPair; import org.apache.james.mailetcontainer.impl.camel.CamelCompositeProcessor; import org.apache.james.mailetcontainer.impl.camel.CamelMailetProcessor; import org.apache.james.queue.api.MailQueueFactory; +import org.apache.james.transport.mailets.RemoveMimeHeader; +import org.apache.james.transport.matchers.All; import org.apache.james.user.api.UsersRepository; import org.apache.james.utils.ConfigurationPerformer; import org.apache.james.utils.ConfigurationProvider; @@ -48,6 +50,7 @@ import org.apache.mailet.MailetContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.common.base.Preconditions; import com.google.common.base.Throwables; import com.google.common.collect.ImmutableList; import com.google.inject.AbstractModule; @@ -75,6 +78,9 @@ public class CamelMailetContainerModule extends AbstractModule { bind(MatcherLoader.class).to(GuiceMatcherLoader.class); Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(MailetModuleConfigurationPerformer.class); + + Multibinder<CamelMailetContainerModule.TransportProcessorCheck> transportProcessorChecks = Multibinder.newSetBinder(binder(), CamelMailetContainerModule.TransportProcessorCheck.class); + transportProcessorChecks.addBinding().to(BccMailetCheck.class); } @Provides @@ -164,4 +170,18 @@ public class CamelMailetContainerModule extends AbstractModule { public interface TransportProcessorCheck { void check(List<MatcherMailetPair> pairs) throws ConfigurationException; } + + public static class BccMailetCheck implements CamelMailetContainerModule.TransportProcessorCheck { + @Override + public void check(List<MatcherMailetPair> pairs) throws ConfigurationException { + Preconditions.checkNotNull(pairs); + pairs.stream() + .filter(pair -> pair.getMailet().getClass().equals(RemoveMimeHeader.class)) + .filter(pair -> pair.getMatcher().getClass().equals(All.class)) + .filter(pair -> pair.getMailet().getMailetConfig().getInitParameter("name").equals("bcc")) + .findAny() + .orElseThrow(() -> new ConfigurationException("Missing RemoveMimeHeader in mailets configuration (mailetcontainer -> processors -> transport). Should be configured to remove Bcc header")); + } + } + } http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java new file mode 100644 index 0000000..9cb8c07 --- /dev/null +++ b/server/container/guice/guice-common/src/main/java/org/apache/james/utils/GuiceServerProbe.java @@ -0,0 +1,352 @@ +/**************************************************************** + * 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.utils; + +import java.io.IOException; +import java.io.InputStream; +import java.util.Collection; +import java.util.Date; +import java.util.List; +import java.util.Map; +import java.util.stream.Collectors; + +import javax.inject.Inject; +import javax.mail.Flags; + +import org.apache.commons.lang.NotImplementedException; +import org.apache.james.adapter.mailbox.SerializableQuota; +import org.apache.james.domainlist.api.DomainList; +import org.apache.james.mailbox.MailboxManager; +import org.apache.james.mailbox.MailboxSession; +import org.apache.james.mailbox.MessageManager; +import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.model.MailboxConstants; +import org.apache.james.mailbox.model.MailboxMetaData; +import org.apache.james.mailbox.model.MailboxPath; +import org.apache.james.mailbox.model.MailboxQuery; +import org.apache.james.mailbox.store.mail.MailboxMapper; +import org.apache.james.mailbox.store.mail.MailboxMapperFactory; +import org.apache.james.mailbox.store.mail.model.Mailbox; +import org.apache.james.rrt.api.RecipientRewriteTable; +import org.apache.james.rrt.lib.Mappings; +import org.apache.james.sieverepository.api.SieveRepository; +import org.apache.james.user.api.UsersRepository; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableList; +import com.google.common.collect.Iterables; + +public class GuiceServerProbe implements ExtendedServerProbe { + + private static final Logger LOGGER = LoggerFactory.getLogger(JmapGuiceServerProbe.class); + + private final MailboxManager mailboxManager; + private final MailboxMapperFactory mailboxMapperFactory; + private final DomainList domainList; + private final UsersRepository usersRepository; + private final SieveRepository sieveRepository; + private final RecipientRewriteTable recipientRewriteTable; + + @Inject + private GuiceServerProbe(MailboxManager mailboxManager, MailboxMapperFactory mailboxMapperFactory, + DomainList domainList, UsersRepository usersRepository, SieveRepository sieveRepository, + RecipientRewriteTable recipientRewriteTable) { + this.mailboxManager = mailboxManager; + this.mailboxMapperFactory = mailboxMapperFactory; + this.domainList = domainList; + this.usersRepository = usersRepository; + this.sieveRepository = sieveRepository; + this.recipientRewriteTable = recipientRewriteTable; + } + + @Override + public void close() throws IOException { + } + + @Override + public void addUser(String userName, String password) throws Exception { + usersRepository.addUser(userName, password); + } + + @Override + public void removeUser(String username) throws Exception { + usersRepository.removeUser(username); + } + + @Override + public String[] listUsers() throws Exception { + return Iterables.toArray(ImmutableList.copyOf(usersRepository.list()), String.class); + } + + @Override + public void setPassword(String userName, String password) throws Exception { + throw new NotImplementedException(); + } + + @Override + public void addDomain(String domain) throws Exception { + domainList.addDomain(domain); + } + + @Override + public boolean containsDomain(String domain) throws Exception { + return domainList.containsDomain(domain); + } + + @Override + public String getDefaultDomain() throws Exception { + return domainList.getDefaultDomain(); + } + + @Override + public void removeDomain(String domain) throws Exception { + domainList.removeDomain(domain); + } + + @Override + public List<String> listDomains() throws Exception { + return domainList.getDomains(); + } + + @Override + public Map<String, Mappings> listMappings() throws Exception { + return recipientRewriteTable.getAllMappings(); + } + + @Override + public void addAddressMapping(String user, String domain, String toAddress) throws Exception { + recipientRewriteTable.addAddressMapping(user, domain, toAddress); + } + + @Override + public void removeAddressMapping(String user, String domain, String fromAddress) throws Exception { + recipientRewriteTable.removeAddressMapping(user, domain, fromAddress); + } + + @Override + public Mappings listUserDomainMappings(String user, String domain) throws Exception { + throw new NotImplementedException(); + } + + @Override + public void addRegexMapping(String user, String domain, String regex) throws Exception { + recipientRewriteTable.addRegexMapping(user, domain, regex); + } + + @Override + public void removeRegexMapping(String user, String domain, String regex) throws Exception { + recipientRewriteTable.removeRegexMapping(user, domain, regex); + } + + @Override + public void copyMailbox(String srcBean, String dstBean) throws Exception { + throw new NotImplementedException(); + } + + @Override + public void deleteUserMailboxesNames(String user) throws Exception { + throw new NotImplementedException(); + } + + @Override + public void createMailbox(String namespace, String user, String name) { + MailboxSession mailboxSession = null; + try { + mailboxSession = mailboxManager.createSystemSession(user, LOGGER); + mailboxManager.startProcessingRequest(mailboxSession); + mailboxManager.createMailbox(new MailboxPath(namespace, user, name), mailboxSession); + } catch (MailboxException e) { + throw Throwables.propagate(e); + } finally { + closeSession(mailboxSession); + } + } + + @Override + public Mailbox getMailbox(String namespace, String user, String name) { + MailboxSession mailboxSession = null; + try { + mailboxSession = mailboxManager.createSystemSession(user, LOGGER); + MailboxMapper mailboxMapper = mailboxMapperFactory.getMailboxMapper(mailboxSession); + return mailboxMapper.findMailboxByPath(new MailboxPath(namespace, user, name)); + } catch (MailboxException e) { + throw Throwables.propagate(e); + } finally { + closeSession(mailboxSession); + } + } + + private void closeSession(MailboxSession session) { + if (session != null) { + mailboxManager.endProcessingRequest(session); + try { + mailboxManager.logout(session, true); + } catch (MailboxException e) { + throw Throwables.propagate(e); + } + } + } + + @Override + public Collection<String> listUserMailboxes(String user) { + MailboxSession mailboxSession = null; + try { + mailboxSession = mailboxManager.createSystemSession(user, LOGGER); + mailboxManager.startProcessingRequest(mailboxSession); + return searchUserMailboxes(user, mailboxSession) + .stream() + .map(MailboxMetaData::getPath) + .map(MailboxPath::getName) + .collect(Collectors.toList()); + } catch (MailboxException e) { + throw Throwables.propagate(e); + } finally { + closeSession(mailboxSession); + } + } + + private List<MailboxMetaData> searchUserMailboxes(String username, MailboxSession session) throws MailboxException { + return mailboxManager.search( + new MailboxQuery(new MailboxPath(MailboxConstants.USER_NAMESPACE, username, ""), + "*", + session.getPathDelimiter()), + session); + } + + @Override + public void deleteMailbox(String namespace, String user, String name) { + MailboxSession mailboxSession = null; + try { + mailboxSession = mailboxManager.createSystemSession(user, LOGGER); + mailboxManager.startProcessingRequest(mailboxSession); + mailboxManager.deleteMailbox(new MailboxPath(namespace, user, name), mailboxSession); + } catch (MailboxException e) { + throw Throwables.propagate(e); + } finally { + closeSession(mailboxSession); + } + } + + @Override + public String getQuotaRoot(String namespace, String user, String name) throws MailboxException { + throw new NotImplementedException(); + } + + @Override + public SerializableQuota getMessageCountQuota(String quotaRoot) throws MailboxException { + throw new NotImplementedException(); + } + + @Override + public SerializableQuota getStorageQuota(String quotaRoot) throws MailboxException { + throw new NotImplementedException(); + } + + @Override + public long getMaxMessageCount(String quotaRoot) throws MailboxException { + throw new NotImplementedException(); + } + + @Override + public long getMaxStorage(String quotaRoot) throws MailboxException { + throw new NotImplementedException(); + } + + @Override + public long getDefaultMaxMessageCount() throws MailboxException { + throw new NotImplementedException(); + } + + @Override + public long getDefaultMaxStorage() throws MailboxException { + throw new NotImplementedException(); + } + + @Override + public void setMaxMessageCount(String quotaRoot, long maxMessageCount) throws MailboxException { + throw new NotImplementedException(); + } + + @Override + public void setMaxStorage(String quotaRoot, long maxSize) throws MailboxException { + throw new NotImplementedException(); + } + + @Override + public void setDefaultMaxMessageCount(long maxDefaultMessageCount) throws MailboxException { + throw new NotImplementedException(); + } + + @Override + public void setDefaultMaxStorage(long maxDefaultSize) throws MailboxException { + throw new NotImplementedException(); + } + + @Override + public void appendMessage(String username, MailboxPath mailboxPath, InputStream message, Date internalDate, boolean isRecent, Flags flags) + throws MailboxException { + + MailboxSession mailboxSession = mailboxManager.createSystemSession(username, LOGGER); + MessageManager messageManager = mailboxManager.getMailbox(mailboxPath, mailboxSession); + messageManager.appendMessage(message, internalDate, mailboxSession, isRecent, flags); + } + + @Override + public void reIndexMailbox(String namespace, String user, String name) throws Exception { + throw new NotImplementedException(); + } + + @Override + public void reIndexAll() throws Exception { + throw new NotImplementedException(); + } + + @Override + public long getSieveQuota() throws Exception { + return sieveRepository.getQuota(); + } + + @Override + public void setSieveQuota(long quota) throws Exception { + sieveRepository.setQuota(quota); + } + + @Override + public void removeSieveQuota() throws Exception { + sieveRepository.removeQuota(); + } + + @Override + public long getSieveQuota(String user) throws Exception { + return sieveRepository.getQuota(user); + } + + @Override + public void setSieveQuota(String user, long quota) throws Exception { + sieveRepository.setQuota(user, quota); + } + + @Override + public void removeSieveQuota(String user) throws Exception { + sieveRepository.removeQuota(user); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java index bdeeeff..fa85594 100644 --- a/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java +++ b/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJamesServerTest.java @@ -18,9 +18,6 @@ ****************************************************************/ package org.apache.james; -import static com.jayway.restassured.RestAssured.given; -import static com.jayway.restassured.config.EncoderConfig.encoderConfig; -import static com.jayway.restassured.config.RestAssuredConfig.newConfig; import static org.assertj.core.api.Assertions.assertThat; import java.io.IOException; @@ -31,15 +28,9 @@ import java.nio.channels.SocketChannel; import java.nio.charset.Charset; import org.junit.After; -import org.junit.Assume; import org.junit.Before; import org.junit.Test; -import com.google.common.base.Charsets; -import com.jayway.restassured.RestAssured; -import com.jayway.restassured.builder.RequestSpecBuilder; -import com.jayway.restassured.http.ContentType; - public abstract class AbstractJamesServerTest { private static final int IMAP_PORT = 1143; // You need to be root (superuser) to bind to ports under 1024. @@ -47,9 +38,8 @@ public abstract class AbstractJamesServerTest { private static final int POP3_PORT = 1110; private static final int SMTP_PORT = 1025; private static final int LMTP_PORT = 1024; - private static final int JMAP_PORT = 1080; - private GuiceJmapJamesServer server; + private GuiceJamesServer server; private SocketChannel socketChannel; @Before @@ -57,17 +47,9 @@ public abstract class AbstractJamesServerTest { server = createJamesServer(); socketChannel = SocketChannel.open(); server.start(); - - RestAssured.requestSpecification = new RequestSpecBuilder() - .setContentType(ContentType.JSON) - .setAccept(ContentType.JSON) - .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8))) - .setPort(server.getJmapPort() - .orElse(JMAP_PORT)) - .build(); } - protected abstract GuiceJmapJamesServer createJamesServer(); + protected abstract GuiceJamesServer createJamesServer(); protected abstract void clean(); @@ -123,17 +105,6 @@ public abstract class AbstractJamesServerTest { assertThat(getServerConnectionResponse(socketChannel)).contains("LMTP Server (JAMES Protocols Server) ready"); } - @Test - public void connectJMAPServerShouldRespondBadRequest() throws Exception { - Assume.assumeTrue(server.getJmapPort().isPresent()); - given() - .body("{\"badAttributeName\": \"value\"}") - .when() - .post("/authentication") - .then() - .statusCode(400); - } - private String getServerConnectionResponse(SocketChannel socketChannel) throws IOException { ByteBuffer byteBuffer = ByteBuffer.allocate(1000); socketChannel.read(byteBuffer); http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java new file mode 100644 index 0000000..43eb665 --- /dev/null +++ b/server/container/guice/guice-common/src/test/java/org/apache/james/AbstractJmapJamesServerTest.java @@ -0,0 +1,140 @@ +/**************************************************************** + * 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 com.jayway.restassured.RestAssured.given; +import static com.jayway.restassured.config.EncoderConfig.encoderConfig; +import static com.jayway.restassured.config.RestAssuredConfig.newConfig; +import static org.assertj.core.api.Assertions.assertThat; + +import java.io.IOException; +import java.net.InetAddress; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; +import java.nio.charset.Charset; + +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.google.common.base.Charsets; +import com.jayway.restassured.RestAssured; +import com.jayway.restassured.builder.RequestSpecBuilder; +import com.jayway.restassured.http.ContentType; + +public abstract class AbstractJmapJamesServerTest { + + private static final int IMAP_PORT = 1143; // You need to be root (superuser) to bind to ports under 1024. + private static final int IMAP_PORT_SSL = 1993; + private static final int POP3_PORT = 1110; + private static final int SMTP_PORT = 1025; + private static final int LMTP_PORT = 1024; + + private GuiceJmapJamesServer server; + private SocketChannel socketChannel; + + @Before + public void setup() throws Exception { + server = createJamesServer(); + socketChannel = SocketChannel.open(); + server.start(); + + RestAssured.requestSpecification = new RequestSpecBuilder() + .setContentType(ContentType.JSON) + .setAccept(ContentType.JSON) + .setConfig(newConfig().encoderConfig(encoderConfig().defaultContentCharset(Charsets.UTF_8))) + .setPort(server.getJmapPort() + .orElseThrow(() -> new RuntimeException("Unable to locate JMAP port"))) + .build(); + } + + protected abstract GuiceJmapJamesServer createJamesServer(); + + protected abstract void clean(); + + @After + public void tearDown() throws Exception { + server.stop(); + clean(); + } + + @Test + public void hostnameShouldBeUsedAsDefaultDomain() throws Exception { + String expectedDefaultDomain = InetAddress.getLocalHost().getHostName(); + + assertThat(server.serverProbe().getDefaultDomain()).isEqualTo(expectedDefaultDomain); + } + + @Test + public void hostnameShouldBeRetrievedWhenRestarting() throws Exception { + server.stop(); + server.start(); + String expectedDefaultDomain = InetAddress.getLocalHost().getHostName(); + + assertThat(server.serverProbe().getDefaultDomain()).isEqualTo(expectedDefaultDomain); + } + + @Test + public void connectIMAPServerShouldSendShabangOnConnect() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", IMAP_PORT)); + assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server"); + } + + @Test + public void connectOnSecondaryIMAPServerIMAPServerShouldSendShabangOnConnect() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", IMAP_PORT_SSL)); + assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server"); + } + + @Test + public void connectPOP3ServerShouldSendShabangOnConnect() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", POP3_PORT)); + assertThat(getServerConnectionResponse(socketChannel)).contains("POP3 server (JAMES POP3 Server ) ready"); + } + + @Test + public void connectSMTPServerShouldSendShabangOnConnect() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", SMTP_PORT)); + assertThat(getServerConnectionResponse(socketChannel)).startsWith("220 JAMES Linagora's SMTP awesome Server"); + } + + @Test + public void connectLMTPServerShouldSendShabangOnConnect() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", LMTP_PORT)); + assertThat(getServerConnectionResponse(socketChannel)).contains("LMTP Server (JAMES Protocols Server) ready"); + } + + @Test + public void connectJMAPServerShouldRespondBadRequest() throws Exception { + given() + .body("{\"badAttributeName\": \"value\"}") + .when() + .post("/authentication") + .then() + .statusCode(400); + } + + private String getServerConnectionResponse(SocketChannel socketChannel) throws IOException { + ByteBuffer byteBuffer = ByteBuffer.allocate(1000); + socketChannel.read(byteBuffer); + byte[] bytes = byteBuffer.array(); + return new String(bytes, Charset.forName("UTF-8")); + } +} http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/guice-common/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/guice-common/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java b/server/container/guice/guice-common/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java index 21245c3..efcfd5c 100644 --- a/server/container/guice/guice-common/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java +++ b/server/container/guice/guice-common/src/test/java/org/apache/james/jmap/MailetPreconditionTest.java @@ -25,6 +25,7 @@ import java.util.Properties; import org.apache.commons.configuration.ConfigurationException; import org.apache.james.jmap.mailet.VacationMailet; import org.apache.james.mailetcontainer.impl.MatcherMailetPair; +import org.apache.james.modules.server.CamelMailetContainerModule; import org.apache.james.transport.mailets.Null; import org.apache.james.transport.mailets.RemoveMimeHeader; import org.apache.james.transport.matchers.All; @@ -71,12 +72,12 @@ public class MailetPreconditionTest { @Test(expected = ConfigurationException.class) public void bccMailetCheckShouldThrowOnEmptyList() throws Exception { - new JMAPModule.BccMailetCheck().check(Lists.newArrayList()); + new CamelMailetContainerModule.BccMailetCheck().check(Lists.newArrayList()); } @Test(expected = NullPointerException.class) public void bccMailetCheckShouldThrowOnNullList() throws Exception { - new JMAPModule.BccMailetCheck().check(null); + new CamelMailetContainerModule.BccMailetCheck().check(null); } @Test(expected = ConfigurationException.class) http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/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 index b707871..73beb1d 100644 --- a/server/container/guice/jpa-guice/pom.xml +++ b/server/container/guice/jpa-guice/pom.xml @@ -191,11 +191,11 @@ </plugins> </build> <dependencies> -<!-- <dependency> - <groupId>${project.groupId}</groupId> - <artifactId>apache-james-backends-cassandra</artifactId> - <type>test-jar</type> - </dependency>--> + <dependency> + <groupId>org.apache.derby</groupId> + <artifactId>derby</artifactId> + <scope>test</scope> + </dependency> <dependency> <groupId>${project.groupId}</groupId> <artifactId>apache-james-mailbox-jpa</artifactId> @@ -212,12 +212,6 @@ </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> http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/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 index 8041205..c0f7d76 100644 --- 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 @@ -19,6 +19,7 @@ package org.apache.james; import com.google.common.annotations.VisibleForTesting; +import com.google.common.base.Preconditions; public class JPAConfiguration { public static Builder builder() { @@ -40,6 +41,8 @@ public class JPAConfiguration { } public JPAConfiguration build() { + Preconditions.checkNotNull(driverName); + Preconditions.checkNotNull(driverURL); return new JPAConfiguration(driverName, driverURL); } } http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/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 index 090965d..ae623ce 100644 --- 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 @@ -19,13 +19,8 @@ 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.data.JPADataModule; +import org.apache.james.modules.data.JPASieveRepositoryModule; import org.apache.james.modules.mailbox.JPAMailboxModule; import org.apache.james.modules.mailbox.LuceneSearchMailboxModule; import org.apache.james.modules.server.ActiveMQQueueModule; @@ -36,25 +31,19 @@ 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 JPADataModule(), + new JPASieveRepositoryModule(), new QuotaModule(), new ActiveMQQueueModule()); - public static void main(String[] args) throws Exception { - GuiceJamesServer server = new GuiceJamesServer(mainServerModule) - .combineWith(jpaServerModule, new JMXServerModule()); + GuiceJamesServer server = new GuiceJamesServer() + .combineWith(jpaServerModule, + new JMXServerModule(), + new LuceneSearchMailboxModule()); server.start(); } http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/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 deleted file mode 100644 index 84eda74..0000000 --- a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADataJmapModule.java +++ /dev/null @@ -1,22 +0,0 @@ -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/11771d03/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADataModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADataModule.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADataModule.java new file mode 100644 index 0000000..ec8023e --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPADataModule.java @@ -0,0 +1,32 @@ +/**************************************************************** + * 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.inject.AbstractModule; + +public class JPADataModule extends AbstractModule { + + @Override + protected void configure() { + install(new JPAUsersRepositoryModule()); + install(new JPADomainListModule()); + install(new JPARecipientRewriteTableModule()); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPASieveRepositoryModule.java ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPASieveRepositoryModule.java b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPASieveRepositoryModule.java new file mode 100644 index 0000000..13fff5b --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/data/JPASieveRepositoryModule.java @@ -0,0 +1,18 @@ +package org.apache.james.modules.data; + +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 JPASieveRepositoryModule extends AbstractModule { + + @Override + protected void configure() { + bind(SieveFileRepository.class).in(Scopes.SINGLETON); + + bind(SieveRepository.class).to(SieveFileRepository.class); + } + +} http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/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 index 52c4237..c12cd00 100644 --- 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 @@ -46,8 +46,8 @@ import org.apache.james.mailbox.jpa.openjpa.OpenJPAMailboxManager; import org.apache.james.mailbox.model.MailboxId; import org.apache.james.mailbox.model.MessageId; import org.apache.james.mailbox.store.Authenticator; +import org.apache.james.mailbox.store.JVMMailboxPathLocker; 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; @@ -71,7 +71,7 @@ public class JPAMailboxModule extends AbstractModule { protected void configure() { bind(JPAMailboxSessionMapperFactory.class).in(Scopes.SINGLETON); bind(OpenJPAMailboxManager.class).in(Scopes.SINGLETON); - bind(NoMailboxPathLocker.class).in(Scopes.SINGLETON); + bind(JVMMailboxPathLocker.class).in(Scopes.SINGLETON); bind(JPASubscriptionManager.class).in(Scopes.SINGLETON); bind(JPAModSeqProvider.class).in(Scopes.SINGLETON); bind(JPAUidProvider.class).in(Scopes.SINGLETON); @@ -90,7 +90,7 @@ public class JPAMailboxModule extends AbstractModule { 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(MailboxPathLocker.class).to(JVMMailboxPathLocker.class); bind(Authenticator.class).to(UserRepositoryAuthenticator.class); bind(MailboxManager.class).to(OpenJPAMailboxManager.class); bind(MailboxId.Factory.class).to(JPAId.Factory.class); @@ -122,7 +122,7 @@ public class JPAMailboxModule extends AbstractModule { properties.put("openjpa.ConnectionDriverName", jpaConfiguration.getDriverName()); properties.put("openjpa.ConnectionURL", jpaConfiguration.getDriverURL()); - return Persistence.createEntityManagerFactory("James", properties); + return Persistence.createEntityManagerFactory("Global", properties); } http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/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 index fa46463..dbb3435 100644 --- 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 @@ -22,11 +22,9 @@ 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; @@ -42,9 +40,6 @@ public class LuceneSearchMailboxModule extends AbstractModule { 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 http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/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 deleted file mode 100644 index 48fe3f1..0000000 --- a/server/container/guice/jpa-guice/src/main/java/org/apache/james/modules/mailbox/ScheduledExecutorServiceProvider.java +++ /dev/null @@ -1,49 +0,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. * - ****************************************************************/ - -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/11771d03/server/container/guice/jpa-guice/src/main/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/server/container/guice/jpa-guice/src/main/resources/META-INF/persistence.xml b/server/container/guice/jpa-guice/src/main/resources/META-INF/persistence.xml new file mode 100644 index 0000000..24a8d67 --- /dev/null +++ b/server/container/guice/jpa-guice/src/main/resources/META-INF/persistence.xml @@ -0,0 +1,45 @@ +<?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. +--> + +<persistence xmlns="http://java.sun.com/xml/ns/persistence" + xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" + xsi:schemaLocation="http://java.sun.com/xml/ns/persistence http://java.sun.com/xml/ns/persistence/persistence_2_0.xsd" + version="2.0"> + + <persistence-unit name="Global" transaction-type="RESOURCE_LOCAL"> + <class>org.apache.james.mailbox.jpa.mail.model.JPAMailbox</class> + <class>org.apache.james.mailbox.jpa.mail.model.JPAUserFlag</class> + <class>org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage</class> + <class>org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage</class> + <class>org.apache.james.mailbox.jpa.mail.model.JPAProperty</class> + <class>org.apache.james.mailbox.jpa.user.model.JPASubscription</class> + <class>org.apache.james.domainlist.jpa.model.JPADomain</class> + <class>org.apache.james.user.jpa.model.JPAUser</class> + <class>org.apache.james.rrt.jpa.model.JPARecipientRewrite</class> + <properties> + <property name="openjpa.jdbc.SynchronizeMappings" value="buildSchema(ForeignKeys=true)"/> + <property name="openjpa.jdbc.MappingDefaults" value="ForeignKeyDeleteAction=cascade, JoinForeignKeyDeleteAction=cascade"/> + <property name="openjpa.jdbc.SchemaFactory" value="native(ForeignKeys=true)"/> + <property name="openjpa.jdbc.QuerySQLCache" value="false"/> + </properties> + + </persistence-unit> + +</persistence> http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/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 index 23ac61c..0684be1 100644 --- 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 @@ -30,7 +30,7 @@ public class JPAJamesServerTest extends AbstractJamesServerTest { @Override protected GuiceJamesServer createJamesServer() { - return new GuiceJamesServer(JPAJamesServerMain.mainServerModule) + return new GuiceJamesServer() .combineWith(JPAJamesServerMain.jpaServerModule) .overrideWith(new TestFilesystemModule(temporaryFolder), new TestJPAConfigurationModule()); http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/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 index e1847cc..7c064c4 100644 --- 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 @@ -30,8 +30,8 @@ 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"; + private static final String JDBC_EMBEDDED_URL = "jdbc:derby:memory:mailboxintegration;create=true"; + private static final String JDBC_EMBEDDED_DRIVER = org.apache.derby.jdbc.EmbeddedDriver.class.getName(); @Override protected void configure() { @@ -45,5 +45,4 @@ public class TestJPAConfigurationModule extends AbstractModule { .driverURL(JDBC_EMBEDDED_URL) .build(); } - } http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/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 index b265f93..426cab8 100644 --- a/server/container/guice/jpa-guice/src/test/resources/mailetcontainer.xml +++ b/server/container/guice/jpa-guice/src/test/resources/mailetcontainer.xml @@ -55,7 +55,6 @@ <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> http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java ---------------------------------------------------------------------- diff --git a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java index 70adef1..424c772 100644 --- a/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java +++ b/server/container/guice/memory-guice/src/test/java/org/apache/james/MemoryJamesServerTest.java @@ -25,7 +25,7 @@ import org.apache.james.modules.TestJMAPServerModule; import org.junit.Rule; import org.junit.rules.TemporaryFolder; -public class MemoryJamesServerTest extends AbstractJamesServerTest { +public class MemoryJamesServerTest extends AbstractJmapJamesServerTest { @Rule public TemporaryFolder temporaryFolder = new TemporaryFolder(); http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/data/data-jpa/src/main/resources/META-INF/persistence.xml ---------------------------------------------------------------------- diff --git a/server/data/data-jpa/src/main/resources/META-INF/persistence.xml b/server/data/data-jpa/src/main/resources/META-INF/persistence.xml index 9e7bdf9..14a6a4f 100644 --- a/server/data/data-jpa/src/main/resources/META-INF/persistence.xml +++ b/server/data/data-jpa/src/main/resources/META-INF/persistence.xml @@ -26,12 +26,6 @@ <persistence-unit name="James" transaction-type="JTA"> <provider>org.apache.openjpa.persistence.PersistenceProviderImpl</provider> <jta-data-source>osgi:service/javax.sql.DataSource/(osgi.jndi.service.name=jdbc/james)</jta-data-source> - <class>org.apache.james.mailbox.jpa.mail.model.JPAMailbox</class> - <class>org.apache.james.mailbox.jpa.mail.model.JPAUserFlag</class> - <class>org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMailboxMessage</class> - <class>org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMailboxMessage</class> - <class>org.apache.james.mailbox.jpa.mail.model.JPAProperty</class> - <class>org.apache.james.mailbox.jpa.user.model.JPASubscription</class> <class>org.apache.james.domainlist.jpa.model.JPADomain</class> <class>org.apache.james.user.jpa.model.JPAUser</class> <class>org.apache.james.rrt.jpa.model.JPARecipientRewrite</class> http://git-wip-us.apache.org/repos/asf/james-project/blob/11771d03/server/pom.xml ---------------------------------------------------------------------- diff --git a/server/pom.xml b/server/pom.xml index efd8a5d..f86c171 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -703,12 +703,6 @@ <version>${project.version}</version> </dependency> <dependency> - <groupId>org.apache.james</groupId> - <artifactId>apache-james-mailbox-lucene</artifactId> - <version>${project.version}</version> - <type>test-jar</type> - </dependency> - <dependency> <groupId>org.apache.james.protocols</groupId> <artifactId>protocols-imap</artifactId> <version>${project.version}</version> @@ -1197,6 +1191,7 @@ <groupId>org.apache.openjpa</groupId> <artifactId>openjpa</artifactId> <version>${openjpa.version}</version> + <scope>runtime</scope> </dependency> <dependency> <groupId>org.apache.geronimo.specs</groupId> --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org