You are viewing a plain text version of this content. The canonical link for it is here.
Posted to server-dev@james.apache.org by no...@apache.org on 2006/11/21 08:42:51 UTC

svn commit: r477544 - in /james/server/trunk/src: conf/ java/org/apache/james/domain/ java/org/apache/james/management/ java/org/apache/james/remotemanager/ java/org/apache/james/services/ java/org/apache/james/util/ test/org/apache/james/remotemanager/

Author: norman
Date: Mon Nov 20 23:42:48 2006
New Revision: 477544

URL: http://svn.apache.org/viewvc?view=rev&rev=477544
Log:
Add JMX and RemoteManager management for DomainList.See JAMES-687
Get sure IPAdresses get only added to domainList if not allready exists
Add junit tests

Added:
    james/server/trunk/src/java/org/apache/james/management/DomainListManagement.java   (with props)
    james/server/trunk/src/java/org/apache/james/management/DomainListManagement.xinfo
    james/server/trunk/src/java/org/apache/james/management/DomainListManagementException.java   (with props)
    james/server/trunk/src/java/org/apache/james/management/DomainListManagementMBean.java   (with props)
    james/server/trunk/src/java/org/apache/james/services/DomainListManagementService.java   (with props)
Modified:
    james/server/trunk/src/conf/james-assembly.xml
    james/server/trunk/src/java/org/apache/james/domain/XMLDomainList.java
    james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java
    james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.xinfo
    james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
    james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java
    james/server/trunk/src/java/org/apache/james/util/DomainListUtil.java
    james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java

Modified: james/server/trunk/src/conf/james-assembly.xml
URL: http://svn.apache.org/viewvc/james/server/trunk/src/conf/james-assembly.xml?view=diff&rev=477544&r1=477543&r2=477544
==============================================================================
--- james/server/trunk/src/conf/james-assembly.xml (original)
+++ james/server/trunk/src/conf/james-assembly.xml Mon Nov 20 23:42:48 2006
@@ -95,6 +95,7 @@
     <provide name="dnsserver" role="org.apache.james.services.DNSServer"/>
     <provide name="processormanagement" role="org.apache.james.services.ProcessorManagementService"/>
     <provide name="virtualusertablemanagement" role="org.apache.james.services.VirtualUserTableManagementService"/>
+    <provide name="domainlistmanagement" role="org.apache.james.services.DomainListManagementService"/>
 </block>
 
   <!-- The User Management block  -->
@@ -238,7 +239,7 @@
     <provide name="dnsserver" role="org.apache.james.services.DNSServer"/>
   </block>
   
-    <block name="defaultvirtualusertable" class="org.apache.james.core.DefaultVirtualUserTable">
+  <block name="defaultvirtualusertable" class="org.apache.james.core.DefaultVirtualUserTable">
     <provide name="virtualusertable-store"
              role="org.apache.james.services.VirtualUserTableStore"/>
   </block>
@@ -278,6 +279,10 @@
   -->
   <!-- #################################################################### -->
   
+  <block name="domainlistmanagement" class="org.apache.james.management.DomainListManagement">
+    <provide name="domainlist"
+             role="org.apache.james.services.DomainList"/>
+  </block>
   
   <!-- Configuration for Cornerstone Blocks only after here
        NOTHING BELOW THIS SHOULD NEED CHANGING,

Modified: james/server/trunk/src/java/org/apache/james/domain/XMLDomainList.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/domain/XMLDomainList.java?view=diff&rev=477544&r1=477543&r2=477544
==============================================================================
--- james/server/trunk/src/java/org/apache/james/domain/XMLDomainList.java (original)
+++ james/server/trunk/src/java/org/apache/james/domain/XMLDomainList.java Mon Nov 20 23:42:48 2006
@@ -77,6 +77,8 @@
     }
 
     /**
+     * The added domains will only added in memory!
+     * 
      * @see org.apache.james.domain.AbstractDomainList#addDomainInternal(java.lang.String)
      */
     protected boolean addDomainInternal(String domain) {

Added: james/server/trunk/src/java/org/apache/james/management/DomainListManagement.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/DomainListManagement.java?view=auto&rev=477544
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/DomainListManagement.java (added)
+++ james/server/trunk/src/java/org/apache/james/management/DomainListManagement.java Mon Nov 20 23:42:48 2006
@@ -0,0 +1,85 @@
+/****************************************************************
+ * 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.management;
+
+import java.util.List;
+
+import org.apache.avalon.framework.service.ServiceException;
+import org.apache.avalon.framework.service.ServiceManager;
+import org.apache.avalon.framework.service.Serviceable;
+import org.apache.james.services.DomainList;
+import org.apache.james.services.DomainListManagementService;
+import org.apache.james.services.ManageableDomainList;
+
+/**
+ * Provide management class for DomainLists
+ */
+public class DomainListManagement implements DomainListManagementService,DomainListManagementMBean,Serviceable {
+    DomainList domList;
+    
+    /**
+     * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
+     */
+    public void service(ServiceManager arg0) throws ServiceException {
+        setDomainList((DomainList) arg0.lookup(DomainList.ROLE));
+    }
+    
+    public void setDomainList(DomainList domList) {
+        this.domList = domList;
+    }
+    
+    /**
+     * @see org.apache.james.services.DomainListManagementService#addDomain(java.lang.String)
+     */
+    public boolean addDomain(String domain) throws DomainListManagementException {
+        if (domList instanceof ManageableDomainList) {
+            return ((ManageableDomainList)domList).addDomain(domain);
+        } else {
+            throw new DomainListManagementException("Used DomainList implementation not support management");
+        }
+    }
+
+    /**
+     * @see org.apache.james.services.DomainListManagementService#removeDomain(java.lang.String)
+     */
+    public boolean removeDomain(String domain) throws DomainListManagementException {
+        if (domList instanceof ManageableDomainList) {
+            return ((ManageableDomainList)domList).removeDomain(domain);
+        } else {
+           throw new DomainListManagementException("Used DomainList implementation not support management");
+        }
+    }
+
+    /**
+     * @see org.apache.james.services.DomainListManagementService#containsDomain(java.lang.String)
+     */
+    public boolean containsDomain(String domain) {
+        return domList.containsDomain(domain);
+    }
+
+    /**
+     * @see org.apache.james.services.DomainListManagementService#getDomains()
+     */
+    public List getDomains() {
+        return domList.getDomains();
+    }
+}

Propchange: james/server/trunk/src/java/org/apache/james/management/DomainListManagement.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/management/DomainListManagement.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/DomainListManagement.xinfo?view=auto&rev=477544
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/DomainListManagement.xinfo (added)
+++ james/server/trunk/src/java/org/apache/james/management/DomainListManagement.xinfo Mon Nov 20 23:42:48 2006
@@ -0,0 +1,24 @@
+<?xml version="1.0"?>
+
+<blockinfo>
+
+  <!-- section to describe block -->
+  <block>
+    <version>1.0</version>
+  </block>
+
+  <services>
+    <service name="org.apache.james.services.DomainListManagementService" version="1.0" />
+  </services>
+  
+  <!-- interfaces that may be exported to manange this block -->
+  <management-access-points>
+    <service name="org.apache.james.management.DomainListManagementMBean"/>
+  </management-access-points>  
+  
+  <dependencies>
+    <dependency>
+      <service name="org.apache.james.services.DomainList" version="1.0"/>
+    </dependency>
+  </dependencies>
+</blockinfo>

Added: james/server/trunk/src/java/org/apache/james/management/DomainListManagementException.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/DomainListManagementException.java?view=auto&rev=477544
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/DomainListManagementException.java (added)
+++ james/server/trunk/src/java/org/apache/james/management/DomainListManagementException.java Mon Nov 20 23:42:48 2006
@@ -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.management;
+
+public class DomainListManagementException extends ManagementException {
+
+    public DomainListManagementException() {
+        super();
+    }
+
+    public DomainListManagementException(String message) {
+        super(message);
+    }
+
+    public DomainListManagementException(Exception e) {
+        super(e);
+    }
+    
+    public DomainListManagementException(String message, Exception e) {
+        super(message, e);
+    }
+
+}

Propchange: james/server/trunk/src/java/org/apache/james/management/DomainListManagementException.java
------------------------------------------------------------------------------
    svn:eol-style = native

Added: james/server/trunk/src/java/org/apache/james/management/DomainListManagementMBean.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/management/DomainListManagementMBean.java?view=auto&rev=477544
==============================================================================
--- james/server/trunk/src/java/org/apache/james/management/DomainListManagementMBean.java (added)
+++ james/server/trunk/src/java/org/apache/james/management/DomainListManagementMBean.java Mon Nov 20 23:42:48 2006
@@ -0,0 +1,77 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+
+
+
+package org.apache.james.management;
+
+import java.util.List;
+
+import org.apache.james.management.DomainListManagementException;
+
+public interface DomainListManagementMBean {
+
+    /**
+     * Add domain to the service
+     * 
+     * @phoenix:mx-operation
+     * @phoenix:mx-description Add domain to the service
+     *
+     * 
+     * @param domain domain to add
+     * @return true if successfully
+     * @throws DomainListManagementException 
+     */
+    public boolean addDomain(String domain) throws DomainListManagementException;
+    
+    /**
+     * Remove domain from the service     
+     *
+     * @phoenix:mx-operation
+     * @phoenix:mx-description Remove domain to the service  
+     * 
+     * @param domain domain to remove
+     * @return true if succesfully
+     * @throws DomainListManagementException 
+     */
+    public boolean removeDomain(String domain) throws DomainListManagementException;
+    
+    /**
+     * Return List of domains which should be used as localdomains. Return null if no
+     * domains were found
+     * 
+     * @phoenix:mx-operation
+     * @phoenix:mx-description Return List of domains which should be used as localdomains. Return null if no
+     *                         domains were found
+     * 
+     * @return domains
+     */
+    public List getDomains();
+    
+    /**
+     * Return true if the domain exists in the service 
+     * 
+     * @phoenix:mx-operation
+     * @phoenix:mx-description Return true if the domain exists in the service
+     * 
+     * @param domain the domain
+     * @return true if the given domain exists in the service
+     */
+    public boolean containsDomain(String domain);
+}

Propchange: james/server/trunk/src/java/org/apache/james/management/DomainListManagementMBean.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java?view=diff&rev=477544&r1=477543&r2=477544
==============================================================================
--- james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java (original)
+++ james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.java Mon Nov 20 23:42:48 2006
@@ -28,6 +28,7 @@
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.james.core.AbstractJamesService;
 import org.apache.james.services.BayesianAnalyzerManagementService;
+import org.apache.james.services.DomainListManagementService;
 import org.apache.james.services.MailServer;
 import org.apache.james.services.ProcessorManagementService;
 import org.apache.james.services.SpoolManagementService;
@@ -95,6 +96,8 @@
 
     private VirtualUserTableManagementService vutManagemenet;
     
+    private DomainListManagementService domListManagement;
+    
     /**
      * Set the UserStore 
      * 
@@ -168,6 +171,15 @@
     }
     
     /**
+     * Set the DomainListManagementService
+     * 
+     * @param domListManagement the DomainListManagementService 
+     */
+    public void setDomainListManagement(DomainListManagementService domListManagement) {
+        this.domListManagement = domListManagement;
+    }
+    
+    /**
      * The configuration data to be passed to the handler
      */
     private RemoteManagerHandlerConfigurationData theConfigData
@@ -198,6 +210,7 @@
         setBayesianAnalyzerManagement((BayesianAnalyzerManagementService) componentManager.lookup(BayesianAnalyzerManagementService.ROLE));     
         setProcessorManagement((ProcessorManagementService) componentManager.lookup(ProcessorManagementService.ROLE)); 
         setVirtualUserTableManagement((VirtualUserTableManagementService) componentManager.lookup(VirtualUserTableManagementService.ROLE));
+        setDomainListManagement((DomainListManagementService) componentManager.lookup(DomainListManagementService.ROLE));
     }
 
     /**
@@ -329,6 +342,13 @@
          */
         public VirtualUserTableManagementService getVirtualUserTableManagement() {
             return RemoteManager.this.vutManagemenet;
+        }
+
+        /**
+         * @see org.apache.james.remotemanager.RemoteManagerHandlerConfigurationData#getDomainListManagement()
+         */
+        public DomainListManagementService getDomainListManagement() {
+            return RemoteManager.this.domListManagement;
         }
     }
 

Modified: james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.xinfo
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.xinfo?view=diff&rev=477544&r1=477543&r2=477544
==============================================================================
--- james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.xinfo (original)
+++ james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManager.xinfo Mon Nov 20 23:42:48 2006
@@ -49,5 +49,8 @@
     <dependency>
       <service name="org.apache.james.services.VirtualUserTableManagementService" version="1.0"/>
     </dependency>
+    <dependency>
+      <service name="org.apache.james.services.DomainListManagementService" version="1.0"/>
+    </dependency>
   </dependencies>
 </blockinfo>

Modified: james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java?view=diff&rev=477544&r1=477543&r2=477544
==============================================================================
--- james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java (original)
+++ james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java Mon Nov 20 23:42:48 2006
@@ -37,6 +37,7 @@
 import org.apache.james.Constants;
 import org.apache.james.core.AbstractJamesHandler;
 import org.apache.james.management.BayesianAnalyzerManagementException;
+import org.apache.james.management.DomainListManagementException;
 import org.apache.james.management.SpoolFilter;
 import org.apache.james.management.VirtualUserTableManagementException;
 import org.apache.james.services.JamesUser;
@@ -95,6 +96,9 @@
         "REMOVEMAPPING",
         "LISTMAPPING",
         "LISTALLMAPPINGS",
+        "ADDDOMAIN",
+        "REMOVEDOMAIN",
+        "LISTDOMAINS",
         "QUIT",
         "SHUTDOWN"
     });
@@ -509,10 +513,13 @@
         out.println("showforwarding [username]                                               shows a user's current email forwarding");
         out.println("unsetforwarding [username]                                              removes a forward");
         out.println("user [repositoryname]                                                   change to another user repository");
-        out.println("addmapping [table=virtualusertablename] user@domain mapping             add mapping for the given emailaddress");
-        out.println("removemapping [table=virtualusertablename] user@domain mapping          remove mapping for the given emailaddress");
-        out.println("listmapping [table=virtualusertablename] user@domain                    list all mappings for the given emailaddress");
-        out.println("listallmappings [table=virtualusertablename]                            list all mappings");
+        out.println("addmapping ([table=virtualusertablename]) [user@domain] [mapping]       add mapping for the given emailaddress");
+        out.println("removemapping ([table=virtualusertablename]) [user@domain] [mapping]    remove mapping for the given emailaddress");
+        out.println("listmapping ([table=virtualusertablename]) [user@domain]                list all mappings for the given emailaddress");
+        out.println("listallmappings ([table=virtualusertablename])                          list all mappings");
+        out.println("adddomain [domainname]                                                  add domain to local domains");
+        out.println("removedomain [domainname]                                               remove domain from local domains");
+        out.println("listdomains                                                             list local domains");
         out.println("listspool [spoolrepositoryname] ([header=name] [regex=value])           list all mails which reside in the spool and have an error state");
         out.println("flushspool [spoolrepositoryname] ([key] | [header=name] [regex=value])  try to resend the mail assing to the given key. If no key is given all mails get resend");
         out.println("deletespool [spoolrepositoryname] ([key] | [header=name] [regex=value]) delete the mail assign to the given key. If no key is given all mails get deleted");
@@ -1616,5 +1623,68 @@
             throw new IllegalArgumentException("Invalid action: " + action);
         }   
     }
+    
+    private boolean doLISTDOMAINS(String argument) {
+        Collection domains = theConfigData.getDomainListManagement().getDomains();
+        if (domains == null) {
+            out.println("No domains found");
+            out.flush();
+        } else {
+            out.println("Domains:");
+                
+            Iterator d = domains.iterator();
+            while(d.hasNext()) {
+                out.println(d.next());
+            }
+            out.flush();
+        }   
+        return true;
+    }
+
+    private boolean doADDDOMAIN(String argument) {
 
+        // check if the command was called correct
+        if (argument == null) {
+            writeLoggedFlushedResponse("Usage: ADDDOMAIN domain");
+            return true;
+        }
+        
+        try {
+            if(theConfigData.getDomainListManagement().addDomain(argument)) {
+                out.println("Adding domain " + argument + " successful");
+                out.flush();
+            } else {
+                out.println("Adding domain " + argument + " fail");
+                out.flush();
+            }
+        } catch (DomainListManagementException e) {
+            getLogger().error("Error on adding domain: " + e);
+            out.println("Error on adding domain: " + e);
+            out.flush();
+        }
+        return true;
+    }
+    
+    private boolean doREMOVEDOMAIN(String argument) {
+        // check if the command was called correct
+        if (argument == null) {
+            writeLoggedFlushedResponse("Usage: REMOVEDOMAIN domain");
+            return true;
+        }
+        
+        try {
+            if(theConfigData.getDomainListManagement().removeDomain(argument)) {
+                out.println("Removing domain " + argument + " successful");
+                out.flush();
+            } else {
+                out.println("Removing domain " + argument + " fail");
+                out.flush();
+            }
+        } catch (DomainListManagementException e) {
+            getLogger().error("Error on removing domain: " + e);
+            out.println("Error on removing domain: " + e);
+            out.flush();
+        }
+        return true;
+    }
 }

Modified: james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java?view=diff&rev=477544&r1=477543&r2=477544
==============================================================================
--- james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java (original)
+++ james/server/trunk/src/java/org/apache/james/remotemanager/RemoteManagerHandlerConfigurationData.java Mon Nov 20 23:42:48 2006
@@ -23,6 +23,7 @@
 
 import org.apache.avalon.cornerstone.services.store.Store;
 import org.apache.james.services.BayesianAnalyzerManagementService;
+import org.apache.james.services.DomainListManagementService;
 import org.apache.james.services.MailServer;
 import org.apache.james.services.ProcessorManagementService;
 import org.apache.james.services.SpoolManagementService;
@@ -117,4 +118,11 @@
      * @return the VirtualUserTableManagementService
      */
     VirtualUserTableManagementService getVirtualUserTableManagement();
+    
+    /**
+     * Return the DomainListManagementService
+     * 
+     * @return the DomainListManagementService
+     */
+    DomainListManagementService getDomainListManagement();
 }

Added: james/server/trunk/src/java/org/apache/james/services/DomainListManagementService.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/services/DomainListManagementService.java?view=auto&rev=477544
==============================================================================
--- james/server/trunk/src/java/org/apache/james/services/DomainListManagementService.java (added)
+++ james/server/trunk/src/java/org/apache/james/services/DomainListManagementService.java Mon Nov 20 23:42:48 2006
@@ -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.services;
+
+import java.util.List;
+
+import org.apache.james.management.DomainListManagementException;
+
+public interface DomainListManagementService {
+
+    public final static String ROLE = "org.apache.james.services.DomainListManagementService";
+    
+    /**
+     * Add domain to the service
+     * 
+     * @param domain domain to add
+     * @return true if successfully
+     * @throws DomainListManagementException 
+     */
+    public boolean addDomain(String domain) throws DomainListManagementException;
+    
+    /**
+     * Remove domain from the service
+     *  
+     * @param domain domain to remove
+     * @return true if succesfully
+     * @throws DomainListManagementException 
+     */
+    public boolean removeDomain(String domain) throws DomainListManagementException;
+    
+    /**
+     * Return List of domains which should be used as localdomains. Return null if no
+     * domains were found
+     * 
+     * @return domains
+     */
+    public List getDomains();
+    
+    /**
+     * Return true if the domain exists in the service 
+     * 
+     * @param domain the domain
+     * @return true if the given domain exists in the service
+     */
+    public boolean containsDomain(String domain);
+}

Propchange: james/server/trunk/src/java/org/apache/james/services/DomainListManagementService.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/trunk/src/java/org/apache/james/util/DomainListUtil.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/java/org/apache/james/util/DomainListUtil.java?view=diff&rev=477544&r1=477543&r2=477544
==============================================================================
--- james/server/trunk/src/java/org/apache/james/util/DomainListUtil.java (original)
+++ james/server/trunk/src/java/org/apache/james/util/DomainListUtil.java Mon Nov 20 23:42:48 2006
@@ -46,7 +46,13 @@
         List domainIP = new ArrayList();
         if (domains.size() > 0 ) {
             for (int i = 0; i < domains.size(); i++) {
-                domainIP.addAll(getDomainIP(domains.get(i).toString(),dns,log));
+                List domList = getDomainIP(domains.get(i).toString(),dns,log);
+            
+                for(int i2 = 0; i2 < domList.size();i2++) {
+                    if(domainIP.contains(domList.get(i2)) == false) {
+                        domainIP.add(domList.get(i2));
+                    }
+                }
             }
         }
         return domainIP;    

Modified: james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java?view=diff&rev=477544&r1=477543&r2=477544
==============================================================================
--- james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java (original)
+++ james/server/trunk/src/test/org/apache/james/remotemanager/RemoteManagerTest.java Mon Nov 20 23:42:48 2006
@@ -24,10 +24,14 @@
 import org.apache.avalon.cornerstone.services.sockets.SocketManager;
 import org.apache.avalon.cornerstone.services.threads.ThreadManager;
 import org.apache.avalon.framework.container.ContainerUtil;
+import org.apache.avalon.framework.service.ServiceException;
 import org.apache.commons.net.telnet.TelnetClient;
+import org.apache.james.domain.XMLDomainList;
+import org.apache.james.management.DomainListManagement;
 import org.apache.james.management.VirtualUserTableManagement;
 import org.apache.james.services.AbstractDNSServer;
 import org.apache.james.services.DNSServer;
+import org.apache.james.services.DomainListManagementService;
 import org.apache.james.services.JamesConnectionManager;
 import org.apache.james.services.MailServer;
 import org.apache.james.services.UsersRepository;
@@ -77,7 +81,6 @@
     protected TelnetClient m_telnetClient;
     private MockUsersRepository m_mockUsersRepository;
     private MockMailServer mailServer;
-    private static final String VUT_TABLE = "VUT";
 
     protected void setUp() throws Exception {
         m_remoteManager = new RemoteManager();
@@ -161,7 +164,7 @@
         readAnswer(3);
     }
 
-    private MockServiceManager setUpServiceManager() {
+    private MockServiceManager setUpServiceManager() throws ServiceException {
         MockServiceManager serviceManager = new MockServiceManager();
         SimpleConnectionManager connectionManager = new SimpleConnectionManager();
         ContainerUtil.enableLogging(connectionManager, new MockLogger());
@@ -180,6 +183,15 @@
         vutManagement.setVirtualUserTableStore(vutStore);
         vutManagement.setDefaultVirtualUserTable(new MockVirtualUserTableManagementImpl());
         serviceManager.put(VirtualUserTableManagementService.ROLE, vutManagement);
+        
+        XMLDomainList xml = new XMLDomainList();
+        ContainerUtil.enableLogging(xml, new MockLogger());
+        ContainerUtil.service(xml, serviceManager);
+        
+        DomainListManagement domManagement = new DomainListManagement();
+        domManagement.setDomainList(xml);
+        
+        serviceManager.put(DomainListManagementService.ROLE, domManagement);
         return serviceManager;
     }
     
@@ -192,6 +204,10 @@
             public InetAddress getLocalHost() throws UnknownHostException {
                 return InetAddress.getLocalHost();
             }
+            
+            public InetAddress[] getAllByName(String name) throws UnknownHostException {
+            return new InetAddress[]{InetAddress.getLocalHost()};
+            }
         };
     
         return dns;
@@ -599,5 +615,64 @@
         sendCommand("listmapping test@test");
         lastLine = readAnswer(2).get(1).toString();
         assertTrue("list mapping", lastLine.endsWith("junit"));
+    }
+    
+    public void testaddDomain() throws IOException {
+        String lastLine;
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("adddomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add domain", lastLine.endsWith("successful"));
+       
+        sendCommand("adddomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add domain which exists", lastLine.endsWith("fail"));
+       
+        sendCommand("listdomains");
+
+        lastLine = readAnswer(2).get(1).toString();
+        assertTrue("list domain", lastLine.endsWith("domain"));       
+    }
+    
+    public void testremoveDomain() throws IOException {
+        String lastLine;
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("adddomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add domain", lastLine.endsWith("successful"));
+       
+        sendCommand("removedomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Remove domain", lastLine.endsWith("successful"));
+       
+        sendCommand("removedomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Remove domain which not exist", lastLine.endsWith("fail"));    
+    }
+    
+    public void testListDomains() throws IOException {
+        String lastLine;
+        finishSetUp(m_testConfiguration);
+        connect();
+        login();
+
+        sendCommand("adddomain domain");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add domain", lastLine.endsWith("successful"));
+       
+        sendCommand("adddomain domain2");
+        lastLine = getLastLine(readAnswer());
+        assertTrue("Add domain", lastLine.endsWith("successful")); 
+        
+        sendCommand("listdomains");
+        List answer = readAnswer(3);
+        assertTrue("list domain 1", answer.get(1).toString().endsWith("domain")); 
+        assertTrue("list domain 2", answer.get(2).toString().endsWith("domain2"));   
     }
 }



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