Author: matthieu Date: Tue Nov 3 16:48:56 2015 New Revision: 1712334 URL: http://svn.apache.org/viewvc?rev=1712334&view=rev Log: JAMES-1626 support IMAP, SMTP, POP and LMTP protocols in cassandra-guice application
Added: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java - copied, changed from r1712333, james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java - copied, changed from r1712333, james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/QuotaModule.java - copied, changed from r1712333, james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceProtocolHandlerLoader.java james/project/trunk/server/container/cassandra-guice/src/test/resources/imapserver.xml james/project/trunk/server/container/cassandra-guice/src/test/resources/lmtpserver.xml james/project/trunk/server/container/cassandra-guice/src/test/resources/pop3server.xml james/project/trunk/server/container/cassandra-guice/src/test/resources/smtpserver.xml Modified: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java Modified: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java?rev=1712334&r1=1712333&r2=1712334&view=diff ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java (original) +++ james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/CassandraJamesServerMain.java Tue Nov 3 16:48:56 2015 @@ -25,9 +25,16 @@ import org.apache.james.modules.data.Cas 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); Modified: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java?rev=1712334&r1=1712333&r2=1712334&view=diff ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java (original) +++ james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/mailbox/CassandraMailboxModule.java Tue Nov 3 16:48:56 2015 @@ -34,6 +34,7 @@ import org.apache.james.mailbox.cassandr 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 @@ public class CassandraMailboxModule exte bind(SubscriptionManager.class).to(CassandraSubscriptionManager.class); bind(new TypeLiteral<MessageMapperFactory<CassandraId>>(){}).to(CassandraMailboxSessionMapperFactory.class); - + bind(MailboxSessionMapperFactory.class).to(CassandraMailboxSessionMapperFactory.class); + bind(MailboxPathLocker.class).to(NoMailboxPathLocker.class); bind(Authenticator.class).to(UserRepositoryAuthenticator.class); Added: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java?rev=1712334&view=auto ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java (added) +++ james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/IMAPServerModule.java Tue Nov 3 16:48:56 2015 @@ -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 Added: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java?rev=1712334&view=auto ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java (added) +++ james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/LMTPServerModule.java Tue Nov 3 16:48:56 2015 @@ -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(); + } + } + +} Added: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java?rev=1712334&view=auto ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java (added) +++ james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/POP3ServerModule.java Tue Nov 3 16:48:56 2015 @@ -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(); + } + } + +} Copied: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java (from r1712333, james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java) URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java?p2=james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java&p1=james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java&r1=1712333&r2=1712334&rev=1712334&view=diff ============================================================================== --- james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java (original) +++ james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/ProtocolHandlerModule.java Tue Nov 3 16:48:56 2015 @@ -16,42 +16,22 @@ * specific language governing permissions and limitations * * under the License. * ****************************************************************/ -package org.apache.james.core.filesystem; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; +package org.apache.james.modules.protocols; +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.protocols.lib.handler.ProtocolHandlerLoader; +import org.apache.james.utils.GuiceProtocolHandlerLoader; -public class FileSystemImpl implements FileSystem { +import com.google.inject.AbstractModule; - private final JamesDirectoriesProvider directoryProvider; - private final ResourceFactory resourceLoader; - - public FileSystemImpl(JamesDirectoriesProvider directoryProvider) { - this.directoryProvider = directoryProvider; - this.resourceLoader = new ResourceFactory(directoryProvider); - } +public class ProtocolHandlerModule extends AbstractModule { @Override - public File getBasedir() throws FileNotFoundException { - return new File(directoryProvider.getRootDirectory()); + protected void configure() { + bind(FileSystem.class).to(FileSystemImpl.class); + bind(ProtocolHandlerLoader.class).to(GuiceProtocolHandlerLoader.class); } - @Override - public InputStream getResource(String url) throws IOException { - return resourceLoader.getResource(url).getInputStream(); - } - - @Override - public File getFile(String fileURL) throws FileNotFoundException { - try { - return resourceLoader.getResource(fileURL).getFile(); - } catch (IOException e) { - throw new FileNotFoundException(e.getMessage()); - } - } -} +} \ No newline at end of file Added: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java?rev=1712334&view=auto ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java (added) +++ james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/protocols/SMTPServerModule.java Tue Nov 3 16:48:56 2015 @@ -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); + } + } + +} Copied: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java (from r1712333, james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java) URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java?p2=james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java&p1=james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java&r1=1712333&r2=1712334&rev=1712334&view=diff ============================================================================== --- james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java (original) +++ james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/FileSystemModule.java Tue Nov 3 16:48:56 2015 @@ -16,42 +16,21 @@ * specific language governing permissions and limitations * * under the License. * ****************************************************************/ -package org.apache.james.core.filesystem; - -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; +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; -public class FileSystemImpl implements FileSystem { - - private final JamesDirectoriesProvider directoryProvider; - private final ResourceFactory resourceLoader; - - public FileSystemImpl(JamesDirectoriesProvider directoryProvider) { - this.directoryProvider = directoryProvider; - this.resourceLoader = new ResourceFactory(directoryProvider); - } +import com.google.inject.AbstractModule; - @Override - public File getBasedir() throws FileNotFoundException { - return new File(directoryProvider.getRootDirectory()); - } +public class FileSystemModule extends AbstractModule { @Override - public InputStream getResource(String url) throws IOException { - return resourceLoader.getResource(url).getInputStream(); + public void configure() { + bind(JamesDirectoriesProvider.class).to(JamesServerResourceLoader.class); + bind(FileSystem.class).to(FileSystemImpl.class); } - @Override - public File getFile(String fileURL) throws FileNotFoundException { - try { - return resourceLoader.getResource(fileURL).getFile(); - } catch (IOException e) { - throw new FileNotFoundException(e.getMessage()); - } - } } Copied: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/QuotaModule.java (from r1712333, james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java) URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/QuotaModule.java?p2=james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/QuotaModule.java&p1=james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java&r1=1712333&r2=1712334&rev=1712334&view=diff ============================================================================== --- james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java (original) +++ james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/modules/server/QuotaModule.java Tue Nov 3 16:48:56 2015 @@ -16,42 +16,22 @@ * specific language governing permissions and limitations * * under the License. * ****************************************************************/ -package org.apache.james.core.filesystem; -import java.io.File; -import java.io.FileNotFoundException; -import java.io.IOException; -import java.io.InputStream; +package org.apache.james.modules.server; -import org.apache.james.filesystem.api.FileSystem; -import org.apache.james.filesystem.api.JamesDirectoriesProvider; +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; -public class FileSystemImpl implements FileSystem { +import com.google.inject.AbstractModule; - private final JamesDirectoriesProvider directoryProvider; - private final ResourceFactory resourceLoader; - - public FileSystemImpl(JamesDirectoriesProvider directoryProvider) { - this.directoryProvider = directoryProvider; - this.resourceLoader = new ResourceFactory(directoryProvider); - } - - @Override - public File getBasedir() throws FileNotFoundException { - return new File(directoryProvider.getRootDirectory()); - } - - @Override - public InputStream getResource(String url) throws IOException { - return resourceLoader.getResource(url).getInputStream(); - } +public class QuotaModule extends AbstractModule { @Override - public File getFile(String fileURL) throws FileNotFoundException { - try { - return resourceLoader.getResource(fileURL).getFile(); - } catch (IOException e) { - throw new FileNotFoundException(e.getMessage()); - } + protected void configure() { + bind(QuotaManager.class).to(NoQuotaManager.class); + bind(QuotaRootResolver.class).to(DefaultQuotaRootResolver.class); } + } Added: james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceProtocolHandlerLoader.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceProtocolHandlerLoader.java?rev=1712334&view=auto ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceProtocolHandlerLoader.java (added) +++ james/project/trunk/server/container/cassandra-guice/src/main/java/org/apache/james/utils/GuiceProtocolHandlerLoader.java Tue Nov 3 16:48:56 2015 @@ -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<ProtocolHandler> clazz = (Class<ProtocolHandler>) ClassLoader.getSystemClassLoader().loadClass(name); + return injector.getInstance(clazz); + } catch (ClassNotFoundException e) { + throw new LoadingException("Can not load " + name); + } + } + +} Modified: james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java?rev=1712334&r1=1712333&r2=1712334&view=diff ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java (original) +++ james/project/trunk/server/container/cassandra-guice/src/test/java/org/apache/james/CassandraJamesServerTest.java Tue Nov 3 16:48:56 2015 @@ -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 @@ 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 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 @@ public class CassandraJamesServerTest { } })); + socketChannel = SocketChannel.open(); server.start(); } @@ -78,17 +86,41 @@ public class CassandraJamesServerTest { server.stop(); } - @Test (expected = AuthenticationFailedException.class) - public void connectIMAPServerShouldThrowWhenNoCredentials() throws Exception { - store().connect(); + @Test + public void connectIMAPServerShouldSendShabangOnConnect() throws Exception { + 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 connectOnSecondaryIMAPServerIMAPServerShouldSendShabangOnConnect() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", IMAP_PORT_SSL)); + assertThat(getServerConnectionResponse(socketChannel)).startsWith("* OK JAMES IMAP4rev1 Server"); } + + @Test + public void connectPOP3ServerShouldSendShabangOnConnect() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", POP3_PORT)); + assertThat(getServerConnectionResponse(socketChannel)).contains("POP3 server (JAMES POP3 Server ) ready"); + } + + @Test + public void connectSMTPServerShouldSendShabangOnConnect() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", SMTP_PORT)); + assertThat(getServerConnectionResponse(socketChannel)).startsWith("220 JAMES Linagora's SMTP awesome Server"); + } + + @Test + public void connectLMTPServerShouldSendShabangOnConnect() throws Exception { + socketChannel.connect(new InetSocketAddress("127.0.0.1", LMTP_PORT)); + assertThat(getServerConnectionResponse(socketChannel)).contains("LMTP Server (JAMES Protocols Server) ready"); + } + + 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")); + } + } Added: james/project/trunk/server/container/cassandra-guice/src/test/resources/imapserver.xml URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/test/resources/imapserver.xml?rev=1712334&view=auto ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/test/resources/imapserver.xml (added) +++ james/project/trunk/server/container/cassandra-guice/src/test/resources/imapserver.xml Tue Nov 3 16:48:56 2015 @@ -0,0 +1,54 @@ +<?xml version="1.0"?> + +<!-- +Licensed to the Apache Software Foundation (ASF) under one +or more contributor license agreements. See the NOTICE file +distributed with this work for additional information +regarding copyright ownership. The ASF licenses this file +to you under the Apache License, Version 2.0 (the +"License"); you may not use this file except in compliance +with the License. You may obtain a copy of the License at + +http://www.apache.org/licenses/LICENSE-2.0 + +Unless required by applicable law or agreed to in writing, +software distributed under the License is distributed on an +"AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY +KIND, either express or implied. See the License for the +specific language governing permissions and limitations +under the License. +--> + + +<imapservers> + <imapserver enabled="true"> + <jmxName>imapserver</jmxName> + <bind>0.0.0.0:1143</bind> + <connectionBacklog>200</connectionBacklog> + <tls socketTLS="false" startTLS="false"> + <!-- To create a new keystore execute: + keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore + --> + <keystore>file://conf/keystore</keystore> + <secret>james72laBalle</secret> + <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider> + </tls> + <connectionLimit>0</connectionLimit> + <connectionLimitPerIP>0</connectionLimitPerIP> + </imapserver> + <imapserver enabled="true"> + <jmxName>imapserver-ssl</jmxName> + <bind>0.0.0.0:1993</bind> + <connectionBacklog>200</connectionBacklog> + <tls socketTLS="false" startTLS="false"> + <!-- To create a new keystore execute: + keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore + --> + <keystore>file://conf/keystore</keystore> + <secret>james72laBalle</secret> + <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider> + </tls> + <connectionLimit>0</connectionLimit> + <connectionLimitPerIP>0</connectionLimitPerIP> + </imapserver> +</imapservers> Added: james/project/trunk/server/container/cassandra-guice/src/test/resources/lmtpserver.xml URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/test/resources/lmtpserver.xml?rev=1712334&view=auto ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/test/resources/lmtpserver.xml (added) +++ james/project/trunk/server/container/cassandra-guice/src/test/resources/lmtpserver.xml Tue Nov 3 16:48:56 2015 @@ -0,0 +1,41 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + --> + +<lmtpservers> + + <lmtpserver enabled="true"> + <jmxName>lmtpserver</jmxName> + <!-- LMTP should not be reachable from outside your network so bind it to loopback--> + <bind>127.0.0.1:1024</bind> + <connectionBacklog>200</connectionBacklog> + <connectiontimeout>1200</connectiontimeout> + <!-- Set the maximum simultaneous incoming connections for this service --> + <connectionLimit>0</connectionLimit> + <!-- Set the maximum simultaneous incoming connections per IP for this service --> + <connectionLimitPerIP>0</connectionLimitPerIP> + <!-- This sets the maximum allowed message size (in kilobytes) for this --> + <!-- LMTP service. If unspecified, the value defaults to 0, which means no limit. --> + <maxmessagesize>0</maxmessagesize> + <handlerchain> + <handler class="org.apache.james.lmtpserver.CoreCmdHandlerLoader"/> + </handlerchain> + </lmtpserver> + +</lmtpservers> Added: james/project/trunk/server/container/cassandra-guice/src/test/resources/pop3server.xml URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/test/resources/pop3server.xml?rev=1712334&view=auto ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/test/resources/pop3server.xml (added) +++ james/project/trunk/server/container/cassandra-guice/src/test/resources/pop3server.xml Tue Nov 3 16:48:56 2015 @@ -0,0 +1,42 @@ +<?xml version="1.0"?> +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + --> + + +<pop3servers> + <pop3server enabled="true"> + <jmxName>pop3server</jmxName> + <bind>0.0.0.0:1110</bind> + <connectionBacklog>200</connectionBacklog> + <tls socketTLS="false" startTLS="false"> + <!-- To create a new keystore execute: + keytool -genkey -alias james -keyalg RSA -keystore /path/to/james/conf/keystore + --> + <keystore>file://conf/keystore</keystore> + <secret>james72laBalle</secret> + <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider> + </tls> + <connectiontimeout>1200</connectiontimeout> + <connectionLimit>0</connectionLimit> + <connectionLimitPerIP>0</connectionLimitPerIP> + <handlerchain> + <handler class="org.apache.james.pop3server.core.CoreCmdHandlerLoader"/> + </handlerchain> + </pop3server> +</pop3servers> Added: james/project/trunk/server/container/cassandra-guice/src/test/resources/smtpserver.xml URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/cassandra-guice/src/test/resources/smtpserver.xml?rev=1712334&view=auto ============================================================================== --- james/project/trunk/server/container/cassandra-guice/src/test/resources/smtpserver.xml (added) +++ james/project/trunk/server/container/cassandra-guice/src/test/resources/smtpserver.xml Tue Nov 3 16:48:56 2015 @@ -0,0 +1,105 @@ +<?xml version="1.0"?> + +<!-- + Licensed to the Apache Software Foundation (ASF) under one + or more contributor license agreements. See the NOTICE file + distributed with this work for additional information + regarding copyright ownership. The ASF licenses this file + to you under the Apache License, Version 2.0 (the + "License"); you may not use this file except in compliance + with the License. You may obtain a copy of the License at + + http://www.apache.org/licenses/LICENSE-2.0 + + Unless required by applicable law or agreed to in writing, + software distributed under the License is distributed on an + "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY + KIND, either express or implied. See the License for the + specific language governing permissions and limitations + under the License. + --> + +<smtpservers> + <smtpserver enabled="true"> + <jmxName>smtpserver-global</jmxName> + <bind>0.0.0.0:1025</bind> + <connectionBacklog>200</connectionBacklog> + <tls socketTLS="false" startTLS="false"> + <keystore>file://conf/keystore</keystore> + <secret>james72laBalle</secret> + <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider> + <algorithm>SunX509</algorithm> + </tls> + <connectiontimeout>360</connectiontimeout> + <connectionLimit>0</connectionLimit> + <connectionLimitPerIP>0</connectionLimitPerIP> + <authRequired>false</authRequired> + <authorizedAddresses>0.0.0.0/0</authorizedAddresses> + <verifyIdentity>true</verifyIdentity> + <maxmessagesize>0</maxmessagesize> + <addressBracketsEnforcement>true</addressBracketsEnforcement> + <smtpGreeting>JAMES Linagora's SMTP awesome Server</smtpGreeting> + <handlerchain> + <handler class="org.apache.james.smtpserver.fastfail.ValidRcptHandler"/> + <handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/> + </handlerchain> + </smtpserver> + <smtpserver enabled="true"> + <jmxName>smtpserver-TLS</jmxName> + <bind>0.0.0.0:10465</bind> + <connectionBacklog>200</connectionBacklog> + <tls socketTLS="false" startTLS="false"> + <keystore>file://conf/keystore</keystore> + <secret>james72laBalle</secret> + <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider> + <algorithm>SunX509</algorithm> + </tls> + <connectiontimeout>360</connectiontimeout> + <connectionLimit>0</connectionLimit> + <connectionLimitPerIP>0</connectionLimitPerIP> + <!-- + Authorize only local users + --> + <authRequired>true</authRequired> + <authorizedAddresses>0.0.0.0/0</authorizedAddresses> + <!-- Trust authenticated users --> + <verifyIdentity>false</verifyIdentity> + <maxmessagesize>0</maxmessagesize> + <addressBracketsEnforcement>true</addressBracketsEnforcement> + <smtpGreeting>JAMES Linagora's SMTP awesome Server</smtpGreeting> + <handlerchain> + <handler class="org.apache.james.smtpserver.fastfail.ValidRcptHandler"/> + <handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/> + </handlerchain> + </smtpserver> + <smtpserver enabled="true"> + <jmxName>smtpserver-authenticated</jmxName> + <bind>0.0.0.0:1587</bind> + <connectionBacklog>200</connectionBacklog> + <tls socketTLS="false" startTLS="false"> + <keystore>file://conf/keystore</keystore> + <secret>james72laBalle</secret> + <provider>org.bouncycastle.jce.provider.BouncyCastleProvider</provider> + <algorithm>SunX509</algorithm> + </tls> + <connectiontimeout>360</connectiontimeout> + <connectionLimit>0</connectionLimit> + <connectionLimitPerIP>0</connectionLimitPerIP> + <!-- + Authorize only local users + --> + <authRequired>true</authRequired> + <authorizedAddresses>0.0.0.0/0</authorizedAddresses> + <!-- Trust authenticated users --> + <verifyIdentity>false</verifyIdentity> + <maxmessagesize>0</maxmessagesize> + <addressBracketsEnforcement>true</addressBracketsEnforcement> + <smtpGreeting>JAMES Linagora's SMTP awesome Server</smtpGreeting> + <handlerchain> + <handler class="org.apache.james.smtpserver.fastfail.ValidRcptHandler"/> + <handler class="org.apache.james.smtpserver.CoreCmdHandlerLoader"/> + </handlerchain> + </smtpserver> +</smtpservers> + + Modified: james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java URL: http://svn.apache.org/viewvc/james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java?rev=1712334&r1=1712333&r2=1712334&view=diff ============================================================================== --- james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java (original) +++ james/project/trunk/server/container/core/src/main/java/org/apache/james/core/filesystem/FileSystemImpl.java Tue Nov 3 16:48:56 2015 @@ -23,6 +23,8 @@ import java.io.FileNotFoundException; 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 F private final JamesDirectoriesProvider directoryProvider; private final ResourceFactory resourceLoader; + @Inject public FileSystemImpl(JamesDirectoriesProvider directoryProvider) { this.directoryProvider = directoryProvider; this.resourceLoader = new ResourceFactory(directoryProvider); --------------------------------------------------------------------- To unsubscribe, e-mail: server-dev-unsubscr...@james.apache.org For additional commands, e-mail: server-dev-h...@james.apache.org