From 36018ed3c4349610a03be3607f7c9e997649fe5f Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Thu, 22 Oct 2015 14:17:08 +0200 Subject: [PATCH 01/39] JAMES-1626 Update maven-bundle-plugin to 2.4.0 --- pom.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/pom.xml b/pom.xml index 179009d76e6..4467ad968e9 100644 --- a/pom.xml +++ b/pom.xml @@ -567,7 +567,7 @@ org.apache.felix maven-bundle-plugin - 2.3.7 + 2.4.0 true From 8b695088f89170aa99de69282f1896062fc7a98d Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Thu, 22 Oct 2015 14:17:10 +0200 Subject: [PATCH 02/39] JAMES-1626 Use javax.inject in Cassandra mailbox --- mailbox/cassandra/pom.xml | 4 + .../cassandra/CassandraMailboxManager.java | 5 + .../CassandraMailboxSessionMapperFactory.java | 2 + .../CassandraSubscriptionManager.java | 3 + .../cassandra/CassandraTypesProvider.java | 95 +++++++++++++++++++ .../mail/CassandraModSeqProvider.java | 2 + .../cassandra/mail/CassandraUidProvider.java | 11 ++- mailbox/store/pom.xml | 4 + .../mailbox/store/StoreMailboxManager.java | 7 ++ 9 files changed, 129 insertions(+), 4 deletions(-) create mode 100644 mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraTypesProvider.java diff --git a/mailbox/cassandra/pom.xml b/mailbox/cassandra/pom.xml index f5dd50d7889..7a3dd6829b9 100644 --- a/mailbox/cassandra/pom.xml +++ b/mailbox/cassandra/pom.xml @@ -151,6 +151,10 @@ guava 16.0 + + javax.inject + javax.inject + ${javax.mail.groupId} ${javax.mail.artifactId} diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java index 8e4be618cbb..485e32021fc 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java @@ -19,6 +19,9 @@ package org.apache.james.mailbox.cassandra; +import javax.inject.Inject; +import javax.inject.Singleton; + import org.apache.james.mailbox.MailboxPathLocker; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.acl.SimpleGroupMembershipResolver; @@ -35,9 +38,11 @@ /** * Cassandra implementation of {@link StoreMailboxManager} */ +@Singleton public class CassandraMailboxManager extends StoreMailboxManager { private MailboxPathLocker locker; + @Inject public CassandraMailboxManager(CassandraMailboxSessionMapperFactory mapperFactory, Authenticator authenticator, final MailboxPathLocker locker) { super(mapperFactory, authenticator, diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java index 8a54650a7c7..9ae3b2d9dee 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxSessionMapperFactory.java @@ -20,6 +20,7 @@ package org.apache.james.mailbox.cassandra; import org.apache.james.backends.cassandra.init.CassandraTypesProvider; +import javax.inject.Inject; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.cassandra.mail.CassandraMailboxMapper; import org.apache.james.mailbox.cassandra.mail.CassandraMessageMapper; @@ -45,6 +46,7 @@ public class CassandraMailboxSessionMapperFactory extends MailboxSessionMapperFa private final CassandraTypesProvider typesProvider; private int maxRetry; + @Inject public CassandraMailboxSessionMapperFactory(UidProvider uidProvider, ModSeqProvider modSeqProvider, Session session, CassandraTypesProvider typesProvider) { this.uidProvider = uidProvider; this.modSeqProvider = modSeqProvider; diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManager.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManager.java index c1428e9be9c..401f388b941 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManager.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraSubscriptionManager.java @@ -19,6 +19,8 @@ package org.apache.james.mailbox.cassandra; +import javax.inject.Inject; + import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.store.StoreSubscriptionManager; import org.apache.james.mailbox.store.user.model.Subscription; @@ -30,6 +32,7 @@ */ public class CassandraSubscriptionManager extends StoreSubscriptionManager { + @Inject public CassandraSubscriptionManager(CassandraMailboxSessionMapperFactory mapperFactory) { super(mapperFactory); } diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraTypesProvider.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraTypesProvider.java new file mode 100644 index 00000000000..f2b4906f6f7 --- /dev/null +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraTypesProvider.java @@ -0,0 +1,95 @@ +/**************************************************************** + * 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.mailbox.cassandra; + +import com.datastax.driver.core.Session; +import com.datastax.driver.core.UserType; +import com.datastax.driver.core.schemabuilder.CreateType; +import com.datastax.driver.core.schemabuilder.SchemaBuilder; +import com.google.common.collect.ImmutableMap; +import org.apache.james.mailbox.cassandra.table.CassandraMailboxTable; +import org.apache.james.mailbox.cassandra.table.CassandraMessageTable; + +import javax.inject.Inject; +import javax.inject.Singleton; +import java.util.Arrays; +import java.util.Optional; +import java.util.stream.Collectors; + +import static com.datastax.driver.core.DataType.text; + +@Singleton +public class CassandraTypesProvider { + + public enum TYPE { + MailboxBase(CassandraMailboxTable.MAILBOX_BASE, + SchemaBuilder.createType(CassandraMailboxTable.MAILBOX_BASE) + .ifNotExists() + .addColumn(CassandraMailboxTable.MailboxBase.NAMESPACE, text()) + .addColumn(CassandraMailboxTable.MailboxBase.USER, text())), + Property(CassandraMessageTable.PROPERTIES, + SchemaBuilder.createType(CassandraMessageTable.PROPERTIES) + .ifNotExists() + .addColumn(CassandraMessageTable.Properties.NAMESPACE, text()) + .addColumn(CassandraMessageTable.Properties.NAME, text()) + .addColumn(CassandraMessageTable.Properties.VALUE, text())) + ; + + private final String name; + private final CreateType createStatement; + + TYPE(String name, CreateType createStatement) { + this.name = name; + this.createStatement = createStatement; + } + + public String getName() { + return name; + } + } + + private final ImmutableMap userTypes; + private final Session session; + + @Inject + public CassandraTypesProvider(Session session) { + this.session = session; + initializeTypes(); + userTypes = ImmutableMap.builder() + .putAll(Arrays.stream(TYPE.values()) + .collect(Collectors.toMap( + (type) -> type, + (type) -> session.getCluster() + .getMetadata() + .getKeyspace(session.getLoggedKeyspace()) + .getUserType(type.name)))).build(); + } + + public UserType getDefinedUserType(TYPE type) { + return Optional.ofNullable(userTypes.get(type)) + .orElseThrow(() -> new RuntimeException("Cassandra UDT " + type.getName() + " can not be retrieved")); + } + + public void initializeTypes() { + Arrays.asList(TYPE.values()) + .forEach((type) -> session.execute(type.createStatement)); + } + +} diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraModSeqProvider.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraModSeqProvider.java index 772a7e3e867..a30e49bc8b8 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraModSeqProvider.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraModSeqProvider.java @@ -29,6 +29,7 @@ import static org.apache.james.mailbox.cassandra.table.CassandraMessageModseqTable.TABLE_NAME; import java.util.Optional; +import javax.inject.Inject; import org.apache.james.backends.cassandra.utils.CassandraConstants; import org.apache.james.backends.cassandra.utils.LightweightTransactionException; @@ -60,6 +61,7 @@ public CassandraModSeqProvider(Session session, int maxRetry) { this.runner = new FunctionRunnerWithRetry(maxRetry); } + @Inject public CassandraModSeqProvider(Session session) { this(session, DEFAULT_MAX_RETRY); } diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraUidProvider.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraUidProvider.java index 2783347539a..59e0ead3ae5 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraUidProvider.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/mail/CassandraUidProvider.java @@ -19,8 +19,6 @@ package org.apache.james.mailbox.cassandra.mail; -import java.util.Optional; - import static com.datastax.driver.core.querybuilder.QueryBuilder.eq; import static com.datastax.driver.core.querybuilder.QueryBuilder.insertInto; import static com.datastax.driver.core.querybuilder.QueryBuilder.select; @@ -32,6 +30,10 @@ import com.datastax.driver.core.querybuilder.BuiltStatement; import com.google.common.base.Throwables; import org.apache.james.backends.cassandra.utils.LightweightTransactionException; + +import java.util.Optional; +import javax.inject.Inject; + import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.cassandra.CassandraId; import org.apache.james.backends.cassandra.utils.FunctionRunnerWithRetry; @@ -39,11 +41,11 @@ import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.store.mail.UidProvider; import org.apache.james.mailbox.store.mail.model.Mailbox; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; import com.datastax.driver.core.ResultSet; import com.datastax.driver.core.Session; -import org.slf4j.Logger; -import org.slf4j.LoggerFactory; public class CassandraUidProvider implements UidProvider { public final static int DEFAULT_MAX_RETRY = 100000; @@ -58,6 +60,7 @@ public CassandraUidProvider(Session session, int maxRetry) { this.runner = new FunctionRunnerWithRetry(maxRetry); } + @Inject public CassandraUidProvider(Session session) { this(session, DEFAULT_MAX_RETRY); } diff --git a/mailbox/store/pom.xml b/mailbox/store/pom.xml index 784a00d1843..48ab78e7f84 100644 --- a/mailbox/store/pom.xml +++ b/mailbox/store/pom.xml @@ -56,6 +56,10 @@ ${javax.mail.groupId} ${javax.mail.artifactId} + + javax.inject + javax.inject + commons-lang commons-lang diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java index 885d98c4d7e..01924f7bcb2 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/StoreMailboxManager.java @@ -26,6 +26,10 @@ import java.util.Locale; import java.util.Random; +import javax.annotation.PostConstruct; +import javax.inject.Inject; +import javax.inject.Singleton; + import org.apache.james.mailbox.MailboxListener; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxPathLocker; @@ -75,6 +79,7 @@ * * @param */ +@Singleton public class StoreMailboxManager implements MailboxManager { public static final char SQL_WILDCARD_CHAR = '%'; @@ -111,6 +116,7 @@ public class StoreMailboxManager implements MailboxManager private int fetchBatchSize = DEFAULT_FETCH_BATCH_SIZE; + @Inject public StoreMailboxManager(MailboxSessionMapperFactory mailboxSessionMapperFactory, final Authenticator authenticator, final MailboxPathLocker locker, final MailboxACLResolver aclResolver, final GroupMembershipResolver groupMembershipResolver) { this.authenticator = authenticator; this.locker = locker; @@ -158,6 +164,7 @@ public void setFetchBatchSize(int fetchBatchSize) { * @throws MailboxException */ @SuppressWarnings("rawtypes") + @PostConstruct public void init() throws MailboxException { // The dispatcher need to have the delegating listener added dispatcher = new MailboxEventDispatcher(getDelegationListener()); From 95948fbc3ee2f5327ffe1b303588a0c7635b8805 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Thu, 22 Oct 2015 14:17:17 +0200 Subject: [PATCH 03/39] JAMES-1626 Use javax.inject in ElasticSearch mailbox --- .../james/mailbox/cassandra/CassandraMailboxManager.java | 7 +++++++ mailbox/elasticsearch/pom.xml | 4 ++++ .../james/mailbox/elasticsearch/ElasticSearchIndexer.java | 3 +++ .../events/ElasticSearchListeningMessageSearchIndex.java | 2 ++ .../elasticsearch/json/MessageToElasticSearchJson.java | 2 ++ .../james/mailbox/elasticsearch/query/QueryConverter.java | 3 +++ .../elasticsearch/search/ElasticSearchSearcher.java | 3 +++ 7 files changed, 24 insertions(+) diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java index 485e32021fc..40f7f511175 100644 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java +++ b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraMailboxManager.java @@ -34,6 +34,7 @@ import org.apache.james.mailbox.store.StoreMessageManager; import org.apache.james.mailbox.store.mail.model.Mailbox; import org.apache.james.mailbox.store.mail.model.impl.SimpleMailbox; +import org.apache.james.mailbox.store.search.MessageSearchIndex; /** * Cassandra implementation of {@link StoreMailboxManager} @@ -52,6 +53,12 @@ public CassandraMailboxManager(CassandraMailboxSessionMapperFactory mapperFactor this.locker = locker; } + @Override + @Inject + public void setMessageSearchIndex(MessageSearchIndex index) { + super.setMessageSearchIndex(index); + } + @Override protected Mailbox doCreateMailbox(MailboxPath mailboxPath, MailboxSession session) throws MailboxException { SimpleMailbox cassandraMailbox = new SimpleMailbox<>(mailboxPath, randomUidValidity()); diff --git a/mailbox/elasticsearch/pom.xml b/mailbox/elasticsearch/pom.xml index 89abaad02e8..4782639ae59 100644 --- a/mailbox/elasticsearch/pom.xml +++ b/mailbox/elasticsearch/pom.xml @@ -201,6 +201,10 @@ awaitility 1.6.3 + + javax.inject + javax.inject + ${javax.mail.groupId} ${javax.mail.artifactId} diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexer.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexer.java index 821f10a0a21..6317fdc4d15 100644 --- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexer.java +++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/ElasticSearchIndexer.java @@ -27,6 +27,8 @@ import com.google.common.base.Preconditions; +import javax.inject.Inject; + public class ElasticSearchIndexer { public static final String MAILBOX_INDEX = "mailbox"; @@ -34,6 +36,7 @@ public class ElasticSearchIndexer { private final ClientProvider clientProvider; + @Inject public ElasticSearchIndexer(ClientProvider clientProvider) { this.clientProvider = clientProvider; } diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java index 968a406e4d5..ece821d8718 100644 --- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java +++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/events/ElasticSearchListeningMessageSearchIndex.java @@ -20,6 +20,7 @@ import java.util.Iterator; +import javax.inject.Inject; import javax.mail.Flags; import org.apache.james.mailbox.MailboxSession; @@ -48,6 +49,7 @@ public class ElasticSearchListeningMessageSearchIndex exte private final ElasticSearchSearcher searcher; private final MessageToElasticSearchJson messageToElasticSearchJson; + @Inject public ElasticSearchListeningMessageSearchIndex(MessageMapperFactory factory, ElasticSearchIndexer indexer, ElasticSearchSearcher searcher, MessageToElasticSearchJson messageToElasticSearchJson) { super(factory); diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java index 21e6e14c7f6..291643cccc0 100644 --- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java +++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/json/MessageToElasticSearchJson.java @@ -19,6 +19,7 @@ package org.apache.james.mailbox.elasticsearch.json; +import javax.inject.Inject; import javax.mail.Flags; import java.time.ZoneId; @@ -45,6 +46,7 @@ public MessageToElasticSearchJson(TextExtractor textExtractor, ZoneId zoneId) { this.mapper.registerModule(new Jdk8Module()); } + @Inject public MessageToElasticSearchJson(TextExtractor textExtractor) { this(textExtractor, ZoneId.systemDefault()); } diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/QueryConverter.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/QueryConverter.java index 00061f5c9b3..4ea0b5ef6b7 100644 --- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/QueryConverter.java +++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/query/QueryConverter.java @@ -23,6 +23,8 @@ import org.apache.james.mailbox.model.SearchQuery; import org.elasticsearch.common.lang3.tuple.Pair; import org.elasticsearch.index.query.QueryBuilder; + +import javax.inject.Inject; import java.util.List; import java.util.function.Function; import java.util.stream.Stream; @@ -36,6 +38,7 @@ public class QueryConverter implements Function, Query private final CriterionConverter criterionConverter; + @Inject public QueryConverter(CriterionConverter criterionConverter) { this.criterionConverter = criterionConverter; } diff --git a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java index 58655a52fa5..b0f17348133 100644 --- a/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java +++ b/mailbox/elasticsearch/src/main/java/org/apache/james/mailbox/elasticsearch/search/ElasticSearchSearcher.java @@ -40,6 +40,8 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import javax.inject.Inject; + public class ElasticSearchSearcher { private static final Logger LOGGER = LoggerFactory.getLogger(ElasticSearchSearcher.class); @@ -47,6 +49,7 @@ public class ElasticSearchSearcher { private final ClientProvider clientProvider; private final QueryConverter queryConverter; + @Inject public ElasticSearchSearcher(ClientProvider clientProvider, QueryConverter queryConverter) { this.clientProvider = clientProvider; this.queryConverter = queryConverter; From cd54d8a92beb2cad877c9c6ea73f60a3de9b3993 Mon Sep 17 00:00:00 2001 From: benwa Date: Thu, 3 Sep 2015 14:22:04 +0200 Subject: [PATCH 04/39] JAMES-1626 All ProtocolHandler should be lifeCycle aware If fixes a longstanding error in SMTPServerTest that return code 554 on DNS blacklist test --- protocols/api/pom.xml | 7 +- .../handler/AbstractProtocolHandlerChain.java | 4 +- .../api/handler/CommandDispatcher.java | 14 ++- .../handler/CommandHandlerResultLogger.java | 11 ++ .../LifecycleAwareProtocolHandler.java | 34 ----- .../api/handler/ProtocolHandler.java | 15 +++ .../imap/core/IMAPCommandDispatcher.java | 14 ++- .../lmtp/AbstractLMTPServerTest.java | 25 +++- protocols/pom.xml | 15 +++ .../protocols/pop3/core/CapaCmdHandler.java | 12 ++ .../protocols/pop3/core/DeleCmdHandler.java | 12 ++ .../protocols/pop3/core/ListCmdHandler.java | 13 ++ .../protocols/pop3/core/NoopCmdHandler.java | 13 ++ .../protocols/pop3/core/QuitCmdHandler.java | 15 +++ .../protocols/pop3/core/RetrCmdHandler.java | 12 ++ .../protocols/pop3/core/RsetCmdHandler.java | 12 ++ .../protocols/pop3/core/StatCmdHandler.java | 12 ++ .../protocols/pop3/core/StlsCmdHandler.java | 14 +++ .../protocols/pop3/core/UidlCmdHandler.java | 12 ++ .../pop3/core/UnknownCmdHandler.java | 12 ++ .../protocols/pop3/core/UserCmdHandler.java | 11 ++ .../pop3/core/WelcomeMessageHandler.java | 12 ++ .../AcceptRecipientIfRelayingIsAllowed.java | 11 ++ .../protocols/smtp/core/DataCmdHandler.java | 35 +++++- .../smtp/core/DataLineMessageHookHandler.java | 12 +- .../protocols/smtp/core/ExpnCmdHandler.java | 11 ++ .../protocols/smtp/core/HeloCmdHandler.java | 13 ++ .../protocols/smtp/core/HelpCmdHandler.java | 12 ++ .../protocols/smtp/core/MailCmdHandler.java | 12 ++ .../protocols/smtp/core/NoopCmdHandler.java | 11 ++ .../smtp/core/PostmasterAbuseRcptHook.java | 11 ++ .../protocols/smtp/core/QuitCmdHandler.java | 14 ++- .../protocols/smtp/core/RcptCmdHandler.java | 13 ++ .../smtp/core/ReceivedDataLineFilter.java | 12 ++ .../protocols/smtp/core/RsetCmdHandler.java | 13 +- .../smtp/core/UnknownCmdHandler.java | 12 ++ .../protocols/smtp/core/VrfyCmdHandler.java | 11 ++ .../smtp/core/WelcomeMessageHandler.java | 12 ++ .../smtp/core/esmtp/AuthCmdHandler.java | 45 ++++++- .../smtp/core/esmtp/EhloCmdHandler.java | 12 ++ .../core/esmtp/MailSizeEsmtpExtension.java | 10 ++ .../smtp/core/esmtp/StartTlsCmdHandler.java | 12 ++ .../smtp/core/fastfail/DNSRBLHandler.java | 14 ++- .../smtp/core/fastfail/MaxRcptHandler.java | 12 ++ .../core/fastfail/MaxUnknownCmdHandler.java | 16 ++- .../fastfail/ResolvableEhloHeloHandler.java | 12 ++ .../smtp/core/fastfail/SpamTrapHandler.java | 17 ++- .../fastfail/SupressDuplicateRcptHandler.java | 12 ++ .../smtp/core/log/HookResultLogger.java | 12 ++ .../james/protocols/smtp/hook/SimpleHook.java | 12 ++ .../smtp/AbstractSMTPServerTest.java | 118 +++++++++++++++++- .../ValidSenderDomainHandlerTest.java | 14 ++- .../protocols/smtp/utils/TestMessageHook.java | 11 ++ .../ProtocolHandlerLoaderBeanFactory.java | 6 +- .../lib/ProtocolHandlerChainImpl.java | 8 +- ...bstractCommandHandlerResultJMXMonitor.java | 10 +- ...bstractConnectHandlerResultJMXMonitor.java | 10 +- .../AbstractLineHandlerResultJMXMonitor.java | 10 +- ...ializingLifecycleAwareProtocolHandler.java | 35 ------ .../lib/mock/MockProtocolHandlerLoader.java | 16 +++ .../lmtpserver/CoreCmdHandlerLoader.java | 12 ++ .../MailboxDeliverToRecipientHandler.java | 11 ++ .../lmtpserver/jmx/JMXHandlersLoader.java | 11 ++ .../pop3server/core/CoreCmdHandlerLoader.java | 11 ++ .../jmx/CommandHandlerResultJMXMonitor.java | 4 +- .../pop3server/jmx/JMXHandlersLoader.java | 11 ++ .../AddDefaultAttributesMessageHook.java | 12 ++ .../AuthRequiredToRelayRcptHook.java | 12 ++ .../smtpserver/CoreCmdHandlerLoader.java | 12 ++ .../DataLineJamesMessageHookHandler.java | 12 ++ .../james/smtpserver/MailPriorityHandler.java | 4 +- .../smtpserver/POP3BeforeSMTPHandler.java | 10 ++ .../james/smtpserver/SendMailHandler.java | 14 ++- ...enderAuthIdentifyVerificationRcptHook.java | 12 ++ .../smtpserver/SetMimeHeaderHandler.java | 4 +- .../smtpserver/UsersRepositoryAuthHook.java | 13 +- .../smtpserver/fastfail/DNSRBLHandler.java | 4 +- .../fastfail/JDBCGreylistHandler.java | 4 +- .../smtpserver/fastfail/MaxRcptHandler.java | 4 +- .../fastfail/MaxUnknownCmdHandler.java | 4 +- .../james/smtpserver/fastfail/SPFHandler.java | 4 +- .../fastfail/SpamAssassinHandler.java | 4 +- .../smtpserver/fastfail/SpamTrapHandler.java | 4 +- .../smtpserver/fastfail/URIRBLHandler.java | 4 +- .../smtpserver/fastfail/ValidRcptHandler.java | 4 +- .../smtpserver/fastfail/ValidRcptMX.java | 4 +- .../fastfail/ValidSenderDomainHandler.java | 11 ++ .../smtpserver/jmx/HookResultJMXMonitor.java | 5 +- .../smtpserver/jmx/JMXHandlersLoader.java | 11 ++ .../james/smtpserver/SMTPServerTest.java | 2 +- 90 files changed, 1012 insertions(+), 162 deletions(-) delete mode 100644 protocols/api/src/main/java/org/apache/james/protocols/api/handler/LifecycleAwareProtocolHandler.java delete mode 100644 server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/lifecycle/InitializingLifecycleAwareProtocolHandler.java diff --git a/protocols/api/pom.xml b/protocols/api/pom.xml index 8cc2710be27..bd2b44dbdbe 100644 --- a/protocols/api/pom.xml +++ b/protocols/api/pom.xml @@ -34,8 +34,11 @@ Apache James :: Protocols :: API - - + + commons-configuration + commons-configuration + + org.slf4j slf4j-api diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/AbstractProtocolHandlerChain.java b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/AbstractProtocolHandlerChain.java index 803caea5bbc..9575acb1641 100644 --- a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/AbstractProtocolHandlerChain.java +++ b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/AbstractProtocolHandlerChain.java @@ -81,8 +81,8 @@ public void wireExtensibleHandlers() throws WiringException { * @see org.apache.james.protocols.api.handler.ProtocolHandlerChain#destroy() */ public void destroy() { - List handlers = getHandlers(LifecycleAwareProtocolHandler.class); - for (LifecycleAwareProtocolHandler handler: handlers) { + List handlers = getHandlers(ProtocolHandler.class); + for (ProtocolHandler handler: handlers) { handler.destroy(); } } diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java index 040d56986ba..5e6d3e2c873 100644 --- a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java +++ b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/CommandDispatcher.java @@ -29,6 +29,8 @@ import java.util.List; import java.util.Locale; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.BaseRequest; import org.apache.james.protocols.api.ProtocolSession; import org.apache.james.protocols.api.Request; @@ -60,7 +62,17 @@ public CommandDispatcher(Collection mandatoryCommands) { public CommandDispatcher() { this(Collections.emptyList()); } - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Add it to map (key as command name, value is an array list of CommandHandlers) * diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/CommandHandlerResultLogger.java b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/CommandHandlerResultLogger.java index f366c13d505..47ac3ea04e3 100644 --- a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/CommandHandlerResultLogger.java +++ b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/CommandHandlerResultLogger.java @@ -18,6 +18,8 @@ ****************************************************************/ package org.apache.james.protocols.api.handler; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.logger.Logger; @@ -53,4 +55,13 @@ protected void log(ProtocolSession session, Response response, String logmessage } } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/LifecycleAwareProtocolHandler.java b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/LifecycleAwareProtocolHandler.java deleted file mode 100644 index 8f0882cce2e..00000000000 --- a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/LifecycleAwareProtocolHandler.java +++ /dev/null @@ -1,34 +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.protocols.api.handler; - - -/** - * This interface allows to handle lifecycles for handlers and hooks - * - */ -public interface LifecycleAwareProtocolHandler extends ProtocolHandler{ - - /** - * Destroy object - */ - void destroy(); - - -} diff --git a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/ProtocolHandler.java b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/ProtocolHandler.java index 9a85e3e452f..930cae50b51 100644 --- a/protocols/api/src/main/java/org/apache/james/protocols/api/handler/ProtocolHandler.java +++ b/protocols/api/src/main/java/org/apache/james/protocols/api/handler/ProtocolHandler.java @@ -19,6 +19,8 @@ package org.apache.james.protocols.api.handler; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; /** * Just the base interface for all kind of "protocol" handlers. @@ -27,5 +29,18 @@ * */ public interface ProtocolHandler { + + /** + * Init with the given {@link Configuration} + * + * @param config + * @throws ConfigurationException + */ + void init(Configuration config) throws ConfigurationException; + + /** + * Destroy object + */ + void destroy(); } diff --git a/protocols/imap/src/main/java/org/apache/james/protocols/imap/core/IMAPCommandDispatcher.java b/protocols/imap/src/main/java/org/apache/james/protocols/imap/core/IMAPCommandDispatcher.java index 30bba9df7ae..073f847e82c 100644 --- a/protocols/imap/src/main/java/org/apache/james/protocols/imap/core/IMAPCommandDispatcher.java +++ b/protocols/imap/src/main/java/org/apache/james/protocols/imap/core/IMAPCommandDispatcher.java @@ -23,6 +23,8 @@ import java.util.regex.Matcher; import java.util.regex.Pattern; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; @@ -44,7 +46,17 @@ protected Request parseRequest(IMAPSession session, ByteBuffer buffer) throws Ex MultiLineHandler handler = new MultiLineHandler() { private static final String BYTES_READ = "BYTES_READ"; - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /* * (non-Javadoc) * @see org.apache.james.protocols.api.handler.MultiLineHandler#isReady(org.apache.james.protocols.api.ProtocolSession, java.nio.ByteBuffer) diff --git a/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPServerTest.java b/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPServerTest.java index 61c22652dd5..be88803eadd 100644 --- a/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPServerTest.java +++ b/protocols/lmtp/src/test/java/org/apache/james/protocols/lmtp/AbstractLMTPServerTest.java @@ -27,6 +27,8 @@ import java.util.Iterator; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.net.smtp.RelayPath; import org.apache.commons.net.smtp.SMTPClient; import org.apache.commons.net.smtp.SMTPReply; @@ -328,7 +330,16 @@ public HookResult deliver(SMTPSession session, MailAddress recipient, MailEnvelo } return result; } - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } private final class TestDeliverHook implements DeliverToRecipientHook { @@ -351,6 +362,16 @@ public HookResult deliver(SMTPSession session, MailAddress recipient, MailEnvelo public List getDelivered() { return delivered; } - }; + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + } } diff --git a/protocols/pom.xml b/protocols/pom.xml index 1594fa8d2ef..a9fe77196e9 100644 --- a/protocols/pom.xml +++ b/protocols/pom.xml @@ -121,6 +121,21 @@ commons-codec ${commons-codec.version} + + commons-configuration + commons-configuration + 1.9 + + + commons-digester + commons-digester + + + commons-beanutils-core + commons-beanutils + + + commons-lang commons-lang diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCmdHandler.java index e33c547a9ac..39ef455af84 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/CapaCmdHandler.java @@ -28,6 +28,8 @@ import java.util.Set; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -44,6 +46,16 @@ public class CapaCmdHandler implements CommandHandler, ExtensibleHa private static final Collection COMMANDS = Collections.unmodifiableCollection(Arrays.asList("CAPA")); private static final Set CAPS = Collections.unmodifiableSet(new HashSet(Arrays.asList("PIPELINING"))); + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * @see * org.apache.james.protocols.api.handler.CommandHandler diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java index 1439adead5d..68a464d097b 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/DeleCmdHandler.java @@ -24,6 +24,8 @@ import java.util.Collections; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; @@ -41,6 +43,16 @@ public class DeleCmdHandler implements CommandHandler { private static final Response SYNTAX_ERROR = new POP3Response(POP3Response.ERR_RESPONSE, "Usage: DELE [mail number]").immutable(); private static final Response DELETED = new POP3Response(POP3Response.OK_RESPONSE, "Message deleted").immutable(); + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a DELE command. This command * deletes a particular mail message from the mailbox. diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java index 7f00f594db8..2ae770b0d8b 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/ListCmdHandler.java @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; @@ -37,8 +39,19 @@ * Handles LIST command */ public class ListCmdHandler implements CommandHandler { + private static final Collection COMMANDS = Collections.unmodifiableCollection(Arrays.asList("LIST")); + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a LIST command. Returns the number * of messages in the mailbox and its aggregate size, or optionally, the diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/NoopCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/NoopCmdHandler.java index 6cd05b2b143..754f5499c58 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/NoopCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/NoopCmdHandler.java @@ -23,6 +23,8 @@ import java.util.Collection; import java.util.Collections; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -33,8 +35,19 @@ * Handles NOOP command */ public class NoopCmdHandler implements CommandHandler { + private static final Collection COMMANDS = Collections.unmodifiableCollection(Arrays.asList("NOOP")); + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a NOOP command. Like all good * NOOPs, does nothing much. diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java index edb77d75c76..d63b1e2132f 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/QuitCmdHandler.java @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.ProtocolSession.State; @@ -37,9 +39,11 @@ * Handles QUIT command */ public class QuitCmdHandler implements CommandHandler { + private static final Collection COMMANDS = Collections.unmodifiableCollection(Arrays.asList("QUIT")); private static final Response SIGN_OFF; private static final Response SIGN_OFF_NOT_CLEAN; + static { POP3Response response = new POP3Response(POP3Response.OK_RESPONSE, "Apache James POP3 Server signing off."); response.setEndSession(true); @@ -49,6 +53,17 @@ public class QuitCmdHandler implements CommandHandler { response.setEndSession(true); SIGN_OFF_NOT_CLEAN = response.immutable(); } + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a QUIT command. This method handles * cleanup of the POP3Handler state. diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java index 5ce0fa43a3a..6969b71b053 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/RetrCmdHandler.java @@ -26,6 +26,8 @@ import java.util.Collections; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; @@ -44,6 +46,16 @@ public class RetrCmdHandler implements CommandHandler { private static final Response SYNTAX_ERROR = new POP3Response(POP3Response.ERR_RESPONSE, "Usage: RETR [mail number]").immutable(); private static final Response ERROR_MESSAGE_RETRIEVE = new POP3Response(POP3Response.ERR_RESPONSE, "Error while retrieving message.").immutable(); + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a RETR command. This command * retrieves a particular mail message from the mailbox. diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java index 6faf7987984..369516b3802 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/RsetCmdHandler.java @@ -27,6 +27,8 @@ import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.ProtocolSession.State; @@ -41,6 +43,16 @@ public class RsetCmdHandler implements CommandHandler { private static final Collection COMMANDS = Collections.unmodifiableCollection(Arrays.asList("RSET")); + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a RSET command. Calls stat() to * reset the mailbox. diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java index 5b8fdee9137..5f634a885fe 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/StatCmdHandler.java @@ -25,6 +25,8 @@ import java.util.Collections; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.ProtocolSession.State; @@ -39,6 +41,16 @@ public class StatCmdHandler implements CommandHandler { private static final Collection COMMANDS = Collections.unmodifiableCollection(Arrays.asList("STAT")); + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a STAT command. Returns the number * of messages in the mailbox and its aggregate size. diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/StlsCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/StlsCmdHandler.java index 04e9e5a3743..0175b136aaf 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/StlsCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/StlsCmdHandler.java @@ -25,6 +25,8 @@ import java.util.HashSet; import java.util.Set; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -37,10 +39,22 @@ * with the STSL command */ public class StlsCmdHandler implements CommandHandler, CapaCapability { + private static final Collection COMMANDS = Collections.unmodifiableCollection(Arrays.asList("STLS")); private static final Set CAPS = Collections.unmodifiableSet(new HashSet(Arrays.asList("STLS"))); private static final Response BEGIN_TLS = new POP3StartTlsResponse(POP3Response.OK_RESPONSE, "Begin TLS negotiation").immutable(); + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * @see CommandHandler#onCommand(org.apache.james.protocols.api.ProtocolSession, Request) */ diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java index 45db866d199..9b4c5b1f3b0 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UidlCmdHandler.java @@ -28,6 +28,8 @@ import java.util.Set; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.ProtocolSession.State; @@ -43,6 +45,16 @@ public class UidlCmdHandler implements CommandHandler, CapaCapabili private static final Collection COMMANDS = Collections.unmodifiableCollection(Arrays.asList("UIDL")); private static final Set CAPS = Collections.unmodifiableSet(new HashSet(Arrays.asList("UIDL"))); + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a UIDL command. Returns a listing * of message ids to the client. diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UnknownCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UnknownCmdHandler.java index 77f4bbea8dd..39576e9e5ca 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UnknownCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UnknownCmdHandler.java @@ -19,6 +19,8 @@ package org.apache.james.protocols.pop3.core; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.UnknownCommandHandler; @@ -36,4 +38,14 @@ public class UnknownCmdHandler extends UnknownCommandHandler { public Response onCommand(POP3Session session, Request request) { return POP3Response.ERR; } + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UserCmdHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UserCmdHandler.java index b03a826f217..172bb75cd20 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UserCmdHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/UserCmdHandler.java @@ -25,6 +25,8 @@ import java.util.HashSet; import java.util.Set; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -39,6 +41,15 @@ public class UserCmdHandler implements CommandHandler, CapaCapabili private static final Collection COMMANDS = Collections.unmodifiableCollection(Arrays.asList("USER")); private static final Set CAPS = Collections.unmodifiableSet(new HashSet(Arrays.asList("USER"))); + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } /** * Handler method called upon receipt of a USER command. Reads in the user diff --git a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/WelcomeMessageHandler.java b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/WelcomeMessageHandler.java index 4a2e615a232..81236c7ea6d 100644 --- a/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/WelcomeMessageHandler.java +++ b/protocols/pop3/src/main/java/org/apache/james/protocols/pop3/core/WelcomeMessageHandler.java @@ -19,6 +19,8 @@ package org.apache.james.protocols.pop3.core; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.ConnectHandler; @@ -27,6 +29,16 @@ public class WelcomeMessageHandler implements ConnectHandler { + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * @see org.apache.james.protocols.api.handler.ConnectHandler * #onConnect(org.apache.james.pop3server.POP3Session) diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AcceptRecipientIfRelayingIsAllowed.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AcceptRecipientIfRelayingIsAllowed.java index 21462a1a036..373a1334403 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AcceptRecipientIfRelayingIsAllowed.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/AcceptRecipientIfRelayingIsAllowed.java @@ -18,6 +18,8 @@ ****************************************************************/ package org.apache.james.protocols.smtp.core; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.HookResult; @@ -40,4 +42,13 @@ public HookResult doRcpt(SMTPSession session, MailAddress sender, return HookResult.declined(); } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java index 530635bf75f..ed722fdaa45 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataCmdHandler.java @@ -26,6 +26,8 @@ import java.util.LinkedList; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; @@ -62,6 +64,16 @@ public SMTPResponse onLine(SMTPSession session, ByteBuffer line) { } return null; } + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } public static final class DataLineFilterWrapper implements LineHandler { @@ -84,13 +96,32 @@ public Response onLine(SMTPSession session, ByteBuffer line) { Response r = filter.onLine(session, line, next); return r; } - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } public final static String MAILENV = "MAILENV"; private LineHandler lineHandler; - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * process DATA command * diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataLineMessageHookHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataLineMessageHookHandler.java index 9a75daaaaa7..213f18c2c77 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataLineMessageHookHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/DataLineMessageHookHandler.java @@ -27,6 +27,8 @@ import java.util.LinkedList; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.ExtensibleHandler; @@ -55,8 +57,16 @@ public class DataLineMessageHookHandler implements DataLineFilter, ExtensibleHan private List messageHandlers; private List rHooks; - + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } /* * (non-Javadoc) diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ExpnCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ExpnCmdHandler.java index dac0758c407..39e26e843ed 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ExpnCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ExpnCmdHandler.java @@ -25,6 +25,8 @@ import java.util.Collection; import java.util.Collections; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -61,4 +63,13 @@ public Collection getImplCommands() { return COMMANDS; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/HeloCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/HeloCmdHandler.java index 05fe3dc1d68..8995be95c48 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/HeloCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/HeloCmdHandler.java @@ -23,6 +23,8 @@ import java.util.Collection; import java.util.Collections; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.api.Response; @@ -48,6 +50,17 @@ public class HeloCmdHandler extends AbstractHookableCmdHandler { DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_ARG) + " Domain address required: " + COMMAND_NAME).immutable(); + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * @see org.apache.james.protocols.api.handler.CommandHandler#getImplCommands() */ diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/HelpCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/HelpCmdHandler.java index ecdfc8d1d11..66e440f5981 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/HelpCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/HelpCmdHandler.java @@ -25,6 +25,8 @@ import java.util.Collection; import java.util.Collections; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -58,4 +60,14 @@ public Response onCommand(SMTPSession session, Request request){ public Collection getImplCommands() { return COMMANDS; } + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java index cbb08e2dd57..2cd248e030f 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/MailCmdHandler.java @@ -29,6 +29,8 @@ import java.util.Map; import java.util.StringTokenizer; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; @@ -69,6 +71,16 @@ public class MailCmdHandler extends AbstractHookableCmdHandler { */ private Map paramHooks; + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * @see * org.apache.james.protocols.smtp.core.AbstractHookableCmdHandler diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/NoopCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/NoopCmdHandler.java index d1be904b63d..99e71c4c112 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/NoopCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/NoopCmdHandler.java @@ -25,6 +25,8 @@ import java.util.Collection; import java.util.Collections; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -61,4 +63,13 @@ public Collection getImplCommands() { return COMMANDS; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/PostmasterAbuseRcptHook.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/PostmasterAbuseRcptHook.java index 82af79fb28a..81f6605601e 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/PostmasterAbuseRcptHook.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/PostmasterAbuseRcptHook.java @@ -18,6 +18,8 @@ ****************************************************************/ package org.apache.james.protocols.smtp.core; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.HookResult; @@ -40,4 +42,13 @@ public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rc } } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/QuitCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/QuitCmdHandler.java index f3395c5bd75..0d74d54c0d3 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/QuitCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/QuitCmdHandler.java @@ -23,6 +23,8 @@ import java.util.Collection; import java.util.Collections; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.smtp.SMTPResponse; import org.apache.james.protocols.smtp.SMTPRetCode; @@ -51,7 +53,17 @@ public class QuitCmdHandler extends AbstractHookableCmdHandler { response.setEndSession(true); SYNTAX_ERROR = response.immutable(); } - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a QUIT command. This method informs * the client that the connection is closing. diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RcptCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RcptCmdHandler.java index 82fc14ab19b..9ced3a57d46 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RcptCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RcptCmdHandler.java @@ -26,6 +26,8 @@ import java.util.Locale; import java.util.StringTokenizer; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -50,6 +52,17 @@ public class RcptCmdHandler extends AbstractHookableCmdHandler impleme private static final Response SYNTAX_ERROR_ARGS = new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_SYNTAX) + " Usage: RCPT TO:").immutable(); private static final Response SYNTAX_ERROR_DELIVERY = new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_SYNTAX) + " Syntax error in parameters or arguments").immutable(); private static final Response SYNTAX_ERROR_ADDRESS = new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_MAILBOX, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.ADDRESS_SYNTAX) + " Syntax error in recipient address").immutable(); + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a RCPT command. Reads recipient. * Does some connection validation. diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java index a1ef93dbb27..740b796d96d 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java @@ -26,6 +26,8 @@ import java.util.List; import java.util.Locale; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPSession; @@ -47,6 +49,16 @@ protected DateFormat initialValue() { } }; + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Return the service type which will be used in the Received headers. * diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RsetCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RsetCmdHandler.java index 7084e1678c5..bcd375039fb 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RsetCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/RsetCmdHandler.java @@ -25,6 +25,8 @@ import java.util.Collection; import java.util.Collections; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -75,5 +77,14 @@ private Response doRSET(SMTPSession session, String argument) { public Collection getImplCommands() { return COMMANDS; } - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/UnknownCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/UnknownCmdHandler.java index 35b7d9bf757..62eb2151891 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/UnknownCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/UnknownCmdHandler.java @@ -25,6 +25,8 @@ import java.util.Collection; import java.util.Collections; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.api.handler.UnknownCommandHandler; import org.apache.james.protocols.api.Response; @@ -45,6 +47,16 @@ public class UnknownCmdHandler extends AbstractHookableCmdHandler{ */ private static final Collection COMMANDS = Collections.unmodifiableCollection(Arrays.asList(UnknownCommandHandler.COMMAND_IDENTIFIER)); + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * @see org.apache.james.protocols.api.handler.CommandHandler#getImplCommands() */ diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/VrfyCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/VrfyCmdHandler.java index b3f584ccb35..831daedf2ad 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/VrfyCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/VrfyCmdHandler.java @@ -25,6 +25,8 @@ import java.util.Collection; import java.util.Collections; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -59,4 +61,13 @@ public Collection getImplCommands() { return COMMANDS; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/WelcomeMessageHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/WelcomeMessageHandler.java index c2271a07b12..8deb4e0ef29 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/WelcomeMessageHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/WelcomeMessageHandler.java @@ -20,6 +20,8 @@ package org.apache.james.protocols.smtp.core; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.ConnectHandler; import org.apache.james.protocols.smtp.SMTPResponse; @@ -58,4 +60,14 @@ public Response onConnect(SMTPSession session) { protected String getServiceType(SMTPSession session) { return SERVICE_TYPE; } + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java index 7c23ab7f178..b6b8dfdc961 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/AuthCmdHandler.java @@ -32,6 +32,8 @@ import java.util.StringTokenizer; import org.apache.commons.codec.binary.Base64; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -127,7 +129,17 @@ private Response handleCommand(SMTPSession session, String line) { private List hooks; private List rHooks; - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * handles AUTH command * @@ -164,6 +176,16 @@ private Response doAUTH(SMTPSession session, String argument) { protected Response onCommand(SMTPSession session, String l) { return doPlainAuthPass(session, l); } + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } }); return AUTH_READY_PLAIN; } else { @@ -177,6 +199,16 @@ protected Response onCommand(SMTPSession session, String l) { protected Response onCommand(SMTPSession session, String l) { return doLoginAuthPass(session, l); } + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } }); return AUTH_READY_USERNAME_LOGIN; } else { @@ -296,7 +328,16 @@ public LineHandler setUser(String user) { protected Response onCommand(SMTPSession session, String l) { return doLoginAuthPassCheck(session, user, l); } - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } }.setUser(user)); return AUTH_READY_PASSWORD_LOGIN; } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java index 264fcbb74cf..593d70a5b32 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/EhloCmdHandler.java @@ -24,6 +24,8 @@ import java.util.Collections; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.smtp.SMTPResponse; @@ -50,6 +52,16 @@ public class EhloCmdHandler extends AbstractHookableCmdHandler impleme private List ehloExtensions; + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a EHLO command. Responds with a * greeting and informs the client whether client authentication is diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java index 3052a95d3d3..4a48b63e080 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java @@ -24,6 +24,8 @@ import java.util.Collections; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.api.handler.LineHandler; @@ -49,7 +51,15 @@ public class MailSizeEsmtpExtension implements MailParametersHook, EhloExtension private static final HookResult SYNTAX_ERROR = new HookResult(HookReturnCode.DENY, SMTPRetCode.SYNTAX_ERROR_ARGUMENTS, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.DELIVERY_INVALID_ARG) + " Syntactically incorrect value for SIZE parameter"); private static final HookResult QUOTA_EXCEEDED = new HookResult(HookReturnCode.DENY, SMTPRetCode.QUOTA_EXCEEDED, DSNStatus.getStatus(DSNStatus.PERMANENT, DSNStatus.SYSTEM_MSG_TOO_BIG) + " Message size exceeds fixed maximum message size"); + @Override + public void init(Configuration config) throws ConfigurationException { + } + + @Override + public void destroy() { + + } /** * @see org.apache.james.protocols.smtp.hook.MailParametersHook#doMailParameter(org.apache.james.protocols.smtp.SMTPSession, java.lang.String, java.lang.String) diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/StartTlsCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/StartTlsCmdHandler.java index 7a13628fe23..fc0272cb15a 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/StartTlsCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/StartTlsCmdHandler.java @@ -24,6 +24,8 @@ import java.util.Collections; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.Request; import org.apache.james.protocols.api.Response; import org.apache.james.protocols.api.handler.CommandHandler; @@ -55,6 +57,16 @@ public Collection getImplCommands() { return COMMANDS; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Handler method called upon receipt of a STARTTLS command. Resets * message-specific, but not authenticated user, state. diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/DNSRBLHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/DNSRBLHandler.java index e44e19130a0..e8b4bd35ab5 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/DNSRBLHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/DNSRBLHandler.java @@ -24,6 +24,8 @@ import java.util.Collections; import java.util.StringTokenizer; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPSession; @@ -50,7 +52,17 @@ public class DNSRBLHandler implements RcptHook { public static final String RBL_BLOCKLISTED_MAIL_ATTRIBUTE_NAME = "org.apache.james.smtpserver.rbl.blocklisted"; public static final String RBL_DETAIL_MAIL_ATTRIBUTE_NAME = "org.apache.james.smtpserver.rbl.detail"; - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Set the whitelist array * diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/MaxRcptHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/MaxRcptHandler.java index 5e10787e41a..30606915c53 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/MaxRcptHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/MaxRcptHandler.java @@ -22,6 +22,8 @@ package org.apache.james.protocols.smtp.core.fastfail; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPRetCode; import org.apache.james.protocols.smtp.SMTPSession; @@ -59,4 +61,14 @@ public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rc return HookResult.declined(); } } + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/MaxUnknownCmdHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/MaxUnknownCmdHandler.java index 7491e8218d3..f182b7d614a 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/MaxUnknownCmdHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/MaxUnknownCmdHandler.java @@ -20,6 +20,8 @@ package org.apache.james.protocols.smtp.core.fastfail; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.HookResult; @@ -36,8 +38,18 @@ public class MaxUnknownCmdHandler implements UnknownHook{ public final static int DEFAULT_MAX_UNKOWN = 5; private final static String UNKOWN_COMMAND_COUNT = "UNKNOWN_COMMAND_COUNT"; - private int maxUnknown = DEFAULT_MAX_UNKOWN;; - + private int maxUnknown = DEFAULT_MAX_UNKOWN; + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public void setMaxUnknownCmdCount(int maxUnknown) { this.maxUnknown = maxUnknown; } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/ResolvableEhloHeloHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/ResolvableEhloHeloHandler.java index 990f76345d1..b3a47eb12fb 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/ResolvableEhloHeloHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/ResolvableEhloHeloHandler.java @@ -23,6 +23,8 @@ import java.net.UnknownHostException; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPRetCode; @@ -41,6 +43,16 @@ public class ResolvableEhloHeloHandler implements RcptHook, HeloHook { public final static String BAD_EHLO_HELO = "BAD_EHLO_HELO"; + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Check if EHLO/HELO is resolvable * diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/SpamTrapHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/SpamTrapHandler.java index 738e752aac9..597dc5bb863 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/SpamTrapHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/SpamTrapHandler.java @@ -25,6 +25,8 @@ import java.util.HashMap; import java.util.Map; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.HookResult; @@ -42,9 +44,18 @@ public class SpamTrapHandler implements RcptHook { private Collection spamTrapRecips = new ArrayList(); /** Default blocktime 12 hours */ - protected long blockTime = 4320000; - - + protected long blockTime = 4320000; + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public void setSpamTrapRecipients(Collection spamTrapRecips) { this.spamTrapRecips = spamTrapRecips; } diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/SupressDuplicateRcptHandler.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/SupressDuplicateRcptHandler.java index d4a9f7cb876..fb363f9923f 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/SupressDuplicateRcptHandler.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/fastfail/SupressDuplicateRcptHandler.java @@ -24,6 +24,8 @@ import java.util.Collection; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPRetCode; @@ -39,6 +41,16 @@ */ public class SupressDuplicateRcptHandler implements RcptHook { + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * @see org.apache.james.protocols.smtp.hook.RcptHook#doRcpt(org.apache.james.protocols.smtp.SMTPSession, org.apache.mailet.MailAddress, org.apache.mailet.MailAddress) */ diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/log/HookResultLogger.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/log/HookResultLogger.java index af4d4c2afe3..431e84e9b6a 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/log/HookResultLogger.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/core/log/HookResultLogger.java @@ -18,6 +18,8 @@ ****************************************************************/ package org.apache.james.protocols.smtp.core.log; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.Hook; import org.apache.james.protocols.smtp.hook.HookResult; @@ -32,6 +34,16 @@ */ public class HookResultLogger implements HookResultHook{ + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public HookResult onHookResult(SMTPSession session, HookResult hResult, long executionTime, Hook hook) { boolean match = false; boolean info = false; diff --git a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/hook/SimpleHook.java b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/hook/SimpleHook.java index 01b72196719..ffc3bc6387a 100644 --- a/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/hook/SimpleHook.java +++ b/protocols/smtp/src/main/java/org/apache/james/protocols/smtp/hook/SimpleHook.java @@ -19,6 +19,8 @@ package org.apache.james.protocols.smtp.hook; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.MailEnvelope; import org.apache.james.protocols.smtp.SMTPSession; @@ -32,6 +34,16 @@ */ public class SimpleHook implements HeloHook, MailHook, RcptHook, MessageHook { + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * Return {@link HookResult} with {@link HookReturnCode#OK} */ diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java index fd6e5b58aae..1e73b35de8b 100644 --- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java +++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/AbstractSMTPServerTest.java @@ -27,6 +27,8 @@ import java.util.List; import java.util.concurrent.atomic.AtomicBoolean; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.net.smtp.SMTPClient; import org.apache.commons.net.smtp.SMTPReply; import org.apache.james.protocols.api.Protocol; @@ -442,6 +444,16 @@ public void testHeloEnforcementDisabled() throws Exception { public void testHeloHookPermanentError() throws Exception { HeloHook hook = new HeloHook() { + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public HookResult doHelo(SMTPSession session, String helo) { return new HookResult(HookReturnCode.DENY); } @@ -481,6 +493,16 @@ public HookResult doHelo(SMTPSession session, String helo) { public void testHeloHookTempraryError() throws Exception { HeloHook hook = new HeloHook() { + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public HookResult doHelo(SMTPSession session, String helo) { return new HookResult(HookReturnCode.DENYSOFT); } @@ -519,6 +541,16 @@ public HookResult doHelo(SMTPSession session, String helo) { public void testMailHookPermanentError() throws Exception { MailHook hook = new MailHook() { + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public HookResult doMail(SMTPSession session, MailAddress sender) { return new HookResult(HookReturnCode.DENY); } @@ -560,6 +592,16 @@ public HookResult doMail(SMTPSession session, MailAddress sender) { public void testMailHookTemporaryError() throws Exception { MailHook hook = new MailHook() { + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public HookResult doMail(SMTPSession session, MailAddress sender) { return new HookResult(HookReturnCode.DENYSOFT); } @@ -602,6 +644,16 @@ public HookResult doMail(SMTPSession session, MailAddress sender) { public void testRcptHookPermanentError() throws Exception { RcptHook hook = new RcptHook() { + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) { if (RCPT1.equals(rcpt.toString())) { return new HookResult(HookReturnCode.DENY); @@ -657,6 +709,16 @@ public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rc public void testRcptHookTemporaryError() throws Exception { RcptHook hook = new RcptHook() { + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) { if (RCPT1.equals(rcpt.toString())) { return new HookResult(HookReturnCode.DENYSOFT); @@ -749,6 +811,16 @@ public void testMessageHookPermanentError() throws Exception { MessageHook hook = new MessageHook() { + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public HookResult onMessage(SMTPSession session, MailEnvelope mail) { return new HookResult(HookReturnCode.DENY); } @@ -803,7 +875,16 @@ public void testMessageHookTemporaryError() throws Exception { MessageHook hook = new MessageHook() { - + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public HookResult onMessage(SMTPSession session, MailEnvelope mail) { return new HookResult(HookReturnCode.DENYSOFT); } @@ -857,7 +938,16 @@ public HookResult onMessage(SMTPSession session, MailEnvelope mail) { public void testConnectHandlerPermananet() throws Exception { ConnectHandler connectHandler = new ConnectHandler() { - + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public Response onConnect(SMTPSession session) { return new SMTPResponse("554", "Bye Bye"); } @@ -892,7 +982,16 @@ public Response onConnect(SMTPSession session) { public void testConnectHandlerTemporary() throws Exception { ConnectHandler connectHandler = new ConnectHandler() { - + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public Response onConnect(SMTPSession session) { return new SMTPResponse("451", "Bye Bye"); } @@ -927,8 +1026,17 @@ public void testDisconnectHandler() throws Exception { final AtomicBoolean called = new AtomicBoolean(false); DisconnectHandler handler = new DisconnectHandler() { - - public void onDisconnect(SMTPSession session) { + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + + public void onDisconnect(SMTPSession session) { called.set(true); } }; diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ValidSenderDomainHandlerTest.java b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ValidSenderDomainHandlerTest.java index 22198be963d..bc31dc4c7a9 100644 --- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ValidSenderDomainHandlerTest.java +++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/core/fastfail/ValidSenderDomainHandlerTest.java @@ -24,6 +24,8 @@ import java.util.HashMap; import java.util.Map; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.MailAddressException; @@ -36,7 +38,17 @@ public class ValidSenderDomainHandlerTest { private ValidSenderDomainHandler createHandler() { return new ValidSenderDomainHandler() { - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + @Override protected boolean hasMXRecord(SMTPSession session, String domain) { if (domain.equals("test.james.apache.org")) { diff --git a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/utils/TestMessageHook.java b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/utils/TestMessageHook.java index 4ad2375eb40..d9fffa1e6a7 100644 --- a/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/utils/TestMessageHook.java +++ b/protocols/smtp/src/test/java/org/apache/james/protocols/smtp/utils/TestMessageHook.java @@ -21,6 +21,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.smtp.MailEnvelope; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.HookResult; @@ -40,4 +42,13 @@ public List getQueued() { return queued; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/bean/factory/protocols/ProtocolHandlerLoaderBeanFactory.java b/server/container/spring/src/main/java/org/apache/james/container/spring/bean/factory/protocols/ProtocolHandlerLoaderBeanFactory.java index ecb7e06bed9..2f06d1e955c 100644 --- a/server/container/spring/src/main/java/org/apache/james/container/spring/bean/factory/protocols/ProtocolHandlerLoaderBeanFactory.java +++ b/server/container/spring/src/main/java/org/apache/james/container/spring/bean/factory/protocols/ProtocolHandlerLoaderBeanFactory.java @@ -21,10 +21,8 @@ import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.james.container.spring.bean.factory.AbstractBeanFactory; -import org.apache.james.protocols.api.handler.LifecycleAwareProtocolHandler; import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.lib.handler.ProtocolHandlerLoader; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; import org.springframework.beans.BeansException; import org.springframework.beans.factory.config.AutowireCapableBeanFactory; @@ -38,9 +36,7 @@ public ProtocolHandler load(String name, Configuration config) throws LoadingExc // Use the classloader which is used for bean instance stuff Class c = (Class) getBeanFactory().getBeanClassLoader().loadClass(name); ProtocolHandler handler = (ProtocolHandler) getBeanFactory().createBean(c, AutowireCapableBeanFactory.AUTOWIRE_AUTODETECT, true); - if (handler instanceof LifecycleAwareProtocolHandler) { - ((InitializingLifecycleAwareProtocolHandler) handler).init(config); - } + handler.init(config); return handler; } catch (ClassNotFoundException e) { throw new LoadingException("Unable to load handler", e); diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java index 2c1ff0cdf61..a6c270eab65 100644 --- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java +++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/ProtocolHandlerChainImpl.java @@ -24,11 +24,11 @@ import org.apache.commons.configuration.DefaultConfigurationBuilder; import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.james.protocols.api.handler.ExtensibleHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.api.handler.ProtocolHandlerChain; import org.apache.james.protocols.api.handler.WiringException; import org.apache.james.protocols.lib.handler.HandlersPackage; import org.apache.james.protocols.lib.handler.ProtocolHandlerLoader; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; import java.util.LinkedList; import java.util.List; @@ -150,12 +150,12 @@ public LinkedList getHandlers(Class type) { } /** - * Destroy all loaded {@link InitializingLifecycleAwareProtocolHandler} + * Destroy all loaded {@link ProtocolHandler} */ @Override public void destroy() { - LinkedList lHandlers = getHandlers(InitializingLifecycleAwareProtocolHandler.class); - for (InitializingLifecycleAwareProtocolHandler handler : lHandlers) { + LinkedList lHandlers = getHandlers(ProtocolHandler.class); + for (ProtocolHandler handler : lHandlers) { handler.destroy(); } } diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractCommandHandlerResultJMXMonitor.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractCommandHandlerResultJMXMonitor.java index 720caad97c6..64b7d2b92f3 100644 --- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractCommandHandlerResultJMXMonitor.java +++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractCommandHandlerResultJMXMonitor.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -28,17 +27,12 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession; import org.apache.james.protocols.api.Response; -import org.apache.james.protocols.api.handler.CommandHandler; -import org.apache.james.protocols.api.handler.ExtensibleHandler; -import org.apache.james.protocols.api.handler.ProtocolHandler; -import org.apache.james.protocols.api.handler.ProtocolHandlerResultHandler; -import org.apache.james.protocols.api.handler.WiringException; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.*; /** * Expose JMX statistics for {@link CommandHandler} */ -public abstract class AbstractCommandHandlerResultJMXMonitor implements ProtocolHandlerResultHandler, ExtensibleHandler, InitializingLifecycleAwareProtocolHandler { +public abstract class AbstractCommandHandlerResultJMXMonitor implements ProtocolHandlerResultHandler, ExtensibleHandler, ProtocolHandler { private final Map cStats = new HashMap(); private String jmxName; diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractConnectHandlerResultJMXMonitor.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractConnectHandlerResultJMXMonitor.java index 3995d59a98f..2c98d27ba18 100644 --- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractConnectHandlerResultJMXMonitor.java +++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractConnectHandlerResultJMXMonitor.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -28,19 +27,14 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession; import org.apache.james.protocols.api.Response; -import org.apache.james.protocols.api.handler.ConnectHandler; -import org.apache.james.protocols.api.handler.ExtensibleHandler; -import org.apache.james.protocols.api.handler.ProtocolHandler; -import org.apache.james.protocols.api.handler.ProtocolHandlerResultHandler; -import org.apache.james.protocols.api.handler.WiringException; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.*; /** * Handler which will gather statistics for {@link ConnectHandler}'s * * @param */ -public abstract class AbstractConnectHandlerResultJMXMonitor implements ProtocolHandlerResultHandler, ExtensibleHandler, InitializingLifecycleAwareProtocolHandler { +public abstract class AbstractConnectHandlerResultJMXMonitor implements ProtocolHandlerResultHandler, ExtensibleHandler, ProtocolHandler { private final Map cStats = new HashMap(); private String jmxName; diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractLineHandlerResultJMXMonitor.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractLineHandlerResultJMXMonitor.java index ebdf89cfb3f..4cd7b8ccb3a 100644 --- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractLineHandlerResultJMXMonitor.java +++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractLineHandlerResultJMXMonitor.java @@ -20,7 +20,6 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; @@ -28,19 +27,14 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession; import org.apache.james.protocols.api.Response; -import org.apache.james.protocols.api.handler.ExtensibleHandler; -import org.apache.james.protocols.api.handler.LineHandler; -import org.apache.james.protocols.api.handler.ProtocolHandler; -import org.apache.james.protocols.api.handler.ProtocolHandlerResultHandler; -import org.apache.james.protocols.api.handler.WiringException; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.*; /** * Handler which will gather statistics for {@link LineHandler}'s * * @param */ -public abstract class AbstractLineHandlerResultJMXMonitor implements ProtocolHandlerResultHandler, ExtensibleHandler, InitializingLifecycleAwareProtocolHandler { +public abstract class AbstractLineHandlerResultJMXMonitor implements ProtocolHandlerResultHandler, ExtensibleHandler, ProtocolHandler { private final Map lStats = new HashMap(); private String jmxName; diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/lifecycle/InitializingLifecycleAwareProtocolHandler.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/lifecycle/InitializingLifecycleAwareProtocolHandler.java deleted file mode 100644 index 882395f8077..00000000000 --- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/lifecycle/InitializingLifecycleAwareProtocolHandler.java +++ /dev/null @@ -1,35 +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.protocols.lib.lifecycle; - -import org.apache.commons.configuration.Configuration; -import org.apache.commons.configuration.ConfigurationException; -import org.apache.james.protocols.api.handler.LifecycleAwareProtocolHandler; - -public interface InitializingLifecycleAwareProtocolHandler extends LifecycleAwareProtocolHandler { - - /** - * Init with the given {@link Configuration} - * - * @param config - * @throws ConfigurationException - */ - public void init(Configuration config) throws ConfigurationException; - -} diff --git a/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/mock/MockProtocolHandlerLoader.java b/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/mock/MockProtocolHandlerLoader.java index 8985cf31a8f..f4cc5568668 100644 --- a/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/mock/MockProtocolHandlerLoader.java +++ b/server/protocols/protocols-library/src/test/java/org/apache/james/protocols/lib/mock/MockProtocolHandlerLoader.java @@ -25,6 +25,7 @@ public ProtocolHandler load(String name, Configuration config) throws LoadingExc ProtocolHandler obj = create(name); injectResources(obj); postConstruct(obj); + init(obj, config); synchronized (this) { loaderRegistry.add(obj); } @@ -129,6 +130,21 @@ private void injectResources(Object resource) { } } + private void init(Object resource, Configuration config) throws IllegalAccessException, InvocationTargetException { + Method[] methods = resource.getClass().getMethods(); + for (Method method : methods) { + if (isInit(method)) { + Object[] args = { config }; + method.invoke(resource, args); + } + } + } + private boolean isInit(Method method) { + return method.getName().equals("init") + && method.getParameterTypes().length == 1 + && method.getParameterTypes()[0].equals(Configuration.class); + } + public Object getObjectForName(String name) { return get(name); } diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/CoreCmdHandlerLoader.java b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/CoreCmdHandlerLoader.java index 2f8f9cbda58..7c3bebe5e20 100644 --- a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/CoreCmdHandlerLoader.java +++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/CoreCmdHandlerLoader.java @@ -22,6 +22,8 @@ import java.util.LinkedList; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.lmtpserver.hook.MailboxDeliverToRecipientHandler; import org.apache.james.protocols.api.handler.CommandDispatcher; import org.apache.james.protocols.api.handler.CommandHandlerResultLogger; @@ -101,4 +103,14 @@ public CoreCmdHandlerLoader() { public List getHandlers() { return commands; } + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java index 689e30d89a2..4bbdcfaa6de 100644 --- a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java +++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/hook/MailboxDeliverToRecipientHandler.java @@ -24,6 +24,8 @@ import javax.inject.Inject; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.mailbox.MailboxManager; import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.exception.MailboxException; @@ -99,4 +101,13 @@ public HookResult deliver(SMTPSession session, MailAddress recipient, MailEnvelo return result; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/jmx/JMXHandlersLoader.java b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/jmx/JMXHandlersLoader.java index 0bef317e197..05576cfc4ad 100644 --- a/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/jmx/JMXHandlersLoader.java +++ b/server/protocols/protocols-lmtp/src/main/java/org/apache/james/lmtpserver/jmx/JMXHandlersLoader.java @@ -21,6 +21,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.lib.handler.HandlersPackage; public class JMXHandlersLoader implements HandlersPackage { @@ -40,4 +42,13 @@ public List getHandlers() { return handlers; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/core/CoreCmdHandlerLoader.java b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/core/CoreCmdHandlerLoader.java index 8aeb6fbc481..30662af4593 100644 --- a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/core/CoreCmdHandlerLoader.java +++ b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/core/CoreCmdHandlerLoader.java @@ -22,6 +22,8 @@ import java.util.LinkedList; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.handler.CommandDispatcher; import org.apache.james.protocols.api.handler.CommandHandlerResultLogger; import org.apache.james.protocols.lib.handler.HandlersPackage; @@ -96,4 +98,13 @@ public List getHandlers() { return commands; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/jmx/CommandHandlerResultJMXMonitor.java b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/jmx/CommandHandlerResultJMXMonitor.java index e9ef1450edf..e376ffc871e 100644 --- a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/jmx/CommandHandlerResultJMXMonitor.java +++ b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/jmx/CommandHandlerResultJMXMonitor.java @@ -22,7 +22,7 @@ import org.apache.james.protocols.api.handler.CommandHandler; -import org.apache.james.protocols.api.handler.LifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.lib.jmx.AbstractCommandHandlerResultJMXMonitor; import org.apache.james.protocols.lib.jmx.AbstractCommandHandlerStats; import org.apache.james.protocols.pop3.POP3Session; @@ -30,7 +30,7 @@ /** * Gather JMX stats for {@link CommandHandler} */ -public class CommandHandlerResultJMXMonitor extends AbstractCommandHandlerResultJMXMonitor implements LifecycleAwareProtocolHandler { +public class CommandHandlerResultJMXMonitor extends AbstractCommandHandlerResultJMXMonitor implements ProtocolHandler { /** * @see org.apache.james.protocols.lib.jmx.AbstractCommandHandlerResultJMXMonitor diff --git a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/jmx/JMXHandlersLoader.java b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/jmx/JMXHandlersLoader.java index 34623f79672..ba41df71d0e 100644 --- a/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/jmx/JMXHandlersLoader.java +++ b/server/protocols/protocols-pop3/src/main/java/org/apache/james/pop3server/jmx/JMXHandlersLoader.java @@ -21,6 +21,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.lib.handler.HandlersPackage; public class JMXHandlersLoader implements HandlersPackage { @@ -39,4 +41,13 @@ public List getHandlers() { return handlers; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AddDefaultAttributesMessageHook.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AddDefaultAttributesMessageHook.java index 675c81e9ec3..e365a4c54b0 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AddDefaultAttributesMessageHook.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AddDefaultAttributesMessageHook.java @@ -18,6 +18,8 @@ ****************************************************************/ package org.apache.james.smtpserver; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.core.MailImpl; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.HookResult; @@ -39,6 +41,16 @@ public class AddDefaultAttributesMessageHook implements JamesMessageHook { */ private final static String SMTP_AUTH_NETWORK_NAME = "org.apache.james.SMTPIsAuthNetwork"; + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public HookResult onMessage(SMTPSession session, Mail mail) { if (mail instanceof MailImpl) { diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AuthRequiredToRelayRcptHook.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AuthRequiredToRelayRcptHook.java index 925f68fbf6d..7d4a39a4cfb 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AuthRequiredToRelayRcptHook.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/AuthRequiredToRelayRcptHook.java @@ -21,6 +21,8 @@ import javax.inject.Inject; import javax.inject.Named; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.domainlist.api.DomainList; import org.apache.james.domainlist.api.DomainListException; import org.apache.james.protocols.smtp.core.AbstractAuthRequiredToRelayRcptHook; @@ -34,6 +36,16 @@ public void setDomainList(@Named("domainlist") DomainList domains) { this.domains = domains; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + /** * @see org.apache.james.protocols.smtp.core.AbstractAuthRequiredToRelayRcptHook#isLocalDomain(java.lang.String) */ diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/CoreCmdHandlerLoader.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/CoreCmdHandlerLoader.java index e7c3fd9d00d..b85c1b6f0e3 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/CoreCmdHandlerLoader.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/CoreCmdHandlerLoader.java @@ -22,6 +22,8 @@ import java.util.LinkedList; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.handler.CommandDispatcher; import org.apache.james.protocols.api.handler.CommandHandlerResultLogger; import org.apache.james.protocols.lib.handler.HandlersPackage; @@ -114,4 +116,14 @@ public CoreCmdHandlerLoader() { public List getHandlers() { return commands; } + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java index d5a55c679cc..14144aef72d 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/DataLineJamesMessageHookHandler.java @@ -19,6 +19,8 @@ package org.apache.james.smtpserver; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.core.MailImpl; import org.apache.james.core.MimeMessageCopyOnWriteProxy; import org.apache.james.core.MimeMessageInputStream; @@ -66,6 +68,16 @@ public class DataLineJamesMessageHookHandler implements DataLineFilter, Extensib private List mHandlers; + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + public Response onLine(SMTPSession session, ByteBuffer lineByteBuffer, LineHandler next) { byte[] line = new byte[lineByteBuffer.remaining()]; diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/MailPriorityHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/MailPriorityHandler.java index 4949d81fdba..49f2eff1b76 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/MailPriorityHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/MailPriorityHandler.java @@ -27,7 +27,7 @@ import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.HierarchicalConfiguration; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.HookResult; import org.apache.james.protocols.smtp.hook.HookReturnCode; @@ -41,7 +41,7 @@ * if the {@link Mail} has more then one recipient, then the highest priority * (which was found) is set */ -public class MailPriorityHandler implements JamesMessageHook, InitializingLifecycleAwareProtocolHandler { +public class MailPriorityHandler implements JamesMessageHook, ProtocolHandler { private final Map prioMap = new HashMap(); diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/POP3BeforeSMTPHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/POP3BeforeSMTPHandler.java index 10be827d4c5..73204195b4b 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/POP3BeforeSMTPHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/POP3BeforeSMTPHandler.java @@ -19,6 +19,7 @@ package org.apache.james.smtpserver; +import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.james.lifecycle.api.Configurable; @@ -76,4 +77,13 @@ public Response onConnect(SMTPSession session) { return null; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SendMailHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SendMailHandler.java index a155dbd0186..919fdeb1fd0 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SendMailHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SendMailHandler.java @@ -21,11 +21,12 @@ import java.util.Collection; -import javax.annotation.PostConstruct; import javax.inject.Inject; import javax.inject.Named; import javax.mail.MessagingException; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.dsn.DSNStatus; import org.apache.james.protocols.smtp.hook.HookResult; @@ -48,11 +49,20 @@ public void setMailQueueFactory(@Named("mailqueuefactory") MailQueueFactory queu this.queueFactory = queueFactory; } - @PostConstruct public void init() { + + } + + @Override + public void init(Configuration config) throws ConfigurationException { queue = queueFactory.getQueue(MailQueueFactory.SPOOL); } + @Override + public void destroy() { + + } + /** * Adds header to the message * diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java index a58d7597b58..1f49ac5f222 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SenderAuthIdentifyVerificationRcptHook.java @@ -21,6 +21,8 @@ import javax.inject.Inject; import javax.inject.Named; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.domainlist.api.DomainList; import org.apache.james.domainlist.api.DomainListException; import org.apache.james.protocols.smtp.MailAddress; @@ -49,6 +51,16 @@ public void setDomainList(@Named("domainlist") DomainList domains) { this.domains = domains; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } + @Override public HookResult doRcpt(SMTPSession session, MailAddress sender, MailAddress rcpt) { ExtendedSMTPSession nSession = (ExtendedSMTPSession) session; diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SetMimeHeaderHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SetMimeHeaderHandler.java index 04239ea4cff..3a1ed3737f7 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SetMimeHeaderHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SetMimeHeaderHandler.java @@ -23,7 +23,7 @@ import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.HookResult; import org.apache.james.protocols.smtp.hook.HookReturnCode; @@ -32,7 +32,7 @@ /** * Adds the header to the message */ -public class SetMimeHeaderHandler implements JamesMessageHook, InitializingLifecycleAwareProtocolHandler { +public class SetMimeHeaderHandler implements JamesMessageHook, ProtocolHandler { /** * The header name and value that needs to be added diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/UsersRepositoryAuthHook.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/UsersRepositoryAuthHook.java index 83c8d39a468..8afdaadf1eb 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/UsersRepositoryAuthHook.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/UsersRepositoryAuthHook.java @@ -21,6 +21,8 @@ import javax.inject.Inject; import javax.inject.Named; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.AuthHook; import org.apache.james.protocols.smtp.hook.HookResult; @@ -71,5 +73,14 @@ public HookResult doAuth(SMTPSession session, String username, String password) } return new HookResult(HookReturnCode.DECLINED); } - + + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/DNSRBLHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/DNSRBLHandler.java index 7b864985cf6..6df8c508232 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/DNSRBLHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/DNSRBLHandler.java @@ -30,9 +30,9 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.james.dnsservice.api.DNSService; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; -public class DNSRBLHandler extends org.apache.james.protocols.smtp.core.fastfail.DNSRBLHandler implements InitializingLifecycleAwareProtocolHandler { +public class DNSRBLHandler extends org.apache.james.protocols.smtp.core.fastfail.DNSRBLHandler implements ProtocolHandler { private DNSService dns; diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/JDBCGreylistHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/JDBCGreylistHandler.java index d4acc872f43..331cb63d906 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/JDBCGreylistHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/JDBCGreylistHandler.java @@ -41,7 +41,7 @@ import org.apache.james.dnsservice.api.DNSService; import org.apache.james.dnsservice.library.netmatcher.NetMatcher; import org.apache.james.filesystem.api.FileSystem; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.core.fastfail.AbstractGreylistHandler; @@ -56,7 +56,7 @@ /** * GreylistHandler which can be used to activate Greylisting */ -public class JDBCGreylistHandler extends AbstractGreylistHandler implements InitializingLifecycleAwareProtocolHandler { +public class JDBCGreylistHandler extends AbstractGreylistHandler implements ProtocolHandler { /** This log is the fall back shared by all instances */ private static final Logger FALLBACK_LOG = LoggerFactory.getLogger(JDBCGreylistHandler.class); diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/MaxRcptHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/MaxRcptHandler.java index 62192b5e93e..a653bc914e7 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/MaxRcptHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/MaxRcptHandler.java @@ -21,9 +21,9 @@ import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; -public class MaxRcptHandler extends org.apache.james.protocols.smtp.core.fastfail.MaxRcptHandler implements InitializingLifecycleAwareProtocolHandler { +public class MaxRcptHandler extends org.apache.james.protocols.smtp.core.fastfail.MaxRcptHandler implements ProtocolHandler { @Override public void init(Configuration config) throws ConfigurationException { diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/MaxUnknownCmdHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/MaxUnknownCmdHandler.java index b0ac34c1682..b5a2c01102d 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/MaxUnknownCmdHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/MaxUnknownCmdHandler.java @@ -21,9 +21,9 @@ import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; -public class MaxUnknownCmdHandler extends org.apache.james.protocols.smtp.core.fastfail.MaxUnknownCmdHandler implements InitializingLifecycleAwareProtocolHandler { +public class MaxUnknownCmdHandler extends org.apache.james.protocols.smtp.core.fastfail.MaxUnknownCmdHandler implements ProtocolHandler { @Override public void init(Configuration config) throws ConfigurationException { diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SPFHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SPFHandler.java index 2a18eea4beb..a0589f18a68 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SPFHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SPFHandler.java @@ -29,7 +29,7 @@ import org.apache.james.jspf.impl.DefaultSPF; import org.apache.james.jspf.impl.SPF; import org.apache.james.protocols.api.ProtocolSession.State; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPRetCode; import org.apache.james.protocols.smtp.SMTPSession; @@ -43,7 +43,7 @@ import org.slf4j.Logger; import org.slf4j.LoggerFactory; -public class SPFHandler implements JamesMessageHook, MailHook, RcptHook, InitializingLifecycleAwareProtocolHandler { +public class SPFHandler implements JamesMessageHook, MailHook, RcptHook, ProtocolHandler { /** This log is the fall back shared by all instances */ private static final Logger FALLBACK_LOG = LoggerFactory.getLogger(SPFHandler.class); diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SpamAssassinHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SpamAssassinHandler.java index 31a849daff2..8211843cc5d 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SpamAssassinHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SpamAssassinHandler.java @@ -25,7 +25,7 @@ import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.ProtocolSession.State; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.dsn.DSNStatus; import org.apache.james.protocols.smtp.hook.HookResult; @@ -63,7 +63,7 @@ * *

*/ -public class SpamAssassinHandler implements JamesMessageHook, InitializingLifecycleAwareProtocolHandler { +public class SpamAssassinHandler implements JamesMessageHook, ProtocolHandler { /** The port spamd is listen on */ private int spamdPort = 783; diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SpamTrapHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SpamTrapHandler.java index 07ff445ae9f..72c5b2e1a18 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SpamTrapHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/SpamTrapHandler.java @@ -21,11 +21,11 @@ import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import java.util.Arrays; -public class SpamTrapHandler extends org.apache.james.protocols.smtp.core.fastfail.SpamTrapHandler implements InitializingLifecycleAwareProtocolHandler { +public class SpamTrapHandler extends org.apache.james.protocols.smtp.core.fastfail.SpamTrapHandler implements ProtocolHandler { @Override public void init(Configuration config) throws ConfigurationException { diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIRBLHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIRBLHandler.java index f5e570696c5..bc165dc12f1 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIRBLHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/URIRBLHandler.java @@ -37,7 +37,7 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.james.dnsservice.api.DNSService; import org.apache.james.protocols.api.ProtocolSession.State; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.dsn.DSNStatus; import org.apache.james.protocols.smtp.hook.HookResult; @@ -51,7 +51,7 @@ * Extract domains from message and check against URIRBLServer. For more * informations see www.surbl.org */ -public class URIRBLHandler implements JamesMessageHook, InitializingLifecycleAwareProtocolHandler { +public class URIRBLHandler implements JamesMessageHook, ProtocolHandler { /** This log is the fall back shared by all instances */ private static final Logger FALLBACK_LOG = LoggerFactory.getLogger(URIRBLHandler.class); diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java index 956add8ffc0..5cb357c0f01 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptHandler.java @@ -25,7 +25,7 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.james.domainlist.api.DomainList; import org.apache.james.domainlist.api.DomainListException; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.core.fastfail.AbstractValidRcptHandler; @@ -39,7 +39,7 @@ /** * Handler which reject invalid recipients */ -public class ValidRcptHandler extends AbstractValidRcptHandler implements InitializingLifecycleAwareProtocolHandler { +public class ValidRcptHandler extends AbstractValidRcptHandler implements ProtocolHandler { private UsersRepository users; diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java index 769ec7cede4..95c363e4668 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidRcptMX.java @@ -31,7 +31,7 @@ import org.apache.james.dnsservice.api.DNSService; import org.apache.james.dnsservice.api.TemporaryResolutionException; import org.apache.james.dnsservice.library.netmatcher.NetMatcher; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.smtp.MailAddress; import org.apache.james.protocols.smtp.SMTPRetCode; import org.apache.james.protocols.smtp.SMTPSession; @@ -46,7 +46,7 @@ * This class can be used to reject email with bogus MX which is send from a * authorized user or an authorized network. */ -public class ValidRcptMX implements InitializingLifecycleAwareProtocolHandler, RcptHook { +public class ValidRcptMX implements RcptHook, ProtocolHandler { /** * This log is the fall back shared by all instances diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidSenderDomainHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidSenderDomainHandler.java index 9423b347571..d3fab355249 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidSenderDomainHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/fastfail/ValidSenderDomainHandler.java @@ -23,6 +23,8 @@ import javax.inject.Inject; import javax.inject.Named; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.dnsservice.api.DNSService; import org.apache.james.protocols.smtp.SMTPSession; @@ -53,4 +55,13 @@ protected boolean hasMXRecord(SMTPSession session, String domain) { } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/jmx/HookResultJMXMonitor.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/jmx/HookResultJMXMonitor.java index 01f9101cdfd..60b0b1e194c 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/jmx/HookResultJMXMonitor.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/jmx/HookResultJMXMonitor.java @@ -20,15 +20,14 @@ import java.util.ArrayList; import java.util.HashMap; -import java.util.Iterator; import java.util.List; import java.util.Map; import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.api.handler.ExtensibleHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; import org.apache.james.protocols.api.handler.WiringException; -import org.apache.james.protocols.lib.lifecycle.InitializingLifecycleAwareProtocolHandler; import org.apache.james.protocols.smtp.SMTPSession; import org.apache.james.protocols.smtp.hook.Hook; import org.apache.james.protocols.smtp.hook.HookResult; @@ -38,7 +37,7 @@ * {@link HookResultHook} implementation which will register a * {@link HookStatsMBean} under JMX for every Hook it processed */ -public class HookResultJMXMonitor implements HookResultHook, ExtensibleHandler, InitializingLifecycleAwareProtocolHandler { +public class HookResultJMXMonitor implements HookResultHook, ExtensibleHandler, ProtocolHandler { private final Map hookStats = new HashMap(); private String jmxPath; diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/jmx/JMXHandlersLoader.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/jmx/JMXHandlersLoader.java index 2699e304fec..4548ae373ae 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/jmx/JMXHandlersLoader.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/jmx/JMXHandlersLoader.java @@ -21,6 +21,8 @@ import java.util.ArrayList; import java.util.List; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; import org.apache.james.protocols.lib.handler.HandlersPackage; public class JMXHandlersLoader implements HandlersPackage { @@ -40,4 +42,13 @@ public List getHandlers() { return handlers; } + @Override + public void init(Configuration config) throws ConfigurationException { + + } + + @Override + public void destroy() { + + } } diff --git a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java index c045e72de61..4b24ef8a403 100644 --- a/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java +++ b/server/protocols/protocols-smtp/src/test/java/org/apache/james/smtpserver/SMTPServerTest.java @@ -1337,7 +1337,7 @@ public void testDNSRBLRejectWorks() throws Exception { smtpProtocol.setSender(sender); smtpProtocol.addRecipient("mail@sample.com"); - assertEquals("reject", 550, smtpProtocol.getReplyCode()); + assertEquals("reject", 554, smtpProtocol.getReplyCode()); smtpProtocol.sendShortMessageData("Subject: test\r\n\r\nTest body testDNSRBLRejectWorks\r\n"); From b8d7ec8c69535c515075af92bb79086291e6f58b Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Thu, 22 Oct 2015 14:17:39 +0200 Subject: [PATCH 05/39] JAMES-1626 cleanup injection annotations to conform to javax.inject usage Removed unneeded @Named annotations, @Resource that doesn't belong to javax.inject and fix some injection usages that only work with Spring --- .../search/SimpleMessageSearchIndex.java | 6 +++ .../mailbox/MailboxCopierManagement.java | 5 +- .../mailbox/MailboxManagerManagement.java | 2 - .../store/UserRepositoryAuthenticator.java | 5 +- .../spring/tool/James23Importer.java | 3 -- .../tool/James23ImporterManagement.java | 2 - .../org/apache/james/spring-server.xml | 10 +++- .../james/domainlist/xml/XMLDomainList.java | 3 ++ .../file/FileMailRepository.java | 3 +- .../james/user/file/UsersFileRepository.java | 5 +- .../jdbc/JDBCMailRepository.java | 3 +- .../domainlist/lib/AbstractDomainList.java | 6 +-- .../domainlist/lib/DomainListManagement.java | 6 +-- .../file/AbstractFileRepository.java | 3 +- .../lib/AbstractRecipientRewriteTable.java | 4 +- .../lib/RecipientRewriteTableManagement.java | 5 +- .../user/lib/AbstractUsersRepository.java | 4 +- .../user/lib/UsersRepositoryManagement.java | 5 +- .../impl/camel/CamelCompositeProcessor.java | 5 +- .../transport/mailets/LocalDelivery.java | 8 +-- .../transport/mailets/RemoteDelivery.java | 8 +-- .../transport/mailets/ToRecipientFolder.java | 23 +++++++-- .../james/transport/mailets/ToRepository.java | 3 +- .../transport/mailets/ToSenderFolder.java | 5 +- .../matchers/AbstractStorageQuota.java | 3 +- .../james/fetchmail/FetchScheduler.java | 4 -- .../james/imapserver/netty/IMAPServer.java | 8 ++- .../imapserver/netty/IMAPServerFactory.java | 9 ++-- .../AbstractConfigurableAsyncServer.java | 3 +- .../netty/AbstractProtocolAsyncServer.java | 3 +- .../lib/mock/MockProtocolHandlerLoader.java | 51 +++++++++++-------- .../MailboxDeliverToRecipientHandler.java | 3 +- .../james/pop3server/POP3ServerTest.java | 9 ++-- .../AuthRequiredToRelayRcptHook.java | 3 +- .../james/smtpserver/JamesMailCmdHandler.java | 3 +- .../james/smtpserver/JamesRcptCmdHandler.java | 3 +- .../james/smtpserver/SendMailHandler.java | 3 +- ...enderAuthIdentifyVerificationRcptHook.java | 5 +- .../smtpserver/UsersRepositoryAuthHook.java | 3 +- .../smtpserver/fastfail/DNSRBLHandler.java | 3 +- .../fastfail/JDBCGreylistHandler.java | 3 +- .../fastfail/ResolvableEhloHeloHandler.java | 3 +- .../ReverseEqualsEhloHeloHandler.java | 3 +- .../james/smtpserver/fastfail/SPFHandler.java | 3 +- .../smtpserver/fastfail/URIRBLHandler.java | 3 +- .../smtpserver/fastfail/ValidRcptHandler.java | 5 +- .../smtpserver/fastfail/ValidRcptMX.java | 3 +- .../fastfail/ValidSenderDomainHandler.java | 2 +- .../james/smtpserver/SMTPServerTest.java | 21 ++++---- .../FileSystemBlobTransferPolicy.java | 5 +- .../spring/activemq-queue-context.xml | 4 +- .../queue/file/FileMailQueueFactory.java | 1 - .../james/queue/jms/JMSMailQueueFactory.java | 7 +-- 53 files changed, 144 insertions(+), 167 deletions(-) diff --git a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java index 667892f5412..7a14bfe5d43 100644 --- a/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java +++ b/mailbox/store/src/main/java/org/apache/james/mailbox/store/search/SimpleMessageSearchIndex.java @@ -23,6 +23,9 @@ import java.util.SortedSet; import java.util.TreeSet; +import javax.inject.Inject; +import javax.inject.Singleton; + import org.apache.james.mailbox.MailboxSession; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.model.MessageRange; @@ -47,9 +50,12 @@ * * @param */ +@Singleton public class SimpleMessageSearchIndex implements MessageSearchIndex { private final MessageMapperFactory factory; + + @Inject public SimpleMessageSearchIndex(MessageMapperFactory factory) { this.factory = factory; } diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java index c2961427d4f..c4e61b3ff61 100644 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java +++ b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxCopierManagement.java @@ -22,7 +22,6 @@ import java.util.HashMap; import java.util.Map; -import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Named; @@ -46,9 +45,7 @@ public class MailboxCopierManagement implements MailboxCopierManagementMBean { private MailboxManagerResolver resolver; @Inject - @Named("mailboxcopier") - @Resource(name = "mailboxcopier") - public void setMailboxCopier(MailboxCopier copier) { + public void setMailboxCopier(@Named("mailboxcopier") MailboxCopier copier) { this.copier = copier; } diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java index d9e1f516a24..098af84511d 100644 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java +++ b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerManagement.java @@ -22,7 +22,6 @@ import java.util.Collections; import java.util.List; -import javax.annotation.Resource; import javax.inject.Inject; import javax.inject.Named; import javax.management.NotCompliantMBeanException; @@ -48,7 +47,6 @@ public class MailboxManagerManagement extends StandardMBean implements MailboxMa private Logger log; @Inject - @Resource(name = "mailboxmanager") public void setMailboxManager(@Named("mailboxmanager") MailboxManager mailboxManager) { this.mailboxManager = mailboxManager; } diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/store/UserRepositoryAuthenticator.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/store/UserRepositoryAuthenticator.java index c69e3063b5e..6d6f4b3e56f 100644 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/store/UserRepositoryAuthenticator.java +++ b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/store/UserRepositoryAuthenticator.java @@ -19,9 +19,7 @@ package org.apache.james.adapter.mailbox.store; -import javax.annotation.Resource; import javax.inject.Inject; -import javax.inject.Named; import org.apache.james.lifecycle.api.LogEnabled; import org.apache.james.mailbox.store.Authenticator; @@ -39,8 +37,7 @@ public class UserRepositoryAuthenticator implements Authenticator, LogEnabled { private Logger log; @Inject - @Resource(name = "usersrepository") - public void setUsersRepository(@Named("usersrepository") UsersRepository repos) { + public void setUsersRepository(UsersRepository repos) { this.repos = repos; } diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java b/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java index be11684c13e..2e71bdc5926 100644 --- a/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java +++ b/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23Importer.java @@ -56,21 +56,18 @@ public class James23Importer implements LogEnabled { * James 3.0 users repository. */ @Inject - @Named("usersrepository") private UsersRepository james30UsersRepository; /** * James 3.0 users repository. */ @Inject - @Named("mailrepositorystore") private MailRepositoryStore mailRepositoryStore; /** * James 3.0 domain list. */ @Inject - @Named("domainlist") private DomainList domainList; /** diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23ImporterManagement.java b/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23ImporterManagement.java index f131f7df4d1..b1a5e49be47 100644 --- a/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23ImporterManagement.java +++ b/server/container/spring/src/main/java/org/apache/james/container/spring/tool/James23ImporterManagement.java @@ -23,7 +23,6 @@ import org.apache.james.user.api.UsersRepositoryException; import javax.inject.Inject; -import javax.inject.Named; import javax.mail.MessagingException; import java.io.IOException; @@ -33,7 +32,6 @@ public class James23ImporterManagement implements James23ImporterManagementMBean { @Inject - @Named("james23importer") private James23Importer james23Importer; @Override diff --git a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml index f6b5f153dac..fe5022289bd 100644 --- a/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml +++ b/server/container/spring/src/main/resources/META-INF/org/apache/james/spring-server.xml @@ -21,9 +21,12 @@ + http://camel.apache.org/schema/spring http://camel.apache.org/schema/spring/camel-spring.xsd + http://www.springframework.org/schema/context + http://www.springframework.org/schema/context/spring-context-2.5.xsd"> @@ -33,6 +36,9 @@ =========================================================================== --> + + + @@ -132,6 +138,8 @@ + + - + + + + + + 4.0.0 + + + org.apache.james + james-server + 3.0.0-beta5-SNAPSHOT + ../../pom.xml + + + james-server-cassandra-guice + bundle + + Apache James :: Server :: Cassandra - guice injection + An advanced email server - Cassandra backend with guice injection + + + + + org.apache.felix + maven-bundle-plugin + true + + + + + + + + disable-build-for-older-jdk + + (,1.8) + + + + + maven-jar-plugin + + + default-jar + none + + + jar + none + + + test-jar + none + + + + + maven-compiler-plugin + + + default-compile + none + + + default-testCompile + none + + + + + maven-surefire-plugin + + + default-test + none + + + + + maven-source-plugin + + + attach-sources + none + + + + + maven-install-plugin + + + default-install + none + + + + + maven-resources-plugin + + + default-resources + none + + + default-testResources + none + + + + + maven-site-plugin + + + attach-descriptor + none + + + + + + + + build-for-jdk-8 + + [1.8,) + + + + + maven-assembly-plugin + + + + fully.qualified.MainClass + + + + jar-with-dependencies + + + + + org.apache.maven.plugins + maven-compiler-plugin + + 1.8 + 1.8 + + + + + + + com.google.guava + guava + 16.0 + + + ${project.groupId} + apache-james-mailbox-cassandra + + + ${project.groupId} + apache-james-mailbox-elasticsearch + + + ${project.groupId} + apache-james-mailbox-tika + + + ${project.groupId} + apache-james-mailbox-tool + + + ${project.groupId} + apache-jsieve-manager-jsieve + + + ${project.groupId} + apache-jsieve-manager-mailet + + + ${project.groupId} + apache-mailet-standard + + + ${project.groupId} + james-server-cli + + + ${project.groupId} + james-server-core + + + ${project.groupId} + james-server-data-api + + + ${project.groupId} + james-server-data-file + + + ${project.groupId} + james-server-data-library + + + ${project.groupId} + james-server-dnsservice-api + + + ${project.groupId} + james-server-dnsservice-dnsjava + + + ${project.groupId} + james-server-dnsservice-library + + + ${project.groupId} + james-server-fetchmail + + + ${project.groupId} + james-server-filesystem-api + + + ${project.groupId} + james-server-lifecycle-api + + + ${project.groupId} + james-server-mailbox-adapter + + + ${project.groupId} + james-server-mailets + + + ${project.groupId} + james-server-mailetcontainer-api + + + ${project.groupId} + james-server-mailetcontainer-camel + + + ${project.groupId} + james-server-protocols-imap4 + + + ${project.groupId} + james-server-protocols-library + + + ${project.groupId} + james-server-protocols-lmtp + + + ${project.groupId} + james-server-protocols-pop3 + + + ${project.groupId} + james-server-protocols-smtp + + + ${project.groupId} + james-server-queue-api + + + ${project.groupId} + james-server-queue-activemq + + + ${project.groupId} + james-server-queue-file + + + ${project.groupId} + james-server-queue-jms + + + ${project.groupId} + james-server-util + + + org.apache.james.protocols + protocols-imap + + + com.fasterxml.jackson.core + jackson-databind + 2.3.3 + + + com.fasterxml.jackson.datatype + jackson-datatype-guava + 2.3.3 + + + com.fasterxml.jackson.datatype + jackson-datatype-jdk8 + 2.4.3 + + + com.google.inject + guice + + + com.google.inject.extensions + guice-multibindings + + + com.jayway.awaitility + awaitility + + + commons-daemon + commons-daemon + + + javax.inject + javax.inject + + + org.antlr + antlr-runtime + 3.2 + test + + + org.apache.camel + camel-core + + + tools + com.sun + + + + + org.apache.onami.lifecycle + org.apache.onami.lifecycle.jsr250 + + + org.assertj + assertj-core + 3.0.0 + test + + + org.cassandraunit + cassandra-unit + 2.0.2.2 + test + + + org.elasticsearch + elasticsearch + 1.5.2 + + + org.slf4j + slf4j-api + + + org.slf4j + slf4j-simple + runtime + + + + + disable-animal-sniffer + + [1.6,) + + + + + org.codehaus.mojo + animal-sniffer-maven-plugin + + + check_java_6 + none + + + + + + + + diff --git a/server/pom.xml b/server/pom.xml index 8e0e4114381..fab38b06fae 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -58,13 +58,14 @@ karaf/features karaf/integration - container/util + container/cassandra-guice container/cli - container/spring container/core + container/filesystem-api container/lifecycle-api container/mailbox-adapter - container/filesystem-api + container/spring + container/util mailet/mailetcontainer-api mailet/mailetcontainer-camel @@ -200,7 +201,11 @@ james-server-spring ${project.version}
- + + org.apache.james + james-server-cassandra-guice + ${project.version} + org.apache.james james-server-queue-api @@ -520,6 +525,11 @@ ${mailbox.version} test + + org.apache.james + apache-james-mailbox-cassandra + ${mailbox.version} + org.apache.james apache-james-mailbox-cassandra @@ -698,6 +708,16 @@ + + org.apache.james + apache-jsieve-manager-jsieve + ${jsieve.version} + + + org.apache.james + apache-jsieve-manager-mailet + ${jsieve.version} + org.apache.james apache-jsieve-manager-api @@ -1204,6 +1224,23 @@ ${pax-swissbox-tinybundles.version} + + + com.google.inject + guice + 4.0 + + + com.google.inject.extensions + guice-multibindings + 4.0 + + + org.apache.onami.lifecycle + org.apache.onami.lifecycle.jsr250 + 0.2.0-SNAPSHOT + + org.apache.james.karaf @@ -1254,7 +1291,6 @@ test ${hadoop.version} - info.cukes cucumber-java @@ -1276,6 +1312,11 @@ ${cucumber.version} test + + com.jayway.awaitility + awaitility + 1.6.3 +
From 8c55733c3ecdcb4b3b0174871a312aefe384ea1b Mon Sep 17 00:00:00 2001 From: benwa Date: Thu, 27 Aug 2015 15:55:39 +0200 Subject: [PATCH 07/39] JAMES-1626 bootstrap guice-based application with Cassandra IMAP server --- backends-common/cassandra/pom.xml | 4 + .../init/CassandraTypesProvider.java | 3 + backends-common/pom.xml | 5 ++ server/container/cassandra-guice/pom.xml | 17 ++++ .../apache/james/CassandraJamesServer.java | 39 +++++++++ .../james/CassandraJamesServerMain.java | 48 +++++++++++ .../data/CassandraDomainListModule.java | 37 +++++++++ .../CassandraRecipientRewriteTableModule.java | 38 +++++++++ .../data/CassandraUsersRepositoryModule.java | 38 +++++++++ .../mailbox/CassandraMailboxModule.java | 70 ++++++++++++++++ .../mailbox/CassandraSessionModule.java | 75 +++++++++++++++++ .../modules/server/DNSServiceModule.java | 40 +++++++++ .../server/SimpleMessageSearchModule.java | 17 ++++ .../apache/james/utils/PropertiesReader.java | 43 ++++++++++ .../james/CassandraJamesServerTest.java | 83 +++++++++++++++++++ .../james/utils/PropertiesReadTest.java | 38 +++++++++ .../src/test/resources/cassandra.properties | 6 ++ .../src/test/resources/test.properties | 6 ++ .../cassandra/CassandraDomainList.java | 3 +- .../CassandraRecipientRewriteTable.java | 3 +- .../cassandra/CassandraUsersRepository.java | 8 +- server/pom.xml | 6 +- 22 files changed, 616 insertions(+), 11 deletions(-) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraDomainListModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraRecipientRewriteTableModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraUsersRepositoryModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/SimpleMessageSearchModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/PropertiesReader.java create mode 100644 server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java create mode 100644 server/container/cassandra-guice/src/test/java/org/apache/james/utils/PropertiesReadTest.java create mode 100644 server/container/cassandra-guice/src/test/resources/cassandra.properties create mode 100644 server/container/cassandra-guice/src/test/resources/test.properties diff --git a/backends-common/cassandra/pom.xml b/backends-common/cassandra/pom.xml index 983b7f45625..97a3a3dd22f 100644 --- a/backends-common/cassandra/pom.xml +++ b/backends-common/cassandra/pom.xml @@ -140,6 +140,10 @@ commons-lang 2.6
+ + javax.inject + javax.inject + org.assertj assertj-core diff --git a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/CassandraTypesProvider.java b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/CassandraTypesProvider.java index 9d94d039c10..a1f852e5a87 100644 --- a/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/CassandraTypesProvider.java +++ b/backends-common/cassandra/src/main/java/org/apache/james/backends/cassandra/init/CassandraTypesProvider.java @@ -21,6 +21,8 @@ import java.util.Optional; +import javax.inject.Inject; + import com.datastax.driver.core.Session; import com.datastax.driver.core.UserType; import com.google.common.collect.ImmutableMap; @@ -31,6 +33,7 @@ public class CassandraTypesProvider { private final ImmutableMap userTypes; + @Inject public CassandraTypesProvider(CassandraModule module, Session session) { userTypes = module.moduleTypes() .stream() diff --git a/backends-common/pom.xml b/backends-common/pom.xml index 7e753295cfe..d682ba8cfc5 100644 --- a/backends-common/pom.xml +++ b/backends-common/pom.xml @@ -44,6 +44,11 @@ guava 16.0 + + javax.inject + javax.inject + 1 + org.assertj assertj-core diff --git a/server/container/cassandra-guice/pom.xml b/server/container/cassandra-guice/pom.xml index e053752ec0c..6b4a893d8ff 100644 --- a/server/container/cassandra-guice/pom.xml +++ b/server/container/cassandra-guice/pom.xml @@ -176,6 +176,18 @@ ${project.groupId} apache-james-mailbox-cassandra + + org.apache.james + apache-james-backends-cassandra + ${apache-backends-cassandra.version} + test-jar + + + ${project.groupId} + apache-james-mailbox-cassandra + test + test-jar + ${project.groupId} apache-james-mailbox-elasticsearch @@ -216,6 +228,11 @@ ${project.groupId} james-server-data-file + + ${project.groupId} + james-server-data-cassandra + + ${project.groupId} james-server-data-library diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java new file mode 100644 index 00000000000..e9541bd513d --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java @@ -0,0 +1,39 @@ +/**************************************************************** + * 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.inject.Guice; +import com.google.inject.Module; + +public class CassandraJamesServer { + + private final Module serverModule; + + public CassandraJamesServer(Module serverModule) { + this.serverModule = serverModule; + } + + public void start() { + Guice.createInjector(serverModule); + } + + public void stop() { + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java new file mode 100644 index 00000000000..08998c0e5c9 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java @@ -0,0 +1,48 @@ +/**************************************************************** + * 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.data.CassandraDomainListModule; +import org.apache.james.modules.data.CassandraRecipientRewriteTableModule; +import org.apache.james.modules.data.CassandraUsersRepositoryModule; +import org.apache.james.modules.mailbox.CassandraMailboxModule; +import org.apache.james.modules.mailbox.CassandraSessionModule; +import org.apache.james.modules.server.DNSServiceModule; +import org.apache.james.modules.server.SimpleMessageSearchModule; + +import com.google.inject.Module; +import com.google.inject.util.Modules; + +public class CassandraJamesServerMain { + + public static final Module defaultModule = Modules.combine(new CassandraMailboxModule(), + new CassandraSessionModule(), + new SimpleMessageSearchModule(), + new CassandraUsersRepositoryModule(), + new CassandraDomainListModule(), + new CassandraRecipientRewriteTableModule(), + new DNSServiceModule()); + + public static void main(String[] args) throws Exception { + CassandraJamesServer server = new CassandraJamesServer(defaultModule); + server.start(); + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraDomainListModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraDomainListModule.java new file mode 100644 index 00000000000..890356d72f1 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraDomainListModule.java @@ -0,0 +1,37 @@ +/**************************************************************** + * 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 org.apache.james.backends.cassandra.components.CassandraModule; +import org.apache.james.domainlist.api.DomainList; +import org.apache.james.domainlist.cassandra.CassandraDomainList; + +import com.google.inject.AbstractModule; +import com.google.inject.multibindings.Multibinder; + +public class CassandraDomainListModule extends AbstractModule { + + @Override + public void configure() { + bind(DomainList.class).to(CassandraDomainList.class); + Multibinder cassandraDataDefinitions = Multibinder.newSetBinder(binder(), CassandraModule.class); + cassandraDataDefinitions.addBinding().to(org.apache.james.domainlist.cassandra.CassandraDomainListModule.class); + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraRecipientRewriteTableModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraRecipientRewriteTableModule.java new file mode 100644 index 00000000000..c28ca2055ab --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraRecipientRewriteTableModule.java @@ -0,0 +1,38 @@ +/**************************************************************** + * 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 org.apache.james.backends.cassandra.components.CassandraModule; +import org.apache.james.rrt.api.RecipientRewriteTable; +import org.apache.james.rrt.cassandra.CassandraRRTModule; +import org.apache.james.rrt.cassandra.CassandraRecipientRewriteTable; + +import com.google.inject.AbstractModule; +import com.google.inject.multibindings.Multibinder; + +public class CassandraRecipientRewriteTableModule extends AbstractModule { + + @Override + public void configure() { + bind(RecipientRewriteTable.class).to(CassandraRecipientRewriteTable.class); + Multibinder cassandraDataDefinitions = Multibinder.newSetBinder(binder(), CassandraModule.class); + cassandraDataDefinitions.addBinding().to(CassandraRRTModule.class); + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraUsersRepositoryModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraUsersRepositoryModule.java new file mode 100644 index 00000000000..a776626dda6 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/data/CassandraUsersRepositoryModule.java @@ -0,0 +1,38 @@ +/**************************************************************** + * 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 org.apache.james.backends.cassandra.components.CassandraModule; +import org.apache.james.user.api.UsersRepository; +import org.apache.james.user.cassandra.CassandraUsersRepository; + +import com.google.inject.AbstractModule; +import com.google.inject.multibindings.Multibinder; + +public class CassandraUsersRepositoryModule extends AbstractModule { + + @Override + public void configure() { + bind(UsersRepository.class).to(CassandraUsersRepository.class); + Multibinder cassandraDataDefinitions = Multibinder.newSetBinder(binder(), CassandraModule.class); + cassandraDataDefinitions.addBinding().to(org.apache.james.user.cassandra.CassandraUsersRepositoryModule.class); + + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java new file mode 100644 index 00000000000..269b280f957 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java @@ -0,0 +1,70 @@ +/**************************************************************** + * Licensed to the Apache Software Foundation (ASF) under one * + * or more contributor license agreements. See the NOTICE file * + * distributed with this work for additional information * + * regarding copyright ownership. The ASF licenses this file * + * to you under the Apache License, Version 2.0 (the * + * "License"); you may not use this file except in compliance * + * with the License. You may obtain a copy of the License at * + * * + * http://www.apache.org/licenses/LICENSE-2.0 * + * * + * Unless required by applicable law or agreed to in writing, * + * software distributed under the License is distributed on an * + * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY * + * KIND, either express or implied. See the License for the * + * specific language governing permissions and limitations * + * under the License. * + ****************************************************************/ +package org.apache.james.modules.mailbox; + +import javax.inject.Singleton; + +import org.apache.james.adapter.mailbox.store.UserRepositoryAuthenticator; +import org.apache.james.backends.cassandra.components.CassandraModule; +import org.apache.james.mailbox.MailboxManager; +import org.apache.james.mailbox.MailboxPathLocker; +import org.apache.james.mailbox.SubscriptionManager; +import org.apache.james.mailbox.cassandra.CassandraId; +import org.apache.james.mailbox.cassandra.CassandraMailboxManager; +import org.apache.james.mailbox.cassandra.CassandraMailboxSessionMapperFactory; +import org.apache.james.mailbox.cassandra.CassandraSubscriptionManager; +import org.apache.james.mailbox.cassandra.mail.CassandraModSeqProvider; +import org.apache.james.mailbox.cassandra.mail.CassandraUidProvider; +import org.apache.james.mailbox.exception.MailboxException; +import org.apache.james.mailbox.store.Authenticator; +import org.apache.james.mailbox.store.NoMailboxPathLocker; +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 com.google.inject.AbstractModule; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.name.Named; + +public class CassandraMailboxModule extends AbstractModule { + + public static final String MAILBOXMANAGER_NAME = "mailboxmanager"; + + @Override + protected void configure() { + bind(SubscriptionManager.class).to(CassandraSubscriptionManager.class); + bind(new TypeLiteral>(){}).to(CassandraMailboxSessionMapperFactory.class); + + bind(MailboxPathLocker.class).to(NoMailboxPathLocker.class); + bind(Authenticator.class).to(UserRepositoryAuthenticator.class); + + bind(new TypeLiteral>(){}).to(new TypeLiteral(){}); + bind(new TypeLiteral>(){}).to(new TypeLiteral(){}); + Multibinder cassandraDataDefinitions = Multibinder.newSetBinder(binder(), CassandraModule.class); + cassandraDataDefinitions.addBinding().to(org.apache.james.mailbox.cassandra.CassandraMailboxModule.class); + } + + @Provides @Named(MAILBOXMANAGER_NAME) @Singleton + public MailboxManager provideMailboxManager(CassandraMailboxManager cassandraMailboxManager) throws MailboxException { + cassandraMailboxManager.init(); + return cassandraMailboxManager; + } +} \ No newline at end of file diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java new file mode 100644 index 00000000000..91427460a6b --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.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.modules.mailbox; + +import com.google.inject.Provides; +import com.google.inject.Singleton; + +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; +import com.google.inject.AbstractModule; + +import java.util.Set; + +import org.apache.james.backends.cassandra.components.CassandraModule; +import org.apache.james.backends.cassandra.init.CassandraModuleComposite; +import org.apache.james.backends.cassandra.init.ClusterFactory; +import org.apache.james.backends.cassandra.init.ClusterWithKeyspaceCreatedFactory; +import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory; +import org.apache.james.utils.PropertiesReader; + +public class CassandraSessionModule extends AbstractModule { + + private final PropertiesReader propertiesReader; + private final String keyspace; + + public CassandraSessionModule() { + propertiesReader = new PropertiesReader("cassandra.properties"); + keyspace = propertiesReader.getProperty("cassandra.keyspace"); + } + + @Override + protected void configure() { + + } + + @Provides + @Singleton + CassandraModule composeDataDefinitions(Set modules) { + return new CassandraModuleComposite(modules.toArray(new CassandraModule[0])); + } + + @Provides + @Singleton + Session provideSession(Cluster cluster, CassandraModule cassandraModule) { + return new SessionWithInitializedTablesFactory(cassandraModule).createSession(cluster, keyspace); + } + + @Provides + @Singleton + Cluster provideCluster() { + return ClusterWithKeyspaceCreatedFactory.clusterWithInitializedKeyspace( + ClusterFactory.createClusterForSingleServerWithoutPassWord( + propertiesReader.getProperty("cassandra.ip"), + Integer.parseInt(propertiesReader.getProperty("cassandra.port"))), + keyspace, + Integer.parseInt(propertiesReader.getProperty("cassandra.replication.factor"))); + } + +} \ No newline at end of file diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java new file mode 100644 index 00000000000..8ca0efd82d3 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java @@ -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. * + ****************************************************************/ +package org.apache.james.modules.server; + +import com.google.inject.Provides; +import com.google.inject.Singleton; +import org.apache.james.dnsservice.api.DNSService; +import org.apache.james.dnsservice.dnsjava.DNSJavaService; + +import com.google.inject.AbstractModule; + +public class DNSServiceModule extends AbstractModule { + + @Override + protected void configure() { + + } + + @Provides + @Singleton + private DNSService provideDNSService() { + return new DNSJavaService(); + } +} \ No newline at end of file diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/SimpleMessageSearchModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/SimpleMessageSearchModule.java new file mode 100644 index 00000000000..28529865992 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/SimpleMessageSearchModule.java @@ -0,0 +1,17 @@ +package org.apache.james.modules.server; + +import org.apache.james.mailbox.cassandra.CassandraId; +import org.apache.james.mailbox.store.search.MessageSearchIndex; +import org.apache.james.mailbox.store.search.SimpleMessageSearchIndex; + +import com.google.inject.AbstractModule; +import com.google.inject.TypeLiteral; + +public class SimpleMessageSearchModule extends AbstractModule { + + @Override + protected void configure() { + bind(new TypeLiteral>(){}).to(new TypeLiteral>(){}); + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/PropertiesReader.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/PropertiesReader.java new file mode 100644 index 00000000000..e859ff738b4 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/PropertiesReader.java @@ -0,0 +1,43 @@ +/**************************************************************** + * 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 com.google.common.base.Throwables; + +import java.io.IOException; +import java.util.Properties; + +public class PropertiesReader { + + private final Properties properties; + + public PropertiesReader(String fileName) { + properties = new Properties(); + try { + properties.load(ClassLoader.getSystemResourceAsStream(fileName)); + } catch (IOException e) { + throw Throwables.propagate(e); + } + } + + public String getProperty(String key) { + return properties.getProperty(key); + } +} diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java new file mode 100644 index 00000000000..7bda7445d13 --- /dev/null +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java @@ -0,0 +1,83 @@ +/**************************************************************** + * 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.Properties; + +import javax.mail.AuthenticationFailedException; +import javax.mail.NoSuchProviderException; +import javax.mail.Session; +import javax.mail.Store; + +import org.apache.james.backends.cassandra.CassandraCluster; +import org.apache.james.backends.cassandra.components.CassandraModule; +import org.junit.After; +import org.junit.Before; +import org.junit.Test; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import com.google.inject.util.Modules; + +public class CassandraJamesServerTest { + + private static final int IMAP_PORT = 1143; // You need to be root (superuser) to bind to ports under 1024. + + private CassandraJamesServer server; + + @Before + public void setup() throws Exception { + server = new CassandraJamesServer(Modules.override(CassandraJamesServerMain.defaultModule) + .with(new AbstractModule() { + + @Override + protected void configure() { + } + + @Provides + @Singleton + com.datastax.driver.core.Session provideSession(CassandraModule cassandraModule) { + CassandraCluster cassandra = CassandraCluster.create(cassandraModule); + return cassandra.getConf(); + } + + })); + server.start(); + } + + @After + public void tearDown() throws Exception { + server.stop(); + } + + @Test (expected = AuthenticationFailedException.class) + public void connectShouldThrowWhenNoCrendentials() throws Exception { + store().connect(); + } + + private Store store() throws NoSuchProviderException { + Properties properties = new Properties(); + properties.put("mail.imap.host", "localhost"); + properties.put("mail.imap.port", String.valueOf(IMAP_PORT)); + Session session = Session.getDefaultInstance(properties); + session.setDebug(true); + return session.getStore("imap"); + } +} diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/PropertiesReadTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/PropertiesReadTest.java new file mode 100644 index 00000000000..e3e33aa2420 --- /dev/null +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/PropertiesReadTest.java @@ -0,0 +1,38 @@ +/**************************************************************** + * 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 static org.assertj.core.api.Assertions.assertThat; + +import org.junit.Test; + +public class PropertiesReadTest { + + @Test + public void getPropertyShouldWork() throws Exception { + PropertiesReader propertiesReader = new PropertiesReader("test.properties"); + assertThat(propertiesReader.getProperty("cassandra.ip")).isEqualTo("127.0.0.1"); + } + + @Test(expected = RuntimeException.class) + public void buildingAPropertiesReaderOnNonExistingValuesShouldThrow() throws Exception { + new PropertiesReader("fake.properties"); + } +} diff --git a/server/container/cassandra-guice/src/test/resources/cassandra.properties b/server/container/cassandra-guice/src/test/resources/cassandra.properties new file mode 100644 index 00000000000..b4db9c1f7a8 --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/cassandra.properties @@ -0,0 +1,6 @@ +# Configuration file for cassandra mailbox + +cassandra.ip=127.0.0.1 +cassandra.port=9142 +cassandra.keyspace=apache_james +cassandra.replication.factor=1 \ No newline at end of file diff --git a/server/container/cassandra-guice/src/test/resources/test.properties b/server/container/cassandra-guice/src/test/resources/test.properties new file mode 100644 index 00000000000..b4db9c1f7a8 --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/test.properties @@ -0,0 +1,6 @@ +# Configuration file for cassandra mailbox + +cassandra.ip=127.0.0.1 +cassandra.port=9142 +cassandra.keyspace=apache_james +cassandra.replication.factor=1 \ No newline at end of file diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/domainlist/cassandra/CassandraDomainList.java b/server/data/data-cassandra/src/main/java/org/apache/james/domainlist/cassandra/CassandraDomainList.java index 53875b7ccc0..233868ebc20 100644 --- a/server/data/data-cassandra/src/main/java/org/apache/james/domainlist/cassandra/CassandraDomainList.java +++ b/server/data/data-cassandra/src/main/java/org/apache/james/domainlist/cassandra/CassandraDomainList.java @@ -29,7 +29,6 @@ import javax.annotation.Resource; import javax.inject.Inject; -import javax.inject.Named; import org.apache.james.backends.cassandra.utils.CassandraConstants; import org.apache.james.backends.cassandra.utils.CassandraUtils; @@ -46,7 +45,7 @@ public class CassandraDomainList extends AbstractDomainList { @Inject @Resource - public void setSession(@Named("cassandra-session") Session session) { + public void setSession(Session session) { this.session = session; } diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java index c728940669b..ad9ba4b3e16 100644 --- a/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java +++ b/server/data/data-cassandra/src/main/java/org/apache/james/rrt/cassandra/CassandraRecipientRewriteTable.java @@ -33,7 +33,6 @@ import javax.annotation.Resource; import javax.inject.Inject; -import javax.inject.Named; import org.apache.james.rrt.api.RecipientRewriteTableException; import org.apache.james.rrt.lib.AbstractRecipientRewriteTable; @@ -49,7 +48,7 @@ public class CassandraRecipientRewriteTable extends AbstractRecipientRewriteTabl @Inject @Resource - public void setSession(@Named("cassandra-session") Session session) { + public void setSession(Session session) { this.session = session; } diff --git a/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java b/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java index 54906f23dd1..a51fbfae87b 100644 --- a/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java +++ b/server/data/data-cassandra/src/main/java/org/apache/james/user/cassandra/CassandraUsersRepository.java @@ -36,7 +36,6 @@ import javax.annotation.Resource; import javax.inject.Inject; -import javax.inject.Named; import org.apache.james.backends.cassandra.utils.CassandraConstants; import org.apache.james.backends.cassandra.utils.CassandraUtils; @@ -58,10 +57,15 @@ public class CassandraUsersRepository extends AbstractUsersRepository { @Inject @Resource - public void setSession(@Named("cassandra-session") Session session) { + public void setSession(Session session) { this.session = session; } + @Override + public boolean supportVirtualHosting() { + return true; + } + @Override public User getUserByName(String name){ ResultSet result = session.execute( diff --git a/server/pom.xml b/server/pom.xml index fab38b06fae..6b384743fdc 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -534,7 +534,7 @@ org.apache.james apache-james-mailbox-cassandra ${mailbox.version} - test + test-jar org.apache.james @@ -545,13 +545,11 @@ org.apache.james apache-james-mailbox-elasticsearch ${mailbox.version} - test org.apache.james apache-james-mailbox-tika ${mailbox.version} - test org.apache.james @@ -903,8 +901,6 @@ ${mockito-core.version} test - - concurrent concurrent From 81279a6664fd485a699f667c62461fdda143b211 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Wed, 21 Oct 2015 14:13:22 +0200 Subject: [PATCH 08/39] JAMES-1626 ConfigurationPerformer will take care of push configuration to class that need it --- .../apache/james/CassandraJamesServer.java | 8 +++- .../james/utils/ConfigurationPerformer.java | 27 ++++++++++++ .../james/utils/ConfigurationsPerformer.java | 41 +++++++++++++++++++ 3 files changed, 74 insertions(+), 2 deletions(-) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationPerformer.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationsPerformer.java diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java index e9541bd513d..d07c5e71556 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java @@ -18,7 +18,10 @@ ****************************************************************/ package org.apache.james; +import org.apache.james.utils.ConfigurationsPerformer; + import com.google.inject.Guice; +import com.google.inject.Injector; import com.google.inject.Module; public class CassandraJamesServer { @@ -29,8 +32,9 @@ public CassandraJamesServer(Module serverModule) { this.serverModule = serverModule; } - public void start() { - Guice.createInjector(serverModule); + public void start() throws Exception { + Injector injector = Guice.createInjector(serverModule); + injector.getInstance(ConfigurationsPerformer.class).initModules(); } public void stop() { diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationPerformer.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationPerformer.java new file mode 100644 index 00000000000..ae2ef871749 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationPerformer.java @@ -0,0 +1,27 @@ +/**************************************************************** + * 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; + + +public interface ConfigurationPerformer { + + void initModule() throws Exception; + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationsPerformer.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationsPerformer.java new file mode 100644 index 00000000000..f64d640dbab --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationsPerformer.java @@ -0,0 +1,41 @@ +/**************************************************************** + * 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 com.google.inject.Inject; + +import java.util.Set; + +public class ConfigurationsPerformer { + + private final Set configurationPerformers; + + @Inject + public ConfigurationsPerformer(Set configurationPerformers) throws Exception { + this.configurationPerformers = configurationPerformers; + } + + public void initModules() throws Exception { + for(ConfigurationPerformer configurationPerformer : configurationPerformers) { + configurationPerformer.initModule(); + } + } + +} From 88c934741dd54b86ec949a60e51aca8f7ca1cf29 Mon Sep 17 00:00:00 2001 From: benwa Date: Mon, 24 Aug 2015 12:12:25 +0200 Subject: [PATCH 09/39] JAMES-1626 Use Onami for lifecycle management (JSR 250 @PreDestroy @PostConstruct) --- .../org/apache/james/CassandraJamesServer.java | 7 ++++++- .../apache/james/CassandraJamesServerMain.java | 17 ++++++++++------- .../server/ConfigurationPerformerModule.java | 15 +++++++++++++++ .../AbstractConnectHandlerResultJMXMonitor.java | 6 +++++- .../james/smtpserver/SendMailHandler.java | 4 ---- 5 files changed, 36 insertions(+), 13 deletions(-) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ConfigurationPerformerModule.java diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java index d07c5e71556..b4ea65d08b8 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServer.java @@ -19,25 +19,30 @@ package org.apache.james; import org.apache.james.utils.ConfigurationsPerformer; +import org.apache.onami.lifecycle.jsr250.PreDestroyModule; import com.google.inject.Guice; import com.google.inject.Injector; import com.google.inject.Module; +import com.google.inject.util.Modules; public class CassandraJamesServer { private final Module serverModule; + private final PreDestroyModule preDestroyModule; public CassandraJamesServer(Module serverModule) { this.serverModule = serverModule; + this.preDestroyModule = new PreDestroyModule(); } public void start() throws Exception { - Injector injector = Guice.createInjector(serverModule); + Injector injector = Guice.createInjector(Modules.combine(serverModule, preDestroyModule)); injector.getInstance(ConfigurationsPerformer.class).initModules(); } public void stop() { + preDestroyModule.getStager().stage(); } } diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java index 08998c0e5c9..bf36f503be6 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java @@ -24,6 +24,7 @@ import org.apache.james.modules.data.CassandraUsersRepositoryModule; import org.apache.james.modules.mailbox.CassandraMailboxModule; import org.apache.james.modules.mailbox.CassandraSessionModule; +import org.apache.james.modules.server.ConfigurationPerformerModule; import org.apache.james.modules.server.DNSServiceModule; import org.apache.james.modules.server.SimpleMessageSearchModule; @@ -32,13 +33,15 @@ public class CassandraJamesServerMain { - public static final Module defaultModule = Modules.combine(new CassandraMailboxModule(), - new CassandraSessionModule(), - new SimpleMessageSearchModule(), - new CassandraUsersRepositoryModule(), - new CassandraDomainListModule(), - new CassandraRecipientRewriteTableModule(), - new DNSServiceModule()); + public static final Module defaultModule = Modules.combine( + new CassandraMailboxModule(), + new ConfigurationPerformerModule(), + new CassandraSessionModule(), + new SimpleMessageSearchModule(), + new CassandraUsersRepositoryModule(), + new CassandraDomainListModule(), + new CassandraRecipientRewriteTableModule(), + new DNSServiceModule()); public static void main(String[] args) throws Exception { CassandraJamesServer server = new CassandraJamesServer(defaultModule); diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ConfigurationPerformerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ConfigurationPerformerModule.java new file mode 100644 index 00000000000..4aab0a60948 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ConfigurationPerformerModule.java @@ -0,0 +1,15 @@ +package org.apache.james.modules.server; + +import org.apache.james.utils.ConfigurationPerformer; + +import com.google.inject.AbstractModule; +import com.google.inject.multibindings.Multibinder; + +public class ConfigurationPerformerModule extends AbstractModule { + + @Override + protected void configure() { + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class); + } + +} diff --git a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractConnectHandlerResultJMXMonitor.java b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractConnectHandlerResultJMXMonitor.java index 2c98d27ba18..da10dc3a158 100644 --- a/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractConnectHandlerResultJMXMonitor.java +++ b/server/protocols/protocols-library/src/main/java/org/apache/james/protocols/lib/jmx/AbstractConnectHandlerResultJMXMonitor.java @@ -25,9 +25,13 @@ import org.apache.commons.configuration.Configuration; import org.apache.commons.configuration.ConfigurationException; +import org.apache.james.protocols.api.handler.ConnectHandler; +import org.apache.james.protocols.api.handler.ExtensibleHandler; +import org.apache.james.protocols.api.handler.ProtocolHandler; +import org.apache.james.protocols.api.handler.ProtocolHandlerResultHandler; +import org.apache.james.protocols.api.handler.WiringException; import org.apache.james.protocols.api.ProtocolSession; import org.apache.james.protocols.api.Response; -import org.apache.james.protocols.api.handler.*; /** * Handler which will gather statistics for {@link ConnectHandler}'s diff --git a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SendMailHandler.java b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SendMailHandler.java index 2e17320f805..10cf7621101 100644 --- a/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SendMailHandler.java +++ b/server/protocols/protocols-smtp/src/main/java/org/apache/james/smtpserver/SendMailHandler.java @@ -48,10 +48,6 @@ public void setMailQueueFactory(MailQueueFactory queueFactory) { this.queueFactory = queueFactory; } - public void init() { - - } - @Override public void init(Configuration config) throws ConfigurationException { queue = queueFactory.getQueue(MailQueueFactory.SPOOL); From 4f62953ee568c874ec0a683f239336657ebb0d77 Mon Sep 17 00:00:00 2001 From: benwa Date: Mon, 17 Aug 2015 17:09:09 +0200 Subject: [PATCH 10/39] JAMES-1626 Add ElasticSearch support to cassandra-guice application --- server/container/cassandra-guice/pom.xml | 6 ++ .../james/CassandraJamesServerMain.java | 4 +- .../mailbox/CassandraMailboxModule.java | 4 ++ .../mailbox/ElasticSearchMailboxModule.java | 58 +++++++++++++++++++ .../james/CassandraJamesServerTest.java | 17 +++++- .../modules/TestElasticSearchModule.java | 52 +++++++++++++++++ .../test/resources/elasticsearch.properties | 26 +++++++++ server/pom.xml | 6 ++ 8 files changed, 168 insertions(+), 5 deletions(-) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java create mode 100644 server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java create mode 100644 server/container/cassandra-guice/src/test/resources/elasticsearch.properties diff --git a/server/container/cassandra-guice/pom.xml b/server/container/cassandra-guice/pom.xml index 6b4a893d8ff..09c5fbeae3d 100644 --- a/server/container/cassandra-guice/pom.xml +++ b/server/container/cassandra-guice/pom.xml @@ -192,6 +192,12 @@ ${project.groupId} apache-james-mailbox-elasticsearch + + ${project.groupId} + apache-james-mailbox-elasticsearch + test-jar + test + ${project.groupId} apache-james-mailbox-tika diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java index bf36f503be6..6655a8bf9d5 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java @@ -24,9 +24,9 @@ import org.apache.james.modules.data.CassandraUsersRepositoryModule; import org.apache.james.modules.mailbox.CassandraMailboxModule; import org.apache.james.modules.mailbox.CassandraSessionModule; +import org.apache.james.modules.mailbox.ElasticSearchMailboxModule; import org.apache.james.modules.server.ConfigurationPerformerModule; import org.apache.james.modules.server.DNSServiceModule; -import org.apache.james.modules.server.SimpleMessageSearchModule; import com.google.inject.Module; import com.google.inject.util.Modules; @@ -37,7 +37,7 @@ public class CassandraJamesServerMain { new CassandraMailboxModule(), new ConfigurationPerformerModule(), new CassandraSessionModule(), - new SimpleMessageSearchModule(), + new ElasticSearchMailboxModule(), new CassandraUsersRepositoryModule(), new CassandraDomainListModule(), new CassandraRecipientRewriteTableModule(), diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java index 269b280f957..7d69c7dcab0 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java @@ -31,12 +31,14 @@ import org.apache.james.mailbox.cassandra.CassandraSubscriptionManager; import org.apache.james.mailbox.cassandra.mail.CassandraModSeqProvider; import org.apache.james.mailbox.cassandra.mail.CassandraUidProvider; +import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex; import org.apache.james.mailbox.exception.MailboxException; import org.apache.james.mailbox.store.Authenticator; import org.apache.james.mailbox.store.NoMailboxPathLocker; 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.mailbox.store.search.MessageSearchIndex; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -50,6 +52,8 @@ public class CassandraMailboxModule extends AbstractModule { @Override protected void configure() { + bind(new TypeLiteral>(){}).to(new TypeLiteral>(){}); + bind(SubscriptionManager.class).to(CassandraSubscriptionManager.class); bind(new TypeLiteral>(){}).to(CassandraMailboxSessionMapperFactory.class); diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java new file mode 100644 index 00000000000..6709e3138a4 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java @@ -0,0 +1,58 @@ +/**************************************************************** + * 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 com.google.inject.AbstractModule; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; +import org.apache.james.mailbox.cassandra.CassandraId; +import org.apache.james.mailbox.elasticsearch.*; +import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex; +import org.apache.james.mailbox.store.extractor.TextExtractor; +import org.apache.james.mailbox.store.search.MessageSearchIndex; +import org.apache.james.mailbox.tika.extractor.TikaTextExtractor; +import org.apache.james.utils.PropertiesReader; + +import javax.inject.Singleton; + +public class ElasticSearchMailboxModule extends AbstractModule { + + @Override + protected void configure() { + bind(new TypeLiteral>(){}).to(new TypeLiteral>() {}); + bind(TextExtractor.class).to(TikaTextExtractor.class); + bind(new TypeLiteral>() {}) + .to(new TypeLiteral>() {}); + } + + @Provides + @Singleton + protected ClientProvider provideClientProvider() { + PropertiesReader propertiesReader = new PropertiesReader("elasticsearch.properties"); + ClientProvider clientProvider = new ClientProviderImpl(propertiesReader.getProperty("elasticsearch.masterHost"), + Integer.parseInt(propertiesReader.getProperty("elasticsearch.port"))); + IndexCreationFactory.createIndex(clientProvider, + Integer.parseInt(propertiesReader.getProperty("elasticsearch.nb.shards")), + Integer.parseInt(propertiesReader.getProperty("elasticsearch.nb.replica"))); + NodeMappingFactory.applyMapping(clientProvider); + return clientProvider; + } + +} diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java index 7bda7445d13..37e739584c4 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java @@ -27,9 +27,14 @@ import org.apache.james.backends.cassandra.CassandraCluster; import org.apache.james.backends.cassandra.components.CassandraModule; +import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch; +import org.apache.james.modules.TestElasticSearchModule; import org.junit.After; import org.junit.Before; +import org.junit.Rule; import org.junit.Test; +import org.junit.rules.RuleChain; +import org.junit.rules.TemporaryFolder; import com.google.inject.AbstractModule; import com.google.inject.Provides; @@ -41,11 +46,17 @@ public class CassandraJamesServerTest { private static final int IMAP_PORT = 1143; // You need to be root (superuser) to bind to ports under 1024. private CassandraJamesServer server; + private TemporaryFolder temporaryFolder = new TemporaryFolder(); + private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder); + + @Rule + public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch); @Before public void setup() throws Exception { server = new CassandraJamesServer(Modules.override(CassandraJamesServerMain.defaultModule) - .with(new AbstractModule() { + .with(new TestElasticSearchModule(embeddedElasticSearch), + new AbstractModule() { @Override protected void configure() { @@ -68,10 +79,10 @@ public void tearDown() throws Exception { } @Test (expected = AuthenticationFailedException.class) - public void connectShouldThrowWhenNoCrendentials() throws Exception { + public void connectIMAPServerShouldThrowWhenNoCredentials() throws Exception { store().connect(); } - + private Store store() throws NoSuchProviderException { Properties properties = new Properties(); properties.put("mail.imap.host", "localhost"); diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java b/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java new file mode 100644 index 00000000000..6da278fbff5 --- /dev/null +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestElasticSearchModule.java @@ -0,0 +1,52 @@ +/**************************************************************** + * 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 com.google.inject.AbstractModule; +import com.google.inject.Provides; +import org.apache.james.mailbox.elasticsearch.ClientProvider; +import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch; +import org.apache.james.mailbox.elasticsearch.IndexCreationFactory; +import org.apache.james.mailbox.elasticsearch.NodeMappingFactory; +import org.apache.james.mailbox.elasticsearch.utils.TestingClientProvider; + +import javax.inject.Singleton; + +public class TestElasticSearchModule extends AbstractModule{ + + private final EmbeddedElasticSearch embeddedElasticSearch; + + public TestElasticSearchModule(EmbeddedElasticSearch embeddedElasticSearch) { + this.embeddedElasticSearch = embeddedElasticSearch; + } + + @Override + protected void configure() { + + } + + @Provides + @Singleton + protected ClientProvider provideClientProvider() { + return NodeMappingFactory.applyMapping( + IndexCreationFactory.createIndex(new TestingClientProvider(embeddedElasticSearch.getNode())) + ); + } +} diff --git a/server/container/cassandra-guice/src/test/resources/elasticsearch.properties b/server/container/cassandra-guice/src/test/resources/elasticsearch.properties new file mode 100644 index 00000000000..454dabe2949 --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/elasticsearch.properties @@ -0,0 +1,26 @@ +# 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 + +# Configuration file for ElasticSearch + +elasticsearch.masterHost=127.0.0.1 +elasticsearch.port=9300 +elasticsearch.nb.shards=1 +elasticsearch.nb.replica=0 \ No newline at end of file diff --git a/server/pom.xml b/server/pom.xml index 6b384743fdc..df9447a2841 100644 --- a/server/pom.xml +++ b/server/pom.xml @@ -546,6 +546,12 @@ apache-james-mailbox-elasticsearch ${mailbox.version} + + org.apache.james + apache-james-mailbox-elasticsearch + ${mailbox.version} + test-jar + org.apache.james apache-james-mailbox-tika From d62e249476603af2b7bfdb59fc90e2ed3ce10f75 Mon Sep 17 00:00:00 2001 From: benwa Date: Tue, 18 Aug 2015 10:33:14 +0200 Subject: [PATCH 11/39] JAMES-1626 Add ActiveMQ support to cassandra-guice application --- .../james/CassandraJamesServerMain.java | 4 +- .../modules/server/ActiveMQQueueModule.java | 57 ++++++++++ .../modules/server/EmbeddedActiveMQ.java | 104 ++++++++++++++++++ 3 files changed, 164 insertions(+), 1 deletion(-) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/EmbeddedActiveMQ.java diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java index 6655a8bf9d5..fb5b40204e7 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java @@ -25,6 +25,7 @@ import org.apache.james.modules.mailbox.CassandraMailboxModule; import org.apache.james.modules.mailbox.CassandraSessionModule; import org.apache.james.modules.mailbox.ElasticSearchMailboxModule; +import org.apache.james.modules.server.ActiveMQQueueModule; import org.apache.james.modules.server.ConfigurationPerformerModule; import org.apache.james.modules.server.DNSServiceModule; @@ -41,7 +42,8 @@ public class CassandraJamesServerMain { new CassandraUsersRepositoryModule(), new CassandraDomainListModule(), new CassandraRecipientRewriteTableModule(), - new DNSServiceModule()); + new DNSServiceModule(), + new ActiveMQQueueModule()); public static void main(String[] args) throws Exception { CassandraJamesServer server = new CassandraJamesServer(defaultModule); diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java new file mode 100644 index 00000000000..95d114fdf22 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ActiveMQQueueModule.java @@ -0,0 +1,57 @@ +/**************************************************************** + * 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.server; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import org.apache.james.queue.activemq.ActiveMQMailQueueFactory; +import org.apache.james.queue.api.MailQueueFactory; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.jms.ConnectionFactory; + +public class ActiveMQQueueModule extends AbstractModule { + + private static Logger LOGGER = LoggerFactory.getLogger(ActiveMQQueueModule.class); + + @Override + protected void configure() { + + } + + @Provides + @Singleton + ConnectionFactory provideEmbededActiveMQ(EmbeddedActiveMQ embeddedActiveMQ) { + return embeddedActiveMQ.getConnectionFactory(); + } + + @Provides + @Singleton + public MailQueueFactory createActiveMailQueueFactory(ConnectionFactory connectionFactory, ActiveMQMailQueueFactory activeMQMailQueueFactory) { + activeMQMailQueueFactory.setUseJMX(true); + activeMQMailQueueFactory.setConnectionFactory(connectionFactory); + activeMQMailQueueFactory.setLog(LOGGER); + activeMQMailQueueFactory.init(); + return activeMQMailQueueFactory; + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/EmbeddedActiveMQ.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/EmbeddedActiveMQ.java new file mode 100644 index 00000000000..3d510693ef1 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/EmbeddedActiveMQ.java @@ -0,0 +1,104 @@ +/**************************************************************** + * 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.server; + +import com.google.common.base.Throwables; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import org.apache.activemq.ActiveMQConnectionFactory; +import org.apache.activemq.ActiveMQPrefetchPolicy; +import org.apache.activemq.blob.BlobTransferPolicy; +import org.apache.activemq.broker.BrokerPlugin; +import org.apache.activemq.broker.BrokerService; +import org.apache.activemq.broker.jmx.ManagementContext; +import org.apache.activemq.plugin.StatisticsBrokerPlugin; +import org.apache.activemq.store.amq.AMQPersistenceAdapter; +import org.apache.james.queue.activemq.FileSystemBlobTransferPolicy; + +import javax.annotation.PreDestroy; +import javax.jms.ConnectionFactory; + +@Singleton +public class EmbeddedActiveMQ { + + private ActiveMQConnectionFactory activeMQConnectionFactory; + private BrokerService brokerService; + + @Inject private EmbeddedActiveMQ() { + try { + launchEmbeddedBroker(); + } catch (Exception e) { + throw Throwables.propagate(e); + } + activeMQConnectionFactory = createActiveMQConnectionFactory(createBlobTransferPolicy()); + } + + public ConnectionFactory getConnectionFactory() { + return activeMQConnectionFactory; + } + + @PreDestroy + public void stop() throws Exception { + brokerService.stop(); + } + + private ActiveMQConnectionFactory createActiveMQConnectionFactory(BlobTransferPolicy blobTransferPolicy) { + ActiveMQConnectionFactory connectionFactory = new ActiveMQConnectionFactory("vm://james?create=false"); + connectionFactory.setBlobTransferPolicy(blobTransferPolicy); + connectionFactory.setPrefetchPolicy(createActiveMQPrefetchPolicy()); + return connectionFactory; + } + + private ActiveMQPrefetchPolicy createActiveMQPrefetchPolicy() { + ActiveMQPrefetchPolicy prefetchPolicy = new ActiveMQPrefetchPolicy(); + prefetchPolicy.setQueuePrefetch(0); + prefetchPolicy.setTopicPrefetch(0); + return prefetchPolicy; + } + + private BlobTransferPolicy createBlobTransferPolicy() { + BlobTransferPolicy blobTransferPolicy = new FileSystemBlobTransferPolicy(); + blobTransferPolicy.setDefaultUploadUrl("file://var/store/activemq/blob-transfer"); + return blobTransferPolicy; + } + + private void launchEmbeddedBroker() throws Exception { + brokerService = new BrokerService(); + brokerService.setBrokerName("james"); + brokerService.setUseJmx(false); + brokerService.setPersistent(true); + brokerService.setDataDirectory("filesystem=file://var/store/activemq/brokers"); + brokerService.setUseShutdownHook(false); + brokerService.setSchedulerSupport(false); + brokerService.setBrokerId("broker"); + String[] uris = {"tcp://localhost:0"}; + brokerService.setTransportConnectorURIs(uris); + ManagementContext managementContext = new ManagementContext(); + managementContext.setCreateConnector(false); + brokerService.setManagementContext(managementContext); + brokerService.setPersistenceAdapter(new AMQPersistenceAdapter()); + BrokerPlugin[] brokerPlugins = {new StatisticsBrokerPlugin()}; + brokerService.setPlugins(brokerPlugins); + String[] transportConnectorsURIs = {"tcp://localhost:0"}; + brokerService.setTransportConnectorURIs(transportConnectorsURIs); + brokerService.start(); + System.out.println("Started : " + brokerService.isStarted()); + } +} From 671bf2ac6a0a2372456e655c16df668bc97f1cf4 Mon Sep 17 00:00:00 2001 From: benwa Date: Thu, 27 Aug 2015 15:43:32 +0200 Subject: [PATCH 12/39] JAMES-1626 Implement an HierarchicalConfiguration reader for guice use --- .../utils/ClassPathConfigurationProvider.java | 65 +++++++++++++ .../ClassPathConfigurationProviderTest.java | 97 +++++++++++++++++++ .../src/test/resources/test.xml | 28 ++++++ 3 files changed, 190 insertions(+) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/ClassPathConfigurationProvider.java create mode 100644 server/container/cassandra-guice/src/test/java/org/apache/james/utils/ClassPathConfigurationProviderTest.java create mode 100644 server/container/cassandra-guice/src/test/resources/test.xml diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ClassPathConfigurationProvider.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ClassPathConfigurationProvider.java new file mode 100644 index 00000000000..972131be16f --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ClassPathConfigurationProvider.java @@ -0,0 +1,65 @@ +/**************************************************************** + * 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 com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.commons.configuration.XMLConfiguration; + +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; +import java.util.Optional; + +public class ClassPathConfigurationProvider { + + private static final String CONFIGURATION_FILE_SUFFIX = ".xml"; + + public HierarchicalConfiguration getConfiguration(String component) throws ConfigurationException { + List configPathParts = Arrays.asList(component.split("\\.")); + HierarchicalConfiguration config = getConfig(retrieveConfigInputStream(configPathParts.get(0))); + return selectHierarchicalConfigPart(config, configPathParts.subList(1, configPathParts.size())); + } + + private InputStream retrieveConfigInputStream(String configurationFileWithoutExtension) throws ConfigurationException { + Preconditions.checkArgument(!Strings.isNullOrEmpty(configurationFileWithoutExtension), "The configuration file name should not be empty or null"); + return Optional.ofNullable(ClassLoader.getSystemResourceAsStream(configurationFileWithoutExtension + CONFIGURATION_FILE_SUFFIX)) + .orElseThrow(() -> new ConfigurationException("Unable to locate configuration file " + configurationFileWithoutExtension + CONFIGURATION_FILE_SUFFIX)); + } + + private XMLConfiguration getConfig(InputStream configStream) throws ConfigurationException { + XMLConfiguration config = new XMLConfiguration(); + config.setDelimiterParsingDisabled(true); + config.setAttributeSplittingDisabled(true); + config.load(configStream); + return config; + } + + private HierarchicalConfiguration selectHierarchicalConfigPart(HierarchicalConfiguration config, List configsPathParts) { + HierarchicalConfiguration currentConfig = config; + for (String nextPathPart : configsPathParts) { + currentConfig = currentConfig.configurationAt(nextPathPart); + } + return currentConfig; + } + +} diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/ClassPathConfigurationProviderTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/ClassPathConfigurationProviderTest.java new file mode 100644 index 00000000000..4cc4347cd07 --- /dev/null +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/ClassPathConfigurationProviderTest.java @@ -0,0 +1,97 @@ +/**************************************************************** + * 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 static org.assertj.core.api.Assertions.assertThat; + +import com.google.common.collect.Lists; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.junit.Before; +import org.junit.Test; + +public class ClassPathConfigurationProviderTest { + + private static final String CONFIG_KEY_1 = "test2"; + private static final String CONFIG_KEY_2 = "property"; + private static final String CONFIG_KEY_3 = "test2"; + private static final String CONFIG_KEY_4 = "james"; + private static final String CONFIG_KEY_5 = "internal"; + private static final String VALUE_1 = "0"; + private static final String VALUE_2 = "awesome"; + private static final String FAKE_CONFIG_KEY = "fake"; + private static final String ROOT_CONFIG_KEY = "test"; + private static final String CONFIG_SEPARATOR = "."; + + private ClassPathConfigurationProvider configurationProvider; + + @Before + public void setUp() { + configurationProvider = new ClassPathConfigurationProvider(); + } + + @Test(expected = IllegalArgumentException.class) + public void emptyFileNameShouldThrow() throws Exception { + configurationProvider.getConfiguration(CONFIG_SEPARATOR + ROOT_CONFIG_KEY); + } + + @Test + public void getConfigurationShouldLoadCorrespondingXMLFile() throws Exception { + HierarchicalConfiguration hierarchicalConfiguration = configurationProvider.getConfiguration(ROOT_CONFIG_KEY); + assertThat(Lists.newArrayList(hierarchicalConfiguration.getKeys())).containsOnly(CONFIG_KEY_1, + CONFIG_KEY_4 + CONFIG_SEPARATOR + CONFIG_KEY_2, + CONFIG_KEY_4 + CONFIG_SEPARATOR + CONFIG_KEY_5 + CONFIG_SEPARATOR + CONFIG_KEY_2); + assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_3)).isEqualTo(VALUE_1); + } + + @Test + public void getConfigurationShouldLoadCorrespondingXMLFilePart() throws Exception { + HierarchicalConfiguration hierarchicalConfiguration = configurationProvider.getConfiguration(ROOT_CONFIG_KEY + CONFIG_SEPARATOR + CONFIG_KEY_4); + assertThat(Lists.newArrayList(hierarchicalConfiguration.getKeys())).containsOnly(CONFIG_KEY_2, + "internal" + CONFIG_SEPARATOR + CONFIG_KEY_2); + assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_2)).isEqualTo(VALUE_2); + } + + @Test + public void getConfigurationShouldLoadCorrespondingXMLFileWhenAPathIsProvidedPart() throws Exception { + HierarchicalConfiguration hierarchicalConfiguration = configurationProvider.getConfiguration(ROOT_CONFIG_KEY + CONFIG_SEPARATOR + CONFIG_KEY_4 + CONFIG_SEPARATOR + "internal"); + assertThat(Lists.newArrayList(hierarchicalConfiguration.getKeys())).containsOnly(CONFIG_KEY_2); + assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_2)).isEqualTo("james"); + } + + @Test + public void multiplesSeparatorsShouldBeTolerated() throws Exception { + HierarchicalConfiguration hierarchicalConfiguration = configurationProvider.getConfiguration(ROOT_CONFIG_KEY + CONFIG_SEPARATOR + CONFIG_SEPARATOR + CONFIG_KEY_4); + assertThat(Lists.newArrayList(hierarchicalConfiguration.getKeys())).containsOnly(CONFIG_KEY_2, + "internal" + CONFIG_SEPARATOR + CONFIG_KEY_2); + assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_2)).isEqualTo(VALUE_2); + } + + @Test(expected = ConfigurationException.class) + public void getConfigurationShouldThrowOnNonExistingXMLFile() throws Exception { + assertThat(configurationProvider.getConfiguration(FAKE_CONFIG_KEY)).isNotNull(); + } + + @Test(expected = IllegalArgumentException.class) + public void getConfigurationShouldThrowOnNonExistingXMLFilePart() throws Exception { + configurationProvider.getConfiguration(ROOT_CONFIG_KEY + CONFIG_SEPARATOR + FAKE_CONFIG_KEY); + } + +} diff --git a/server/container/cassandra-guice/src/test/resources/test.xml b/server/container/cassandra-guice/src/test/resources/test.xml new file mode 100644 index 00000000000..8d89ecc444b --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/test.xml @@ -0,0 +1,28 @@ + + + + 0 + + awesome + + james + + + \ No newline at end of file From 2b1e16f81086e4a2f24181a167cdfb2f138fba1c Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Thu, 22 Oct 2015 14:19:35 +0200 Subject: [PATCH 13/39] JAMES-1626 support IMAP, SMTP, POP and LMTP protocols in cassandra-guice application --- .../james/CassandraJamesServerMain.java | 16 ++- .../mailbox/CassandraMailboxModule.java | 4 +- .../modules/protocols/IMAPServerModule.java | 103 +++++++++++++++++ .../modules/protocols/LMTPServerModule.java | 61 ++++++++++ .../modules/protocols/POP3ServerModule.java | 61 ++++++++++ .../protocols/ProtocolHandlerModule.java | 37 ++++++ .../modules/protocols/SMTPServerModule.java | 68 ++++++++++++ .../modules/server/FileSystemModule.java | 36 ++++++ .../james/modules/server/QuotaModule.java | 37 ++++++ .../utils/GuiceProtocolHandlerLoader.java | 59 ++++++++++ .../james/CassandraJamesServerTest.java | 60 +++++++--- .../src/test/resources/imapserver.xml | 54 +++++++++ .../src/test/resources/lmtpserver.xml | 41 +++++++ .../src/test/resources/pop3server.xml | 42 +++++++ .../src/test/resources/smtpserver.xml | 105 ++++++++++++++++++ .../james/core/filesystem/FileSystemImpl.java | 3 + 16 files changed, 771 insertions(+), 16 deletions(-) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/QuotaModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceProtocolHandlerLoader.java create mode 100644 server/container/cassandra-guice/src/test/resources/imapserver.xml create mode 100644 server/container/cassandra-guice/src/test/resources/lmtpserver.xml create mode 100644 server/container/cassandra-guice/src/test/resources/pop3server.xml create mode 100644 server/container/cassandra-guice/src/test/resources/smtpserver.xml diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java index fb5b40204e7..a6a069f9a59 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java @@ -25,9 +25,16 @@ import org.apache.james.modules.mailbox.CassandraMailboxModule; import org.apache.james.modules.mailbox.CassandraSessionModule; import org.apache.james.modules.mailbox.ElasticSearchMailboxModule; +import org.apache.james.modules.protocols.IMAPServerModule; +import org.apache.james.modules.protocols.LMTPServerModule; +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.ActiveMQQueueModule; import org.apache.james.modules.server.ConfigurationPerformerModule; import org.apache.james.modules.server.DNSServiceModule; +import org.apache.james.modules.server.FileSystemModule; +import org.apache.james.modules.server.QuotaModule; import com.google.inject.Module; import com.google.inject.util.Modules; @@ -43,7 +50,14 @@ public class CassandraJamesServerMain { new CassandraDomainListModule(), new CassandraRecipientRewriteTableModule(), new DNSServiceModule(), - new ActiveMQQueueModule()); + new IMAPServerModule(), + new ProtocolHandlerModule(), + new POP3ServerModule(), + new SMTPServerModule(), + new LMTPServerModule(), + new ActiveMQQueueModule(), + new QuotaModule(), + new FileSystemModule()); public static void main(String[] args) throws Exception { CassandraJamesServer server = new CassandraJamesServer(defaultModule); diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java index 7d69c7dcab0..0c7073c12dd 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java @@ -34,6 +34,7 @@ import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex; import org.apache.james.mailbox.exception.MailboxException; 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.MessageMapperFactory; import org.apache.james.mailbox.store.mail.ModSeqProvider; @@ -56,7 +57,8 @@ protected void configure() { bind(SubscriptionManager.class).to(CassandraSubscriptionManager.class); bind(new TypeLiteral>(){}).to(CassandraMailboxSessionMapperFactory.class); - + bind(MailboxSessionMapperFactory.class).to(CassandraMailboxSessionMapperFactory.class); + bind(MailboxPathLocker.class).to(NoMailboxPathLocker.class); bind(Authenticator.class).to(UserRepositoryAuthenticator.class); diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java new file mode 100644 index 00000000000..176c5bbb3ce --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java @@ -0,0 +1,103 @@ +/**************************************************************** + * 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.protocols; + +import com.google.inject.Inject; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.name.Named; +import org.apache.james.imap.api.process.ImapProcessor; +import org.apache.james.imap.decode.ImapDecoder; +import org.apache.james.imap.encode.ImapEncoder; +import org.apache.james.imap.encode.main.DefaultImapEncoderFactory; +import org.apache.james.imap.main.DefaultImapDecoderFactory; +import org.apache.james.imap.processor.main.DefaultImapProcessorFactory; +import org.apache.james.imapserver.netty.IMAPServerFactory; +import org.apache.james.mailbox.MailboxManager; +import org.apache.james.mailbox.SubscriptionManager; +import org.apache.james.mailbox.quota.QuotaManager; +import org.apache.james.mailbox.quota.QuotaRootResolver; +import org.apache.james.modules.mailbox.CassandraMailboxModule; +import org.apache.james.utils.ClassPathConfigurationProvider; +import org.apache.james.utils.ConfigurationPerformer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.common.collect.ImmutableSet; +import com.google.inject.AbstractModule; + +public class IMAPServerModule extends AbstractModule { + + private static final Logger LOGGER = LoggerFactory.getLogger(IMAPServerModule.class); + + @Override + protected void configure() { + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(IMAPModuleConfigurationPerformer.class); + } + + @Provides + @Singleton + ImapProcessor provideImapProcessor( + @Named(CassandraMailboxModule.MAILBOXMANAGER_NAME)MailboxManager mailboxManager, + SubscriptionManager subscriptionManager, + QuotaManager quotaManager, + QuotaRootResolver quotaRootResolver) { + return DefaultImapProcessorFactory.createXListSupportingProcessor( + mailboxManager, + subscriptionManager, + null, + quotaManager, + quotaRootResolver, + 120, + ImmutableSet.of("ACL", "MOVE")); + } + + @Provides + @Singleton + ImapDecoder provideImapDecoder() { + return DefaultImapDecoderFactory.createDecoder(); + } + + @Provides + @Singleton + ImapEncoder provideImapEncoder() { + return new DefaultImapEncoderFactory().buildImapEncoder(); + } + + @Singleton + public static class IMAPModuleConfigurationPerformer implements ConfigurationPerformer { + + private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final IMAPServerFactory imapServerFactory; + + @Inject + public IMAPModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, IMAPServerFactory imapServerFactory) { + this.classPathConfigurationProvider = classPathConfigurationProvider; + this.imapServerFactory = imapServerFactory; + } + + @Override + public void initModule() throws Exception { + imapServerFactory.setLog(LOGGER); + imapServerFactory.configure(classPathConfigurationProvider.getConfiguration("imapserver")); + imapServerFactory.init(); + } + } +} \ No newline at end of file diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java new file mode 100644 index 00000000000..7d48341efe6 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.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.modules.protocols; + +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import org.apache.james.lmtpserver.netty.LMTPServerFactory; +import org.apache.james.utils.ClassPathConfigurationProvider; +import org.apache.james.utils.ConfigurationPerformer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class LMTPServerModule extends AbstractModule { + + private static final Logger LOGGER = LoggerFactory.getLogger(LMTPServerModule.class); + + @Override + protected void configure() { + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(LMTPModuleConfigurationPerformer.class); + } + + @Singleton + public static class LMTPModuleConfigurationPerformer implements ConfigurationPerformer { + + private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final LMTPServerFactory lmtpServerFactory; + + @Inject + public LMTPModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, LMTPServerFactory lmtpServerFactory) { + this.classPathConfigurationProvider = classPathConfigurationProvider; + this.lmtpServerFactory = lmtpServerFactory; + } + + @Override + public void initModule() throws Exception { + lmtpServerFactory.setLog(LOGGER); + lmtpServerFactory.configure(classPathConfigurationProvider.getConfiguration("lmtpserver")); + lmtpServerFactory.init(); + } + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java new file mode 100644 index 00000000000..879d196761d --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.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.modules.protocols; + +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import org.apache.james.pop3server.netty.POP3ServerFactory; +import org.apache.james.utils.ClassPathConfigurationProvider; +import org.apache.james.utils.ConfigurationPerformer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class POP3ServerModule extends AbstractModule { + + private static final Logger LOGGER = LoggerFactory.getLogger(POP3ServerModule.class); + + @Override + protected void configure() { + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(POP3ModuleConfigurationPerformer.class); + } + + @Singleton + public static class POP3ModuleConfigurationPerformer implements ConfigurationPerformer { + + private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final POP3ServerFactory pop3ServerFactory; + + @Inject + public POP3ModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, POP3ServerFactory pop3ServerFactory) { + this.classPathConfigurationProvider = classPathConfigurationProvider; + this.pop3ServerFactory = pop3ServerFactory; + } + + @Override + public void initModule() throws Exception { + pop3ServerFactory.setLog(LOGGER); + pop3ServerFactory.configure(classPathConfigurationProvider.getConfiguration("pop3server")); + pop3ServerFactory.init(); + } + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java new file mode 100644 index 00000000000..2b012a33452 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java @@ -0,0 +1,37 @@ +/**************************************************************** + * 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.protocols; + +import org.apache.james.core.filesystem.FileSystemImpl; +import org.apache.james.filesystem.api.FileSystem; +import org.apache.james.protocols.lib.handler.ProtocolHandlerLoader; +import org.apache.james.utils.GuiceProtocolHandlerLoader; + +import com.google.inject.AbstractModule; + +public class ProtocolHandlerModule extends AbstractModule { + + @Override + protected void configure() { + bind(FileSystem.class).to(FileSystemImpl.class); + bind(ProtocolHandlerLoader.class).to(GuiceProtocolHandlerLoader.class); + } + +} \ No newline at end of file diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java new file mode 100644 index 00000000000..5c7b6c9cb7b --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java @@ -0,0 +1,68 @@ +/**************************************************************** + * 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.protocols; + +import org.apache.james.smtpserver.SendMailHandler; +import org.apache.james.smtpserver.netty.SMTPServerFactory; +import org.apache.james.utils.ClassPathConfigurationProvider; +import org.apache.james.utils.ConfigurationPerformer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; + +public class SMTPServerModule extends AbstractModule { + + private static final Logger LOGGER = LoggerFactory.getLogger(SMTPServerModule.class); + + @Override + protected void configure() { + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(SMTPModuleConfigurationPerformer.class); + } + + @Singleton + public static class SMTPModuleConfigurationPerformer implements ConfigurationPerformer { + + private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final SMTPServerFactory smtpServerFactory; + private final SendMailHandler sendMailHandler; + + @Inject + public SMTPModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, + SMTPServerFactory smtpServerFactory, + SendMailHandler sendMailHandler) { + this.classPathConfigurationProvider = classPathConfigurationProvider; + this.smtpServerFactory = smtpServerFactory; + this.sendMailHandler = sendMailHandler; + } + + @Override + public void initModule() throws Exception { + smtpServerFactory.setLog(LOGGER); + smtpServerFactory.configure(classPathConfigurationProvider.getConfiguration("smtpserver")); + smtpServerFactory.init(); + sendMailHandler.init(null); + } + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java new file mode 100644 index 00000000000..bd85c798acd --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java @@ -0,0 +1,36 @@ +/**************************************************************** + * 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.server; + +import org.apache.james.core.JamesServerResourceLoader; +import org.apache.james.core.filesystem.FileSystemImpl; +import org.apache.james.filesystem.api.FileSystem; +import org.apache.james.filesystem.api.JamesDirectoriesProvider; + +import com.google.inject.AbstractModule; + +public class FileSystemModule extends AbstractModule { + + @Override + public void configure() { + bind(JamesDirectoriesProvider.class).to(JamesServerResourceLoader.class); + bind(FileSystem.class).to(FileSystemImpl.class); + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/QuotaModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/QuotaModule.java new file mode 100644 index 00000000000..3901efff055 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/QuotaModule.java @@ -0,0 +1,37 @@ +/**************************************************************** + * 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.server; + +import org.apache.james.mailbox.quota.QuotaManager; +import org.apache.james.mailbox.quota.QuotaRootResolver; +import org.apache.james.mailbox.store.quota.DefaultQuotaRootResolver; +import org.apache.james.mailbox.store.quota.NoQuotaManager; + +import com.google.inject.AbstractModule; + +public class QuotaModule extends AbstractModule { + + @Override + protected void configure() { + bind(QuotaManager.class).to(NoQuotaManager.class); + bind(QuotaRootResolver.class).to(DefaultQuotaRootResolver.class); + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceProtocolHandlerLoader.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceProtocolHandlerLoader.java new file mode 100644 index 00000000000..8b5b0cae3cc --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceProtocolHandlerLoader.java @@ -0,0 +1,59 @@ +/**************************************************************** + * 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 com.google.common.base.Throwables; +import com.google.inject.Inject; +import com.google.inject.Injector; +import org.apache.commons.configuration.Configuration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.james.protocols.api.handler.ProtocolHandler; +import org.apache.james.protocols.lib.handler.ProtocolHandlerLoader; + +public class GuiceProtocolHandlerLoader implements ProtocolHandlerLoader { + + private final Injector injector; + + @Inject + public GuiceProtocolHandlerLoader(Injector injector) { + this.injector = injector; + } + + @Override + public ProtocolHandler load(String name, Configuration config) throws LoadingException { + ProtocolHandler handler = createProtocolHandler(name); + try { + handler.init(config); + } catch (ConfigurationException e) { + throw Throwables.propagate(e); + } + return handler; + } + + private ProtocolHandler createProtocolHandler(String name) throws LoadingException { + try { + Class clazz = (Class) ClassLoader.getSystemClassLoader().loadClass(name); + return injector.getInstance(clazz); + } catch (ClassNotFoundException e) { + throw new LoadingException("Can not load " + name); + } + } + +} diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java index 37e739584c4..1af2cf9060b 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java @@ -18,12 +18,13 @@ ****************************************************************/ package org.apache.james; -import java.util.Properties; +import static org.assertj.core.api.Assertions.assertThat; -import javax.mail.AuthenticationFailedException; -import javax.mail.NoSuchProviderException; -import javax.mail.Session; -import javax.mail.Store; +import java.io.IOException; +import java.net.InetSocketAddress; +import java.nio.ByteBuffer; +import java.nio.channels.SocketChannel; +import java.nio.charset.Charset; import org.apache.james.backends.cassandra.CassandraCluster; import org.apache.james.backends.cassandra.components.CassandraModule; @@ -44,10 +45,16 @@ public class CassandraJamesServerTest { 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; + public static final int BUFFER_SIZE = 1000; private CassandraJamesServer server; private TemporaryFolder temporaryFolder = new TemporaryFolder(); private EmbeddedElasticSearch embeddedElasticSearch = new EmbeddedElasticSearch(temporaryFolder); + private SocketChannel socketChannel; @Rule public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch); @@ -70,6 +77,7 @@ com.datastax.driver.core.Session provideSession(CassandraModule cassandraModule) } })); + socketChannel = SocketChannel.open(); server.start(); } @@ -78,17 +86,41 @@ public void tearDown() throws Exception { server.stop(); } - @Test (expected = AuthenticationFailedException.class) + @Test public void connectIMAPServerShouldThrowWhenNoCredentials() throws Exception { - store().connect(); + socketChannel.connect(new InetSocketAddress("127.0.0.1", IMAP_PORT)); + assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server"); } - private Store store() throws NoSuchProviderException { - Properties properties = new Properties(); - properties.put("mail.imap.host", "localhost"); - properties.put("mail.imap.port", String.valueOf(IMAP_PORT)); - Session session = Session.getDefaultInstance(properties); - session.setDebug(true); - return session.getStore("imap"); + @Test + public void connectOnSecondaryIMAPServerIMAPServerShouldThrowWhenNoCredentials() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", IMAP_PORT_SSL)); + assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server"); } + + @Test + public void connectPOP3ServerShouldThrowWhenNoCredentials() 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 connectSMTPServerShouldNotThrowWhenNoCredentials() 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 connectLMTPServerShouldNotThrowWhenNoCredentials() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", LMTP_PORT)); + assertThat(getServerConnectionResponse(socketChannel)).contains("LMTP Server (JAMES Protocols Server) ready"); + } + + 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")); + } + } diff --git a/server/container/cassandra-guice/src/test/resources/imapserver.xml b/server/container/cassandra-guice/src/test/resources/imapserver.xml new file mode 100644 index 00000000000..ff478a9cd70 --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/imapserver.xml @@ -0,0 +1,54 @@ + + + + + + + + imapserver + 0.0.0.0:1143 + 200 + + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + + 0 + 0 + + + imapserver-ssl + 0.0.0.0:1993 + 200 + + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + + 0 + 0 + + diff --git a/server/container/cassandra-guice/src/test/resources/lmtpserver.xml b/server/container/cassandra-guice/src/test/resources/lmtpserver.xml new file mode 100644 index 00000000000..5c4a9c74ce8 --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/lmtpserver.xml @@ -0,0 +1,41 @@ + + + + + + + lmtpserver + + 127.0.0.1:1024 + 200 + 1200 + + 0 + + 0 + + + 0 + + + + + + diff --git a/server/container/cassandra-guice/src/test/resources/pop3server.xml b/server/container/cassandra-guice/src/test/resources/pop3server.xml new file mode 100644 index 00000000000..e4187da352b --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/pop3server.xml @@ -0,0 +1,42 @@ + + + + + + + pop3server + 0.0.0.0:1110 + 200 + + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + + 1200 + 0 + 0 + + + + + diff --git a/server/container/cassandra-guice/src/test/resources/smtpserver.xml b/server/container/cassandra-guice/src/test/resources/smtpserver.xml new file mode 100644 index 00000000000..a3d4b8f05a0 --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/smtpserver.xml @@ -0,0 +1,105 @@ + + + + + + + smtpserver-global + 0.0.0.0:1025 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + false + 0.0.0.0/0 + true + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + smtpserver-TLS + 0.0.0.0:10465 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + + true + 0.0.0.0/0 + + false + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + smtpserver-authenticated + 0.0.0.0:1587 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + + true + 0.0.0.0/0 + + false + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + + diff --git a/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java b/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java index 012b6fdcaa5..b4dfadc0536 100644 --- a/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java +++ b/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java @@ -23,6 +23,8 @@ import java.io.IOException; import java.io.InputStream; +import javax.inject.Inject; + import org.apache.james.filesystem.api.FileSystem; import org.apache.james.filesystem.api.JamesDirectoriesProvider; @@ -31,6 +33,7 @@ public class FileSystemImpl implements FileSystem { private final JamesDirectoriesProvider directoryProvider; private final ResourceFactory resourceLoader; + @Inject public FileSystemImpl(JamesDirectoriesProvider directoryProvider) { this.directoryProvider = directoryProvider; this.resourceLoader = new ResourceFactory(directoryProvider); From 91caf381fa160293e5ab8ba57f426d700e157348 Mon Sep 17 00:00:00 2001 From: benwa Date: Mon, 31 Aug 2015 15:30:27 +0200 Subject: [PATCH 14/39] JAMES-1626 Implement a guice MailboxManagerResolver --- .../utils/GuiceMailboxManagerResolver.java | 59 +++++++++++++++++++ .../james/utils/MailboxManagerDefinition.java | 57 ++++++++++++++++++ .../MailboxManagerResolverException.java | 8 +++ 3 files changed, 124 insertions(+) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/MailboxManagerDefinition.java diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java new file mode 100644 index 00000000000..d87b3c36d0c --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMailboxManagerResolver.java @@ -0,0 +1,59 @@ +/**************************************************************** + * 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.util.Map; +import java.util.Optional; +import java.util.Set; +import java.util.stream.Collectors; + +import org.apache.james.adapter.mailbox.MailboxManagerResolver; +import org.apache.james.adapter.mailbox.MailboxManagerResolverException; +import org.apache.james.mailbox.MailboxManager; + +import com.google.common.collect.ImmutableMap; +import com.google.inject.Inject; + +public class GuiceMailboxManagerResolver implements MailboxManagerResolver { + + private ImmutableMap managers; + + @Inject + private GuiceMailboxManagerResolver(Set managers) { + this.managers = indexManagersByName(managers); + } + + private static ImmutableMap indexManagersByName(Set managers) { + return ImmutableMap.copyOf(managers.stream().collect( + Collectors.toMap(MailboxManagerDefinition::getName, MailboxManagerDefinition::getManager))); + } + + @Override + public Map getMailboxManagerBeans() { + return managers; + } + + @Override + public MailboxManager resolveMailboxManager(String mailboxManagerClassName) { + return Optional.ofNullable(managers.get(mailboxManagerClassName)).orElseThrow( + () -> new MailboxManagerResolverException("Unable to find a mailbox manager with name " + mailboxManagerClassName)); + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/MailboxManagerDefinition.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/MailboxManagerDefinition.java new file mode 100644 index 00000000000..211398a2cf0 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/MailboxManagerDefinition.java @@ -0,0 +1,57 @@ +/**************************************************************** + * 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 org.apache.james.mailbox.MailboxManager; + +import com.google.common.base.Objects; + +public class MailboxManagerDefinition { + + private final String name; + private final MailboxManager manager; + + public MailboxManagerDefinition(String name, MailboxManager manager) { + this.name = name; + this.manager = manager; + } + + public MailboxManager getManager() { + return manager; + } + + public String getName() { + return name; + } + + @Override + public int hashCode() { + return Objects.hashCode(name, manager); + } + + @Override + public boolean equals(Object obj) { + if (obj instanceof MailboxManagerDefinition) { + MailboxManagerDefinition other = (MailboxManagerDefinition) obj; + return Objects.equal(name, other.name) && Objects.equal(manager, other.manager); + } + return false; + } +} \ No newline at end of file diff --git a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java index 80cf7d80f98..d80f3caaf80 100644 --- a/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java +++ b/server/container/mailbox-adapter/src/main/java/org/apache/james/adapter/mailbox/MailboxManagerResolverException.java @@ -20,8 +20,16 @@ public class MailboxManagerResolverException extends RuntimeException { + public MailboxManagerResolverException() { + super(); + } + public MailboxManagerResolverException(Throwable cause) { super(cause); } + public MailboxManagerResolverException(String message) { + super(message); + } + } \ No newline at end of file From 8fd3700c14ae31704760a6ab7bd278ae80b5857a Mon Sep 17 00:00:00 2001 From: benwa Date: Tue, 25 Aug 2015 17:17:51 +0200 Subject: [PATCH 15/39] JAMES-1626 Add JMX support to cassandra-guice application --- .../james/CassandraJamesServerMain.java | 5 +- .../james/modules/server/JMXServer.java | 118 ++++++++++++++++++ .../james/modules/server/JMXServerModule.java | 114 +++++++++++++++++ .../src/test/resources/jmx.properties | 28 +++++ .../java/org/apache/james/cli/ServerCmd.java | 1 + .../james/cli/probe/impl/JmxServerProbe.java | 12 +- 6 files changed, 271 insertions(+), 7 deletions(-) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServer.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServerModule.java create mode 100644 server/container/cassandra-guice/src/test/resources/jmx.properties diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java index a6a069f9a59..458d77acbd7 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java @@ -34,6 +34,7 @@ import org.apache.james.modules.server.ConfigurationPerformerModule; import org.apache.james.modules.server.DNSServiceModule; import org.apache.james.modules.server.FileSystemModule; +import org.apache.james.modules.server.JMXServerModule; import org.apache.james.modules.server.QuotaModule; import com.google.inject.Module; @@ -60,7 +61,9 @@ public class CassandraJamesServerMain { new FileSystemModule()); public static void main(String[] args) throws Exception { - CassandraJamesServer server = new CassandraJamesServer(defaultModule); + CassandraJamesServer server = new CassandraJamesServer(Modules.combine( + defaultModule, + new JMXServerModule())); server.start(); } diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServer.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServer.java new file mode 100644 index 00000000000..db15ac5aebf --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServer.java @@ -0,0 +1,118 @@ +/**************************************************************** + * 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.server; + +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableMap; +import org.apache.james.util.RestrictingRMISocketFactory; +import org.apache.james.utils.PropertiesReader; + +import javax.annotation.PreDestroy; +import javax.management.MBeanServer; +import javax.management.ObjectName; +import javax.management.remote.JMXConnectorServer; +import javax.management.remote.JMXConnectorServerFactory; +import javax.management.remote.JMXServiceURL; +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.rmi.registry.LocateRegistry; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; + +public class JMXServer { + + private final Set registeredKeys; + private final Object lock; + private JMXConnectorServer jmxConnectorServer; + private boolean isStarted; + + public JMXServer() { + isStarted = false; + registeredKeys = new HashSet<>(); + lock = new Object(); + } + + public void start() { + synchronized (lock) { + if (isStarted) { + return; + } + isStarted = true; + doStart(); + } + } + + @PreDestroy + public void stop() { + synchronized (lock) { + if (!isStarted) { + return; + } + isStarted = false; + doStop(); + } + } + + public void register(String key, Object remote) throws Exception { + ManagementFactory.getPlatformMBeanServer().registerMBean(remote, new ObjectName(key)); + synchronized (lock) { + registeredKeys.add(key); + } + } + + private void doStart() { + PropertiesReader propertiesReader = new PropertiesReader("jmx.properties"); + String address = propertiesReader.getProperty("jmx.address"); + int port = Integer.parseInt(propertiesReader.getProperty("jmx.port")); + String serviceURL = "service:jmx:rmi://" + address + "/jndi/rmi://" + address+ ":" + port +"/jmxrmi"; + try { + RestrictingRMISocketFactory restrictingRMISocketFactory = new RestrictingRMISocketFactory(address); + LocateRegistry.createRegistry(port, restrictingRMISocketFactory, restrictingRMISocketFactory); + + Map environment = ImmutableMap.of(); + jmxConnectorServer = JMXConnectorServerFactory.newJMXConnectorServer(new JMXServiceURL(serviceURL), + environment, + ManagementFactory.getPlatformMBeanServer()); + + jmxConnectorServer.start(); + } catch (Exception e) { + throw Throwables.propagate(e); + } + } + + private void doStop() { + try { + MBeanServer mBeanServer = ManagementFactory.getPlatformMBeanServer(); + registeredKeys.forEach(key -> { + try { + mBeanServer.unregisterMBean(new ObjectName(key)); + } catch (Exception e) { + throw Throwables.propagate(e); + } + }); + registeredKeys.clear(); + jmxConnectorServer.stop(); + } catch (IOException e) { + throw Throwables.propagate(e); + } + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServerModule.java new file mode 100644 index 00000000000..019b546e9df --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServerModule.java @@ -0,0 +1,114 @@ +/**************************************************************** + * 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.server; + +import org.apache.james.adapter.mailbox.MailboxCopierManagement; +import org.apache.james.adapter.mailbox.MailboxCopierManagementMBean; +import org.apache.james.adapter.mailbox.MailboxManagerManagement; +import org.apache.james.adapter.mailbox.MailboxManagerManagementMBean; +import org.apache.james.adapter.mailbox.MailboxManagerResolver; +import org.apache.james.domainlist.api.DomainListManagementMBean; +import org.apache.james.domainlist.lib.DomainListManagement; +import org.apache.james.mailbox.cassandra.CassandraMailboxManager; +import org.apache.james.mailbox.copier.MailboxCopier; +import org.apache.james.mailbox.copier.MailboxCopierImpl; +import org.apache.james.mailetcontainer.api.jmx.MailSpoolerMBean; +import org.apache.james.mailetcontainer.impl.JamesMailSpooler; +import org.apache.james.rrt.api.RecipientRewriteTableManagementMBean; +import org.apache.james.rrt.lib.RecipientRewriteTableManagement; +import org.apache.james.user.api.UsersRepositoryManagementMBean; +import org.apache.james.user.lib.UsersRepositoryManagement; +import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.GuiceMailboxManagerResolver; +import org.apache.james.utils.MailboxManagerDefinition; + +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.name.Names; + +public class JMXServerModule extends AbstractModule { + + private static final String JMX_COMPONENT_DOMAINLIST = "org.apache.james:type=component,name=domainlist"; + private static final String JMX_COMPONENT_USERS_REPOSITORY = "org.apache.james:type=component,name=usersrepository"; + private static final String JMX_COMPONENT_RECIPIENTREWRITETABLE = "org.apache.james:type=component,name=recipientrewritetable"; + private static final String JMX_COMPONENT_NAME_MAILBOXMANAGERBEAN = "org.apache.james:type=component,name=mailboxmanagerbean"; + private static final String JMX_COMPONENT_MAILBOXCOPIER = "org.apache.james:type=component,name=mailboxcopier"; + + @Override + protected void configure() { + bind(MailboxCopier.class).annotatedWith(Names.named("mailboxcopier")).to(MailboxCopierImpl.class); + bind(MailboxCopierManagementMBean.class).to(MailboxCopierManagement.class); + bind(MailboxManagerResolver.class).to(GuiceMailboxManagerResolver.class); + bind(DomainListManagementMBean.class).to(DomainListManagement.class); + bind(UsersRepositoryManagementMBean.class).to(UsersRepositoryManagement.class); + bind(MailboxManagerManagementMBean.class).to(MailboxManagerManagement.class); + bind(RecipientRewriteTableManagementMBean.class).to(RecipientRewriteTableManagement.class); + bind(MailSpoolerMBean.class).to(JamesMailSpooler.class); + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(JMXModuleConfigurationPerformer.class); + Multibinder.newSetBinder(binder(), MailboxManagerDefinition.class).addBinding().to(CassandraMailboxManagerDefinition.class); + } + + @Singleton + private static class CassandraMailboxManagerDefinition extends MailboxManagerDefinition { + @Inject + private CassandraMailboxManagerDefinition(CassandraMailboxManager manager) { + super("cassandra-mailboxmanager", manager); + } + } + + @Singleton + public static class JMXModuleConfigurationPerformer implements ConfigurationPerformer { + + private final JMXServer jmxServer; + private final DomainListManagementMBean domainListManagementMBean; + private final UsersRepositoryManagementMBean usersRepositoryManagementMBean; + private final RecipientRewriteTableManagementMBean recipientRewriteTableManagementMBean; + private final MailboxManagerManagementMBean mailboxManagerManagementMBean; + private final MailboxCopierManagementMBean mailboxCopierManagementMBean; + + @Inject + public JMXModuleConfigurationPerformer(JMXServer jmxServer, + DomainListManagementMBean domainListManagementMBean, + UsersRepositoryManagementMBean usersRepositoryManagementMBean, + RecipientRewriteTableManagementMBean recipientRewriteTableManagementMBean, + MailboxManagerManagementMBean mailboxManagerManagementMBean, + MailboxCopierManagementMBean mailboxCopierManagementMBean) { + this.jmxServer = jmxServer; + this.domainListManagementMBean = domainListManagementMBean; + this.usersRepositoryManagementMBean = usersRepositoryManagementMBean; + this.recipientRewriteTableManagementMBean = recipientRewriteTableManagementMBean; + this.mailboxManagerManagementMBean = mailboxManagerManagementMBean; + this.mailboxCopierManagementMBean = mailboxCopierManagementMBean; + } + + @Override + public void initModule() throws Exception { + jmxServer.start(); + jmxServer.register(JMX_COMPONENT_DOMAINLIST, domainListManagementMBean); + jmxServer.register(JMX_COMPONENT_USERS_REPOSITORY, usersRepositoryManagementMBean); + jmxServer.register(JMX_COMPONENT_RECIPIENTREWRITETABLE, recipientRewriteTableManagementMBean); + jmxServer.register(JMX_COMPONENT_NAME_MAILBOXMANAGERBEAN, mailboxManagerManagementMBean); + jmxServer.register(JMX_COMPONENT_MAILBOXCOPIER, mailboxCopierManagementMBean); + } + } + +} diff --git a/server/container/cassandra-guice/src/test/resources/jmx.properties b/server/container/cassandra-guice/src/test/resources/jmx.properties new file mode 100644 index 00000000000..a1dbdf8924b --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/jmx.properties @@ -0,0 +1,28 @@ +# 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 + +# 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 + +jmx.address=127.0.0.1 +jmx.port=9999 diff --git a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java index 42d0f4a424c..b50df81b1f9 100644 --- a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java +++ b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java @@ -103,6 +103,7 @@ public static void main(String[] args) { failWithMessage("Error connecting to remote JMX agent : " + ioe.getMessage()); } catch (Exception e) { failWithMessage("Error while executing command:" + e.getMessage()); + e.printStackTrace(); } } diff --git a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java index cdb77f49357..fedbb071362 100644 --- a/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java +++ b/server/container/cli/src/main/java/org/apache/james/cli/probe/impl/JmxServerProbe.java @@ -44,12 +44,12 @@ public class JmxServerProbe implements ServerProbe { // TODO: Move this to somewhere else - private final static String DOMAINLIST_OBJECT_NAME = "org.apache.james:type=component,name=domainlist"; - private final static String VIRTUALUSERTABLE_OBJECT_NAME = "org.apache.james:type=component,name=recipientrewritetable"; - private final static String USERSREPOSITORY_OBJECT_NAME = "org.apache.james:type=component,name=usersrepository"; - private final static String MAILBOXCOPIER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxcopier"; - private final static String MAILBOXMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxmanagerbean"; - private final static String QUOTAMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=quotamanagerbean"; + public final static String DOMAINLIST_OBJECT_NAME = "org.apache.james:type=component,name=domainlist"; + public final static String VIRTUALUSERTABLE_OBJECT_NAME = "org.apache.james:type=component,name=recipientrewritetable"; + public final static String USERSREPOSITORY_OBJECT_NAME = "org.apache.james:type=component,name=usersrepository"; + public final static String MAILBOXCOPIER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxcopier"; + public final static String MAILBOXMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=mailboxmanagerbean"; + public final static String QUOTAMANAGER_OBJECT_NAME = "org.apache.james:type=component,name=quotamanagerbean"; private JMXConnector jmxc; From 4170732b3de5406272ce88a1eabdb6a72b94c514 Mon Sep 17 00:00:00 2001 From: benwa Date: Thu, 27 Aug 2015 16:14:58 +0200 Subject: [PATCH 16/39] JAMES-1626 Implement an InMemory MailRepository --- .../james/CassandraJamesServerMain.java | 4 +- .../server/MailStoreRepositoryModule.java | 87 ++++++++++ .../utils/InMemoryMailRepositoryStore.java | 158 ++++++++++++++++++ .../james/utils/MailRepositoryProvider.java | 29 ++++ .../InMemoryMailRepositoryStoreTest.java | 106 ++++++++++++ .../resources/fakemailrepositorystore.xml | 31 ++++ .../test/resources/mailrepositorystore.xml | 31 ++++ 7 files changed, 445 insertions(+), 1 deletion(-) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/InMemoryMailRepositoryStore.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/MailRepositoryProvider.java create mode 100644 server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java create mode 100644 server/container/cassandra-guice/src/test/resources/fakemailrepositorystore.xml create mode 100644 server/container/cassandra-guice/src/test/resources/mailrepositorystore.xml diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java index 458d77acbd7..7419e51ebf0 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java @@ -35,6 +35,7 @@ import org.apache.james.modules.server.DNSServiceModule; import org.apache.james.modules.server.FileSystemModule; import org.apache.james.modules.server.JMXServerModule; +import org.apache.james.modules.server.MailStoreRepositoryModule; import org.apache.james.modules.server.QuotaModule; import com.google.inject.Module; @@ -58,7 +59,8 @@ public class CassandraJamesServerMain { new LMTPServerModule(), new ActiveMQQueueModule(), new QuotaModule(), - new FileSystemModule()); + new FileSystemModule(), + new MailStoreRepositoryModule()); public static void main(String[] args) throws Exception { CassandraJamesServer server = new CassandraJamesServer(Modules.combine( diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java new file mode 100644 index 00000000000..a699938aa7e --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java @@ -0,0 +1,87 @@ +/**************************************************************** + * 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.server; + +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import org.apache.james.filesystem.api.FileSystem; +import org.apache.james.mailrepository.api.MailRepository; +import org.apache.james.mailrepository.api.MailRepositoryStore; +import org.apache.james.mailrepository.file.FileMailRepository; +import org.apache.james.utils.ClassPathConfigurationProvider; +import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.InMemoryMailRepositoryStore; +import org.apache.james.utils.MailRepositoryProvider; + +public class MailStoreRepositoryModule extends AbstractModule { + + @Override + protected void configure() { + bind(MailRepositoryStore.class).to(InMemoryMailRepositoryStore.class); + Multibinder multibinder = Multibinder.newSetBinder(binder(), MailRepositoryProvider.class); + multibinder.addBinding().to(FileMailRepositoryProvider.class); + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(MailRepositoryStoreModuleConfigurationPerformer.class); + } + + public static class FileMailRepositoryProvider implements MailRepositoryProvider { + + private final FileSystem fileSystem; + + @Inject + public FileMailRepositoryProvider(FileSystem fileSystem) { + this.fileSystem = fileSystem; + } + + @Override + public String canonicalName() { + return FileMailRepository.class.getCanonicalName(); + } + + @Override + public MailRepository get() { + FileMailRepository fileMailRepository = new FileMailRepository(); + fileMailRepository.setFileSystem(fileSystem); + return fileMailRepository; + } + } + + @Singleton + public static class MailRepositoryStoreModuleConfigurationPerformer implements ConfigurationPerformer { + + private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final InMemoryMailRepositoryStore javaMailRepositoryStore; + + @Inject + public MailRepositoryStoreModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, + InMemoryMailRepositoryStore javaMailRepositoryStore) { + this.classPathConfigurationProvider = classPathConfigurationProvider; + this.javaMailRepositoryStore = javaMailRepositoryStore; + } + + @Override + public void initModule() throws Exception { + javaMailRepositoryStore.configure(classPathConfigurationProvider.getConfiguration("mailrepositorystore")); + javaMailRepositoryStore.init(); + } + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/InMemoryMailRepositoryStore.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/InMemoryMailRepositoryStore.java new file mode 100644 index 00000000000..16273800664 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/InMemoryMailRepositoryStore.java @@ -0,0 +1,158 @@ +/**************************************************************** + * 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 com.google.inject.Inject; +import org.apache.commons.configuration.CombinedConfiguration; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.DefaultConfigurationBuilder; +import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.james.lifecycle.api.Configurable; +import org.apache.james.lifecycle.api.LogEnabled; +import org.apache.james.mailrepository.api.MailRepository; +import org.apache.james.mailrepository.api.MailRepositoryStore; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +import javax.inject.Singleton; +import java.util.Set; +import java.util.Map; +import java.util.HashMap; +import java.util.List; +import java.util.concurrent.ConcurrentHashMap; +import java.util.concurrent.ConcurrentMap; +import java.util.stream.Collectors; + +@Singleton +public class InMemoryMailRepositoryStore implements MailRepositoryStore { + + private static final Logger LOGGER = LoggerFactory.getLogger(InMemoryMailRepositoryStore.class); + + private Set mailRepositories; + private ConcurrentMap destinationToRepositoryAssociations; + private Map protocolToRepositoryProvider; + private Map perProtocolMailRepositoryDefaultConfiguration; + private HierarchicalConfiguration configuration; + + @Inject + public InMemoryMailRepositoryStore(Set mailRepositories) { + this.mailRepositories = mailRepositories; + this.destinationToRepositoryAssociations = new ConcurrentHashMap<>(); + this.protocolToRepositoryProvider = new HashMap<>(); + this.perProtocolMailRepositoryDefaultConfiguration = new HashMap<>(); + } + + @Override + public List getUrls() { + return destinationToRepositoryAssociations.keySet() + .stream() + .collect(Collectors.toList()); + } + + public void configure(HierarchicalConfiguration configuration) throws ConfigurationException { + this.configuration = configuration; + } + + public void init() throws Exception { + LOGGER.info("JamesMailStore init... " + this); + List registeredClasses = configuration.configurationsAt("mailrepositories.mailrepository"); + for (HierarchicalConfiguration registeredClass : registeredClasses) { + readConfigurationEntry(registeredClass); + } + } + + @Override + public MailRepository select(String destination) throws MailRepositoryStoreException { + MailRepository mailRepository = destinationToRepositoryAssociations.get(destination); + if (mailRepository != null) { + return mailRepository; + } + String protocol = retrieveProtocol(destination); + mailRepository = retrieveMailRepository(protocol); + mailRepository = initialiseNewRepository(mailRepository, createRepositoryCombinedConfig(destination, protocol)); + destinationToRepositoryAssociations.putIfAbsent(destination, mailRepository); + return mailRepository; + } + + private void readConfigurationEntry(HierarchicalConfiguration repositoryConfiguration) throws ConfigurationException { + String className = repositoryConfiguration.getString("[@class]"); + MailRepositoryProvider usedMailRepository = mailRepositories.stream() + .filter(mailRepositoryProvider -> mailRepositoryProvider.canonicalName().equals(className)) + .findAny() + .orElseThrow(() -> new ConfigurationException("MailRepository " + className + " has not been registered")); + for (String protocol : repositoryConfiguration.getStringArray("protocols.protocol")) { + protocolToRepositoryProvider.put(protocol, usedMailRepository); + registerRepositoryDefaultConfiguration(repositoryConfiguration, protocol); + } + } + + private void registerRepositoryDefaultConfiguration(HierarchicalConfiguration repositoryConfiguration, String protocol) { + HierarchicalConfiguration defConf = null; + if (repositoryConfiguration.getKeys("config").hasNext()) { + defConf = repositoryConfiguration.configurationAt("config"); + } + if (defConf != null) { + perProtocolMailRepositoryDefaultConfiguration.put(protocol, defConf); + } + } + + private CombinedConfiguration createRepositoryCombinedConfig(String destination, String protocol) { + final CombinedConfiguration config = new CombinedConfiguration(); + HierarchicalConfiguration defaultProtocolConfig = perProtocolMailRepositoryDefaultConfiguration.get(protocol); + if (defaultProtocolConfig != null) { + config.addConfiguration(defaultProtocolConfig); + } + DefaultConfigurationBuilder builder = new DefaultConfigurationBuilder(); + builder.addProperty("[@destinationURL]", destination); + config.addConfiguration(builder); + return config; + } + + private MailRepository initialiseNewRepository(MailRepository mailRepository, CombinedConfiguration config) throws MailRepositoryStoreException { + try { + if (mailRepository instanceof LogEnabled) { + ((LogEnabled) mailRepository).setLog(LOGGER); + } + if (mailRepository instanceof Configurable) { + ((Configurable) mailRepository).configure(config); + } + return mailRepository; + } catch (Exception e) { + throw new MailRepositoryStoreException("Cannot init mail repository", e); + } + } + + private MailRepository retrieveMailRepository(String protocol) throws MailRepositoryStoreException { + MailRepositoryProvider repositoryProvider = protocolToRepositoryProvider.get(protocol); + if (repositoryProvider == null) { + throw new MailRepositoryStoreException("No Mail Repository associated with " + protocol); + } + return repositoryProvider.get(); + } + + private String retrieveProtocol(String destination) throws MailRepositoryStoreException { + int protocolSeparatorPosition = destination.indexOf(':'); + if (protocolSeparatorPosition == -1) { + throw new MailRepositoryStoreException("Destination is malformed. Must be a valid URL: " + destination); + } + return destination.substring(0, protocolSeparatorPosition); + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/MailRepositoryProvider.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/MailRepositoryProvider.java new file mode 100644 index 00000000000..52b7d15a9f4 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/MailRepositoryProvider.java @@ -0,0 +1,29 @@ +/**************************************************************** + * 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 org.apache.james.mailrepository.api.MailRepository; + +import javax.inject.Provider; + +public interface MailRepositoryProvider extends Provider { + + String canonicalName(); +} diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java new file mode 100644 index 00000000000..3fea862f565 --- /dev/null +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java @@ -0,0 +1,106 @@ +/**************************************************************** + * 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 static org.assertj.core.api.Assertions.assertThat; +import static org.assertj.core.api.Assertions.fail; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.james.core.JamesServerResourceLoader; +import org.apache.james.core.filesystem.FileSystemImpl; +import org.apache.james.mailrepository.api.MailRepositoryStore; +import org.apache.james.mailrepository.file.FileMailRepository; +import org.apache.james.modules.server.MailStoreRepositoryModule; +import org.junit.Before; +import org.junit.Test; + +import com.google.common.collect.Sets; + +public class InMemoryMailRepositoryStoreTest { + + private InMemoryMailRepositoryStore repositoryStore; + + @Before + public void setUp() throws Exception { + repositoryStore = new InMemoryMailRepositoryStore(Sets.newHashSet( + new MailStoreRepositoryModule.FileMailRepositoryProvider( + new FileSystemImpl(new JamesServerResourceLoader())))); + repositoryStore.configure(new ClassPathConfigurationProvider().getConfiguration("mailrepositorystore")); + repositoryStore.init(); + } + + @Test(expected = MailRepositoryStore.MailRepositoryStoreException.class) + public void selectingANonRegisteredProtocolShouldFail() throws Exception { + repositoryStore.select("proto://repo"); + } + + @Test + public void selectingARegisteredProtocolShouldWork() throws Exception { + assertThat(repositoryStore.select("file://repo")).isInstanceOf(FileMailRepository.class); + } + + @Test + public void selectingTwiceARegisteredProtocolWithSameDestinationShouldReturnTheSameResult() throws Exception { + assertThat(repositoryStore.select("file://repo")).isEqualTo(repositoryStore.select("file://repo")); + } + + @Test + public void selectingTwiceARegisteredProtocolWithDifferentDestinationShouldReturnDifferentResults() throws Exception { + assertThat(repositoryStore.select("file://repo")).isNotEqualTo(repositoryStore.select("file://repo1")); + } + + @Test(expected = ConfigurationException.class) + public void configureShouldThrowWhenNonValidClassesAreProvided() throws Exception { + try { + repositoryStore = new InMemoryMailRepositoryStore(Sets.newHashSet( + new MailStoreRepositoryModule.FileMailRepositoryProvider( + new FileSystemImpl(new JamesServerResourceLoader())))); + repositoryStore.configure(new ClassPathConfigurationProvider().getConfiguration("fakemailrepositorystore")); + } catch (Exception e) { + fail("Unexpected failure : ", e); + } + repositoryStore.init(); + } + + @Test + public void getUrlsShouldBeEmptyIfNoSelectWerePerformed() { + assertThat(repositoryStore.getUrls()).isEmpty(); + } + + @Test + public void getUrlsShouldReturnUsedUrls() throws Exception { + String url1 = "file://repo1"; + String url2 = "file://repo2"; + String url3 = "file://repo3"; + repositoryStore.select(url1); + repositoryStore.select(url2); + repositoryStore.select(url3); + assertThat(repositoryStore.getUrls()).containsOnly(url1, url2, url3); + } + + @Test + public void getUrlsResultsShouldNotBeDuplicated() throws Exception { + String url1 = "file://repo1"; + repositoryStore.select(url1); + repositoryStore.select(url1); + assertThat(repositoryStore.getUrls()).containsExactly(url1); + } + +} diff --git a/server/container/cassandra-guice/src/test/resources/fakemailrepositorystore.xml b/server/container/cassandra-guice/src/test/resources/fakemailrepositorystore.xml new file mode 100644 index 00000000000..2d19a802da9 --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/fakemailrepositorystore.xml @@ -0,0 +1,31 @@ + + + + + + + + + file + + + + + diff --git a/server/container/cassandra-guice/src/test/resources/mailrepositorystore.xml b/server/container/cassandra-guice/src/test/resources/mailrepositorystore.xml new file mode 100644 index 00000000000..3ca4a1d0056 --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/mailrepositorystore.xml @@ -0,0 +1,31 @@ + + + + + + + + + file + + + + + From 57ddc660778d181201f2c602667fb8580be0830b Mon Sep 17 00:00:00 2001 From: benwa Date: Thu, 27 Aug 2015 16:18:58 +0200 Subject: [PATCH 17/39] JAMES-1626 Add mailet support in cassandra-guice module --- .../james/CassandraJamesServerMain.java | 8 +- .../server/CamelMailetContainerModule.java | 107 ++++++++++++ .../james/modules/server/SieveModule.java | 37 ++++ .../james/utils/GuiceGenericLoader.java | 46 +++++ .../apache/james/utils/GuiceMailetLoader.java | 52 ++++++ .../james/utils/GuiceMatcherLoader.java | 52 ++++++ .../james/CassandraJamesServerTest.java | 26 ++- .../src/test/resources/mailetcontainer.xml | 165 ++++++++++++++++++ .../apache/james/system/hbase/TablePool.java | 1 - 9 files changed, 490 insertions(+), 4 deletions(-) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/SieveModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceGenericLoader.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMailetLoader.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMatcherLoader.java create mode 100644 server/container/cassandra-guice/src/test/resources/mailetcontainer.xml diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java index 7419e51ebf0..e6e0da2048b 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java @@ -31,12 +31,14 @@ import org.apache.james.modules.protocols.ProtocolHandlerModule; import org.apache.james.modules.protocols.SMTPServerModule; import org.apache.james.modules.server.ActiveMQQueueModule; +import org.apache.james.modules.server.CamelMailetContainerModule; import org.apache.james.modules.server.ConfigurationPerformerModule; import org.apache.james.modules.server.DNSServiceModule; import org.apache.james.modules.server.FileSystemModule; import org.apache.james.modules.server.JMXServerModule; import org.apache.james.modules.server.MailStoreRepositoryModule; import org.apache.james.modules.server.QuotaModule; +import org.apache.james.modules.server.SieveModule; import com.google.inject.Module; import com.google.inject.util.Modules; @@ -58,9 +60,11 @@ public class CassandraJamesServerMain { new SMTPServerModule(), new LMTPServerModule(), new ActiveMQQueueModule(), - new QuotaModule(), new FileSystemModule(), - new MailStoreRepositoryModule()); + new SieveModule(), + new MailStoreRepositoryModule(), + new CamelMailetContainerModule(), + new QuotaModule()); public static void main(String[] args) throws Exception { CassandraJamesServer server = new CassandraJamesServer(Modules.combine( diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java new file mode 100644 index 00000000000..b85d8846303 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java @@ -0,0 +1,107 @@ +/**************************************************************** + * 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.server; + +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import org.apache.camel.impl.DefaultCamelContext; +import org.apache.james.dnsservice.api.DNSService; +import org.apache.james.domainlist.api.DomainList; +import org.apache.james.mailetcontainer.api.MailProcessor; +import org.apache.james.mailetcontainer.api.MailetLoader; +import org.apache.james.mailetcontainer.api.MatcherLoader; +import org.apache.james.mailetcontainer.api.jmx.MailSpoolerMBean; +import org.apache.james.mailetcontainer.impl.JamesMailSpooler; +import org.apache.james.mailetcontainer.impl.JamesMailetContext; +import org.apache.james.mailetcontainer.impl.camel.CamelCompositeProcessor; +import org.apache.james.user.api.UsersRepository; +import org.apache.james.utils.ClassPathConfigurationProvider; +import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.GuiceMailetLoader; +import org.apache.james.utils.GuiceMatcherLoader; +import org.apache.mailet.MailetContext; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; + +public class CamelMailetContainerModule extends AbstractModule { + + private final static Logger LOGGER = LoggerFactory.getLogger(CamelMailetContainerModule.class); + + @Override + protected void configure() { + bind(MailProcessor.class).to(CamelCompositeProcessor.class); + bind(MailSpoolerMBean.class).to(JamesMailSpooler.class); + bind(MailetLoader.class).to(GuiceMailetLoader.class); + bind(MatcherLoader.class).to(GuiceMatcherLoader.class); + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(IMAPModuleConfigurationPerformer.class); + } + + @Provides + @Singleton + private MailetContext provideMailetContext(MailProcessor processorList, + DNSService dns, + UsersRepository localusers, + DomainList domains) { + JamesMailetContext jamesMailetContext = new JamesMailetContext(); + jamesMailetContext.setLog(LOGGER); + jamesMailetContext.setDNSService(dns); + jamesMailetContext.setMailProcessor(processorList); + jamesMailetContext.setUsersRepository(localusers); + jamesMailetContext.setDomainList(domains); + return jamesMailetContext; + } + + @Singleton + public static class IMAPModuleConfigurationPerformer implements ConfigurationPerformer { + + private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final CamelCompositeProcessor camelCompositeProcessor; + private final JamesMailSpooler jamesMailSpooler; + private final JamesMailetContext mailetContext; + + @Inject + public IMAPModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, + CamelCompositeProcessor camelCompositeProcessor, + JamesMailSpooler jamesMailSpooler, + JamesMailetContext mailetContext) { + this.classPathConfigurationProvider = classPathConfigurationProvider; + this.camelCompositeProcessor = camelCompositeProcessor; + this.jamesMailSpooler = jamesMailSpooler; + this.mailetContext = mailetContext; + } + + @Override + public void initModule() throws Exception { + camelCompositeProcessor.setLog(LOGGER); + camelCompositeProcessor.setCamelContext(new DefaultCamelContext()); + camelCompositeProcessor.configure(classPathConfigurationProvider.getConfiguration("mailetcontainer").configurationAt("processors")); + camelCompositeProcessor.init(); + jamesMailSpooler.setLog(LOGGER); + jamesMailSpooler.configure(classPathConfigurationProvider.getConfiguration("mailetcontainer").configurationAt("spooler")); + jamesMailSpooler.init(); + mailetContext.setLog(LOGGER); + mailetContext.configure(classPathConfigurationProvider.getConfiguration("mailetcontainer").configurationAt("context")); + } + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/SieveModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/SieveModule.java new file mode 100644 index 00000000000..229b479d314 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/SieveModule.java @@ -0,0 +1,37 @@ +/**************************************************************** + * 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.server; + +import org.apache.james.managesieve.api.SieveParser; +import org.apache.james.managesieve.jsieve.Parser; +import org.apache.james.sieverepository.api.SieveRepository; +import org.apache.james.sieverepository.file.SieveFileRepository; + +import com.google.inject.AbstractModule; + +public class SieveModule extends AbstractModule { + + @Override + protected void configure() { + bind(SieveParser.class).to(Parser.class); + bind(SieveRepository.class).to(SieveFileRepository.class); + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceGenericLoader.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceGenericLoader.java new file mode 100644 index 00000000000..31175b34225 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceGenericLoader.java @@ -0,0 +1,46 @@ +/**************************************************************** + * 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 com.google.inject.Injector; + +public class GuiceGenericLoader { + + private final Injector injector; + private final String defaultPackageName; + + public GuiceGenericLoader(Injector injector, String defaultPackageName) { + this.injector = injector; + this.defaultPackageName = defaultPackageName; + } + + public T instanciate(String className) throws Exception { + Class clazz = (Class) ClassLoader.getSystemClassLoader().loadClass(constructFullName(className)); + return injector.getInstance(clazz); + } + + private String constructFullName(String name) { + if (! name.contains(".")) { + return defaultPackageName + name; + } + return name; + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMailetLoader.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMailetLoader.java new file mode 100644 index 00000000000..3efdce67348 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMailetLoader.java @@ -0,0 +1,52 @@ +/**************************************************************** + * 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 com.google.inject.Inject; +import com.google.inject.Injector; +import org.apache.james.mailetcontainer.api.MailetLoader; +import org.apache.mailet.Mailet; +import org.apache.mailet.MailetConfig; + +import javax.mail.MessagingException; + +public class GuiceMailetLoader implements MailetLoader { + + private static final String STANDARD_PACKAGE = "org.apache.james.transport.mailets."; + + private final GuiceGenericLoader genericLoader; + + @Inject + public GuiceMailetLoader(Injector injector) { + this.genericLoader = new GuiceGenericLoader<>(injector, STANDARD_PACKAGE); + } + + @Override + public Mailet getMailet(MailetConfig config) throws MessagingException { + try { + Mailet result = genericLoader.instanciate(config.getMailetName()); + result.init(config); + return result; + } catch (Exception e) { + throw new MessagingException("Can not load mailet " + config.getMailetName(), e); + } + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMatcherLoader.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMatcherLoader.java new file mode 100644 index 00000000000..a6d966be50b --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceMatcherLoader.java @@ -0,0 +1,52 @@ +/**************************************************************** + * 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 com.google.inject.Inject; +import com.google.inject.Injector; +import org.apache.james.mailetcontainer.api.MatcherLoader; +import org.apache.mailet.Matcher; +import org.apache.mailet.MatcherConfig; + +import javax.mail.MessagingException; + +public class GuiceMatcherLoader implements MatcherLoader { + + private static final String STANDARD_PACKAGE = "org.apache.james.transport.matchers."; + + private final GuiceGenericLoader genericLoader; + + @Inject + public GuiceMatcherLoader(Injector injector) { + this.genericLoader = new GuiceGenericLoader<>(injector, STANDARD_PACKAGE); + } + + @Override + public Matcher getMatcher(MatcherConfig config) throws MessagingException { + try { + Matcher result = genericLoader.instanciate(config.getMatcherName()); + result.init(config); + return result; + } catch (Exception e) { + throw new MessagingException("Can not load matcher " + config.getMatcherName(), e); + } + } + +} diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java index 1af2cf9060b..b7a5c8b037a 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java @@ -20,6 +20,7 @@ import static org.assertj.core.api.Assertions.assertThat; +import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; @@ -28,6 +29,8 @@ import org.apache.james.backends.cassandra.CassandraCluster; import org.apache.james.backends.cassandra.components.CassandraModule; +import org.apache.james.core.JamesServerResourceLoader; +import org.apache.james.filesystem.api.JamesDirectoriesProvider; import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch; import org.apache.james.modules.TestElasticSearchModule; import org.junit.After; @@ -59,10 +62,30 @@ public class CassandraJamesServerTest { @Rule public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch); + private static class TestFilesystemModule extends AbstractModule { + + JamesServerResourceLoader jamesServerResourceLoader; + + TestFilesystemModule(File tmpDir) { + jamesServerResourceLoader = new JamesServerResourceLoader() { + @Override + public String getRootDirectory() { + return tmpDir.getAbsolutePath(); + } + }; + } + + @Override + protected void configure() { + bind(JamesDirectoriesProvider.class).toInstance(jamesServerResourceLoader); + } + } + @Before public void setup() throws Exception { server = new CassandraJamesServer(Modules.override(CassandraJamesServerMain.defaultModule) - .with(new TestElasticSearchModule(embeddedElasticSearch), + .with(new TestElasticSearchModule(embeddedElasticSearch), + new TestFilesystemModule(temporaryFolder.newFolder()), new AbstractModule() { @Override @@ -78,6 +101,7 @@ com.datastax.driver.core.Session provideSession(CassandraModule cassandraModule) })); socketChannel = SocketChannel.open(); + server.start(); } diff --git a/server/container/cassandra-guice/src/test/resources/mailetcontainer.xml b/server/container/cassandra-guice/src/test/resources/mailetcontainer.xml new file mode 100644 index 00000000000..1bd6f71f285 --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/mailetcontainer.xml @@ -0,0 +1,165 @@ + + + + + + + + postmaster@james.minet.net + + + + 20 + + + + + + + + + sieve-manager-check + + + transport + + + true + + + transport + + + transport + + + + + + + spam + 550 Requested action not taken: rejected - see http://njabl.org/ + + + transport + + + + + + + file://var/mail/error/ + + + + + + + X-UserIsAuth + true + + + X-WasSigned + true + + + + + local-address-error + 550 - Requested action not taken: no such user here + + + outgoing + 5000, 100000, 500000 + 25 + 0 + 10 + true + bounces + + + relay-denied + + + + + + file://var/mail/spam/ + + + + + + none + + + file://var/mail/address-error/ + + + + + + none + + + file://var/mail/relay-denied/ + Warning: You are sending an e-mail to a remote server. You must be authentified to perform such an operation + + + + + + false + + + + + + + sieve-manager + + + + heads + none + false + [REJECTED] + + You can't send messages to configure SIEVE on this serveur unless you are the official SIEVE manager. + + + + + + + + true + + + file:/root/james-server-app-3.0.0-beta5-SNAPSHOT/conf/managesieve.help.txt + + + + + + + + diff --git a/server/data/data-hbase/src/main/java/org/apache/james/system/hbase/TablePool.java b/server/data/data-hbase/src/main/java/org/apache/james/system/hbase/TablePool.java index e6392c7ea13..615551c7889 100644 --- a/server/data/data-hbase/src/main/java/org/apache/james/system/hbase/TablePool.java +++ b/server/data/data-hbase/src/main/java/org/apache/james/system/hbase/TablePool.java @@ -28,7 +28,6 @@ import org.apache.hadoop.hbase.client.HTableInterface; import org.apache.hadoop.hbase.client.HTablePool; import org.apache.james.domainlist.hbase.def.HDomainList; -import org.apache.james.rrt.api.RecipientRewriteTable; import org.apache.james.rrt.hbase.def.HRecipientRewriteTable; import org.apache.james.user.api.UsersRepository; import org.apache.james.user.hbase.def.HUsersRepository; From fdfbb821105281212cff5c30826a019697e8cd77 Mon Sep 17 00:00:00 2001 From: benwa Date: Wed, 2 Sep 2015 18:51:37 +0200 Subject: [PATCH 18/39] JAMES-1626 Add DNSService support in cassandra-guice application --- .../modules/server/DNSServiceModule.java | 32 ++++++++++++++++--- .../src/test/resources/dnsservice.xml | 29 +++++++++++++++++ server/dns-service/dnsservice-dnsjava/pom.xml | 4 +++ .../dnsservice/dnsjava/DNSJavaService.java | 2 ++ 4 files changed, 62 insertions(+), 5 deletions(-) create mode 100644 server/container/cassandra-guice/src/test/resources/dnsservice.xml diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java index 8ca0efd82d3..ffe1b7a9e55 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java @@ -18,23 +18,45 @@ ****************************************************************/ package org.apache.james.modules.server; -import com.google.inject.Provides; +import com.google.inject.Inject; import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; import org.apache.james.dnsservice.api.DNSService; import org.apache.james.dnsservice.dnsjava.DNSJavaService; import com.google.inject.AbstractModule; +import org.apache.james.utils.ClassPathConfigurationProvider; +import org.apache.james.utils.ConfigurationPerformer; +import org.slf4j.Logger; +import org.slf4j.LoggerFactory; public class DNSServiceModule extends AbstractModule { + private static final Logger LOGGER = LoggerFactory.getLogger(DNSServiceModule.class); + @Override protected void configure() { - + bind(DNSService.class).to(DNSJavaService.class); + Multibinder.newSetBinder(binder(), ConfigurationPerformer.class).addBinding().to(DNSServiceConfigurationPerformer.class); } - @Provides @Singleton - private DNSService provideDNSService() { - return new DNSJavaService(); + public static class DNSServiceConfigurationPerformer implements ConfigurationPerformer { + + private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final DNSJavaService dnsService; + + @Inject + public DNSServiceConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, + DNSJavaService dnsService) { + this.classPathConfigurationProvider = classPathConfigurationProvider; + this.dnsService = dnsService; + } + + public void initModule() throws Exception { + dnsService.setLog(LOGGER); + dnsService.configure(classPathConfigurationProvider.getConfiguration("dnsservice")); + dnsService.init(); + } } } \ No newline at end of file diff --git a/server/container/cassandra-guice/src/test/resources/dnsservice.xml b/server/container/cassandra-guice/src/test/resources/dnsservice.xml new file mode 100644 index 00000000000..0978a00b899 --- /dev/null +++ b/server/container/cassandra-guice/src/test/resources/dnsservice.xml @@ -0,0 +1,29 @@ + + + + + + 8.8.8.8 + 62.210.16.6 + + false + false + 50000 + diff --git a/server/dns-service/dnsservice-dnsjava/pom.xml b/server/dns-service/dnsservice-dnsjava/pom.xml index d73a381cbf7..56ede46980b 100644 --- a/server/dns-service/dnsservice-dnsjava/pom.xml +++ b/server/dns-service/dnsservice-dnsjava/pom.xml @@ -59,6 +59,10 @@ dnsjava dnsjava + + javax.inject + javax.inject + org.apache.geronimo.specs geronimo-annotation_1.1_spec diff --git a/server/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java b/server/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java index 7445a4467fb..c6cc9ac168b 100644 --- a/server/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java +++ b/server/dns-service/dnsservice-dnsjava/src/main/java/org/apache/james/dnsservice/dnsjava/DNSJavaService.java @@ -44,6 +44,7 @@ import org.xbill.DNS.Type; import javax.annotation.PostConstruct; +import javax.inject.Singleton; import java.net.InetAddress; import java.net.UnknownHostException; import java.util.ArrayList; @@ -56,6 +57,7 @@ /** * Provides DNS client functionality to services running inside James */ +@Singleton public class DNSJavaService implements DNSService, DNSServiceMBean, LogEnabled, Configurable { /** From d04ba06b436bd1851ad41143f462c285d8ffa604 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Fri, 11 Sep 2015 15:46:03 +0200 Subject: [PATCH 19/39] JAMES-1626 Add interface ConfigurationProvider to allow multiple implementations --- .../james/CassandraJamesServerMain.java | 4 ++- .../modules/protocols/IMAPServerModule.java | 20 +++++------ .../modules/protocols/LMTPServerModule.java | 19 ++++++----- .../modules/protocols/POP3ServerModule.java | 19 ++++++----- .../modules/protocols/SMTPServerModule.java | 12 +++---- .../server/CamelMailetContainerModule.java | 25 +++++++------- .../server/ConfigurationProviderModule.java | 33 +++++++++++++++++++ .../modules/server/DNSServiceModule.java | 20 +++++------ .../server/MailStoreRepositoryModule.java | 13 ++++---- .../james/utils/ConfigurationProvider.java | 30 +++++++++++++++++ ...er.java => FileConfigurationProvider.java} | 3 +- ...ava => FileConfigurationProviderTest.java} | 6 ++-- .../InMemoryMailRepositoryStoreTest.java | 4 +-- 13 files changed, 139 insertions(+), 69 deletions(-) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ConfigurationProviderModule.java create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationProvider.java rename server/container/cassandra-guice/src/main/java/org/apache/james/utils/{ClassPathConfigurationProvider.java => FileConfigurationProvider.java} (97%) rename server/container/cassandra-guice/src/test/java/org/apache/james/utils/{ClassPathConfigurationProviderTest.java => FileConfigurationProviderTest.java} (96%) diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java index e6e0da2048b..27ad824ba32 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java @@ -33,6 +33,7 @@ import org.apache.james.modules.server.ActiveMQQueueModule; import org.apache.james.modules.server.CamelMailetContainerModule; import org.apache.james.modules.server.ConfigurationPerformerModule; +import org.apache.james.modules.server.ConfigurationProviderModule; import org.apache.james.modules.server.DNSServiceModule; import org.apache.james.modules.server.FileSystemModule; import org.apache.james.modules.server.JMXServerModule; @@ -64,7 +65,8 @@ public class CassandraJamesServerMain { new SieveModule(), new MailStoreRepositoryModule(), new CamelMailetContainerModule(), - new QuotaModule()); + new QuotaModule(), + new ConfigurationProviderModule()); public static void main(String[] args) throws Exception { CassandraJamesServer server = new CassandraJamesServer(Modules.combine( diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java index 176c5bbb3ce..1b9b8ac990a 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java @@ -18,11 +18,6 @@ ****************************************************************/ package org.apache.james.modules.protocols; -import com.google.inject.Inject; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import com.google.inject.multibindings.Multibinder; -import com.google.inject.name.Named; import org.apache.james.imap.api.process.ImapProcessor; import org.apache.james.imap.decode.ImapDecoder; import org.apache.james.imap.encode.ImapEncoder; @@ -35,13 +30,18 @@ import org.apache.james.mailbox.quota.QuotaManager; import org.apache.james.mailbox.quota.QuotaRootResolver; import org.apache.james.modules.mailbox.CassandraMailboxModule; -import org.apache.james.utils.ClassPathConfigurationProvider; import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.ConfigurationProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; import com.google.common.collect.ImmutableSet; import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; +import com.google.inject.name.Named; public class IMAPServerModule extends AbstractModule { @@ -84,19 +84,19 @@ ImapEncoder provideImapEncoder() { @Singleton public static class IMAPModuleConfigurationPerformer implements ConfigurationPerformer { - private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final ConfigurationProvider configurationProvider; private final IMAPServerFactory imapServerFactory; @Inject - public IMAPModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, IMAPServerFactory imapServerFactory) { - this.classPathConfigurationProvider = classPathConfigurationProvider; + public IMAPModuleConfigurationPerformer(ConfigurationProvider configurationProvider, IMAPServerFactory imapServerFactory) { + this.configurationProvider = configurationProvider; this.imapServerFactory = imapServerFactory; } @Override public void initModule() throws Exception { imapServerFactory.setLog(LOGGER); - imapServerFactory.configure(classPathConfigurationProvider.getConfiguration("imapserver")); + imapServerFactory.configure(configurationProvider.getConfiguration("imapserver")); imapServerFactory.init(); } } diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java index 7d48341efe6..a7b7c835a6f 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java @@ -19,16 +19,17 @@ package org.apache.james.modules.protocols; -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import com.google.inject.multibindings.Multibinder; import org.apache.james.lmtpserver.netty.LMTPServerFactory; -import org.apache.james.utils.ClassPathConfigurationProvider; import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.ConfigurationProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; + public class LMTPServerModule extends AbstractModule { private static final Logger LOGGER = LoggerFactory.getLogger(LMTPServerModule.class); @@ -41,19 +42,19 @@ protected void configure() { @Singleton public static class LMTPModuleConfigurationPerformer implements ConfigurationPerformer { - private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final ConfigurationProvider configurationProvider; private final LMTPServerFactory lmtpServerFactory; @Inject - public LMTPModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, LMTPServerFactory lmtpServerFactory) { - this.classPathConfigurationProvider = classPathConfigurationProvider; + public LMTPModuleConfigurationPerformer(ConfigurationProvider configurationProvider, LMTPServerFactory lmtpServerFactory) { + this.configurationProvider = configurationProvider; this.lmtpServerFactory = lmtpServerFactory; } @Override public void initModule() throws Exception { lmtpServerFactory.setLog(LOGGER); - lmtpServerFactory.configure(classPathConfigurationProvider.getConfiguration("lmtpserver")); + lmtpServerFactory.configure(configurationProvider.getConfiguration("lmtpserver")); lmtpServerFactory.init(); } } diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java index 879d196761d..2bbe6a82e79 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java @@ -19,16 +19,17 @@ package org.apache.james.modules.protocols; -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import com.google.inject.multibindings.Multibinder; import org.apache.james.pop3server.netty.POP3ServerFactory; -import org.apache.james.utils.ClassPathConfigurationProvider; import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.ConfigurationProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; + public class POP3ServerModule extends AbstractModule { private static final Logger LOGGER = LoggerFactory.getLogger(POP3ServerModule.class); @@ -41,19 +42,19 @@ protected void configure() { @Singleton public static class POP3ModuleConfigurationPerformer implements ConfigurationPerformer { - private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final ConfigurationProvider configurationProvider; private final POP3ServerFactory pop3ServerFactory; @Inject - public POP3ModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, POP3ServerFactory pop3ServerFactory) { - this.classPathConfigurationProvider = classPathConfigurationProvider; + public POP3ModuleConfigurationPerformer(ConfigurationProvider configurationProvider, POP3ServerFactory pop3ServerFactory) { + this.configurationProvider = configurationProvider; this.pop3ServerFactory = pop3ServerFactory; } @Override public void initModule() throws Exception { pop3ServerFactory.setLog(LOGGER); - pop3ServerFactory.configure(classPathConfigurationProvider.getConfiguration("pop3server")); + pop3ServerFactory.configure(configurationProvider.getConfiguration("pop3server")); pop3ServerFactory.init(); } } diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java index 5c7b6c9cb7b..62758225165 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java @@ -21,8 +21,8 @@ import org.apache.james.smtpserver.SendMailHandler; import org.apache.james.smtpserver.netty.SMTPServerFactory; -import org.apache.james.utils.ClassPathConfigurationProvider; import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.ConfigurationProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; @@ -43,15 +43,15 @@ protected void configure() { @Singleton public static class SMTPModuleConfigurationPerformer implements ConfigurationPerformer { - private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final ConfigurationProvider configurationProvider; private final SMTPServerFactory smtpServerFactory; private final SendMailHandler sendMailHandler; @Inject - public SMTPModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, + public SMTPModuleConfigurationPerformer(ConfigurationProvider configurationProvider, SMTPServerFactory smtpServerFactory, - SendMailHandler sendMailHandler) { - this.classPathConfigurationProvider = classPathConfigurationProvider; + SendMailHandler sendMailHandler) { + this.configurationProvider = configurationProvider; this.smtpServerFactory = smtpServerFactory; this.sendMailHandler = sendMailHandler; } @@ -59,7 +59,7 @@ public SMTPModuleConfigurationPerformer(ClassPathConfigurationProvider classPath @Override public void initModule() throws Exception { smtpServerFactory.setLog(LOGGER); - smtpServerFactory.configure(classPathConfigurationProvider.getConfiguration("smtpserver")); + smtpServerFactory.configure(configurationProvider.getConfiguration("smtpserver")); smtpServerFactory.init(); sendMailHandler.init(null); } diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java index b85d8846303..5bd769d8f90 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/CamelMailetContainerModule.java @@ -19,11 +19,6 @@ package org.apache.james.modules.server; -import com.google.inject.AbstractModule; -import com.google.inject.Inject; -import com.google.inject.Provides; -import com.google.inject.Singleton; -import com.google.inject.multibindings.Multibinder; import org.apache.camel.impl.DefaultCamelContext; import org.apache.james.dnsservice.api.DNSService; import org.apache.james.domainlist.api.DomainList; @@ -35,14 +30,20 @@ import org.apache.james.mailetcontainer.impl.JamesMailetContext; import org.apache.james.mailetcontainer.impl.camel.CamelCompositeProcessor; import org.apache.james.user.api.UsersRepository; -import org.apache.james.utils.ClassPathConfigurationProvider; import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.ConfigurationProvider; import org.apache.james.utils.GuiceMailetLoader; import org.apache.james.utils.GuiceMatcherLoader; import org.apache.mailet.MailetContext; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Provides; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; + public class CamelMailetContainerModule extends AbstractModule { private final static Logger LOGGER = LoggerFactory.getLogger(CamelMailetContainerModule.class); @@ -74,17 +75,17 @@ private MailetContext provideMailetContext(MailProcessor processorList, @Singleton public static class IMAPModuleConfigurationPerformer implements ConfigurationPerformer { - private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final ConfigurationProvider configurationProvider; private final CamelCompositeProcessor camelCompositeProcessor; private final JamesMailSpooler jamesMailSpooler; private final JamesMailetContext mailetContext; @Inject - public IMAPModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, + public IMAPModuleConfigurationPerformer(ConfigurationProvider configurationProvider, CamelCompositeProcessor camelCompositeProcessor, JamesMailSpooler jamesMailSpooler, JamesMailetContext mailetContext) { - this.classPathConfigurationProvider = classPathConfigurationProvider; + this.configurationProvider = configurationProvider; this.camelCompositeProcessor = camelCompositeProcessor; this.jamesMailSpooler = jamesMailSpooler; this.mailetContext = mailetContext; @@ -94,13 +95,13 @@ public IMAPModuleConfigurationPerformer(ClassPathConfigurationProvider classPath public void initModule() throws Exception { camelCompositeProcessor.setLog(LOGGER); camelCompositeProcessor.setCamelContext(new DefaultCamelContext()); - camelCompositeProcessor.configure(classPathConfigurationProvider.getConfiguration("mailetcontainer").configurationAt("processors")); + camelCompositeProcessor.configure(configurationProvider.getConfiguration("mailetcontainer").configurationAt("processors")); camelCompositeProcessor.init(); jamesMailSpooler.setLog(LOGGER); - jamesMailSpooler.configure(classPathConfigurationProvider.getConfiguration("mailetcontainer").configurationAt("spooler")); + jamesMailSpooler.configure(configurationProvider.getConfiguration("mailetcontainer").configurationAt("spooler")); jamesMailSpooler.init(); mailetContext.setLog(LOGGER); - mailetContext.configure(classPathConfigurationProvider.getConfiguration("mailetcontainer").configurationAt("context")); + mailetContext.configure(configurationProvider.getConfiguration("mailetcontainer").configurationAt("context")); } } diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ConfigurationProviderModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ConfigurationProviderModule.java new file mode 100644 index 00000000000..f9d3cff0af2 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/ConfigurationProviderModule.java @@ -0,0 +1,33 @@ +/**************************************************************** + * 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.server; + +import org.apache.james.utils.ConfigurationProvider; +import org.apache.james.utils.FileConfigurationProvider; + +import com.google.inject.AbstractModule; + +public class ConfigurationProviderModule extends AbstractModule { + + @Override + public void configure() { + bind(ConfigurationProvider.class).to(FileConfigurationProvider.class); + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java index ffe1b7a9e55..5d3b49f137f 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/DNSServiceModule.java @@ -18,18 +18,18 @@ ****************************************************************/ package org.apache.james.modules.server; -import com.google.inject.Inject; -import com.google.inject.Singleton; -import com.google.inject.multibindings.Multibinder; import org.apache.james.dnsservice.api.DNSService; import org.apache.james.dnsservice.dnsjava.DNSJavaService; - -import com.google.inject.AbstractModule; -import org.apache.james.utils.ClassPathConfigurationProvider; import org.apache.james.utils.ConfigurationPerformer; +import org.apache.james.utils.ConfigurationProvider; import org.slf4j.Logger; import org.slf4j.LoggerFactory; +import com.google.inject.AbstractModule; +import com.google.inject.Inject; +import com.google.inject.Singleton; +import com.google.inject.multibindings.Multibinder; + public class DNSServiceModule extends AbstractModule { private static final Logger LOGGER = LoggerFactory.getLogger(DNSServiceModule.class); @@ -43,19 +43,19 @@ protected void configure() { @Singleton public static class DNSServiceConfigurationPerformer implements ConfigurationPerformer { - private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final ConfigurationProvider configurationProvider; private final DNSJavaService dnsService; @Inject - public DNSServiceConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, + public DNSServiceConfigurationPerformer(ConfigurationProvider configurationProvider, DNSJavaService dnsService) { - this.classPathConfigurationProvider = classPathConfigurationProvider; + this.configurationProvider = configurationProvider; this.dnsService = dnsService; } public void initModule() throws Exception { dnsService.setLog(LOGGER); - dnsService.configure(classPathConfigurationProvider.getConfiguration("dnsservice")); + dnsService.configure(configurationProvider.getConfiguration("dnsservice")); dnsService.init(); } } diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java index a699938aa7e..39d6b543185 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/MailStoreRepositoryModule.java @@ -23,11 +23,12 @@ import com.google.inject.Inject; import com.google.inject.Singleton; import com.google.inject.multibindings.Multibinder; + import org.apache.james.filesystem.api.FileSystem; import org.apache.james.mailrepository.api.MailRepository; import org.apache.james.mailrepository.api.MailRepositoryStore; import org.apache.james.mailrepository.file.FileMailRepository; -import org.apache.james.utils.ClassPathConfigurationProvider; +import org.apache.james.utils.ConfigurationProvider; import org.apache.james.utils.ConfigurationPerformer; import org.apache.james.utils.InMemoryMailRepositoryStore; import org.apache.james.utils.MailRepositoryProvider; @@ -67,19 +68,19 @@ public MailRepository get() { @Singleton public static class MailRepositoryStoreModuleConfigurationPerformer implements ConfigurationPerformer { - private final ClassPathConfigurationProvider classPathConfigurationProvider; + private final ConfigurationProvider configurationProvider; private final InMemoryMailRepositoryStore javaMailRepositoryStore; @Inject - public MailRepositoryStoreModuleConfigurationPerformer(ClassPathConfigurationProvider classPathConfigurationProvider, - InMemoryMailRepositoryStore javaMailRepositoryStore) { - this.classPathConfigurationProvider = classPathConfigurationProvider; + public MailRepositoryStoreModuleConfigurationPerformer(ConfigurationProvider configurationProvider, + InMemoryMailRepositoryStore javaMailRepositoryStore) { + this.configurationProvider = configurationProvider; this.javaMailRepositoryStore = javaMailRepositoryStore; } @Override public void initModule() throws Exception { - javaMailRepositoryStore.configure(classPathConfigurationProvider.getConfiguration("mailrepositorystore")); + javaMailRepositoryStore.configure(configurationProvider.getConfiguration("mailrepositorystore")); javaMailRepositoryStore.init(); } } diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationProvider.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationProvider.java new file mode 100644 index 00000000000..cf3126e07f7 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ConfigurationProvider.java @@ -0,0 +1,30 @@ +/**************************************************************** + * 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 org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.HierarchicalConfiguration; + +public interface ConfigurationProvider { + + HierarchicalConfiguration getConfiguration(String component) + throws ConfigurationException; + +} \ No newline at end of file diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ClassPathConfigurationProvider.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/FileConfigurationProvider.java similarity index 97% rename from server/container/cassandra-guice/src/main/java/org/apache/james/utils/ClassPathConfigurationProvider.java rename to server/container/cassandra-guice/src/main/java/org/apache/james/utils/FileConfigurationProvider.java index 972131be16f..7b9d513b827 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/ClassPathConfigurationProvider.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/FileConfigurationProvider.java @@ -30,10 +30,11 @@ import java.util.List; import java.util.Optional; -public class ClassPathConfigurationProvider { +public class FileConfigurationProvider implements ConfigurationProvider { private static final String CONFIGURATION_FILE_SUFFIX = ".xml"; + @Override public HierarchicalConfiguration getConfiguration(String component) throws ConfigurationException { List configPathParts = Arrays.asList(component.split("\\.")); HierarchicalConfiguration config = getConfig(retrieveConfigInputStream(configPathParts.get(0))); diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/ClassPathConfigurationProviderTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java similarity index 96% rename from server/container/cassandra-guice/src/test/java/org/apache/james/utils/ClassPathConfigurationProviderTest.java rename to server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java index 4cc4347cd07..679ec714924 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/ClassPathConfigurationProviderTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java @@ -27,7 +27,7 @@ import org.junit.Before; import org.junit.Test; -public class ClassPathConfigurationProviderTest { +public class FileConfigurationProviderTest { private static final String CONFIG_KEY_1 = "test2"; private static final String CONFIG_KEY_2 = "property"; @@ -40,11 +40,11 @@ public class ClassPathConfigurationProviderTest { private static final String ROOT_CONFIG_KEY = "test"; private static final String CONFIG_SEPARATOR = "."; - private ClassPathConfigurationProvider configurationProvider; + private FileConfigurationProvider configurationProvider; @Before public void setUp() { - configurationProvider = new ClassPathConfigurationProvider(); + configurationProvider = new FileConfigurationProvider(); } @Test(expected = IllegalArgumentException.class) diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java index 3fea862f565..751406dedc9 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java @@ -42,7 +42,7 @@ public void setUp() throws Exception { repositoryStore = new InMemoryMailRepositoryStore(Sets.newHashSet( new MailStoreRepositoryModule.FileMailRepositoryProvider( new FileSystemImpl(new JamesServerResourceLoader())))); - repositoryStore.configure(new ClassPathConfigurationProvider().getConfiguration("mailrepositorystore")); + repositoryStore.configure(new FileConfigurationProvider().getConfiguration("mailrepositorystore")); repositoryStore.init(); } @@ -72,7 +72,7 @@ public void configureShouldThrowWhenNonValidClassesAreProvided() throws Exceptio repositoryStore = new InMemoryMailRepositoryStore(Sets.newHashSet( new MailStoreRepositoryModule.FileMailRepositoryProvider( new FileSystemImpl(new JamesServerResourceLoader())))); - repositoryStore.configure(new ClassPathConfigurationProvider().getConfiguration("fakemailrepositorystore")); + repositoryStore.configure(new FileConfigurationProvider().getConfiguration("fakemailrepositorystore")); } catch (Exception e) { fail("Unexpected failure : ", e); } From cc700567da351d74a6bc3bdde6b5f6b000af9546 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Fri, 11 Sep 2015 15:48:43 +0200 Subject: [PATCH 20/39] JAMES-1626 Implement a packaging policy for the cassandra-guice application --- server/container/cassandra-guice/pom.xml | 42 ++++++++++++++++-------- 1 file changed, 29 insertions(+), 13 deletions(-) diff --git a/server/container/cassandra-guice/pom.xml b/server/container/cassandra-guice/pom.xml index 09c5fbeae3d..88f52cad8ef 100644 --- a/server/container/cassandra-guice/pom.xml +++ b/server/container/cassandra-guice/pom.xml @@ -30,7 +30,7 @@ james-server-cassandra-guice - bundle + jar Apache James :: Server :: Cassandra - guice injection An advanced email server - Cassandra backend with guice injection @@ -45,7 +45,6 @@ - disable-build-for-older-jdk @@ -144,17 +143,34 @@ - maven-assembly-plugin - - - - fully.qualified.MainClass - - - - jar-with-dependencies - - + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/${project.build.finalName}.lib + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + ${project.build.finalName}.lib/ + org.apache.james.CassandraJamesServerMain + false + + + org.apache.maven.plugins From 16d820223de747de1cd10cf9e37799cb4f57f14f Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Fri, 11 Sep 2015 15:51:04 +0200 Subject: [PATCH 21/39] JAMES-1626 use Filesystem to resolve configuration properties files --- .../mailbox/CassandraSessionModule.java | 48 ++++++++++--------- .../mailbox/ElasticSearchMailboxModule.java | 32 ++++++++----- 2 files changed, 45 insertions(+), 35 deletions(-) diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java index 91427460a6b..a3777924104 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java @@ -18,35 +18,28 @@ ****************************************************************/ package org.apache.james.modules.mailbox; -import com.google.inject.Provides; -import com.google.inject.Singleton; - -import com.datastax.driver.core.Cluster; -import com.datastax.driver.core.Session; -import com.google.inject.AbstractModule; - +import java.io.FileNotFoundException; import java.util.Set; +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; import org.apache.james.backends.cassandra.components.CassandraModule; import org.apache.james.backends.cassandra.init.CassandraModuleComposite; import org.apache.james.backends.cassandra.init.ClusterFactory; import org.apache.james.backends.cassandra.init.ClusterWithKeyspaceCreatedFactory; import org.apache.james.backends.cassandra.init.SessionWithInitializedTablesFactory; -import org.apache.james.utils.PropertiesReader; +import org.apache.james.filesystem.api.FileSystem; -public class CassandraSessionModule extends AbstractModule { - - private final PropertiesReader propertiesReader; - private final String keyspace; +import com.datastax.driver.core.Cluster; +import com.datastax.driver.core.Session; +import com.google.inject.AbstractModule; +import com.google.inject.Provides; +import com.google.inject.Singleton; - public CassandraSessionModule() { - propertiesReader = new PropertiesReader("cassandra.properties"); - keyspace = propertiesReader.getProperty("cassandra.keyspace"); - } +public class CassandraSessionModule extends AbstractModule { @Override protected void configure() { - } @Provides @@ -57,19 +50,28 @@ CassandraModule composeDataDefinitions(Set modules) { @Provides @Singleton - Session provideSession(Cluster cluster, CassandraModule cassandraModule) { + Session provideSession(FileSystem fileSystem, Cluster cluster, CassandraModule cassandraModule) + throws FileNotFoundException, ConfigurationException{ + PropertiesConfiguration configuration = getConfiguration(fileSystem); + String keyspace = configuration.getString("cassandra.keyspace"); return new SessionWithInitializedTablesFactory(cassandraModule).createSession(cluster, keyspace); } @Provides @Singleton - Cluster provideCluster() { + Cluster provideCluster(FileSystem fileSystem) throws FileNotFoundException, ConfigurationException { + PropertiesConfiguration configuration = getConfiguration(fileSystem); + return ClusterWithKeyspaceCreatedFactory.clusterWithInitializedKeyspace( ClusterFactory.createClusterForSingleServerWithoutPassWord( - propertiesReader.getProperty("cassandra.ip"), - Integer.parseInt(propertiesReader.getProperty("cassandra.port"))), - keyspace, - Integer.parseInt(propertiesReader.getProperty("cassandra.replication.factor"))); + configuration.getString("cassandra.ip"), + configuration.getInt("cassandra.port")), + configuration.getString("cassandra.keyspace"), + configuration.getInt("cassandra.replication.factor")); } + private PropertiesConfiguration getConfiguration(FileSystem fileSystem) throws FileNotFoundException, ConfigurationException { + return new PropertiesConfiguration(fileSystem.getFile("cassandra.properties")); + } + } \ No newline at end of file diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java index 6709e3138a4..4c8f7cc179e 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java @@ -19,18 +19,26 @@ package org.apache.james.modules.mailbox; -import com.google.inject.AbstractModule; -import com.google.inject.Provides; -import com.google.inject.TypeLiteral; +import java.io.FileNotFoundException; + +import javax.inject.Singleton; + +import org.apache.commons.configuration.ConfigurationException; +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.james.filesystem.api.FileSystem; import org.apache.james.mailbox.cassandra.CassandraId; -import org.apache.james.mailbox.elasticsearch.*; +import org.apache.james.mailbox.elasticsearch.ClientProvider; +import org.apache.james.mailbox.elasticsearch.ClientProviderImpl; +import org.apache.james.mailbox.elasticsearch.IndexCreationFactory; +import org.apache.james.mailbox.elasticsearch.NodeMappingFactory; import org.apache.james.mailbox.elasticsearch.events.ElasticSearchListeningMessageSearchIndex; import org.apache.james.mailbox.store.extractor.TextExtractor; import org.apache.james.mailbox.store.search.MessageSearchIndex; import org.apache.james.mailbox.tika.extractor.TikaTextExtractor; -import org.apache.james.utils.PropertiesReader; -import javax.inject.Singleton; +import com.google.inject.AbstractModule; +import com.google.inject.Provides; +import com.google.inject.TypeLiteral; public class ElasticSearchMailboxModule extends AbstractModule { @@ -44,13 +52,13 @@ protected void configure() { @Provides @Singleton - protected ClientProvider provideClientProvider() { - PropertiesReader propertiesReader = new PropertiesReader("elasticsearch.properties"); - ClientProvider clientProvider = new ClientProviderImpl(propertiesReader.getProperty("elasticsearch.masterHost"), - Integer.parseInt(propertiesReader.getProperty("elasticsearch.port"))); + protected ClientProvider provideClientProvider(FileSystem fileSystem) throws ConfigurationException, FileNotFoundException { + PropertiesConfiguration propertiesReader = new PropertiesConfiguration(fileSystem.getFile("elasticsearch.properties")); + ClientProvider clientProvider = new ClientProviderImpl(propertiesReader.getString("elasticsearch.masterHost"), + propertiesReader.getInt("elasticsearch.port")); IndexCreationFactory.createIndex(clientProvider, - Integer.parseInt(propertiesReader.getProperty("elasticsearch.nb.shards")), - Integer.parseInt(propertiesReader.getProperty("elasticsearch.nb.replica"))); + propertiesReader.getInt("elasticsearch.nb.shards"), + propertiesReader.getInt("elasticsearch.nb.replica")); NodeMappingFactory.applyMapping(clientProvider); return clientProvider; } From 0ad44534631ebbae433c1b758455b5fb331d8c57 Mon Sep 17 00:00:00 2001 From: Antoine Duprat Date: Wed, 9 Sep 2015 15:55:22 +0200 Subject: [PATCH 22/39] JAMES-1626 Fix a typo on the site in the server index file --- server/src/site/xdoc/index.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/site/xdoc/index.xml b/server/src/site/xdoc/index.xml index d7c0e144d62..6f41a337dcf 100644 --- a/server/src/site/xdoc/index.xml +++ b/server/src/site/xdoc/index.xml @@ -118,7 +118,7 @@ - +

Configure the stores,... via the well-known Spring framework - read more.

From 6d2364f52b317dfff268677759c3215df87c0e1c Mon Sep 17 00:00:00 2001 From: Antoine Duprat Date: Thu, 10 Sep 2015 14:48:33 +0200 Subject: [PATCH 23/39] JAMES-1626 Add configuration documentation --- server/src/site/xdoc/config-cassandra.xml | 49 +++++ server/src/site/xdoc/config-elasticsearch.xml | 45 ++++ server/src/site/xdoc/config-guice.xml | 99 +++++++++ server/src/site/xdoc/index.xml | 10 +- .../src/site/xdoc/quick-start-cassandra.xml | 192 ++++++++++++++++++ 5 files changed, 394 insertions(+), 1 deletion(-) create mode 100644 server/src/site/xdoc/config-cassandra.xml create mode 100644 server/src/site/xdoc/config-elasticsearch.xml create mode 100644 server/src/site/xdoc/config-guice.xml create mode 100644 server/src/site/xdoc/quick-start-cassandra.xml diff --git a/server/src/site/xdoc/config-cassandra.xml b/server/src/site/xdoc/config-cassandra.xml new file mode 100644 index 00000000000..6241480afff --- /dev/null +++ b/server/src/site/xdoc/config-cassandra.xml @@ -0,0 +1,49 @@ + + + + + + Apache James Server 3 - Cassandra Configuration + + + + +
+ +

Consult cassandra-template.properties to get some examples and hints.

+ +
+
cassandra.ip
+
Is the IP (or host) of the Cassandra used. (cluster is not yet supported)
+
cassandra.port
+
Is the port used to connect to Cassandra.
+
cassandra.keyspace
+
Is the name of the keyspace used by James.
+
cassandra.replication.factor
+
Is the replication factor. (should be 1, as cluster is not yet supported)
+
+ +

If you want more explanation about Cassandra configuration, you should visit the dedicated documentation.

+ +
+ + + +
diff --git a/server/src/site/xdoc/config-elasticsearch.xml b/server/src/site/xdoc/config-elasticsearch.xml new file mode 100644 index 00000000000..bcd7d0e416b --- /dev/null +++ b/server/src/site/xdoc/config-elasticsearch.xml @@ -0,0 +1,45 @@ + + + + + + Apache James Server 3 - ElasticSearch Configuration + + + + +
+ +

Consult elasticsearch-template.properties to get some examples and hints.

+ +
+
elasticsearch.clusterName
+
Is the name of the cluster used by James.
+
elasticsearch.masterHost
+
Is the IP (or host) of the ElasticSearch master
+
+ +

If you want more explanation about ElasticSearch configuration, you should visit the dedicated documentation.

+ +
+ + + +
diff --git a/server/src/site/xdoc/config-guice.xml b/server/src/site/xdoc/config-guice.xml new file mode 100644 index 00000000000..148c11a755d --- /dev/null +++ b/server/src/site/xdoc/config-guice.xml @@ -0,0 +1,99 @@ + + + + + + Apache James Server 3 - Guice configuration + + + + +
+ +

Such configuration is only developed for Cassandra backend.

+

You are encouraged to contribute by developing a new backend guice module. + Have a look to the james-server-cassandra-guice artifact. +

+ +

We provide a sample-configuration folder with needed files to run James. + You can start by copying it and modify these files according to your needs.

+ +

You can/must configure James for the following:

+ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + +
Config File SampleConfig AreaConfig Comment
cassandra-template.propertiesCassandra Configuration
dnsservice.xmlDNS Service Configuration
elasticsearch-template.propertiesElasticSearch Configuration
imapserver.xmlIMAP4 Configuration
lmtpserver.xmlLMTP Configuration
mailetcontainer.xmlMailet Container Configuration
pop3server.xmlPOP3 Configuration
smtpserver.xmlSMTP Configuration
+ +

See also more specific configurations related to TLS, + Sieve and + Antispam.

+ +
+ + + +
diff --git a/server/src/site/xdoc/index.xml b/server/src/site/xdoc/index.xml index 6f41a337dcf..ca4bf79c62e 100644 --- a/server/src/site/xdoc/index.xml +++ b/server/src/site/xdoc/index.xml @@ -64,6 +64,12 @@ manage, monitor and develop Apache James Server.

+

+ We are currently working on an experimental module which goal is to simplify the configuration process. + This module only supports the Cassandra backend yet, + and may be started with docker. +

+

Download Apache James Mail Server 3.0-beta4 and quick-start it!

@@ -120,10 +126,12 @@ -

Configure the stores,... via the well-known Spring framework - read more.

+

Configure the stores,...

+

via the well-known Spring framework - read more.

+

or via the Guice module - read more.

diff --git a/server/src/site/xdoc/quick-start-cassandra.xml b/server/src/site/xdoc/quick-start-cassandra.xml new file mode 100644 index 00000000000..f68d586668a --- /dev/null +++ b/server/src/site/xdoc/quick-start-cassandra.xml @@ -0,0 +1,192 @@ + + + + + + Apache James Server 3 - Quick Start for Cassandra backend + + + + +
+ +

The goal of the document is to allow anyone to start with James on Docker as an operational mail server.

+

The method described bellow should not be used in production.

+ + +Step 0: Requirements +#################### + + * Java 8 SDK + * 512MB RAM (launches with -Xmx512M - can use less, can need more, depending on load) + * Docker 1.7.1+ + * Maven 3.3 + +Step 1: Download +################# + + * Clone the James git repository + +$ git clone git://git.apache.org/james.git + + * Then go to the James folder + +$ cd james + +Step 3: Compile +############### + + * Compile the Guice Cassandra project + +$ mvn package -DskipTests + +Step 3: Deploy +############## + +3.1. Deploy Cassandra (optional) +You may skip this part if you already have a running Cassandra on your network. + +$ docker run --name=cassandra cassandra + +3.2. Deploy ElasticSearch (optional) +You may skip this part if you already have a running ElasticSearch on your network. + +$ docker run --name=elasticsearch elasticsearch:1.5.2 + +Step 4: Configure +################# + + * Follow the Cassandra guice configuration documentation. + * We need to provide the key we will use for TLS. For obvious reasons, this is not provided in this git. + +Copy your TSL keys to ./conf/keystore or generate it using : + +$ keytool -genkey -alias james -keyalg RSA -keystore ./conf/keystore + +Configure your domain in the ./conf/domainlist.xml file. + +Step 5: Start +############# + + * Run James + +$ java -Dworking.directory=WORKING_PATH -jar container/cassandra-guice/target/james-server-cassandra-guice-beta5-SNAPSHOT.jar + +Where : +- WORKING_PATH is the path where are located your configuration file folder. + +Step 6: Create Domains and Users +################################ + +Time to add domains and users. + +Give enough rights to the James CLI + +$ chmod 755 app/target/appassembler/bin/james-cli.sh + +$ ./app/target/appassembler/bin/james-cli.sh -h 127.0.0.1 -p 9999 adduser USER_MAIL_ADDRESS PASSWORD + +Where : +- USER_MAIL_ADDRESS is the mail address that will be used by this user. +- PASSWORD is the password that will be used by this user. + +Step 8: Test +############ + +$ telnet HOSTNAME 25 +Trying HOSTNAME... +Connected to HOSTNAME. +Escape character is '^]'. +220 172.16.1.131 SMTP Server (JAMES SMTP Server 3.0-beta4) ready Sat, 6 Nov 2010 17:31:33 +0100 (CET) +ehlo test +250-172.16.1.131 Hello test (aoscommunity.com [127.0.0.1]) +250-PIPELINING +250-ENHANCEDSTATUSCODES +250 8BITMIME +mail from:<YOUR_NAME@YOUR_DOMAIN> +250 2.1.0 Sender <YOUR_NAME@YOUR_DOMAIN> OK +rcpt to:<YOUR_NAME@YOUR_DOMAIN> +250 2.1.5 Recipient <YOUR_NAME@YOUR_DOMAIN> OK +data +354 Ok Send data ending with <CRLF>.<CRLF> +subject: test + +this is a test +. +250 2.6.0 Message received +quit +Connection closed by foreign host. + +Step 8: Manage +############## + +8.1. Manage via james-cli + + usage: +$ docker exec james-cassandra /root/james-server-app-3.0.0-beta5-SNAPSHOT/bin/james-cli.sh -h 127.0.0.1 -p 9999 + + Available commands: + adduser </username> </password> + removeuser </username> + listusers + adddomain </domainname> + removedomain </domainname> + listdomains + +8.2. Manage via JMX + + * Launch jconsole (or any other JMX client) and connect on URL=service:jmx:rmi:///jndi/rmi://localhost:HOSTNAME/jmxrmi + * Select the MBeans tab and open the org.apache.james node to view attributes and execute operations. + +Step 9: Monitor +############### + + * Monitor the ./log/james-server.log log file. + + * Monitor via JMX (launch any JMX client and connect to URL=service:jmx:rmi:///jndi/rmi://HOSTNAME:9999/jmxrmi) + + * Check ./var folder usage + + mail + +-error + +-address-error + +-relay-denied + +-spam + + store + +-maildir + +-derby + +-jackrabbit + +-activemq + +-brokers + +-james + +-blob-transfer + +-outgoing + +-spool + + * Check /tmp folder usage + + + +
+ + + +
From 7fe035ca5674a8ba9dc219469ea868cfe3a60247 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 15 Sep 2015 12:21:32 +0200 Subject: [PATCH 24/39] JAMES-1626 sample configuration and readme --- server/container/cassandra-guice/README.adoc | 39 +++++ .../sample-configuration/cassandra.properties | 6 + .../sample-configuration/dnsservice.xml | 29 ++++ .../sample-configuration/domainlist.xml | 28 ++++ .../elasticsearch.properties | 26 ++++ .../sample-configuration/imapserver.xml | 54 +++++++ .../sample-configuration/jcr-repository.xml | 72 +++++++++ .../sample-configuration/jmx.properties | 28 ++++ .../sample-configuration/lmtpserver.xml | 41 ++++++ .../sample-configuration/mailetcontainer.xml | 137 ++++++++++++++++++ .../mailrepositorystore.xml | 34 +++++ .../sample-configuration/pop3server.xml | 42 ++++++ .../recipientrewritetable.xml | 27 ++++ .../sample-configuration/smtpserver.xml | 105 ++++++++++++++ .../sample-configuration/usersrepository.xml | 26 ++++ 15 files changed, 694 insertions(+) create mode 100644 server/container/cassandra-guice/README.adoc create mode 100644 server/container/cassandra-guice/sample-configuration/cassandra.properties create mode 100644 server/container/cassandra-guice/sample-configuration/dnsservice.xml create mode 100644 server/container/cassandra-guice/sample-configuration/domainlist.xml create mode 100644 server/container/cassandra-guice/sample-configuration/elasticsearch.properties create mode 100644 server/container/cassandra-guice/sample-configuration/imapserver.xml create mode 100644 server/container/cassandra-guice/sample-configuration/jcr-repository.xml create mode 100644 server/container/cassandra-guice/sample-configuration/jmx.properties create mode 100644 server/container/cassandra-guice/sample-configuration/lmtpserver.xml create mode 100644 server/container/cassandra-guice/sample-configuration/mailetcontainer.xml create mode 100644 server/container/cassandra-guice/sample-configuration/mailrepositorystore.xml create mode 100644 server/container/cassandra-guice/sample-configuration/pop3server.xml create mode 100644 server/container/cassandra-guice/sample-configuration/recipientrewritetable.xml create mode 100644 server/container/cassandra-guice/sample-configuration/smtpserver.xml create mode 100644 server/container/cassandra-guice/sample-configuration/usersrepository.xml diff --git a/server/container/cassandra-guice/README.adoc b/server/container/cassandra-guice/README.adoc new file mode 100644 index 00000000000..7b6698e180f --- /dev/null +++ b/server/container/cassandra-guice/README.adoc @@ -0,0 +1,39 @@ += Guice-Cassandra 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-cassandra-guice-${version}.jar + * james-server-cassandra-guice-${version}.lib + +== Running + +=== Requirements + + * Cassandra + * ElasticSearch 1.5.2 + +=== 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 need to have a Cassandra and an ElasticSearch instance running. + +Once everything is set up, you just have to run the jar with : + +[source] +---- +$ java -Dworking.directory=sample-configuration -jar target/james-server-cassandra-guice-${version}.jar +---- diff --git a/server/container/cassandra-guice/sample-configuration/cassandra.properties b/server/container/cassandra-guice/sample-configuration/cassandra.properties new file mode 100644 index 00000000000..1358332a51e --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/cassandra.properties @@ -0,0 +1,6 @@ +# Configuration file for cassandra mailbox + +cassandra.ip=172.17.0.2 +cassandra.port=9042 +cassandra.keyspace=apache_james +cassandra.replication.factor=1 \ No newline at end of file diff --git a/server/container/cassandra-guice/sample-configuration/dnsservice.xml b/server/container/cassandra-guice/sample-configuration/dnsservice.xml new file mode 100644 index 00000000000..0978a00b899 --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/dnsservice.xml @@ -0,0 +1,29 @@ + + + + + + 8.8.8.8 + 62.210.16.6 + + false + false + 50000 + diff --git a/server/container/cassandra-guice/sample-configuration/domainlist.xml b/server/container/cassandra-guice/sample-configuration/domainlist.xml new file mode 100644 index 00000000000..8d001185bbb --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/domainlist.xml @@ -0,0 +1,28 @@ + + + + + + james.apache.org + + true + true + localhost + diff --git a/server/container/cassandra-guice/sample-configuration/elasticsearch.properties b/server/container/cassandra-guice/sample-configuration/elasticsearch.properties new file mode 100644 index 00000000000..924404c41c7 --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/elasticsearch.properties @@ -0,0 +1,26 @@ +# 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 + +# Configuration file for ElasticSearch + +elasticsearch.masterHost=172.17.0.1 +elasticsearch.port=9300 +elasticsearch.nb.shards=1 +elasticsearch.nb.replica=0 \ No newline at end of file diff --git a/server/container/cassandra-guice/sample-configuration/imapserver.xml b/server/container/cassandra-guice/sample-configuration/imapserver.xml new file mode 100644 index 00000000000..c03b978fb5a --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/imapserver.xml @@ -0,0 +1,54 @@ + + + + + + + + imapserver + 0.0.0.0:1143 + 200 + + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + + 0 + 0 + + + imapserver-ssl + 0.0.0.0:1993 + 200 + + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + + 0 + 0 + + diff --git a/server/container/cassandra-guice/sample-configuration/jcr-repository.xml b/server/container/cassandra-guice/sample-configuration/jcr-repository.xml new file mode 100644 index 00000000000..c1b998a75f7 --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/jcr-repository.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/server/container/cassandra-guice/sample-configuration/jmx.properties b/server/container/cassandra-guice/sample-configuration/jmx.properties new file mode 100644 index 00000000000..a1dbdf8924b --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/jmx.properties @@ -0,0 +1,28 @@ +# 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 + +# 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 + +jmx.address=127.0.0.1 +jmx.port=9999 diff --git a/server/container/cassandra-guice/sample-configuration/lmtpserver.xml b/server/container/cassandra-guice/sample-configuration/lmtpserver.xml new file mode 100644 index 00000000000..87a0caaf793 --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/lmtpserver.xml @@ -0,0 +1,41 @@ + + + + + + + lmtpserver + + 127.0.0.1:1024 + 200 + 1200 + + 0 + + 0 + + + 0 + + + + + + diff --git a/server/container/cassandra-guice/sample-configuration/mailetcontainer.xml b/server/container/cassandra-guice/sample-configuration/mailetcontainer.xml new file mode 100644 index 00000000000..968b59c4d0e --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/mailetcontainer.xml @@ -0,0 +1,137 @@ + + + + + + + + postmaster@james.minet.net + + + + 20 + + + + + + + + + sieve-manager-check + + + transport + + + true + + + transport + + + transport + + + + + + + spam + 550 Requested action not taken: rejected - see http://njabl.org/ + + + transport + + + + + + + file://var/mail/error/ + + + + + + + X-UserIsAuth + true + + + X-WasSigned + true + + + + + local-address-error + 550 - Requested action not taken: no such user here + + + outgoing + 5000, 100000, 500000 + 25 + 0 + 10 + true + bounces + + + relay-denied + + + + + + file://var/mail/spam/ + + + + + + none + + + file://var/mail/address-error/ + + + + + + none + + + file://var/mail/relay-denied/ + Warning: You are sending an e-mail to a remote server. You must be authentified to perform such an operation + + + + + + false + + + + + + + diff --git a/server/container/cassandra-guice/sample-configuration/mailrepositorystore.xml b/server/container/cassandra-guice/sample-configuration/mailrepositorystore.xml new file mode 100644 index 00000000000..acca810221d --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/mailrepositorystore.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + file + + + + + + diff --git a/server/container/cassandra-guice/sample-configuration/pop3server.xml b/server/container/cassandra-guice/sample-configuration/pop3server.xml new file mode 100644 index 00000000000..c57c8324d6f --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/pop3server.xml @@ -0,0 +1,42 @@ + + + + + + + pop3server + 0.0.0.0:1110 + 200 + + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + + 1200 + 0 + 0 + + + + + diff --git a/server/container/cassandra-guice/sample-configuration/recipientrewritetable.xml b/server/container/cassandra-guice/sample-configuration/recipientrewritetable.xml new file mode 100644 index 00000000000..7e7f586a3c8 --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/recipientrewritetable.xml @@ -0,0 +1,27 @@ + + + + + + true + 10 + some@domain=some + + diff --git a/server/container/cassandra-guice/sample-configuration/smtpserver.xml b/server/container/cassandra-guice/sample-configuration/smtpserver.xml new file mode 100644 index 00000000000..c34fcd1c37c --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/smtpserver.xml @@ -0,0 +1,105 @@ + + + + + + + smtpserver-global + 0.0.0.0:1025 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + false + 0.0.0.0/0 + true + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + smtpserver-TLS + 0.0.0.0:1465 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + + true + 0.0.0.0/0 + + false + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + smtpserver-authenticated + 0.0.0.0:1587 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + + true + 0.0.0.0/0 + + false + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + + diff --git a/server/container/cassandra-guice/sample-configuration/usersrepository.xml b/server/container/cassandra-guice/sample-configuration/usersrepository.xml new file mode 100644 index 00000000000..43afa130870 --- /dev/null +++ b/server/container/cassandra-guice/sample-configuration/usersrepository.xml @@ -0,0 +1,26 @@ + + + + + + MD5 + true + + From 7fc1d15cc07db33c843f8fd39d6eb7ffe85b8cf7 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Thu, 22 Oct 2015 14:21:25 +0200 Subject: [PATCH 25/39] JAMES-1626 use FileSystem to find configuration files --- .../backends/cassandra/CassandraCluster.java | 7 ++- .../james/CassandraJamesServerMain.java | 10 +-- .../james/modules/CommonServicesModule.java | 61 +++++++++++++++++++ .../mailbox/CassandraSessionModule.java | 2 +- .../mailbox/ElasticSearchMailboxModule.java | 2 +- .../protocols/ProtocolHandlerModule.java | 3 - .../james/modules/server/JMXServer.java | 37 ++++++----- .../utils/FileConfigurationProvider.java | 38 +++++++++--- .../james/CassandraJamesServerTest.java | 23 +------ .../james/modules/TestFilesystemModule.java} | 24 +++++--- .../utils/FileConfigurationProviderTest.java | 12 +++- .../InMemoryMailRepositoryStoreTest.java | 13 ++-- .../src/test/resources/cassandra.properties | 6 -- .../test/resources/elasticsearch.properties | 26 -------- .../src/test/resources/jmx.properties | 28 --------- .../james/core/JamesServerResourceLoader.java | 8 ++- .../james/core/filesystem/FileSystemImpl.java | 2 + .../core/filesystem/FileSystemImplTest.java | 15 +---- .../JamesServerApplicationContext.java | 2 +- .../spring/filesystem/FileSystemImplTest.java | 16 +---- 20 files changed, 172 insertions(+), 163 deletions(-) create mode 100644 server/container/cassandra-guice/src/main/java/org/apache/james/modules/CommonServicesModule.java rename server/container/cassandra-guice/src/{main/java/org/apache/james/modules/server/FileSystemModule.java => test/java/org/apache/james/modules/TestFilesystemModule.java} (68%) delete mode 100644 server/container/cassandra-guice/src/test/resources/cassandra.properties delete mode 100644 server/container/cassandra-guice/src/test/resources/elasticsearch.properties delete mode 100644 server/container/cassandra-guice/src/test/resources/jmx.properties diff --git a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java index dfe2c1aa3f8..d60e3430e87 100644 --- a/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java +++ b/backends-common/cassandra/src/test/java/org/apache/james/backends/cassandra/CassandraCluster.java @@ -77,9 +77,8 @@ public void clearAllTables() { private Optional tryInitializeSession() { try { - Cluster cluster = ClusterFactory.createClusterForSingleServerWithoutPassWord(CLUSTER_IP, CLUSTER_PORT_TEST); Cluster clusterWithInitializedKeyspace = ClusterWithKeyspaceCreatedFactory - .clusterWithInitializedKeyspace(cluster, KEYSPACE_NAME, REPLICATION_FACTOR); + .clusterWithInitializedKeyspace(getCluster(), KEYSPACE_NAME, REPLICATION_FACTOR); return Optional.of(new SessionWithInitializedTablesFactory(module).createSession(clusterWithInitializedKeyspace, KEYSPACE_NAME)); } catch (NoHostAvailableException exception) { sleep(SLEEP_BEFORE_RETRY); @@ -87,6 +86,10 @@ private Optional tryInitializeSession() { } } + public Cluster getCluster() { + return ClusterFactory.createClusterForSingleServerWithoutPassWord(CLUSTER_IP, CLUSTER_PORT_TEST); + } + private void sleep(long sleepMs) { try { Thread.sleep(sleepMs); diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java index 27ad824ba32..1ddab6e2e7a 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java @@ -19,6 +19,7 @@ package org.apache.james; +import org.apache.james.modules.CommonServicesModule; import org.apache.james.modules.data.CassandraDomainListModule; import org.apache.james.modules.data.CassandraRecipientRewriteTableModule; import org.apache.james.modules.data.CassandraUsersRepositoryModule; @@ -35,7 +36,6 @@ import org.apache.james.modules.server.ConfigurationPerformerModule; import org.apache.james.modules.server.ConfigurationProviderModule; import org.apache.james.modules.server.DNSServiceModule; -import org.apache.james.modules.server.FileSystemModule; import org.apache.james.modules.server.JMXServerModule; import org.apache.james.modules.server.MailStoreRepositoryModule; import org.apache.james.modules.server.QuotaModule; @@ -47,8 +47,9 @@ public class CassandraJamesServerMain { public static final Module defaultModule = Modules.combine( - new CassandraMailboxModule(), + new CommonServicesModule(), new ConfigurationPerformerModule(), + new CassandraMailboxModule(), new CassandraSessionModule(), new ElasticSearchMailboxModule(), new CassandraUsersRepositoryModule(), @@ -61,7 +62,6 @@ public class CassandraJamesServerMain { new SMTPServerModule(), new LMTPServerModule(), new ActiveMQQueueModule(), - new FileSystemModule(), new SieveModule(), new MailStoreRepositoryModule(), new CamelMailetContainerModule(), @@ -70,8 +70,8 @@ public class CassandraJamesServerMain { public static void main(String[] args) throws Exception { CassandraJamesServer server = new CassandraJamesServer(Modules.combine( - defaultModule, - new JMXServerModule())); + defaultModule, + new JMXServerModule())); server.start(); } diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/CommonServicesModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/CommonServicesModule.java new file mode 100644 index 00000000000..b380d2e72c7 --- /dev/null +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/CommonServicesModule.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.modules; + +import java.util.Optional; + +import javax.inject.Named; +import javax.inject.Singleton; + +import org.apache.commons.cli.MissingArgumentException; +import org.apache.james.core.JamesServerResourceLoader; +import org.apache.james.core.filesystem.FileSystemImpl; +import org.apache.james.filesystem.api.FileSystem; +import org.apache.james.filesystem.api.JamesDirectoriesProvider; +import org.apache.james.utils.ConfigurationProvider; +import org.apache.james.utils.FileConfigurationProvider; + +import com.google.inject.AbstractModule; +import com.google.inject.Provides; + +public class CommonServicesModule extends AbstractModule { + + public static final String CONFIGURATION_PATH = "configurationPath"; + + @Override + protected void configure() { + bind(FileSystem.class).to(FileSystemImpl.class); + bind(ConfigurationProvider.class).to(FileConfigurationProvider.class); + } + + @Provides @Singleton @Named(CONFIGURATION_PATH) + public String configurationPath() { + return FileSystem.FILE_PROTOCOL_AND_CONF; + } + + @Provides @Singleton + public JamesDirectoriesProvider directories() throws MissingArgumentException { + String rootDirectory = Optional + .ofNullable(System.getProperty("working.directory")) + .orElseThrow(() -> new MissingArgumentException("Server needs a working.directory env entry")); + return new JamesServerResourceLoader(rootDirectory); + } + +} diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java index a3777924104..c3588ba3e6f 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraSessionModule.java @@ -71,7 +71,7 @@ Cluster provideCluster(FileSystem fileSystem) throws FileNotFoundException, Conf } private PropertiesConfiguration getConfiguration(FileSystem fileSystem) throws FileNotFoundException, ConfigurationException { - return new PropertiesConfiguration(fileSystem.getFile("cassandra.properties")); + return new PropertiesConfiguration(fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + "cassandra.properties")); } } \ No newline at end of file diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java index 4c8f7cc179e..4ba750ff5b2 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/ElasticSearchMailboxModule.java @@ -53,7 +53,7 @@ protected void configure() { @Provides @Singleton protected ClientProvider provideClientProvider(FileSystem fileSystem) throws ConfigurationException, FileNotFoundException { - PropertiesConfiguration propertiesReader = new PropertiesConfiguration(fileSystem.getFile("elasticsearch.properties")); + PropertiesConfiguration propertiesReader = new PropertiesConfiguration(fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + "elasticsearch.properties")); ClientProvider clientProvider = new ClientProviderImpl(propertiesReader.getString("elasticsearch.masterHost"), propertiesReader.getInt("elasticsearch.port")); IndexCreationFactory.createIndex(clientProvider, diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java index 2b012a33452..10d20d258b0 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java @@ -19,8 +19,6 @@ package org.apache.james.modules.protocols; -import org.apache.james.core.filesystem.FileSystemImpl; -import org.apache.james.filesystem.api.FileSystem; import org.apache.james.protocols.lib.handler.ProtocolHandlerLoader; import org.apache.james.utils.GuiceProtocolHandlerLoader; @@ -30,7 +28,6 @@ public class ProtocolHandlerModule extends AbstractModule { @Override protected void configure() { - bind(FileSystem.class).to(FileSystemImpl.class); bind(ProtocolHandlerLoader.class).to(GuiceProtocolHandlerLoader.class); } diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServer.java b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServer.java index db15ac5aebf..4b4e63d4a70 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServer.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/JMXServer.java @@ -19,32 +19,39 @@ package org.apache.james.modules.server; -import com.google.common.base.Throwables; -import com.google.common.collect.ImmutableMap; -import org.apache.james.util.RestrictingRMISocketFactory; -import org.apache.james.utils.PropertiesReader; +import java.io.IOException; +import java.lang.management.ManagementFactory; +import java.rmi.registry.LocateRegistry; +import java.util.HashSet; +import java.util.Map; +import java.util.Set; import javax.annotation.PreDestroy; +import javax.inject.Inject; import javax.management.MBeanServer; import javax.management.ObjectName; import javax.management.remote.JMXConnectorServer; import javax.management.remote.JMXConnectorServerFactory; import javax.management.remote.JMXServiceURL; -import java.io.IOException; -import java.lang.management.ManagementFactory; -import java.rmi.registry.LocateRegistry; -import java.util.HashSet; -import java.util.Map; -import java.util.Set; + +import org.apache.commons.configuration.PropertiesConfiguration; +import org.apache.james.filesystem.api.FileSystem; +import org.apache.james.util.RestrictingRMISocketFactory; + +import com.google.common.base.Throwables; +import com.google.common.collect.ImmutableMap; public class JMXServer { + private final FileSystem fileSystem; private final Set registeredKeys; private final Object lock; private JMXConnectorServer jmxConnectorServer; private boolean isStarted; - public JMXServer() { + @Inject + public JMXServer(FileSystem fileSystem) { + this.fileSystem = fileSystem; isStarted = false; registeredKeys = new HashSet<>(); lock = new Object(); @@ -79,11 +86,11 @@ public void register(String key, Object remote) throws Exception { } private void doStart() { - PropertiesReader propertiesReader = new PropertiesReader("jmx.properties"); - String address = propertiesReader.getProperty("jmx.address"); - int port = Integer.parseInt(propertiesReader.getProperty("jmx.port")); - String serviceURL = "service:jmx:rmi://" + address + "/jndi/rmi://" + address+ ":" + port +"/jmxrmi"; try { + PropertiesConfiguration configuration = new PropertiesConfiguration(fileSystem.getFile(FileSystem.FILE_PROTOCOL_AND_CONF + "jmx.properties")); + String address = configuration.getString("jmx.address"); + int port = configuration.getInt("jmx.port"); + String serviceURL = "service:jmx:rmi://" + address + "/jndi/rmi://" + address+ ":" + port +"/jmxrmi"; RestrictingRMISocketFactory restrictingRMISocketFactory = new RestrictingRMISocketFactory(address); LocateRegistry.createRegistry(port, restrictingRMISocketFactory, restrictingRMISocketFactory); diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/FileConfigurationProvider.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/FileConfigurationProvider.java index 7b9d513b827..75ad86bc3b4 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/FileConfigurationProvider.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/FileConfigurationProvider.java @@ -19,21 +19,40 @@ package org.apache.james.utils; -import com.google.common.base.Preconditions; -import com.google.common.base.Strings; +import java.io.IOException; +import java.io.InputStream; +import java.util.Arrays; +import java.util.List; + +import javax.inject.Inject; +import javax.inject.Named; + +import org.apache.commons.cli.MissingArgumentException; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.HierarchicalConfiguration; import org.apache.commons.configuration.XMLConfiguration; +import org.apache.james.filesystem.api.FileSystem; +import org.apache.james.modules.CommonServicesModule; -import java.io.InputStream; -import java.util.Arrays; -import java.util.List; -import java.util.Optional; +import com.google.common.base.Preconditions; +import com.google.common.base.Strings; +import com.google.inject.Singleton; +@Singleton public class FileConfigurationProvider implements ConfigurationProvider { private static final String CONFIGURATION_FILE_SUFFIX = ".xml"; + + private final FileSystem fileSystem; + private String configurationPrefix; + + @Inject + public FileConfigurationProvider(FileSystem fileSystem, @Named(CommonServicesModule.CONFIGURATION_PATH) String configurationPrefix) throws MissingArgumentException { + this.fileSystem = fileSystem; + this.configurationPrefix = configurationPrefix; + } + @Override public HierarchicalConfiguration getConfiguration(String component) throws ConfigurationException { List configPathParts = Arrays.asList(component.split("\\.")); @@ -43,8 +62,11 @@ public HierarchicalConfiguration getConfiguration(String component) throws Confi private InputStream retrieveConfigInputStream(String configurationFileWithoutExtension) throws ConfigurationException { Preconditions.checkArgument(!Strings.isNullOrEmpty(configurationFileWithoutExtension), "The configuration file name should not be empty or null"); - return Optional.ofNullable(ClassLoader.getSystemResourceAsStream(configurationFileWithoutExtension + CONFIGURATION_FILE_SUFFIX)) - .orElseThrow(() -> new ConfigurationException("Unable to locate configuration file " + configurationFileWithoutExtension + CONFIGURATION_FILE_SUFFIX)); + try { + return fileSystem.getResource(configurationPrefix + configurationFileWithoutExtension + CONFIGURATION_FILE_SUFFIX); + } catch (IOException e) { + throw new ConfigurationException("Unable to locate configuration file " + configurationFileWithoutExtension + CONFIGURATION_FILE_SUFFIX, e); + } } private XMLConfiguration getConfig(InputStream configStream) throws ConfigurationException { diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java index b7a5c8b037a..e79894ee7f6 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java @@ -20,7 +20,6 @@ import static org.assertj.core.api.Assertions.assertThat; -import java.io.File; import java.io.IOException; import java.net.InetSocketAddress; import java.nio.ByteBuffer; @@ -29,10 +28,9 @@ import org.apache.james.backends.cassandra.CassandraCluster; import org.apache.james.backends.cassandra.components.CassandraModule; -import org.apache.james.core.JamesServerResourceLoader; -import org.apache.james.filesystem.api.JamesDirectoriesProvider; import org.apache.james.mailbox.elasticsearch.EmbeddedElasticSearch; import org.apache.james.modules.TestElasticSearchModule; +import org.apache.james.modules.TestFilesystemModule; import org.junit.After; import org.junit.Before; import org.junit.Rule; @@ -62,25 +60,6 @@ public class CassandraJamesServerTest { @Rule public RuleChain chain = RuleChain.outerRule(temporaryFolder).around(embeddedElasticSearch); - private static class TestFilesystemModule extends AbstractModule { - - JamesServerResourceLoader jamesServerResourceLoader; - - TestFilesystemModule(File tmpDir) { - jamesServerResourceLoader = new JamesServerResourceLoader() { - @Override - public String getRootDirectory() { - return tmpDir.getAbsolutePath(); - } - }; - } - - @Override - protected void configure() { - bind(JamesDirectoriesProvider.class).toInstance(jamesServerResourceLoader); - } - } - @Before public void setup() throws Exception { server = new CassandraJamesServer(Modules.override(CassandraJamesServerMain.defaultModule) diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java b/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestFilesystemModule.java similarity index 68% rename from server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java rename to server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestFilesystemModule.java index bd85c798acd..63b46b47e2d 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/modules/TestFilesystemModule.java @@ -16,21 +16,31 @@ * specific language governing permissions and limitations * * under the License. * ****************************************************************/ -package org.apache.james.modules.server; + +package org.apache.james.modules; + +import java.io.File; import org.apache.james.core.JamesServerResourceLoader; -import org.apache.james.core.filesystem.FileSystemImpl; import org.apache.james.filesystem.api.FileSystem; import org.apache.james.filesystem.api.JamesDirectoriesProvider; +import org.apache.james.modules.CommonServicesModule; import com.google.inject.AbstractModule; +import com.google.inject.name.Names; -public class FileSystemModule extends AbstractModule { +public class TestFilesystemModule extends AbstractModule { + + private File workingDirectory; - @Override - public void configure() { - bind(JamesDirectoriesProvider.class).to(JamesServerResourceLoader.class); - bind(FileSystem.class).to(FileSystemImpl.class); + public TestFilesystemModule(File workingDirectory) { + this.workingDirectory = workingDirectory; } + @Override + protected void configure() { + bind(JamesDirectoriesProvider.class).toInstance(new JamesServerResourceLoader(workingDirectory.getAbsolutePath())); + bindConstant().annotatedWith(Names.named(CommonServicesModule.CONFIGURATION_PATH)).to(FileSystem.CLASSPATH_PROTOCOL); + } + } diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java index 679ec714924..f4d07307269 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java @@ -21,12 +21,17 @@ import static org.assertj.core.api.Assertions.assertThat; -import com.google.common.collect.Lists; +import org.apache.commons.cli.MissingArgumentException; import org.apache.commons.configuration.ConfigurationException; import org.apache.commons.configuration.HierarchicalConfiguration; +import org.apache.james.core.JamesServerResourceLoader; +import org.apache.james.core.filesystem.FileSystemImpl; +import org.apache.james.filesystem.api.FileSystem; import org.junit.Before; import org.junit.Test; +import com.google.common.collect.Lists; + public class FileConfigurationProviderTest { private static final String CONFIG_KEY_1 = "test2"; @@ -43,8 +48,9 @@ public class FileConfigurationProviderTest { private FileConfigurationProvider configurationProvider; @Before - public void setUp() { - configurationProvider = new FileConfigurationProvider(); + public void setUp() throws MissingArgumentException { + FileSystemImpl fileSystem = new FileSystemImpl(new JamesServerResourceLoader("../")); + configurationProvider = new FileConfigurationProvider(fileSystem, FileSystem.CLASSPATH_PROTOCOL); } @Test(expected = IllegalArgumentException.class) diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java index 751406dedc9..d8582b3f5db 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/InMemoryMailRepositoryStoreTest.java @@ -25,6 +25,7 @@ import org.apache.commons.configuration.ConfigurationException; import org.apache.james.core.JamesServerResourceLoader; import org.apache.james.core.filesystem.FileSystemImpl; +import org.apache.james.filesystem.api.FileSystem; import org.apache.james.mailrepository.api.MailRepositoryStore; import org.apache.james.mailrepository.file.FileMailRepository; import org.apache.james.modules.server.MailStoreRepositoryModule; @@ -36,13 +37,15 @@ public class InMemoryMailRepositoryStoreTest { private InMemoryMailRepositoryStore repositoryStore; + private FileSystemImpl fileSystem; @Before public void setUp() throws Exception { + fileSystem = new FileSystemImpl(new JamesServerResourceLoader("../")); repositoryStore = new InMemoryMailRepositoryStore(Sets.newHashSet( new MailStoreRepositoryModule.FileMailRepositoryProvider( - new FileSystemImpl(new JamesServerResourceLoader())))); - repositoryStore.configure(new FileConfigurationProvider().getConfiguration("mailrepositorystore")); + fileSystem))); + repositoryStore.configure(new FileConfigurationProvider(fileSystem, FileSystem.CLASSPATH_PROTOCOL).getConfiguration("mailrepositorystore")); repositoryStore.init(); } @@ -71,9 +74,9 @@ public void configureShouldThrowWhenNonValidClassesAreProvided() throws Exceptio try { repositoryStore = new InMemoryMailRepositoryStore(Sets.newHashSet( new MailStoreRepositoryModule.FileMailRepositoryProvider( - new FileSystemImpl(new JamesServerResourceLoader())))); - repositoryStore.configure(new FileConfigurationProvider().getConfiguration("fakemailrepositorystore")); - } catch (Exception e) { + fileSystem))); + repositoryStore.configure(new FileConfigurationProvider(fileSystem, FileSystem.CLASSPATH_PROTOCOL).getConfiguration("fakemailrepositorystore")); + } catch (ConfigurationException e) { fail("Unexpected failure : ", e); } repositoryStore.init(); diff --git a/server/container/cassandra-guice/src/test/resources/cassandra.properties b/server/container/cassandra-guice/src/test/resources/cassandra.properties deleted file mode 100644 index b4db9c1f7a8..00000000000 --- a/server/container/cassandra-guice/src/test/resources/cassandra.properties +++ /dev/null @@ -1,6 +0,0 @@ -# Configuration file for cassandra mailbox - -cassandra.ip=127.0.0.1 -cassandra.port=9142 -cassandra.keyspace=apache_james -cassandra.replication.factor=1 \ No newline at end of file diff --git a/server/container/cassandra-guice/src/test/resources/elasticsearch.properties b/server/container/cassandra-guice/src/test/resources/elasticsearch.properties deleted file mode 100644 index 454dabe2949..00000000000 --- a/server/container/cassandra-guice/src/test/resources/elasticsearch.properties +++ /dev/null @@ -1,26 +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. - -# This template file can be used as example for James Server configuration -# DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS - -# Configuration file for ElasticSearch - -elasticsearch.masterHost=127.0.0.1 -elasticsearch.port=9300 -elasticsearch.nb.shards=1 -elasticsearch.nb.replica=0 \ No newline at end of file diff --git a/server/container/cassandra-guice/src/test/resources/jmx.properties b/server/container/cassandra-guice/src/test/resources/jmx.properties deleted file mode 100644 index a1dbdf8924b..00000000000 --- a/server/container/cassandra-guice/src/test/resources/jmx.properties +++ /dev/null @@ -1,28 +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. -# - -# This template file can be used as example for James Server configuration -# DO NOT USE IT AS SUCH AND ADAPT IT TO YOUR NEEDS - -# 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 - -jmx.address=127.0.0.1 -jmx.port=9999 diff --git a/server/container/core/src/main/java/org/apache/james/core/JamesServerResourceLoader.java b/server/container/core/src/main/java/org/apache/james/core/JamesServerResourceLoader.java index 456771198db..4b3e5cb9d77 100644 --- a/server/container/core/src/main/java/org/apache/james/core/JamesServerResourceLoader.java +++ b/server/container/core/src/main/java/org/apache/james/core/JamesServerResourceLoader.java @@ -22,6 +22,12 @@ public class JamesServerResourceLoader implements JamesDirectoriesProvider { + private final String rootDirectory; + + public JamesServerResourceLoader(String rootDirectory) { + this.rootDirectory = rootDirectory; + } + /** * @see org.apache.james.container.spring.resource.JamesResourceLoader#getAbsoluteDirectory() */ @@ -60,7 +66,7 @@ public String getExternalLibraryDirectory() { * org.apache.james.container.spring.resource.JamesResourceLoader#getRootDirectory() */ public String getRootDirectory() { - return "../"; + return rootDirectory; } } \ No newline at end of file diff --git a/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java b/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java index b4dfadc0536..7724d769214 100644 --- a/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java +++ b/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java @@ -24,10 +24,12 @@ import java.io.InputStream; import javax.inject.Inject; +import javax.inject.Singleton; import org.apache.james.filesystem.api.FileSystem; import org.apache.james.filesystem.api.JamesDirectoriesProvider; +@Singleton public class FileSystemImpl implements FileSystem { private final JamesDirectoriesProvider directoryProvider; diff --git a/server/container/core/src/test/java/org/apache/james/core/filesystem/FileSystemImplTest.java b/server/container/core/src/test/java/org/apache/james/core/filesystem/FileSystemImplTest.java index 7dda1cd84a7..28c9de4ef23 100644 --- a/server/container/core/src/test/java/org/apache/james/core/filesystem/FileSystemImplTest.java +++ b/server/container/core/src/test/java/org/apache/james/core/filesystem/FileSystemImplTest.java @@ -26,20 +26,7 @@ public class FileSystemImplTest extends AbstractFileSystemTest { @Override protected FileSystem buildFileSystem(String configurationRootDirectory) { - return new FileSystemImpl(new TestDirectoryProvider(configurationRootDirectory)); + return new FileSystemImpl(new JamesServerResourceLoader(configurationRootDirectory)); } - private class TestDirectoryProvider extends JamesServerResourceLoader { - private String configurationRootDirectory; - - public TestDirectoryProvider(String configurationRootDirectory) { - this.configurationRootDirectory = configurationRootDirectory; - } - - @Override - public String getRootDirectory() { - return configurationRootDirectory; - } - } - } diff --git a/server/container/spring/src/main/java/org/apache/james/container/spring/context/JamesServerApplicationContext.java b/server/container/spring/src/main/java/org/apache/james/container/spring/context/JamesServerApplicationContext.java index 1d6d11a3192..06dba52b10c 100644 --- a/server/container/spring/src/main/java/org/apache/james/container/spring/context/JamesServerApplicationContext.java +++ b/server/container/spring/src/main/java/org/apache/james/container/spring/context/JamesServerApplicationContext.java @@ -34,7 +34,7 @@ public class JamesServerApplicationContext extends ClassPathXmlApplicationContex * The resourceloader to use. This must be defined as static, otherwise it * will fail to startup.. */ - private final static JamesResourceLoader resourceLoader = new DefaultJamesResourceLoader(new JamesServerResourceLoader()); + private final static JamesResourceLoader resourceLoader = new DefaultJamesResourceLoader(new JamesServerResourceLoader("../")); public JamesServerApplicationContext(String[] configs) { super(configs); diff --git a/server/container/spring/src/test/java/org/apache/james/container/spring/filesystem/FileSystemImplTest.java b/server/container/spring/src/test/java/org/apache/james/container/spring/filesystem/FileSystemImplTest.java index f2a567a70de..b6b6604f031 100644 --- a/server/container/spring/src/test/java/org/apache/james/container/spring/filesystem/FileSystemImplTest.java +++ b/server/container/spring/src/test/java/org/apache/james/container/spring/filesystem/FileSystemImplTest.java @@ -44,21 +44,7 @@ public TestApplicationContextProvider(String configurationRootDirectory, String[ @Override public JamesResourceLoader getResourceLoader() { - return new DefaultJamesResourceLoader(new TestDirectoryProvider(configurationRootDirectory)); - } - } - - private static class TestDirectoryProvider extends JamesServerResourceLoader { - - private String configurationRootDirectory; - - public TestDirectoryProvider(String configurationRootDirectory) { - this.configurationRootDirectory = configurationRootDirectory; - } - - @Override - public String getRootDirectory() { - return configurationRootDirectory; + return new DefaultJamesResourceLoader(new JamesServerResourceLoader(configurationRootDirectory)); } } From 6fe829d546e84a00d2cc8ff9e311fbb28c728902 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Wed, 28 Oct 2015 12:58:35 +0100 Subject: [PATCH 26/39] JAMES-1626 move everything needed to run spring james under dockerfiles/run/spring --- README.txt | 16 ++++++++-------- dockerfiles/{ => run/spring}/Dockerfile | 0 .../{ => run/spring}/destination/.gitignore | 0 .../conf/META-INF/jpa-mappings-template.xml | 0 .../conf/META-INF/persistence-template.xml | 0 .../destination/conf/META-INF/persistence.xml | 0 .../destination/conf/cassandra.properties | 0 .../spring}/destination/conf/dnsservice.xml | 0 .../spring}/destination/conf/domainlist.xml | 0 .../destination/conf/elasticsearch.properties | 0 .../spring}/destination/conf/fetchmail.xml | 0 .../spring}/destination/conf/imapserver.xml | 0 .../spring}/destination/conf/indexer.xml | 0 .../destination/conf/james-database.properties | 0 .../spring}/destination/conf/jcr-repository.xml | 0 .../spring}/destination/conf/jmx.properties | 0 .../spring}/destination/conf/lib/README.txt | 0 .../spring}/destination/conf/lmtpserver.xml | 0 .../spring}/destination/conf/log4j.properties | 0 .../spring}/destination/conf/mailbox.xml | 0 .../spring}/destination/conf/mailetcontainer.xml | 0 .../destination/conf/mailrepositorystore.xml | 0 .../destination/conf/managesieve.help.txt | 0 .../spring}/destination/conf/pop3server.xml | 0 .../{ => run/spring}/destination/conf/quota.xml | 0 .../destination/conf/recipientrewritetable.xml | 0 .../spring}/destination/conf/smtpserver.xml | 0 .../spring}/destination/conf/sqlResources.xml | 0 .../spring}/destination/conf/usersrepository.xml | 0 .../{ => run/spring}/destination/var/.gitignore | 0 30 files changed, 8 insertions(+), 8 deletions(-) rename dockerfiles/{ => run/spring}/Dockerfile (100%) rename dockerfiles/{ => run/spring}/destination/.gitignore (100%) rename dockerfiles/{ => run/spring}/destination/conf/META-INF/jpa-mappings-template.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/META-INF/persistence-template.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/META-INF/persistence.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/cassandra.properties (100%) rename dockerfiles/{ => run/spring}/destination/conf/dnsservice.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/domainlist.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/elasticsearch.properties (100%) rename dockerfiles/{ => run/spring}/destination/conf/fetchmail.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/imapserver.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/indexer.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/james-database.properties (100%) rename dockerfiles/{ => run/spring}/destination/conf/jcr-repository.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/jmx.properties (100%) rename dockerfiles/{ => run/spring}/destination/conf/lib/README.txt (100%) rename dockerfiles/{ => run/spring}/destination/conf/lmtpserver.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/log4j.properties (100%) rename dockerfiles/{ => run/spring}/destination/conf/mailbox.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/mailetcontainer.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/mailrepositorystore.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/managesieve.help.txt (100%) rename dockerfiles/{ => run/spring}/destination/conf/pop3server.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/quota.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/recipientrewritetable.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/smtpserver.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/sqlResources.xml (100%) rename dockerfiles/{ => run/spring}/destination/conf/usersrepository.xml (100%) rename dockerfiles/{ => run/spring}/destination/var/.gitignore (100%) diff --git a/README.txt b/README.txt index 144ba280015..33935ea89b6 100644 --- a/README.txt +++ b/README.txt @@ -57,13 +57,13 @@ First step, you have to build the Docker image $ docker build -t james/project dockerfiles/compilation/java-6 In order to run the build, you have to launch the following command: -$ docker run -v $PWD/.m2:/root/.m2 -v $PWD:/origin -v $PWD/dockerfiles/destination:/destination -t james/project -s SHA1 +$ docker run -v $PWD/.m2:/root/.m2 -v $PWD:/origin -v $PWD/dockerfiles/run/spring/destination:/destination -t james/project -s SHA1 Where: - $PWD/.m2:/root/.m2: is the first volume used to share the maven repository, as we don't want to download all dependencies on each build -- $PWD/dockerfiles/destination:/destination: is the third volume used to get the compiled elements, +- $PWD/dockerfiles/run/spring/destination:/destination: is the third volume used to get the compiled elements, as it is needed by the container that will run James. - SHA1 (optional): is the given git SHA1 of the james-project repository to build or trunk if none. - -s option: given tests will not be played while building. Not specifying means play tests. @@ -74,13 +74,13 @@ First step, you have to build the Docker image $ docker build -t james/project dockerfiles/compilation/java-8 In order to run the build, you have to launch the following command: -$ docker run -v $PWD/.m2:/root/.m2 -v $PWD:/origin -v $PWD/dockerfiles/destination:/destination -t james/project -s SHA1 +$ docker run -v $PWD/.m2:/root/.m2 -v $PWD:/origin -v $PWD/dockerfiles/run/spring/destination:/destination -t james/project -s SHA1 Where: - $PWD/.m2:/root/.m2: is the first volume used to share the maven repository, as we don't want to download all dependencies on each build -- $PWD/dockerfiles/destination:/destination: is the third volume used to get the compiled elements, +- $PWD/dockerfiles/run/spring/destination:/destination: is the third volume used to get the compiled elements, as it is needed by the container that will run James. - SHA1 (optional): is the given git SHA1 of the james-project repository to build or trunk if none. - -s option: given tests will not be played while building. Not specifying means play tests. @@ -92,7 +92,7 @@ This feature is only available for Java 8 / Cassandra mailbox backend yet. * Requirements -You should have the zip resulting of the build in the ./dockerfiles/destination folder. +You should have the zip resulting of the build in the ./dockerfiles/run/spring/destination folder. * Howto ? @@ -104,11 +104,11 @@ $ docker run -d --name=elasticsearch elasticsearch:1.5.2 We need to provide the key we will use for TLS. For obvious reasons, this is not provided in this git. -Copy your TSL keys to destination/conf/keystore or generate it using the following command. The password must be james72laBalle to match default configuration. -$ keytool -genkey -alias james -keyalg RSA -keystore dockerfiles/destination/conf/keystore +Copy your TSL keys to destination/run/spring/conf/keystore or generate it using the following command. The password must be james72laBalle to match default configuration. +$ keytool -genkey -alias james -keyalg RSA -keystore dockerfiles/run/spring/destination/conf/keystore Then we need to build james container : -$ docker build -t james_run dockerfiles +$ docker build -t james_run dockerfiles/run/spring/ To run this container : $ docker run --hostname HOSTNAME -p "25:25" -p "110:110" -p "143:143" -p "465:465" -p "587:587" -p "993:993" --link cassandra:cassandra --link elasticsearch:elasticsearch --name james_run -t james_run diff --git a/dockerfiles/Dockerfile b/dockerfiles/run/spring/Dockerfile similarity index 100% rename from dockerfiles/Dockerfile rename to dockerfiles/run/spring/Dockerfile diff --git a/dockerfiles/destination/.gitignore b/dockerfiles/run/spring/destination/.gitignore similarity index 100% rename from dockerfiles/destination/.gitignore rename to dockerfiles/run/spring/destination/.gitignore diff --git a/dockerfiles/destination/conf/META-INF/jpa-mappings-template.xml b/dockerfiles/run/spring/destination/conf/META-INF/jpa-mappings-template.xml similarity index 100% rename from dockerfiles/destination/conf/META-INF/jpa-mappings-template.xml rename to dockerfiles/run/spring/destination/conf/META-INF/jpa-mappings-template.xml diff --git a/dockerfiles/destination/conf/META-INF/persistence-template.xml b/dockerfiles/run/spring/destination/conf/META-INF/persistence-template.xml similarity index 100% rename from dockerfiles/destination/conf/META-INF/persistence-template.xml rename to dockerfiles/run/spring/destination/conf/META-INF/persistence-template.xml diff --git a/dockerfiles/destination/conf/META-INF/persistence.xml b/dockerfiles/run/spring/destination/conf/META-INF/persistence.xml similarity index 100% rename from dockerfiles/destination/conf/META-INF/persistence.xml rename to dockerfiles/run/spring/destination/conf/META-INF/persistence.xml diff --git a/dockerfiles/destination/conf/cassandra.properties b/dockerfiles/run/spring/destination/conf/cassandra.properties similarity index 100% rename from dockerfiles/destination/conf/cassandra.properties rename to dockerfiles/run/spring/destination/conf/cassandra.properties diff --git a/dockerfiles/destination/conf/dnsservice.xml b/dockerfiles/run/spring/destination/conf/dnsservice.xml similarity index 100% rename from dockerfiles/destination/conf/dnsservice.xml rename to dockerfiles/run/spring/destination/conf/dnsservice.xml diff --git a/dockerfiles/destination/conf/domainlist.xml b/dockerfiles/run/spring/destination/conf/domainlist.xml similarity index 100% rename from dockerfiles/destination/conf/domainlist.xml rename to dockerfiles/run/spring/destination/conf/domainlist.xml diff --git a/dockerfiles/destination/conf/elasticsearch.properties b/dockerfiles/run/spring/destination/conf/elasticsearch.properties similarity index 100% rename from dockerfiles/destination/conf/elasticsearch.properties rename to dockerfiles/run/spring/destination/conf/elasticsearch.properties diff --git a/dockerfiles/destination/conf/fetchmail.xml b/dockerfiles/run/spring/destination/conf/fetchmail.xml similarity index 100% rename from dockerfiles/destination/conf/fetchmail.xml rename to dockerfiles/run/spring/destination/conf/fetchmail.xml diff --git a/dockerfiles/destination/conf/imapserver.xml b/dockerfiles/run/spring/destination/conf/imapserver.xml similarity index 100% rename from dockerfiles/destination/conf/imapserver.xml rename to dockerfiles/run/spring/destination/conf/imapserver.xml diff --git a/dockerfiles/destination/conf/indexer.xml b/dockerfiles/run/spring/destination/conf/indexer.xml similarity index 100% rename from dockerfiles/destination/conf/indexer.xml rename to dockerfiles/run/spring/destination/conf/indexer.xml diff --git a/dockerfiles/destination/conf/james-database.properties b/dockerfiles/run/spring/destination/conf/james-database.properties similarity index 100% rename from dockerfiles/destination/conf/james-database.properties rename to dockerfiles/run/spring/destination/conf/james-database.properties diff --git a/dockerfiles/destination/conf/jcr-repository.xml b/dockerfiles/run/spring/destination/conf/jcr-repository.xml similarity index 100% rename from dockerfiles/destination/conf/jcr-repository.xml rename to dockerfiles/run/spring/destination/conf/jcr-repository.xml diff --git a/dockerfiles/destination/conf/jmx.properties b/dockerfiles/run/spring/destination/conf/jmx.properties similarity index 100% rename from dockerfiles/destination/conf/jmx.properties rename to dockerfiles/run/spring/destination/conf/jmx.properties diff --git a/dockerfiles/destination/conf/lib/README.txt b/dockerfiles/run/spring/destination/conf/lib/README.txt similarity index 100% rename from dockerfiles/destination/conf/lib/README.txt rename to dockerfiles/run/spring/destination/conf/lib/README.txt diff --git a/dockerfiles/destination/conf/lmtpserver.xml b/dockerfiles/run/spring/destination/conf/lmtpserver.xml similarity index 100% rename from dockerfiles/destination/conf/lmtpserver.xml rename to dockerfiles/run/spring/destination/conf/lmtpserver.xml diff --git a/dockerfiles/destination/conf/log4j.properties b/dockerfiles/run/spring/destination/conf/log4j.properties similarity index 100% rename from dockerfiles/destination/conf/log4j.properties rename to dockerfiles/run/spring/destination/conf/log4j.properties diff --git a/dockerfiles/destination/conf/mailbox.xml b/dockerfiles/run/spring/destination/conf/mailbox.xml similarity index 100% rename from dockerfiles/destination/conf/mailbox.xml rename to dockerfiles/run/spring/destination/conf/mailbox.xml diff --git a/dockerfiles/destination/conf/mailetcontainer.xml b/dockerfiles/run/spring/destination/conf/mailetcontainer.xml similarity index 100% rename from dockerfiles/destination/conf/mailetcontainer.xml rename to dockerfiles/run/spring/destination/conf/mailetcontainer.xml diff --git a/dockerfiles/destination/conf/mailrepositorystore.xml b/dockerfiles/run/spring/destination/conf/mailrepositorystore.xml similarity index 100% rename from dockerfiles/destination/conf/mailrepositorystore.xml rename to dockerfiles/run/spring/destination/conf/mailrepositorystore.xml diff --git a/dockerfiles/destination/conf/managesieve.help.txt b/dockerfiles/run/spring/destination/conf/managesieve.help.txt similarity index 100% rename from dockerfiles/destination/conf/managesieve.help.txt rename to dockerfiles/run/spring/destination/conf/managesieve.help.txt diff --git a/dockerfiles/destination/conf/pop3server.xml b/dockerfiles/run/spring/destination/conf/pop3server.xml similarity index 100% rename from dockerfiles/destination/conf/pop3server.xml rename to dockerfiles/run/spring/destination/conf/pop3server.xml diff --git a/dockerfiles/destination/conf/quota.xml b/dockerfiles/run/spring/destination/conf/quota.xml similarity index 100% rename from dockerfiles/destination/conf/quota.xml rename to dockerfiles/run/spring/destination/conf/quota.xml diff --git a/dockerfiles/destination/conf/recipientrewritetable.xml b/dockerfiles/run/spring/destination/conf/recipientrewritetable.xml similarity index 100% rename from dockerfiles/destination/conf/recipientrewritetable.xml rename to dockerfiles/run/spring/destination/conf/recipientrewritetable.xml diff --git a/dockerfiles/destination/conf/smtpserver.xml b/dockerfiles/run/spring/destination/conf/smtpserver.xml similarity index 100% rename from dockerfiles/destination/conf/smtpserver.xml rename to dockerfiles/run/spring/destination/conf/smtpserver.xml diff --git a/dockerfiles/destination/conf/sqlResources.xml b/dockerfiles/run/spring/destination/conf/sqlResources.xml similarity index 100% rename from dockerfiles/destination/conf/sqlResources.xml rename to dockerfiles/run/spring/destination/conf/sqlResources.xml diff --git a/dockerfiles/destination/conf/usersrepository.xml b/dockerfiles/run/spring/destination/conf/usersrepository.xml similarity index 100% rename from dockerfiles/destination/conf/usersrepository.xml rename to dockerfiles/run/spring/destination/conf/usersrepository.xml diff --git a/dockerfiles/destination/var/.gitignore b/dockerfiles/run/spring/destination/var/.gitignore similarity index 100% rename from dockerfiles/destination/var/.gitignore rename to dockerfiles/run/spring/destination/var/.gitignore From 4f9277f45e72f382e3a7545322b08be2fc5246ea Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Wed, 28 Oct 2015 13:52:59 +0100 Subject: [PATCH 27/39] JAMES-1626 bundle cli into a runnable jar --- server/container/cli/pom.xml | 30 ++++++++++++++++++++++++++++++ 1 file changed, 30 insertions(+) diff --git a/server/container/cli/pom.xml b/server/container/cli/pom.xml index 68bda12bc2d..479e6e1b89c 100644 --- a/server/container/cli/pom.xml +++ b/server/container/cli/pom.xml @@ -93,6 +93,36 @@ maven-bundle-plugin true
+ + org.apache.maven.plugins + maven-dependency-plugin + + + copy-dependencies + package + + copy-dependencies + + + ${project.build.directory}/${project.build.finalName}.lib + + + + + + org.apache.maven.plugins + maven-jar-plugin + + + + true + ${project.build.finalName}.lib/ + org.apache.james.cli.ServerCmd + false + + + +
From cc2c320e6c0c8bbbdef7985f9bb2f58659074bf4 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Wed, 28 Oct 2015 11:55:57 +0100 Subject: [PATCH 28/39] JAMES-1626 cassandra-guice docker support --- README.txt | 11 +- dockerfiles/compilation/java-8/compile.sh | 4 + dockerfiles/run/guice/Dockerfile | 27 + .../conf/META-INF/jpa-mappings-template.xml | 40 + .../conf/META-INF/persistence-template.xml | 80 ++ .../destination/conf/META-INF/persistence.xml | 47 + .../destination/conf/cassandra.properties | 6 + .../run/guice/destination/conf/dnsservice.xml | 29 + .../run/guice/destination/conf/domainlist.xml | 28 + .../destination/conf/elasticsearch.properties | 26 + .../run/guice/destination/conf/fetchmail.xml | 288 ++++++ .../run/guice/destination/conf/imapserver.xml | 54 + .../run/guice/destination/conf/indexer.xml | 23 + .../conf/james-database.properties | 40 + .../guice/destination/conf/jcr-repository.xml | 72 ++ .../run/guice/destination/conf/jmx.properties | 28 + .../run/guice/destination/conf/lib/README.txt | 1 + .../run/guice/destination/conf/lmtpserver.xml | 41 + .../guice/destination/conf/log4j.properties | 137 +++ .../destination/conf/mailetcontainer.xml | 165 ++++ .../destination/conf/mailrepositorystore.xml | 34 + .../destination/conf/managesieve.help.txt | 112 +++ .../run/guice/destination/conf/pop3server.xml | 42 + .../run/guice/destination/conf/quota.xml | 53 + .../conf/recipientrewritetable.xml | 26 + .../run/guice/destination/conf/smtpserver.xml | 105 ++ .../guice/destination/conf/sqlResources.xml | 931 ++++++++++++++++++ .../destination/conf/usersrepository.xml | 25 + 28 files changed, 2474 insertions(+), 1 deletion(-) create mode 100644 dockerfiles/run/guice/Dockerfile create mode 100644 dockerfiles/run/guice/destination/conf/META-INF/jpa-mappings-template.xml create mode 100644 dockerfiles/run/guice/destination/conf/META-INF/persistence-template.xml create mode 100644 dockerfiles/run/guice/destination/conf/META-INF/persistence.xml create mode 100644 dockerfiles/run/guice/destination/conf/cassandra.properties create mode 100644 dockerfiles/run/guice/destination/conf/dnsservice.xml create mode 100644 dockerfiles/run/guice/destination/conf/domainlist.xml create mode 100644 dockerfiles/run/guice/destination/conf/elasticsearch.properties create mode 100644 dockerfiles/run/guice/destination/conf/fetchmail.xml create mode 100644 dockerfiles/run/guice/destination/conf/imapserver.xml create mode 100644 dockerfiles/run/guice/destination/conf/indexer.xml create mode 100644 dockerfiles/run/guice/destination/conf/james-database.properties create mode 100644 dockerfiles/run/guice/destination/conf/jcr-repository.xml create mode 100644 dockerfiles/run/guice/destination/conf/jmx.properties create mode 100644 dockerfiles/run/guice/destination/conf/lib/README.txt create mode 100644 dockerfiles/run/guice/destination/conf/lmtpserver.xml create mode 100644 dockerfiles/run/guice/destination/conf/log4j.properties create mode 100644 dockerfiles/run/guice/destination/conf/mailetcontainer.xml create mode 100644 dockerfiles/run/guice/destination/conf/mailrepositorystore.xml create mode 100644 dockerfiles/run/guice/destination/conf/managesieve.help.txt create mode 100644 dockerfiles/run/guice/destination/conf/pop3server.xml create mode 100644 dockerfiles/run/guice/destination/conf/quota.xml create mode 100644 dockerfiles/run/guice/destination/conf/recipientrewritetable.xml create mode 100644 dockerfiles/run/guice/destination/conf/smtpserver.xml create mode 100644 dockerfiles/run/guice/destination/conf/sqlResources.xml create mode 100644 dockerfiles/run/guice/destination/conf/usersrepository.xml diff --git a/README.txt b/README.txt index 33935ea89b6..5bdedabefad 100644 --- a/README.txt +++ b/README.txt @@ -68,7 +68,6 @@ as it is needed by the container that will run James. - SHA1 (optional): is the given git SHA1 of the james-project repository to build or trunk if none. - -s option: given tests will not be played while building. Not specifying means play tests. - * Java 8 First step, you have to build the Docker image $ docker build -t james/project dockerfiles/compilation/java-8 @@ -160,6 +159,16 @@ Where : Beware : you will have concurrency issues if multiple containers are running on this single volume. +How to run James in Docker using guice container +================================================ + +You have to follow above documentation and replace spring by guice in paths. + +Once you run the container, you have to use the following command to launch the cli : + +$ docker exec james_run java -jar /root/james-cli.jar -h localhost + + Running deployement Tests ========================= diff --git a/dockerfiles/compilation/java-8/compile.sh b/dockerfiles/compilation/java-8/compile.sh index b95a88af585..0e68d1bb6a4 100755 --- a/dockerfiles/compilation/java-8/compile.sh +++ b/dockerfiles/compilation/java-8/compile.sh @@ -53,4 +53,8 @@ fi if [ $? -eq 0 ]; then cp server/app/target/james-server-app-*-app.zip $DESTINATION + cp server/container/cassandra-guice/target/james-server-cassandra-guice-*-SNAPSHOT.jar $DESTINATION + cp -r server/container/cassandra-guice/target/james-server-cassandra-guice-*-SNAPSHOT.lib $DESTINATION + cp server/container/cli/target/james-server-cli-*.jar $DESTINATION + cp -r server/container/cli/target/james-server-cli-*.lib $DESTINATION fi diff --git a/dockerfiles/run/guice/Dockerfile b/dockerfiles/run/guice/Dockerfile new file mode 100644 index 00000000000..cd03111d340 --- /dev/null +++ b/dockerfiles/run/guice/Dockerfile @@ -0,0 +1,27 @@ +# Run James +# +# VERSION 1.0 + +FROM java:openjdk-8-jdk + +# Ports that are used +# +# 25 SMTP without authentication +# 110 POP3 +# 143 IMAP with startTLS enabled +# 465 SMTP with authentication and socketTLS enabled +# 587 SMTP with authentication and startTLS enabled +# 993 IMAP with socketTLS enabled + +EXPOSE 25 110 143 465 587 993 + +WORKDIR /root + +# Get data we need to run James : build results and configuration +ADD destination/james-server-cassandra-guice-*.jar /root/james-server.jar +ADD destination/james-server-cassandra-guice-3.0.0-beta5-SNAPSHOT.lib /root/james-server-cassandra-guice-3.0.0-beta5-SNAPSHOT.lib +ADD destination/james-server-cli-3.0.0-beta5-SNAPSHOT.jar /root/james-cli.jar +ADD destination/james-server-cli-3.0.0-beta5-SNAPSHOT.lib /root/james-server-cli-3.0.0-beta5-SNAPSHOT.lib +ADD destination/conf /root/conf + +ENTRYPOINT java -Dworking.directory=/root/ -jar james-server.jar diff --git a/dockerfiles/run/guice/destination/conf/META-INF/jpa-mappings-template.xml b/dockerfiles/run/guice/destination/conf/META-INF/jpa-mappings-template.xml new file mode 100644 index 00000000000..fe76d25d0ac --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/META-INF/jpa-mappings-template.xml @@ -0,0 +1,40 @@ + + + + + + + + + + + + + + + + + + + + diff --git a/dockerfiles/run/guice/destination/conf/META-INF/persistence-template.xml b/dockerfiles/run/guice/destination/conf/META-INF/persistence-template.xml new file mode 100644 index 00000000000..950e1ab6bbb --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/META-INF/persistence-template.xml @@ -0,0 +1,80 @@ + + + + + + + + + META-INF/jpa-mappings-template.xml + + + org.apache.james.mailbox.jpa.mail.model.JPAMailbox + org.apache.james.mailbox.jpa.mail.model.JPAUserFlag + org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMessage + + + + + org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMessage + + org.apache.james.mailbox.jpa.mail.model.JPAProperty + org.apache.james.mailbox.jpa.user.model.JPASubscription + + + org.apache.james.domainlist.jpa.model.JPADomain + + + org.apache.james.user.jpa.model.JPAUser + + + org.apache.james.rrt.jpa.model.JPARecipientRewrite + + + + + + + + + + + + + + + + + + + diff --git a/dockerfiles/run/guice/destination/conf/META-INF/persistence.xml b/dockerfiles/run/guice/destination/conf/META-INF/persistence.xml new file mode 100644 index 00000000000..66462619c08 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/META-INF/persistence.xml @@ -0,0 +1,47 @@ + + + + + + + + org.apache.james.mailbox.jpa.mail.model.JPAMailbox + org.apache.james.mailbox.jpa.mail.model.JPAUserFlag + org.apache.james.mailbox.jpa.mail.model.openjpa.AbstractJPAMessage + org.apache.james.mailbox.jpa.mail.model.openjpa.JPAMessage + org.apache.james.mailbox.jpa.mail.model.JPAProperty + org.apache.james.mailbox.jpa.user.model.JPASubscription + org.apache.james.domainlist.jpa.model.JPADomain + org.apache.james.user.jpa.model.JPAUser + org.apache.james.rrt.jpa.model.JPARecipientRewrite + + + + + + + + + + + diff --git a/dockerfiles/run/guice/destination/conf/cassandra.properties b/dockerfiles/run/guice/destination/conf/cassandra.properties new file mode 100644 index 00000000000..c6a7342fcfa --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/cassandra.properties @@ -0,0 +1,6 @@ +# Configuration file for cassandra mailbox + +cassandra.ip=cassandra +cassandra.port=9042 +cassandra.keyspace=apache_james +cassandra.replication.factor=1 \ No newline at end of file diff --git a/dockerfiles/run/guice/destination/conf/dnsservice.xml b/dockerfiles/run/guice/destination/conf/dnsservice.xml new file mode 100644 index 00000000000..0978a00b899 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/dnsservice.xml @@ -0,0 +1,29 @@ + + + + + + 8.8.8.8 + 62.210.16.6 + + false + false + 50000 + diff --git a/dockerfiles/run/guice/destination/conf/domainlist.xml b/dockerfiles/run/guice/destination/conf/domainlist.xml new file mode 100644 index 00000000000..fc64fd214a1 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/domainlist.xml @@ -0,0 +1,28 @@ + + + + + + james.linagora.com + + true + true + localhost + diff --git a/dockerfiles/run/guice/destination/conf/elasticsearch.properties b/dockerfiles/run/guice/destination/conf/elasticsearch.properties new file mode 100644 index 00000000000..2eec9530711 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/elasticsearch.properties @@ -0,0 +1,26 @@ +# 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 + +# Configuration file for ElasticSearch + +elasticsearch.masterHost=elasticsearch +elasticsearch.port=9300 +elasticsearch.nb.shards=1 +elasticsearch.nb.replica=0 diff --git a/dockerfiles/run/guice/destination/conf/fetchmail.xml b/dockerfiles/run/guice/destination/conf/fetchmail.xml new file mode 100644 index 00000000000..96aa9460fc4 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/fetchmail.xml @@ -0,0 +1,288 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 5 + + + fetchmail + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + pop.server.com + + + 600000 + + + + pop3 + + + INBOX + + + + + + + + + + + + + + false + + + + false + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + wibble@localhost, flobble@localhost + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dockerfiles/run/guice/destination/conf/imapserver.xml b/dockerfiles/run/guice/destination/conf/imapserver.xml new file mode 100644 index 00000000000..8ccb1179c9a --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/imapserver.xml @@ -0,0 +1,54 @@ + + + + + + + + imapserver + 0.0.0.0:143 + 200 + + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + + 0 + 0 + + + imapserver-ssl + 0.0.0.0:993 + 200 + + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + + 0 + 0 + + diff --git a/dockerfiles/run/guice/destination/conf/indexer.xml b/dockerfiles/run/guice/destination/conf/indexer.xml new file mode 100644 index 00000000000..ced1a62274e --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/indexer.xml @@ -0,0 +1,23 @@ + + + + + elasticsearch + diff --git a/dockerfiles/run/guice/destination/conf/james-database.properties b/dockerfiles/run/guice/destination/conf/james-database.properties new file mode 100644 index 00000000000..b3ac7ebc6e5 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/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 diff --git a/dockerfiles/run/guice/destination/conf/jcr-repository.xml b/dockerfiles/run/guice/destination/conf/jcr-repository.xml new file mode 100644 index 00000000000..c1b998a75f7 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/jcr-repository.xml @@ -0,0 +1,72 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + diff --git a/dockerfiles/run/guice/destination/conf/jmx.properties b/dockerfiles/run/guice/destination/conf/jmx.properties new file mode 100644 index 00000000000..a1dbdf8924b --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/jmx.properties @@ -0,0 +1,28 @@ +# 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 + +# 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 + +jmx.address=127.0.0.1 +jmx.port=9999 diff --git a/dockerfiles/run/guice/destination/conf/lib/README.txt b/dockerfiles/run/guice/destination/conf/lib/README.txt new file mode 100644 index 00000000000..d536d44b732 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/lib/README.txt @@ -0,0 +1 @@ +# Put every jar you want to have included in the classpath in here \ No newline at end of file diff --git a/dockerfiles/run/guice/destination/conf/lmtpserver.xml b/dockerfiles/run/guice/destination/conf/lmtpserver.xml new file mode 100644 index 00000000000..ce079b0e4d1 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/lmtpserver.xml @@ -0,0 +1,41 @@ + + + + + + + lmtpserver + + 127.0.0.1:24 + 200 + 1200 + + 0 + + 0 + + + 0 + + + + + + diff --git a/dockerfiles/run/guice/destination/conf/log4j.properties b/dockerfiles/run/guice/destination/conf/log4j.properties new file mode 100644 index 00000000000..cdcfbd866ac --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/log4j.properties @@ -0,0 +1,137 @@ +# 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. + +# See http://james.apache.org/server/3/config.html for usage + +log4j.rootLogger=DEBUG + +log4j.appender.CONS=org.apache.log4j.ConsoleAppender +log4j.appender.CONS.layout=org.apache.log4j.PatternLayout +log4j.appender.CONS.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.FILE=org.apache.log4j.DailyRollingFileAppender +log4j.appender.FILE.File=../log/james-server.log +log4j.appender.FILE.layout=org.apache.log4j.PatternLayout +log4j.appender.FILE.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.MAILBOXMANAGER=org.apache.log4j.DailyRollingFileAppender +log4j.appender.MAILBOXMANAGER.File=../log/mailboxmanager.log +log4j.appender.MAILBOXMANAGER.DatePattern='.'yyyy-MM-dd +log4j.appender.MAILBOXMANAGER.layout=org.apache.log4j.PatternLayout +log4j.appender.MAILBOXMANAGER.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.IMAPSERVER=org.apache.log4j.DailyRollingFileAppender +log4j.appender.IMAPSERVER.File=../log/imapserver.log +log4j.appender.IMAPSERVER.DatePattern='.'yyyy-MM-dd +log4j.appender.IMAPSERVER.layout=org.apache.log4j.PatternLayout +log4j.appender.IMAPSERVER.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.MAILETCONTAINER=org.apache.log4j.DailyRollingFileAppender +log4j.appender.MAILETCONTAINER.File=../log/mailetcontainer.log +log4j.appender.MAILETCONTAINER.DatePattern='.'yyyy-MM-dd +log4j.appender.MAILETCONTAINER.layout=org.apache.log4j.PatternLayout +log4j.appender.MAILETCONTAINER.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.DNSSERVICE=org.apache.log4j.DailyRollingFileAppender +log4j.appender.DNSSERVICE.File=../log/dnsservice.log +log4j.appender.DNSSERVICE.DatePattern='.'yyyy-MM-dd +log4j.appender.DNSSERVICE.layout=org.apache.log4j.PatternLayout +log4j.appender.DNSSERVICE.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.POP3SERVER=org.apache.log4j.DailyRollingFileAppender +log4j.appender.POP3SERVER.File=../log/pop3server.log +log4j.appender.POP3SERVER.DatePattern='.'yyyy-MM-dd +log4j.appender.POP3SERVER.layout=org.apache.log4j.PatternLayout +log4j.appender.POP3SERVER.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.SMTPSERVER=org.apache.log4j.DailyRollingFileAppender +log4j.appender.SMTPSERVER.File=../log/smtpserver.log +log4j.appender.SMTPSERVER.DatePattern='.'yyyy-MM-dd +log4j.appender.SMTPSERVER.layout=org.apache.log4j.PatternLayout +log4j.appender.SMTPSERVER.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.LMTPSERVER=org.apache.log4j.DailyRollingFileAppender +log4j.appender.LMTPSERVER.File=../log/lmtpserver.log +log4j.appender.LMTPSERVER.DatePattern='.'yyyy-MM-dd +log4j.appender.LMTPSERVER.layout=org.apache.log4j.PatternLayout +log4j.appender.LMTPSERVER.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.MAILREPOSITORYSTORE=org.apache.log4j.DailyRollingFileAppender +log4j.appender.MAILREPOSITORYSTORE.File=../log/mailrepositorystore.log +log4j.appender.MAILREPOSITORYSTORE.DatePattern='.'yyyy-MM-dd +log4j.appender.MAILREPOSITORYSTORE.layout=org.apache.log4j.PatternLayout +log4j.appender.MAILREPOSITORYSTORE.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.USERSREPOSITORY=org.apache.log4j.DailyRollingFileAppender +log4j.appender.USERSREPOSITORY.File=../log/usersrepository.log +log4j.appender.USERSREPOSITORY.DatePattern='.'yyyy-MM-dd +log4j.appender.USERSREPOSITORY.layout=org.apache.log4j.PatternLayout +log4j.appender.USERSREPOSITORY.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.FETCHMAIL=org.apache.log4j.DailyRollingFileAppender +log4j.appender.FETCHMAIL.File=../log/fetchmail.log +log4j.appender.FETCHMAIL.DatePattern='.'yyyy-MM-dd +log4j.appender.FETCHMAIL.layout=org.apache.log4j.PatternLayout +log4j.appender.FETCHMAIL.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.DOMAINLIST=org.apache.log4j.DailyRollingFileAppender +log4j.appender.DOMAINLIST.File=../log/domainlist.log +log4j.appender.DOMAINLIST.DatePattern='.'yyyy-MM-dd +log4j.appender.DOMAINLIST.layout=org.apache.log4j.PatternLayout +log4j.appender.DOMAINLIST.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.VIRTUALUSERTABLE=org.apache.log4j.DailyRollingFileAppender +log4j.appender.VIRTUALUSERTABLE.File=../log/virtualusertable.log +log4j.appender.VIRTUALUSERTABLE.DatePattern='.'yyyy-MM-dd +log4j.appender.VIRTUALUSERTABLE.layout=org.apache.log4j.PatternLayout +log4j.appender.VIRTUALUSERTABLE.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.appender.MAILQUEUEFACTORY=org.apache.log4j.DailyRollingFileAppender +log4j.appender.MAILQUEUEFACTORY.File=../log/mailqueuefactory.log +log4j.appender.MAILQUEUEFACTORY.DatePattern='.'yyyy-MM-dd +log4j.appender.MAILQUEUEFACTORY.layout=org.apache.log4j.PatternLayout +log4j.appender.MAILQUEUEFACTORY.layout.ConversionPattern=%-5p %d{HH:mm:ss,SSS} | %c | %m%n + +log4j.logger.org.apache.jackrabbit=ERROR, CONS, FILE + +log4j.logger.org.apache.xbean.spring=WARN, CONS, FILE +log4j.logger.org.apache.activemq=WARN, CONS, FILE + +log4j.logger.org.apache.camel=WARN, CONS, FILE +log4j.logger.org.springframework=WARN, CONS, FILE +log4j.logger.org.apache.james=DEBUG, CONS, FILE + +log4j.logger.james=WARN, CONS, FILE +log4j.logger=DEBUG, CONS, FILE + +log4j.logger.james.mailboxmanager=DEBUG, MAILBOXMANAGER +log4j.logger.james.imapserver=DEBUG, IMAPSERVER +log4j.logger.james.mailetcontainer=DEBUG, MAILETCONTAINER +log4j.logger.james.mailetcontext=DEBUG, MAILETCONTAINER +log4j.logger.james.mailspooler=DEBUG, MAILETCONTAINER +log4j.logger.james.mailprocessor=DEBUG, MAILETCONTAINER +log4j.logger.james.dnsservice=DEBUG, DNSSERVICE +log4j.logger.james.pop3server=DEBUG, POP3SERVER +log4j.logger.james.smtpserver=DEBUG, SMTPSERVER +log4j.logger.james.lmtpserver=DEBUG, LMTPSERVER +log4j.logger.james.mailrepositorystore=DEBUG, MAILREPOSITORYSTORE +log4j.logger.james.usersrepository=DEBUG, USERSREPOSITORY +log4j.logger.james.fetchmail=DEBUG, FETCHMAIL +log4j.logger.james.domainlist=DEBUG, DOMAINLIST +log4j.logger.james.virtualusertable=DEBUG, VIRTUALUSERTABLE +log4j.logger.james.mailqueuefactory=DEBUG, MAILQUEUEFACTORY +log4j.logger.etm.core.monitor.EtmMonitor= DEBUG, CONS, FILE diff --git a/dockerfiles/run/guice/destination/conf/mailetcontainer.xml b/dockerfiles/run/guice/destination/conf/mailetcontainer.xml new file mode 100644 index 00000000000..678c344e5e7 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/mailetcontainer.xml @@ -0,0 +1,165 @@ + + + + + + + + postmaster@james.minet.net + + + + 20 + + + + + + + + + sieve-manager-check + + + transport + + + true + + + transport + + + transport + + + + + + + spam + 550 Requested action not taken: rejected - see http://njabl.org/ + + + transport + + + + + + + file://var/mail/error/ + + + + + + + X-UserIsAuth + true + + + X-WasSigned + true + + + + + local-address-error + 550 - Requested action not taken: no such user here + + + outgoing + 5000, 100000, 500000 + 25 + 0 + 10 + true + bounces + + + relay-denied + + + + + + file://var/mail/spam/ + + + + + + none + + + file://var/mail/address-error/ + + + + + + none + + + file://var/mail/relay-denied/ + Warning: You are sending an e-mail to a remote server. You must be authentified to perform such an operation + + + + + + false + + + + + + + sieve-manager + + + + heads + none + false + [REJECTED] + + You can't send messages to configure SIEVE on this serveur unless you are the official SIEVE manager. + + + + + + + + true + + + file:/root/james-server-app-3.0.0-beta5-SNAPSHOT/conf/managesieve.help.txt + + + + + + + + diff --git a/dockerfiles/run/guice/destination/conf/mailrepositorystore.xml b/dockerfiles/run/guice/destination/conf/mailrepositorystore.xml new file mode 100644 index 00000000000..acca810221d --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/mailrepositorystore.xml @@ -0,0 +1,34 @@ + + + + + + + + + + + file + + + + + + diff --git a/dockerfiles/run/guice/destination/conf/managesieve.help.txt b/dockerfiles/run/guice/destination/conf/managesieve.help.txt new file mode 100644 index 00000000000..f45c78dba7c --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/managesieve.help.txt @@ -0,0 +1,112 @@ +managesieve implements the commands defined by RFC 5804 ((http://tools.ietf.org/html/rfc5804) to manage sieve scripts via mail messages. A mail is sent to the managesieve user with the command and parameters in the subject header. Sieve scripts are exchanged as mail attachments. + +Consult your mail administrator for the name of the managesieve user configured for your installation. + +Users MUST be SMTP authenticated to execute all except the CAPABILITY and HELP commands (see note (1) below). + +Commands are executed and answered within the namespace of the sending user as denoted by the sender header of the mail. Thus, a command such as LISTSCRIPTS lists the scripts within namespace of the user identified by the sender header. + +The supported commands are summarised in "Command Summary" below. Generally the responses are self describing. For full details see RFC 5804 - Commands (http://tools.ietf.org/html/rfc5804#section-2). + +In these descriptions the following keywords apply: + +- sieve-name + The name of a sieve script enclosed in parentheses, eg: "my script". An empty name is not allowed. +- active-sieve-name + As sieve-name, except an empty name, eg: "", is allowed. +- old-sieve-name + As sieve-name +- new-sieve-name + As sieve-name +- sieve-script + A mail attachment recognised as a sieve script. This is the first attachment in a mail satisfying any of these characteristics: + - A MIME type of "application/sieve" + - A filename with the suffix ".sieve" + - A filename with the suffix ".siv" + Returned sieve-scripts always have the MIME type of "application/sieve" + +Command Summary +--------------- + +CAPABILITY + Subject: + CAPABILITY + Attachments: + none +Answers the capabilities of the underlying sieve inplementation. + +CHECKSCRIPT + Subject: + CHECKSCRIPT + Attachments: + sieve-script +Verifies the attached sieve-script without storing it on the server. + +DELETESCRIPT + Subject: + DELETESCRIPT sieve-name + Attachments: + none +Deletes the named sieve script. + +GETACTIVE + Subject: + GETACTIVE + Attachments: + none +Answers the active sieve script as an attachment. + +GETSCRIPT + Subject: + GETSCRIPT sieve-name + Attachments: + none +Answers the named sieve script as an attachment. + +HAVESPACE + Subject: + HAVESPACE sieve-name number + Attachments: + none +Answers OK if there is available space to store a script with the given name of the given size, else NO. + +HELP + Subject: + HELP + Attachments: + none +Answers this text. + +LISTSCRIPTS + Subject: + LISTSCRIPTS + Attachments: + none +Answers a list of the sieve scripts stored on the server, indicating which, if any, is the active script. + +PUTSCRIPT + Subject: + PUTSCRIPT sieve-name + Attachments: + sieve-script +Verifies the attached sieve-script and if there are no errors stores it on the server using the given name. + +RENAMESCRIPT + Subject: + RENAMESCRIPT old-sieve-name new-sieve-name + Attachments: + none +Renames the script stored on the server named old-sieve-name to new-sieve-name. + +SETACTIVE + Subject: + SETACTIVE active-sieve-name + Attachments: + none +Sets the active script on the server to the given name. Use an empty string, "", to deactivate all scripts. + +Notes +----- +1) Some mail servers optionally allow configurations that enable local clients to post without SMTP authentication, such configurations will fail as managesieve requires SMTP authentication in all circumstances. To repeat, users MUST be SMTP authenticated to execute all except the CAPABILITY and HELP commands. + + diff --git a/dockerfiles/run/guice/destination/conf/pop3server.xml b/dockerfiles/run/guice/destination/conf/pop3server.xml new file mode 100644 index 00000000000..df8fbef9ea8 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/pop3server.xml @@ -0,0 +1,42 @@ + + + + + + + pop3server + 0.0.0.0:110 + 200 + + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + + 1200 + 0 + 0 + + + + + diff --git a/dockerfiles/run/guice/destination/conf/quota.xml b/dockerfiles/run/guice/destination/conf/quota.xml new file mode 100644 index 00000000000..70162e0d4fd --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/quota.xml @@ -0,0 +1,53 @@ + + + + + + + + + + + + default + + + cassandra + + + cassandra + + + store + + + event + + diff --git a/dockerfiles/run/guice/destination/conf/recipientrewritetable.xml b/dockerfiles/run/guice/destination/conf/recipientrewritetable.xml new file mode 100644 index 00000000000..fde339bd5c3 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/recipientrewritetable.xml @@ -0,0 +1,26 @@ + + + + + + true + 10 + + diff --git a/dockerfiles/run/guice/destination/conf/smtpserver.xml b/dockerfiles/run/guice/destination/conf/smtpserver.xml new file mode 100644 index 00000000000..bc609bee0f7 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/smtpserver.xml @@ -0,0 +1,105 @@ + + + + + + + smtpserver-global + 0.0.0.0:25 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + false + 0.0.0.0/0 + true + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + smtpserver-TLS + 0.0.0.0:465 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + + true + 0.0.0.0/0 + + false + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + smtpserver-authenticated + 0.0.0.0:587 + 200 + + file://conf/keystore + james72laBalle + org.bouncycastle.jce.provider.BouncyCastleProvider + SunX509 + + 360 + 0 + 0 + + true + 0.0.0.0/0 + + false + 0 + true + JAMES Linagora's SMTP awesome Server + + + + + + + + diff --git a/dockerfiles/run/guice/destination/conf/sqlResources.xml b/dockerfiles/run/guice/destination/conf/sqlResources.xml new file mode 100644 index 00000000000..82cfa2605b1 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/sqlResources.xml @@ -0,0 +1,931 @@ + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + ${table} + + + SELECT username, pwdHash, pwdAlgorithm, useForwarding, + forwardDestination, useAlias, alias + FROM ${table} + ORDER BY username + + + + + + SELECT username, pwdHash, pwdAlgorithm, useForwarding, + forwardDestination, useAlias, alias + FROM ${table} + WHERE lower(username) = ? + + + + SELECT username, pwdHash, pwdAlgorithm, useForwarding, + forwardDestination, useAlias, alias + FROM ${table} + WHERE username = ? + + + + INSERT INTO ${table} + (username, pwdHash, pwdAlgorithm, useForwarding, forwardDestination, useAlias, alias) + VALUES (?,?,?,?,?,?,?) + + + + UPDATE ${table} SET + pwdHash = ?, pwdAlgorithm = ?, useForwarding = ?, forwardDestination = ?, useAlias = ?, alias = ? + WHERE username = ? + + + + DELETE FROM ${table} WHERE username = ? + + + CREATE CACHED TABLE ${table} (username VARCHAR(64) NOT NULL, pwdHash VARCHAR(50), pwdAlgorithm VARCHAR(20), useForwarding INTEGER, forwardDestination VARCHAR(255), useAlias INTEGER, alias VARCHAR(255), PRIMARY KEY(username)) + CREATE TABLE ${table} (username VARCHAR(64) NOT NULL, pwdHash VARCHAR(50), pwdAlgorithm VARCHAR(20), useForwarding SMALLINT, forwardDestination VARCHAR(255), useAlias SMALLINT, alias VARCHAR(255), PRIMARY KEY(username)) + + + + + ${table} + + + SELECT username, pwdHash, pwdAlgorithm + FROM ${table} + + + + INSERT INTO ${table} + (username, pwdHash, pwdAlgorithm) + VALUES (?,?,?) + + + + UPDATE ${table} SET + pwdHash = ?, pwdAlgorithm = ? + WHERE username = ? + + + + DELETE FROM ${table} WHERE username = ? + + + CREATE CACHED TABLE ${table} (username VARCHAR(64) NOT NULL, pwdHash VARCHAR(50), pwdAlgorithm VARCHAR(20), PRIMARY KEY(username)) + CREATE TABLE ${table} (username VARCHAR(64) NOT NULL, pwdHash VARCHAR(50), pwdAlgorithm VARCHAR(20), PRIMARY KEY(username)) + + + + + + + ${table} + + + SELECT listSubscriber + FROM ${table} + WHERE listName = '${key}' + + + + INSERT INTO ${table} + (listSubscriber, listName) + VALUES (?, '${key}') + + + + UPDATE ${table} SET + listSubscriber = ? + WHERE listSubscriber = ? AND listName = '${key}' + + + + DELETE FROM ${table} + WHERE listSubscriber = ? AND listName = '${key}' + + + + CREATE CACHED TABLE ${table} (listName VARCHAR(64) NOT NULL, listSubscriber VARCHAR(255) NOT NULL, PRIMARY KEY(listName, listSubscriber)) + CREATE TABLE ${table} (listName VARCHAR(64) NOT NULL, listSubscriber VARCHAR(255) NOT NULL, PRIMARY KEY(listName, listSubscriber)) + + + + + + SELECT count(*) FROM ${table} WHERE message_name = ? AND repository_name = ? + + + UPDATE ${table} SET message_state = ?, error_message = ?, sender = ?, recipients = ?, remote_host = ?, remote_addr = ?, last_updated = ? WHERE message_name = ? AND repository_name = ? + + + UPDATE ${table} SET message_body = ? WHERE message_name = ? AND repository_name = ? + + + UPDATE ${table} SET message_attributes = ? WHERE message_name = ? AND repository_name = ? + + + INSERT INTO ${table} (message_name, + repository_name, message_state, error_message, sender, recipients, + remote_host, remote_addr, last_updated, message_body, + message_attributes) VALUES (?, ?, ?, ?, ?, ?, ?, ?, ?, ?, ?) + + + SELECT message_state, error_message, sender, recipients, remote_host, remote_addr, last_updated FROM ${table} WHERE message_name = ? AND repository_name = ? + + + SELECT message_body FROM ${table} WHERE message_name = ? AND repository_name = ? + + + SELECT message_attributes FROM ${table} WHERE message_name = ? AND repository_name = ? + + + + SELECT datalength(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ? + SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ? + SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ? + SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ? + SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ? + SELECT dbms_lob.getlength(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ? + SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ? + SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ? + SELECT length(message_body) FROM ${table} WHERE message_name = ? AND repository_name = ? + + + DELETE FROM ${table} WHERE message_name = ? AND repository_name = ? + + + SELECT message_name, message_state, last_updated FROM ${table} WHERE repository_name = ? ORDER BY last_updated ASC + + + + CREATE TABLE ${table} ( + message_name varchar (200) NOT NULL, + repository_name varchar (100) NOT NULL, + message_state varchar (30) NOT NULL , + error_message varchar (200) NULL , + sender varchar (255) NULL , + recipients text NOT NULL , + remote_host varchar (255) NOT NULL , + remote_addr varchar (20) NOT NULL , + message_body longblob NOT NULL , + message_attributes longblob NULL , + last_updated datetime NOT NULL, + PRIMARY KEY (repository_name, message_name) + ) + + + CREATE CACHED TABLE ${table} ( + message_name varchar (200) NOT NULL, + repository_name varchar (255) NOT NULL, + message_state varchar (30) NOT NULL , + error_message varchar (200) NULL , + sender varchar (255) NULL , + recipients varchar NOT NULL , + remote_host varchar (255) NOT NULL , + remote_addr varchar (20) NOT NULL , + message_body varchar NOT NULL , + message_attributes varchar NULL , + last_updated timestamp NOT NULL, + PRIMARY KEY (repository_name, message_name) + ) + + + CREATE CACHED TABLE ${table} ( + message_name varchar (200) NOT NULL, + repository_name varchar (255) NOT NULL, + message_state varchar (30) NOT NULL , + error_message varchar (200) NULL , + sender varchar (255) NULL , + recipients varchar NOT NULL , + remote_host varchar (255) NOT NULL , + remote_addr varchar (20) NOT NULL , + message_body varchar NOT NULL , + message_attributes varchar NULL , + last_updated timestamp NOT NULL, + PRIMARY KEY (repository_name, message_name) + ) + + + CREATE TABLE [${table}] ( + [message_name] [varchar] (200) NOT NULL, + [repository_name] [varchar] (255) NOT NULL, + [message_state] [varchar] (30) NOT NULL , + [error_message] [varchar] (1000) NULL , + [sender] [varchar] (255) NULL , + [recipients] [text] NOT NULL , + [remote_host] [varchar] (255) NOT NULL , + [remote_addr] [varchar] (20) NOT NULL , + [message_body] [image] NOT NULL , + [message_attributes] [image] NULL , + [last_updated] [datetime] NOT NULL, + PRIMARY KEY (repository_name, message_name) + ) + + + CREATE TABLE ${table} ( + message_name varchar2(200) NOT NULL , + repository_name varchar2(255) NOT NULL , + message_state varchar2(30) NOT NULL , + error_message varchar2(200) NULL , + sender varchar2(255) , + recipients varchar2(1000) NOT NULL , + remote_host varchar2(100) NOT NULL , + remote_addr varchar2(20) NOT NULL , + message_body blob NOT NULL , + message_attributes blob NULL , + last_updated date NOT NULL , + PRIMARY KEY (repository_name, message_name) + ) + + + CREATE TABLE ${table} ( + message_name varchar (200) NOT NULL, + repository_name varchar (255) NOT NULL, + message_state varchar (30) NOT NULL , + error_message varchar (200) NULL , + sender varchar (255) NULL , + recipients text NOT NULL , + remote_host varchar (255) NOT NULL , + remote_addr varchar (20) NOT NULL , + message_body bytea NOT NULL , + message_attributes bytea NULL , + last_updated timestamp NOT NULL, + PRIMARY KEY (repository_name, message_name) + ) + + + CREATE TABLE ${table} ( + message_name varchar (200) NOT NULL, + repository_name varchar (200) NOT NULL, + message_state varchar (30) NOT NULL , + error_message varchar (200) NULL , + sender varchar (200) NULL , + recipients long NOT NULL , + remote_host varchar (100) NOT NULL , + remote_addr varchar (20) NOT NULL , + message_body long byte NOT NULL , + message_attributes long byte NULL , + last_updated date NOT NULL, + PRIMARY KEY (repository_name, message_name) + ) + + + CREATE TABLE ${table} ( + message_name varchar(200) NOT NULL , + repository_name varchar(255) NOT NULL , + message_state varchar(30) NOT NULL , + error_message varchar(200) , + sender varchar(255) , + recipients varchar(1000) NOT NULL , + remote_host varchar(100) NOT NULL , + remote_addr varchar(20) NOT NULL , + message_body blob NOT NULL , + message_attributes blob , + last_updated timestamp NOT NULL , + PRIMARY KEY (repository_name, message_name) + ) + + + CREATE TABLE ${table} ( + message_name varchar (200) NOT NULL, + repository_name varchar (255) NOT NULL, + message_state varchar (30) NOT NULL , + error_message varchar (200) , + sender varchar (255) , + recipients LONG VARCHAR NOT NULL , + remote_host varchar (255) NOT NULL , + remote_addr varchar (20) NOT NULL , + message_body LONG BYTE NOT NULL , + message_attributes LONG BYTE , + last_updated DATE NOT NULL + ) + + + CREATE TABLE ${table} ( + message_name varchar (200) NOT NULL, + repository_name varchar (255) NOT NULL, + message_state varchar (30) NOT NULL , + error_message varchar (200) , + sender varchar (255) , + recipients long varchar NOT NULL , + remote_host varchar (255) NOT NULL , + remote_addr varchar (20) NOT NULL , + message_body blob NOT NULL , + message_attributes blob , + last_updated timestamp NOT NULL, + PRIMARY KEY (repository_name, message_name) + ) + + + + + + bayesiananalysis_ham + bayesiananalysis_spam + bayesiananalysis_messagecounts + + + SELECT HAMCOUNT, SPAMCOUNT FROM bayesiananalysis_messagecounts + + + INSERT INTO bayesiananalysis_messagecounts (HAMCOUNT, SPAMCOUNT) VALUES (0,0) + + + UPDATE bayesiananalysis_messagecounts SET HAMCOUNT=(HAMCOUNT + ?) + + + UPDATE bayesiananalysis_messagecounts SET SPAMCOUNT=(SPAMCOUNT + ?) + + + SELECT TOKEN, OCCURRENCES FROM bayesiananalysis_ham + + + SELECT TOKEN, OCCURRENCES FROM bayesiananalysis_spam + + + INSERT INTO bayesiananalysis_ham (TOKEN, OCCURRENCES) VALUES (?,?) + + + INSERT INTO bayesiananalysis_spam (TOKEN, OCCURRENCES) VALUES (?,?) + + + UPDATE bayesiananalysis_ham SET OCCURRENCES=(OCCURRENCES + ?) WHERE (TOKEN=?) + + + UPDATE bayesiananalysis_spam SET OCCURRENCES=(OCCURRENCES + ?) WHERE (TOKEN=?) + + + DELETE FROM bayesiananalysis_ham + + + DELETE FROM bayesiananalysis_spam + + + DELETE FROM bayesiananalysis_messagecounts + + + + + CREATE TABLE bayesiananalysis_ham ( + token varchar(128) binary NOT NULL default '', + occurrences int(11) NOT NULL default '0', + PRIMARY KEY (token) + ) TYPE=InnoDB + + + CREATE TABLE [bayesiananalysis_ham] ( + [token] [varchar] (128) COLLATE Latin1_General_CS_AS NOT NULL, + [occurrences] [int] NOT NULL default (0), + PRIMARY KEY (token) + ) + + + CREATE TABLE bayesiananalysis_ham ( + token varchar(128) NOT NULL, + occurrences INTEGER NOT NULL default 0, + PRIMARY KEY (token) + ) + + + CREATE TABLE bayesiananalysis_ham ( + token varchar(128) NOT NULL, + occurrences int NOT NULL default 0, + PRIMARY KEY (token) + ) + + + + + CREATE TABLE bayesiananalysis_spam ( + token varchar(128) binary NOT NULL default '', + occurrences int(11) NOT NULL default '0', + PRIMARY KEY (token) + ) TYPE=InnoDB + + + CREATE TABLE [bayesiananalysis_spam] ( + [token] [varchar] (128) COLLATE Latin1_General_CS_AS NOT NULL, + [occurrences] [int] NOT NULL default (0), + PRIMARY KEY (token) + ) + + + CREATE TABLE bayesiananalysis_spam ( + token varchar (128) NOT NULL, + occurrences INTEGER NOT NULL default 0, + PRIMARY KEY (token) + ) + + + CREATE TABLE bayesiananalysis_spam ( + token varchar (128) NOT NULL, + occurrences int NOT NULL default 0, + PRIMARY KEY (token) + ) + + + + + CREATE TABLE bayesiananalysis_messagecounts ( + hamcount int(11) NOT NULL default '0', + spamcount int(11) NOT NULL default '0' + ) TYPE=InnoDB + + + CREATE TABLE [bayesiananalysis_messagecounts] ( + [hamcount] [int] NOT NULL default (0), + [spamcount] [int] NOT NULL default (0) + ) + + + CREATE TABLE bayesiananalysis_messagecounts ( + hamcount INTEGER NOT NULL default 0, + spamcount INTEGER NOT NULL default 0 + ) + + + CREATE TABLE bayesiananalysis_messagecounts ( + hamcount int NOT NULL default 0, + spamcount int NOT NULL default 0 + ) + + + + + + whitelist + + + SELECT localUser, localHost FROM whitelist where (localUser=? AND localHost=? AND remoteUser=? AND remoteHost=?) + + + SELECT remoteUser, remoteHost FROM whitelist where (localUser=? AND localHost=?) ORDER BY remoteUser, remoteHost + + + INSERT INTO whitelist (localUser, localHost, remoteUser, remoteHost) VALUES (?,?,?,?) + + + DELETE FROM whitelist where (localUser=? AND localHost=? AND remoteUser=? AND remoteHost=?) + + + + CREATE TABLE whitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + remoteUser varchar (64) NOT NULL, + remoteHost varchar (255) NOT NULL, + PRIMARY KEY (localUser, localHost, remoteUser, remoteHost) + ) + + CREATE CACHED TABLE ${table} ( + CREATE TABLE whitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + remoteUser varchar (64) NOT NULL, + remoteHost varchar (255) NOT NULL, + PRIMARY KEY (localUser, localHost, remoteUser, remoteHost) + ) + + CREATE TABLE whitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) character set latin1 NOT NULL, + remoteUser varchar (64) NOT NULL, + remoteHost varchar (255) character set latin1 NOT NULL, + PRIMARY KEY (localUser, localHost, remoteUser, remoteHost) + ) TYPE=InnoDB + + + CREATE TABLE [whitelist] ( + [localUser] [varchar] (64) NOT NULL, + [localHost] [varchar] (255) NOT NULL, + [remoteUser] [varchar] (64) NOT NULL, + [remoteHost] [varchar] (255) NOT NULL, + PRIMARY KEY (localUser, localHost, remoteUser, remoteHost) + ) + + + CREATE TABLE whitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + remoteUser varchar (64) NOT NULL, + remoteHost varchar (255) NOT NULL, + PRIMARY KEY (localUser, localHost, remoteUser, remoteHost) + ) + + + CREATE TABLE whitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + remoteUser varchar (64) NOT NULL, + remoteHost varchar (255) NOT NULL, + PRIMARY KEY (localUser, localHost, remoteUser, remoteHost) + ) + + + CREATE TABLE whitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + remoteUser varchar (64) NOT NULL, + remoteHost varchar (255) NOT NULL, + PRIMARY KEY (localUser, localHost, remoteUser, remoteHost) + ) + + + CREATE TABLE whitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + remoteUser varchar (64) NOT NULL, + remoteHost varchar (255) NOT NULL, + PRIMARY KEY (localUser, localHost, remoteUser, remoteHost) + ) + + + CREATE TABLE whitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + remoteUser varchar (64) NOT NULL, + remoteHost varchar (255) NOT NULL, + PRIMARY KEY (localUser, localHost, remoteUser, remoteHost) + ) + + + CREATE TABLE whitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + remoteUser varchar (64) NOT NULL, + remoteHost varchar (255) NOT NULL, + PRIMARY KEY (localUser, localHost, remoteUser, remoteHost) + ) + + + + + + + networkWhitelist + + + SELECT network FROM networkWhitelist where (localUser=? AND localHost=?) + + + + CREATE TABLE networkWhitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + network varchar (255) NOT NULL, + PRIMARY KEY (localUser, localHost) + ) + + CREATE CACHED TABLE ${table} ( + CREATE TABLE networkWhitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + network varchar (255) NOT NULL + ) + + CREATE TABLE networkWhitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) character set latin1 NOT NULL, + network varchar (255) NOT NULL + ) TYPE=InnoDB + + + CREATE TABLE [networkWhitelist] ( + [localUser] [varchar] (64) NOT NULL, + [localHost] [varchar] (255) NOT NULL, + [network] [varchar] (255) NOT NULL + ) + + + CREATE TABLE networkWhitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + network varchar (255) NOT NULL + ) + + + CREATE TABLE networkWhitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + network varchar (255) NOT NULL + ) + + + CREATE TABLE networkWhitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + network varchar (255) NOT NULL + ) + + + CREATE TABLE networkWhitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + network varchar (255) NOT NULL + ) + + + CREATE TABLE networkWhitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + network varchar (255) NOT NULL + ) + + + CREATE TABLE networkWhitelist ( + localUser varchar (64) NOT NULL, + localHost varchar (255) NOT NULL, + network varchar (255) NOT NULL + ) + + + + + + + greylist + + + SELECT create_time,count FROM greylist WHERE ipaddress = ? AND sender = ? AND recip = ? + + + INSERT INTO greylist (ipaddress,sender,recip,count,create_time) values (?,?,?,?,?) + + + DELETE FROM greylist WHERE create_time < ? AND count = 0 + + + DELETE FROM greylist WHERE create_time < ? + + + UPDATE greylist SET create_time = ? , count = ? WHERE ipaddress = ? AND sender = ? AND recip = ? + + + + CREATE TABLE greylist ( + ipaddress varchar (20) NOT NULL, + sender varchar (255) NOT NULL, + recip varchar (255) NOT NULL, + count int NOT NULL, + create_time datetime NOT NULL, + PRIMARY KEY (ipaddress,sender,recip) + ) + + + CREATE CACHED TABLE ${table} ( + CREATE TABLE greylist ( + ipaddress varchar (20) NOT NULL, + sender varchar (255) NOT NULL, + recip varchar (255) NOT NULL, + count int NOT NULL, + create_time timestamo NOT NULL, + PRIMARY KEY (ipaddress,sender,recip) + ) + + CREATE TABLE greylist ( + ipaddress varchar (20) NOT NULL, + sender varchar (255) NOT NULL, + recip varchar (255) NOT NULL, + count int NOT NULL, + create_time datetime NOT NULL, + PRIMARY KEY (ipaddress,sender,recip) + ) TYPE=InnoDB + + + CREATE TABLE [greylist] ( + [ipaddress] [varchar] (20) NOT NULL, + [sender] [varchar] (255) NOT NULL, + [recip] [varchar] (255) NOT NULL, + [count] [int] NOT NULL, + [create_time] [datetime] NOT NULL, + PRIMARY KEY (ipaddress,sender,recip) + ) + + + CREATE TABLE greylist ( + ipaddress varchar2(20) NOT NULL, + sender varchar2(255) NOT NULL, + recip varchar2(255) NOT NULL, + count int NOT NULL, + create_time datetime NOT NULL, + PRIMARY KEY (ipaddress,sender,recip) + ) + + + CREATE TABLE greylist ( + ipaddress varchar (20) NOT NULL, + sender varchar (255) NOT NULL, + recip varchar (255) NOT NULL, + count int NOT NULL, + create_time timestamp NOT NULL, + PRIMARY KEY (ipaddress,sender,recip) + ) + + + CREATE TABLE greylist ( + ipaddress varchar (20) NOT NULL, + sender varchar (255) NOT NULL, + recip varchar (255) NOT NULL, + count int NOT NULL, + create_time date NOT NULL, + PRIMARY KEY (ipaddress,sender,recip) + ) + + + CREATE TABLE greylist ( + ipaddress varchar (20) NOT NULL, + sender varchar (255) NOT NULL, + recip varchar (255) NOT NULL, + count int NOT NULL, + create_time timestamp NOT NULL, + PRIMARY KEY (ipaddress,sender,recip) + ) + + + CREATE TABLE greylist ( + ipaddress varchar (20) NOT NULL, + sender varchar (255) NOT NULL, + recip varchar (255) NOT NULL, + count int NOT NULL, + create_time date NOT NULL, + PRIMARY KEY (ipaddress,sender,recip) + ) + + + CREATE TABLE greylist ( + ipaddress varchar (20) NOT NULL, + sender varchar (255) NOT NULL, + recip varchar (255) NOT NULL, + count int NOT NULL, + create_time timestamp NOT NULL, + PRIMARY KEY (ipaddress,sender,recip) + ) + + + + + + + select RecipientRewriteTable.target_address,(RecipientRewriteTable."user" || '@' ||RecipientRewriteTable.domain) from RecipientRewriteTable, RecipientRewriteTable as VUTDomains where ((RecipientRewriteTable."user") like ? or (RecipientRewriteTable."user") = '*') and (RecipientRewriteTable.domain like ? or (RecipientRewriteTable.domain = '*')) order by 2 desc + select RecipientRewriteTable.target_address from RecipientRewriteTable, RecipientRewriteTable as VUTDomains where (RecipientRewriteTable.user like ? or RecipientRewriteTable.user = '*') and (RecipientRewriteTable.domain like ? or (RecipientRewriteTable.domain = '*')) order by concat(RecipientRewriteTable.user,'@',RecipientRewriteTable.domain) desc limit 1 + select RecipientRewriteTable.target_address from RecipientRewriteTable, RecipientRewriteTable as VUTDomains where (RecipientRewriteTable.user like ? or RecipientRewriteTable.user = '*') and (RecipientRewriteTable.domain like ? or (RecipientRewriteTable.domain = '*')) order by (RecipientRewriteTable.user || '@' || RecipientRewriteTable.domain) desc limit 1 + + select RecipientRewriteTable.target_address from RecipientRewriteTable where RecipientRewriteTable."user" = ? and RecipientRewriteTable.domain = ? + select RecipientRewriteTable.target_address from RecipientRewriteTable where RecipientRewriteTable.user = ? and RecipientRewriteTable.domain = ? + + delete from RecipientRewriteTable where RecipientRewriteTable."user" = ? and RecipientRewriteTable.domain = ? and RecipientRewriteTable.target_address = ? + + update RecipientRewriteTable set RecipientRewriteTable.target_address = ? where RecipientRewriteTable."user" = ? and RecipientRewriteTable.domain = ? + + insert into RecipientRewriteTable values(?,?,?) + + select * from RecipientRewriteTable + + + + CREATE TABLE RecipientRewriteTable ( + user varchar(64) NOT NULL default '', + domain varchar(255) NOT NULL default '', + target_address varchar(255) NOT NULL default '', + PRIMARY KEY (user,domain) + ) + + + + + CREATE TABLE RecipientRewriteTable ( + "user" varchar(64) NOT NULL default '', + domain varchar(255) NOT NULL default '', + target_address varchar(255) NOT NULL default '', + PRIMARY KEY ("user",domain) + ) + + + CREATE TABLE RecipientRewriteTable ( + "user" varchar (64) NOT NULL default '', + domain varchar (255) NOT NULL default '', + target_address varchar (255) NOT NULL default '', + PRIMARY KEY ("user",domain) + ) + + + + + diff --git a/dockerfiles/run/guice/destination/conf/usersrepository.xml b/dockerfiles/run/guice/destination/conf/usersrepository.xml new file mode 100644 index 00000000000..85046b30835 --- /dev/null +++ b/dockerfiles/run/guice/destination/conf/usersrepository.xml @@ -0,0 +1,25 @@ + + + + + MD5 + true + + From e352f770ff5afe5361c3e5b39649e90762d178d2 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 3 Nov 2015 14:59:40 +0100 Subject: [PATCH 29/39] fixup! JAMES-1626 Implement an HierarchicalConfiguration reader for guice use --- .../org/apache/james/utils/FileConfigurationProviderTest.java | 3 +-- 1 file changed, 1 insertion(+), 2 deletions(-) diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java index f4d07307269..15c0dc05da1 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java @@ -36,7 +36,6 @@ public class FileConfigurationProviderTest { private static final String CONFIG_KEY_1 = "test2"; private static final String CONFIG_KEY_2 = "property"; - private static final String CONFIG_KEY_3 = "test2"; private static final String CONFIG_KEY_4 = "james"; private static final String CONFIG_KEY_5 = "internal"; private static final String VALUE_1 = "0"; @@ -64,7 +63,7 @@ public void getConfigurationShouldLoadCorrespondingXMLFile() throws Exception { assertThat(Lists.newArrayList(hierarchicalConfiguration.getKeys())).containsOnly(CONFIG_KEY_1, CONFIG_KEY_4 + CONFIG_SEPARATOR + CONFIG_KEY_2, CONFIG_KEY_4 + CONFIG_SEPARATOR + CONFIG_KEY_5 + CONFIG_SEPARATOR + CONFIG_KEY_2); - assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_3)).isEqualTo(VALUE_1); + assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_1)).isEqualTo(VALUE_1); } @Test From 70372f9ef0d16842ea1d4b3363c903438fda6d08 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 3 Nov 2015 15:16:37 +0100 Subject: [PATCH 30/39] fixup! JAMES-1626 Implement an HierarchicalConfiguration reader for guice use --- .../utils/FileConfigurationProvider.java | 14 +++--- .../utils/FileConfigurationProviderTest.java | 47 +++++++++++++------ 2 files changed, 40 insertions(+), 21 deletions(-) diff --git a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/FileConfigurationProvider.java b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/FileConfigurationProvider.java index 75ad86bc3b4..b28a94a5dd2 100644 --- a/server/container/cassandra-guice/src/main/java/org/apache/james/utils/FileConfigurationProvider.java +++ b/server/container/cassandra-guice/src/main/java/org/apache/james/utils/FileConfigurationProvider.java @@ -21,7 +21,6 @@ import java.io.IOException; import java.io.InputStream; -import java.util.Arrays; import java.util.List; import javax.inject.Inject; @@ -35,7 +34,9 @@ import org.apache.james.modules.CommonServicesModule; import com.google.common.base.Preconditions; +import com.google.common.base.Splitter; import com.google.common.base.Strings; +import com.google.common.collect.Iterables; import com.google.inject.Singleton; @Singleton @@ -44,8 +45,7 @@ public class FileConfigurationProvider implements ConfigurationProvider { private static final String CONFIGURATION_FILE_SUFFIX = ".xml"; private final FileSystem fileSystem; - - private String configurationPrefix; + private final String configurationPrefix; @Inject public FileConfigurationProvider(FileSystem fileSystem, @Named(CommonServicesModule.CONFIGURATION_PATH) String configurationPrefix) throws MissingArgumentException { @@ -55,9 +55,11 @@ public FileConfigurationProvider(FileSystem fileSystem, @Named(CommonServicesMod @Override public HierarchicalConfiguration getConfiguration(String component) throws ConfigurationException { - List configPathParts = Arrays.asList(component.split("\\.")); + Preconditions.checkNotNull(component); + List configPathParts = Splitter.on(".").splitToList(component); + Preconditions.checkArgument(!configPathParts.isEmpty()); HierarchicalConfiguration config = getConfig(retrieveConfigInputStream(configPathParts.get(0))); - return selectHierarchicalConfigPart(config, configPathParts.subList(1, configPathParts.size())); + return selectHierarchicalConfigPart(config, Iterables.skip(configPathParts, 1)); } private InputStream retrieveConfigInputStream(String configurationFileWithoutExtension) throws ConfigurationException { @@ -77,7 +79,7 @@ private XMLConfiguration getConfig(InputStream configStream) throws Configuratio return config; } - private HierarchicalConfiguration selectHierarchicalConfigPart(HierarchicalConfiguration config, List configsPathParts) { + private HierarchicalConfiguration selectHierarchicalConfigPart(HierarchicalConfiguration config, Iterable configsPathParts) { HierarchicalConfiguration currentConfig = config; for (String nextPathPart : configsPathParts) { currentConfig = currentConfig.configurationAt(nextPathPart); diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java index 15c0dc05da1..4fe0360caae 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/FileConfigurationProviderTest.java @@ -30,8 +30,6 @@ import org.junit.Before; import org.junit.Test; -import com.google.common.collect.Lists; - public class FileConfigurationProviderTest { private static final String CONFIG_KEY_1 = "test2"; @@ -40,6 +38,7 @@ public class FileConfigurationProviderTest { private static final String CONFIG_KEY_5 = "internal"; private static final String VALUE_1 = "0"; private static final String VALUE_2 = "awesome"; + private static final String VALUE_3 = "james"; private static final String FAKE_CONFIG_KEY = "fake"; private static final String ROOT_CONFIG_KEY = "test"; private static final String CONFIG_SEPARATOR = "."; @@ -52,6 +51,21 @@ public void setUp() throws MissingArgumentException { configurationProvider = new FileConfigurationProvider(fileSystem, FileSystem.CLASSPATH_PROTOCOL); } + @Test(expected = IllegalArgumentException.class) + public void emptyArgumentShouldThrow() throws Exception { + configurationProvider.getConfiguration(""); + } + + @Test(expected = NullPointerException.class) + public void nullArgumentShouldThrow() throws Exception { + configurationProvider.getConfiguration(null); + } + + @Test(expected = IllegalArgumentException.class) + public void configSeparatorArgumentShouldThrow() throws Exception { + configurationProvider.getConfiguration(CONFIG_SEPARATOR); + } + @Test(expected = IllegalArgumentException.class) public void emptyFileNameShouldThrow() throws Exception { configurationProvider.getConfiguration(CONFIG_SEPARATOR + ROOT_CONFIG_KEY); @@ -60,32 +74,35 @@ public void emptyFileNameShouldThrow() throws Exception { @Test public void getConfigurationShouldLoadCorrespondingXMLFile() throws Exception { HierarchicalConfiguration hierarchicalConfiguration = configurationProvider.getConfiguration(ROOT_CONFIG_KEY); - assertThat(Lists.newArrayList(hierarchicalConfiguration.getKeys())).containsOnly(CONFIG_KEY_1, - CONFIG_KEY_4 + CONFIG_SEPARATOR + CONFIG_KEY_2, - CONFIG_KEY_4 + CONFIG_SEPARATOR + CONFIG_KEY_5 + CONFIG_SEPARATOR + CONFIG_KEY_2); + assertThat(hierarchicalConfiguration.getKeys()).containsOnly(CONFIG_KEY_1, + String.join(CONFIG_SEPARATOR, CONFIG_KEY_4, CONFIG_KEY_2), + String.join(CONFIG_SEPARATOR, CONFIG_KEY_4, CONFIG_KEY_5, CONFIG_KEY_2)); assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_1)).isEqualTo(VALUE_1); } @Test public void getConfigurationShouldLoadCorrespondingXMLFilePart() throws Exception { - HierarchicalConfiguration hierarchicalConfiguration = configurationProvider.getConfiguration(ROOT_CONFIG_KEY + CONFIG_SEPARATOR + CONFIG_KEY_4); - assertThat(Lists.newArrayList(hierarchicalConfiguration.getKeys())).containsOnly(CONFIG_KEY_2, - "internal" + CONFIG_SEPARATOR + CONFIG_KEY_2); + HierarchicalConfiguration hierarchicalConfiguration = configurationProvider.getConfiguration( + String.join(CONFIG_SEPARATOR, ROOT_CONFIG_KEY, CONFIG_KEY_4)); + assertThat(hierarchicalConfiguration.getKeys()).containsOnly(CONFIG_KEY_2, + String.join(CONFIG_SEPARATOR, CONFIG_KEY_5, CONFIG_KEY_2)); assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_2)).isEqualTo(VALUE_2); } @Test public void getConfigurationShouldLoadCorrespondingXMLFileWhenAPathIsProvidedPart() throws Exception { - HierarchicalConfiguration hierarchicalConfiguration = configurationProvider.getConfiguration(ROOT_CONFIG_KEY + CONFIG_SEPARATOR + CONFIG_KEY_4 + CONFIG_SEPARATOR + "internal"); - assertThat(Lists.newArrayList(hierarchicalConfiguration.getKeys())).containsOnly(CONFIG_KEY_2); - assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_2)).isEqualTo("james"); + HierarchicalConfiguration hierarchicalConfiguration = configurationProvider.getConfiguration( + String.join(CONFIG_SEPARATOR, ROOT_CONFIG_KEY, CONFIG_KEY_4, CONFIG_KEY_5)); + assertThat(hierarchicalConfiguration.getKeys()).containsOnly(CONFIG_KEY_2); + assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_2)).isEqualTo(VALUE_3); } @Test public void multiplesSeparatorsShouldBeTolerated() throws Exception { - HierarchicalConfiguration hierarchicalConfiguration = configurationProvider.getConfiguration(ROOT_CONFIG_KEY + CONFIG_SEPARATOR + CONFIG_SEPARATOR + CONFIG_KEY_4); - assertThat(Lists.newArrayList(hierarchicalConfiguration.getKeys())).containsOnly(CONFIG_KEY_2, - "internal" + CONFIG_SEPARATOR + CONFIG_KEY_2); + HierarchicalConfiguration hierarchicalConfiguration = configurationProvider.getConfiguration( + ROOT_CONFIG_KEY + CONFIG_SEPARATOR + CONFIG_SEPARATOR + CONFIG_KEY_4); + assertThat(hierarchicalConfiguration.getKeys()).containsOnly(CONFIG_KEY_2, + String.join(CONFIG_SEPARATOR, CONFIG_KEY_5, CONFIG_KEY_2)); assertThat(hierarchicalConfiguration.getProperty(CONFIG_KEY_2)).isEqualTo(VALUE_2); } @@ -96,7 +113,7 @@ public void getConfigurationShouldThrowOnNonExistingXMLFile() throws Exception { @Test(expected = IllegalArgumentException.class) public void getConfigurationShouldThrowOnNonExistingXMLFilePart() throws Exception { - configurationProvider.getConfiguration(ROOT_CONFIG_KEY + CONFIG_SEPARATOR + FAKE_CONFIG_KEY); + configurationProvider.getConfiguration(String.join(CONFIG_SEPARATOR, ROOT_CONFIG_KEY, FAKE_CONFIG_KEY)); } } From 694292c38ccb1b3e05d332a61f616aa8c05f009a Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 3 Nov 2015 15:21:11 +0100 Subject: [PATCH 31/39] fixup! JAMES-1626 bootstrap guice-based application with Cassandra IMAP server --- .../java/org/apache/james/utils/PropertiesReadTest.java | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/PropertiesReadTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/PropertiesReadTest.java index e3e33aa2420..1d3de346778 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/utils/PropertiesReadTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/utils/PropertiesReadTest.java @@ -30,6 +30,12 @@ public void getPropertyShouldWork() throws Exception { PropertiesReader propertiesReader = new PropertiesReader("test.properties"); assertThat(propertiesReader.getProperty("cassandra.ip")).isEqualTo("127.0.0.1"); } + + @Test + public void getAbsentPropertyShouldReturnNull() throws Exception { + PropertiesReader propertiesReader = new PropertiesReader("test.properties"); + assertThat(propertiesReader.getProperty("cassandra.isslow")).isNull(); + } @Test(expected = RuntimeException.class) public void buildingAPropertiesReaderOnNonExistingValuesShouldThrow() throws Exception { From b73fdd6cd6d939a69c41380a6526043a51ac81ac Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 3 Nov 2015 15:24:56 +0100 Subject: [PATCH 32/39] fixup! JAMES-1626 sample configuration and readme --- server/container/cassandra-guice/README.adoc | 6 ++++++ 1 file changed, 6 insertions(+) diff --git a/server/container/cassandra-guice/README.adoc b/server/container/cassandra-guice/README.adoc index 7b6698e180f..e3648fff971 100644 --- a/server/container/cassandra-guice/README.adoc +++ b/server/container/cassandra-guice/README.adoc @@ -29,6 +29,12 @@ To run james, you have to create a directory containing required configuration f 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 +---- + You need to have a Cassandra and an ElasticSearch instance running. Once everything is set up, you just have to run the jar with : From 3012e2e1fb900b28ff5adcdb9c034cee4fd0aaaa Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 3 Nov 2015 15:26:31 +0100 Subject: [PATCH 33/39] fixup! JAMES-1626 Use javax.inject in Cassandra mailbox --- .../cassandra/CassandraTypesProvider.java | 95 ------------------- 1 file changed, 95 deletions(-) delete mode 100644 mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraTypesProvider.java diff --git a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraTypesProvider.java b/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraTypesProvider.java deleted file mode 100644 index f2b4906f6f7..00000000000 --- a/mailbox/cassandra/src/main/java/org/apache/james/mailbox/cassandra/CassandraTypesProvider.java +++ /dev/null @@ -1,95 +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.mailbox.cassandra; - -import com.datastax.driver.core.Session; -import com.datastax.driver.core.UserType; -import com.datastax.driver.core.schemabuilder.CreateType; -import com.datastax.driver.core.schemabuilder.SchemaBuilder; -import com.google.common.collect.ImmutableMap; -import org.apache.james.mailbox.cassandra.table.CassandraMailboxTable; -import org.apache.james.mailbox.cassandra.table.CassandraMessageTable; - -import javax.inject.Inject; -import javax.inject.Singleton; -import java.util.Arrays; -import java.util.Optional; -import java.util.stream.Collectors; - -import static com.datastax.driver.core.DataType.text; - -@Singleton -public class CassandraTypesProvider { - - public enum TYPE { - MailboxBase(CassandraMailboxTable.MAILBOX_BASE, - SchemaBuilder.createType(CassandraMailboxTable.MAILBOX_BASE) - .ifNotExists() - .addColumn(CassandraMailboxTable.MailboxBase.NAMESPACE, text()) - .addColumn(CassandraMailboxTable.MailboxBase.USER, text())), - Property(CassandraMessageTable.PROPERTIES, - SchemaBuilder.createType(CassandraMessageTable.PROPERTIES) - .ifNotExists() - .addColumn(CassandraMessageTable.Properties.NAMESPACE, text()) - .addColumn(CassandraMessageTable.Properties.NAME, text()) - .addColumn(CassandraMessageTable.Properties.VALUE, text())) - ; - - private final String name; - private final CreateType createStatement; - - TYPE(String name, CreateType createStatement) { - this.name = name; - this.createStatement = createStatement; - } - - public String getName() { - return name; - } - } - - private final ImmutableMap userTypes; - private final Session session; - - @Inject - public CassandraTypesProvider(Session session) { - this.session = session; - initializeTypes(); - userTypes = ImmutableMap.builder() - .putAll(Arrays.stream(TYPE.values()) - .collect(Collectors.toMap( - (type) -> type, - (type) -> session.getCluster() - .getMetadata() - .getKeyspace(session.getLoggedKeyspace()) - .getUserType(type.name)))).build(); - } - - public UserType getDefinedUserType(TYPE type) { - return Optional.ofNullable(userTypes.get(type)) - .orElseThrow(() -> new RuntimeException("Cassandra UDT " + type.getName() + " can not be retrieved")); - } - - public void initializeTypes() { - Arrays.asList(TYPE.values()) - .forEach((type) -> session.execute(type.createStatement)); - } - -} From 794b982547a613df2e961fab139c6855b806b49d Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 3 Nov 2015 15:28:48 +0100 Subject: [PATCH 34/39] fixup! JAMES-1626 support IMAP, SMTP, POP and LMTP protocols in cassandra-guice application --- .../org/apache/james/CassandraJamesServerTest.java | 10 +++++----- 1 file changed, 5 insertions(+), 5 deletions(-) diff --git a/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java index e79894ee7f6..bdf656d2089 100644 --- a/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java +++ b/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java @@ -90,31 +90,31 @@ public void tearDown() throws Exception { } @Test - public void connectIMAPServerShouldThrowWhenNoCredentials() throws Exception { + 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 connectOnSecondaryIMAPServerIMAPServerShouldThrowWhenNoCredentials() throws Exception { + 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 connectPOP3ServerShouldThrowWhenNoCredentials() throws Exception { + 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 connectSMTPServerShouldNotThrowWhenNoCredentials() throws Exception { + 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 connectLMTPServerShouldNotThrowWhenNoCredentials() throws Exception { + 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"); } From 4d9f37a484eef64a43420033e3e7e3a898b0397c Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 3 Nov 2015 15:44:08 +0100 Subject: [PATCH 35/39] fixup! JAMES-1626 Add JMX support to cassandra-guice application --- .../cli/src/main/java/org/apache/james/cli/ServerCmd.java | 1 - 1 file changed, 1 deletion(-) diff --git a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java index b50df81b1f9..42d0f4a424c 100644 --- a/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java +++ b/server/container/cli/src/main/java/org/apache/james/cli/ServerCmd.java @@ -103,7 +103,6 @@ public static void main(String[] args) { failWithMessage("Error connecting to remote JMX agent : " + ioe.getMessage()); } catch (Exception e) { failWithMessage("Error while executing command:" + e.getMessage()); - e.printStackTrace(); } } From e3ff938face93d63def99ff9c1b53d8d4feec38c Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 3 Nov 2015 15:46:21 +0100 Subject: [PATCH 36/39] fixup! JAMES-1626 cassandra-guice project creation --- server/container/cassandra-guice/pom.xml | 9 ++++----- 1 file changed, 4 insertions(+), 5 deletions(-) diff --git a/server/container/cassandra-guice/pom.xml b/server/container/cassandra-guice/pom.xml index 88f52cad8ef..a0d2cb692e4 100644 --- a/server/container/cassandra-guice/pom.xml +++ b/server/container/cassandra-guice/pom.xml @@ -183,11 +183,6 @@ - - com.google.guava - guava - 16.0 - ${project.groupId} apache-james-mailbox-cassandra @@ -358,6 +353,10 @@ jackson-datatype-jdk8 2.4.3 + + com.google.guava + guava + com.google.inject guice From 10652036692ec5ff46a28b01e0ed24495dc90e01 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 3 Nov 2015 15:48:38 +0100 Subject: [PATCH 37/39] fixup! JAMES-1626 bootstrap guice-based application with Cassandra IMAP server --- server/container/cassandra-guice/pom.xml | 11 +++++------ 1 file changed, 5 insertions(+), 6 deletions(-) diff --git a/server/container/cassandra-guice/pom.xml b/server/container/cassandra-guice/pom.xml index a0d2cb692e4..e7ed82eb312 100644 --- a/server/container/cassandra-guice/pom.xml +++ b/server/container/cassandra-guice/pom.xml @@ -184,15 +184,14 @@ - ${project.groupId} - apache-james-mailbox-cassandra - - org.apache.james apache-james-backends-cassandra - ${apache-backends-cassandra.version} test-jar - + + + ${project.groupId} + apache-james-mailbox-cassandra + ${project.groupId} apache-james-mailbox-cassandra From ff9aa869b8603dfb0c8ebc6dfac962eeee38261b Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 3 Nov 2015 16:47:47 +0100 Subject: [PATCH 38/39] fixup! JAMES-1626 Add configuration documentation --- .../src/site/xdoc/quick-start-cassandra.xml | 21 +++++++------------ 1 file changed, 8 insertions(+), 13 deletions(-) diff --git a/server/src/site/xdoc/quick-start-cassandra.xml b/server/src/site/xdoc/quick-start-cassandra.xml index f68d586668a..ee8f8d8b40e 100644 --- a/server/src/site/xdoc/quick-start-cassandra.xml +++ b/server/src/site/xdoc/quick-start-cassandra.xml @@ -44,18 +44,14 @@ Step 1: Download * Clone the James git repository -$ git clone git://git.apache.org/james.git - - * Then go to the James folder - -$ cd james +$ git clone git://git.apache.org/james-project.git Step 3: Compile ############### * Compile the Guice Cassandra project -$ mvn package -DskipTests +$ mvn package -DskipTests -am -pl server/container/cassandra-guice Step 3: Deploy ############## @@ -80,14 +76,14 @@ Copy your TSL keys to ./conf/keystore or generate it using : $ keytool -genkey -alias james -keyalg RSA -keystore ./conf/keystore -Configure your domain in the ./conf/domainlist.xml file. +I will have to put the keystore password in the right xml files (imapserver.xml, pop3server.xml, smtpserver.xml) Step 5: Start ############# * Run James -$ java -Dworking.directory=WORKING_PATH -jar container/cassandra-guice/target/james-server-cassandra-guice-beta5-SNAPSHOT.jar +$ java -Dworking.directory=WORKING_PATH -jar server/container/cassandra-guice/target/james-server-cassandra-guice-beta5-SNAPSHOT.jar Where : - WORKING_PATH is the path where are located your configuration file folder. @@ -97,13 +93,12 @@ Step 6: Create Domains and Users Time to add domains and users. -Give enough rights to the James CLI - -$ chmod 755 app/target/appassembler/bin/james-cli.sh +$ java -jar server/container/cli/target/james-server-cli-3.0.0-beta5-SNAPSHOT.jar -h 127.0.0.1 -p 9999 adddomain DOMAIN -$ ./app/target/appassembler/bin/james-cli.sh -h 127.0.0.1 -p 9999 adduser USER_MAIL_ADDRESS PASSWORD +$ java -jar server/container/cli/target/james-server-cli-3.0.0-beta5-SNAPSHOT.jar -h 127.0.0.1 -p 9999 adduser USER_MAIL_ADDRESS PASSWORD Where : +- DOMAIN is the domain you want to handle with this server. - USER_MAIL_ADDRESS is the mail address that will be used by this user. - PASSWORD is the password that will be used by this user. @@ -140,7 +135,7 @@ Step 8: Manage 8.1. Manage via james-cli usage: -$ docker exec james-cassandra /root/james-server-app-3.0.0-beta5-SNAPSHOT/bin/james-cli.sh -h 127.0.0.1 -p 9999 +$ java -jar server/container/cli/target/james-server-cli-3.0.0-beta5-SNAPSHOT.jar -h 127.0.0.1 -p 9999 Available commands: adduser </username> </password> From 7ec6d77d13edf89429f97492a0ca54f3287fee37 Mon Sep 17 00:00:00 2001 From: Matthieu Baechler Date: Tue, 3 Nov 2015 17:12:05 +0100 Subject: [PATCH 39/39] fixup! JAMES-1626 Add configuration documentation --- server/src/site/xdoc/quick-start-cassandra.xml | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/server/src/site/xdoc/quick-start-cassandra.xml b/server/src/site/xdoc/quick-start-cassandra.xml index ee8f8d8b40e..ae9cc5f5647 100644 --- a/server/src/site/xdoc/quick-start-cassandra.xml +++ b/server/src/site/xdoc/quick-start-cassandra.xml @@ -76,7 +76,7 @@ Copy your TSL keys to ./conf/keystore or generate it using : $ keytool -genkey -alias james -keyalg RSA -keystore ./conf/keystore -I will have to put the keystore password in the right xml files (imapserver.xml, pop3server.xml, smtpserver.xml) +You will have to put the keystore password in the right xml files (imapserver.xml, pop3server.xml, smtpserver.xml) Step 5: Start #############