james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r883772 - in /james/server/trunk: phoenix-deployment/src/test/org/apache/james/ spoolmanager-function/src/main/java/org/apache/james/transport/mailets/ spoolmanager-function/src/test/java/org/apache/james/transport/ spoolmanager-function/sr...
Date Tue, 24 Nov 2009 16:36:57 GMT
Author: norman
Date: Tue Nov 24 16:36:56 2009
New Revision: 883772

URL: http://svn.apache.org/viewvc?rev=883772&view=rev
Log:
More decoupling of Avalon to move to Guice (JAMES-893)

Modified:
    james/server/trunk/phoenix-deployment/src/test/org/apache/james/AvalonJamesTest.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
    james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/ToMultiRepository.java
    james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/LinearProcessorTest.java
    james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/mailets/LocalDeliveryTest.java

Modified: james/server/trunk/phoenix-deployment/src/test/org/apache/james/AvalonJamesTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/phoenix-deployment/src/test/org/apache/james/AvalonJamesTest.java?rev=883772&r1=883771&r2=883772&view=diff
==============================================================================
--- james/server/trunk/phoenix-deployment/src/test/org/apache/james/AvalonJamesTest.java (original)
+++ james/server/trunk/phoenix-deployment/src/test/org/apache/james/AvalonJamesTest.java Tue
Nov 24 16:36:56 2009
@@ -30,7 +30,6 @@
 import org.apache.james.services.SpoolRepository;
 import org.apache.james.test.mock.avalon.MockLogger;
 import org.apache.james.test.mock.avalon.MockServiceManager;
-import org.apache.james.userrepository.MockUsersRepository;
 
 public class AvalonJamesTest extends JamesTest{
 

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java?rev=883772&r1=883771&r2=883772&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
(original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/LocalDelivery.java
Tue Nov 24 16:36:56 2009
@@ -22,11 +22,15 @@
 package org.apache.james.transport.mailets;
 
 import org.apache.commons.collections.iterators.IteratorChain;
+import org.apache.james.api.user.UsersRepository;
+import org.apache.james.api.user.UsersStore;
+import org.apache.james.services.MailServer;
 import org.apache.mailet.base.GenericMailet;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailetConfig;
 import org.apache.mailet.MailetContext;
 
+import javax.annotation.Resource;
 import javax.mail.MessagingException;
 
 import java.util.ArrayList;
@@ -53,6 +57,29 @@
      */
     private ToMultiRepository deliveryMailet;
 
+    private UsersRepository usersRepository;
+
+    private UsersStore usersStore;
+
+    private MailServer mailServer;
+
+
+    @Resource(name="org.apache.james.api.user.UsersRepository")
+    public void setUsersRepository(UsersRepository usersRepository) {
+        this.usersRepository = usersRepository;
+    }
+    
+    @Resource(name="org.apache.james.api.user.UsersStore")
+    public void setUsersStore(UsersStore usersStore) {
+        this.usersStore = usersStore;
+    }
+    
+    @Resource(name="org.apache.james.services.MailServer")
+    public void setMailServer(MailServer mailServer) {
+        this.mailServer = mailServer;
+    }
+    
+    
     /**
      * Delivers a mail to a local mailbox.
      * 
@@ -85,8 +112,11 @@
         super.init();
         
         aliasingMailet = new UsersRepositoryAliasingForwarding();
+        aliasingMailet.setUsersRepository(usersRepository);
+        aliasingMailet.setUsersStore(usersStore);
         aliasingMailet.init(getMailetConfig());
         deliveryMailet = new ToMultiRepository();
+        deliveryMailet.setMailServer(mailServer);
         MailetConfig m = new MailetConfig() {
 
             /**

Modified: james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/ToMultiRepository.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/ToMultiRepository.java?rev=883772&r1=883771&r2=883772&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/ToMultiRepository.java
(original)
+++ james/server/trunk/spoolmanager-function/src/main/java/org/apache/james/transport/mailets/ToMultiRepository.java
Tue Nov 24 16:36:56 2009
@@ -22,10 +22,7 @@
 package org.apache.james.transport.mailets;
 
 import org.apache.avalon.cornerstone.services.store.Store;
-import org.apache.avalon.framework.configuration.DefaultConfiguration;
-import org.apache.avalon.framework.service.ServiceException;
-import org.apache.avalon.framework.service.ServiceManager;
-import org.apache.james.Constants;
+import org.apache.commons.configuration.DefaultConfigurationBuilder;
 import org.apache.james.core.MailImpl;
 import org.apache.james.services.MailRepository;
 import org.apache.james.services.MailServer;
@@ -34,6 +31,7 @@
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.base.RFC2822Headers;
 
+import javax.annotation.Resource;
 import javax.mail.Header;
 import javax.mail.MessagingException;
 import javax.mail.internet.InternetHeaders;
@@ -114,6 +112,12 @@
      */
     private boolean resetReturnPath;
 
+    
+    @Resource(name="org.apache.james.services.MailServer")
+    public void setMailServer(MailServer mailServer) {
+        this.mailServer = mailServer;
+    }
+    
     /**
      * Delivers a mail to a local mailbox.
      * 
@@ -261,17 +265,7 @@
      */
     public void init() throws MessagingException {
         super.init();
-        ServiceManager compMgr = (ServiceManager) getMailetContext()
-                .getAttribute(Constants.AVALON_COMPONENT_MANAGER);
-
-        try {
-            // Instantiate the a MailRepository for outgoing mails
-            store = (Store) compMgr.lookup(Store.ROLE);
-        } catch (ServiceException cnfe) {
-            log("Failed to retrieve Store component:" + cnfe.getMessage());
-        } catch (Exception e) {
-            log("Failed to retrieve Store component:" + e.getMessage());
-        }
+   
 
         repositoryUrl = getInitParameter("repositoryUrl");
         if (repositoryUrl != null) {
@@ -286,17 +280,6 @@
             if (!SELECTOR_LOCALPART.equals(repositorySelector) && !SELECTOR_FULL.equals(repositorySelector))
{
                 throw new MessagingException("repositorySelector valid options are "+SELECTOR_FULL+"
or "+SELECTOR_LOCALPART);
             }
-        } else {
-
-            try {
-                // Instantiate the a MailRepository for outgoing mails
-                mailServer = (MailServer) compMgr.lookup(MailServer.ROLE);
-            } catch (ServiceException cnfe) {
-                log("Failed to retrieve MailServer component:" + cnfe.getMessage());
-            } catch (Exception e) {
-                log("Failed to retrieve MailServer component:" + e.getMessage());
-            }
-            
         }
 
         deliveryHeader = getInitParameter("addDeliveryHeader");
@@ -325,10 +308,9 @@
             StringBuffer destinationBuffer = new StringBuffer(192).append(
             repositoryUrl).append(userName).append("/");
             String destination = destinationBuffer.toString();
-            DefaultConfiguration mboxConf = new DefaultConfiguration(
-                    "repository", "generated:ToMultiRepository.getUserInbox()");
-            mboxConf.setAttribute("destinationURL", destination);
-            mboxConf.setAttribute("type", repositoryType);
+            DefaultConfigurationBuilder mboxConf = new DefaultConfigurationBuilder();
+            mboxConf.addProperty("[@destinationURL]", destination);
+            mboxConf.addProperty("[@type]", repositoryType);
             try {
                 userInbox = (MailRepository) store.select(mboxConf);
             } catch (Exception e) {

Modified: james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/LinearProcessorTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/LinearProcessorTest.java?rev=883772&r1=883771&r2=883772&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/LinearProcessorTest.java
(original)
+++ james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/LinearProcessorTest.java
Tue Nov 24 16:36:56 2009
@@ -20,8 +20,6 @@
 package org.apache.james.transport;
 
 import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.avalon.framework.logger.ConsoleLogger;
-import org.apache.avalon.framework.logger.Logger;
 import org.apache.commons.logging.impl.SimpleLog;
 import org.apache.james.core.MailImpl;
 import org.apache.james.core.MimeMessageCopyOnWriteProxy;
@@ -237,8 +235,7 @@
         }
         mimeMessage = new MimeMessageCopyOnWriteProxy(mmis);
         linearProcessor = new LinearProcessor();
-        Logger l = new ConsoleLogger();
-        ContainerUtil.enableLogging(linearProcessor, l);
+        linearProcessor.setLogger(new SimpleLog("Logger"));
     }
 
     public void tearDown() throws Exception {

Modified: james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/mailets/LocalDeliveryTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/mailets/LocalDeliveryTest.java?rev=883772&r1=883771&r2=883772&view=diff
==============================================================================
--- james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/mailets/LocalDeliveryTest.java
(original)
+++ james/server/trunk/spoolmanager-function/src/test/java/org/apache/james/transport/mailets/LocalDeliveryTest.java
Tue Nov 24 16:36:56 2009
@@ -19,39 +19,35 @@
 
 package org.apache.james.transport.mailets;
 
+import java.util.ArrayList;
+import java.util.Arrays;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.List;
+import java.util.Properties;
+
+import javax.mail.MessagingException;
+import javax.mail.internet.MimeMessage;
+import javax.mail.internet.ParseException;
+
+import junit.framework.TestCase;
+
 import org.apache.avalon.framework.container.ContainerUtil;
-import org.apache.james.Constants;
-import org.apache.james.api.user.UsersRepository;
 import org.apache.james.core.MailImpl;
 import org.apache.james.impl.user.DefaultJamesUser;
 import org.apache.james.services.MailRepository;
-import org.apache.james.services.MailServer;
-import org.apache.james.test.mock.avalon.MockServiceManager;
 import org.apache.james.test.mock.james.InMemorySpoolRepository;
 import org.apache.james.test.mock.james.MockMailServer;
-import org.apache.mailet.base.test.FakeMimeMessage;
-import org.apache.mailet.base.test.FakeMail;
-import org.apache.mailet.base.test.FakeMailContext;
-import org.apache.mailet.base.test.FakeMailetConfig;
-import org.apache.mailet.base.test.MailUtil;
 import org.apache.james.userrepository.MockUsersRepository;
 import org.apache.mailet.Mail;
 import org.apache.mailet.MailAddress;
 import org.apache.mailet.Mailet;
-
-import javax.mail.MessagingException;
-import javax.mail.internet.MimeMessage;
-import javax.mail.internet.ParseException;
-
-import java.util.ArrayList;
-import java.util.Arrays;
-import java.util.Collection;
-import java.util.HashMap;
-import java.util.Iterator;
-import java.util.List;
-import java.util.Properties;
-
-import junit.framework.TestCase;
+import org.apache.mailet.base.test.FakeMail;
+import org.apache.mailet.base.test.FakeMailContext;
+import org.apache.mailet.base.test.FakeMailetConfig;
+import org.apache.mailet.base.test.FakeMimeMessage;
+import org.apache.mailet.base.test.MailUtil;
 
 /**
  * Test LocalDelivery Mailet
@@ -60,7 +56,6 @@
 
     private HashMap mailboxes;
     private FakeMailContext mockMailetContext;
-    private MockServiceManager mockServiceManager;
     private MockMailServer mockMailServer;
     private MockUsersRepository mockUsersRepository;
 
@@ -242,7 +237,6 @@
      * 
      */
     public void setUp() throws ParseException {
-        mockServiceManager = new MockServiceManager();
         mockUsersRepository = new MockUsersRepository();
         mockUsersRepository.setForceUseJamesUser();
         mockUsersRepository.addUser("localuser", "password");
@@ -268,7 +262,6 @@
         u = (DefaultJamesUser) mockUsersRepository.getUserByName("forwardToLocal");
         u.setForwarding(true);
         u.setForwardingDestination(new MailAddress("localuser@ignoreddomain"));
-        mockServiceManager.put(UsersRepository.ROLE,mockUsersRepository);
         mockMailServer = new MockMailServer(mockUsersRepository);
         mailboxes = new HashMap();
         mailboxes.put("localuser", new InMemorySpoolRepository());
@@ -279,7 +272,6 @@
             String mboxName = (String) mbi.next();
             mockMailServer.setUserInbox(mboxName, (MailRepository) mailboxes.get(mboxName));
         }
-        mockServiceManager.put(MailServer.ROLE, mockMailServer);
 
         mockMailetContext = new FakeMailContext() {
 
@@ -306,13 +298,11 @@
         mockUsersRepository.setEnableAliases(false);
         mockUsersRepository.setEnableForwarding(false);
         mockUsersRepository.setIgnoreCase(false);
-        mockMailetContext.setAttribute(Constants.AVALON_COMPONENT_MANAGER, mockServiceManager);
     }
     
     public void tearDown() {
         mockMailetContext = null;
         mailboxes = null;
-        mockServiceManager = null;
     }
 
     /**
@@ -400,7 +390,9 @@
     
     public Mailet getMailet(Properties p) throws MessagingException {
         FakeMailetConfig mockMailetConfig = new FakeMailetConfig("TestedLocalDelivery", mockMailetContext,
p);
-        Mailet m = new LocalDelivery();
+        LocalDelivery m = new LocalDelivery();
+        m.setUsersRepository(mockUsersRepository);
+        m.setMailServer(mockMailServer);
         m.init(mockMailetConfig);
         return m;
     }



---------------------------------------------------------------------
To unsubscribe, e-mail: server-dev-unsubscribe@james.apache.org
For additional commands, e-mail: server-dev-help@james.apache.org


Mime
View raw message