james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From nor...@apache.org
Subject svn commit: r418591 - in /james/server/sandbox/handlerapi/src: conf/ java/org/apache/james/smtpserver/ java/org/apache/james/smtpserver/core/
Date Sun, 02 Jul 2006 13:16:44 GMT
Author: norman
Date: Sun Jul  2 06:16:43 2006
New Revision: 418591

URL: http://svn.apache.org/viewvc?rev=418591&view=rev
Log:
Add BaseCmdHandler which holds the default commandhandlers

Added:
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/CommandsHandler.java
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/core/
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/core/BaseCmdHandler.java
Modified:
    james/server/sandbox/handlerapi/src/conf/james-config.xml
    james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java

Modified: james/server/sandbox/handlerapi/src/conf/james-config.xml
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/conf/james-config.xml?rev=418591&r1=418590&r2=418591&view=diff
==============================================================================
--- james/server/sandbox/handlerapi/src/conf/james-config.xml (original)
+++ james/server/sandbox/handlerapi/src/conf/james-config.xml Sun Jul  2 06:16:43 2006
@@ -932,83 +932,8 @@
             -->            
             
             <!-- The command handler configuration -->
-            <handler command="HELO" class="org.apache.james.smtpserver.HeloCmdHandler">
-                <!-- If is set to true helo is only accepted if it can be resolved -->
-                <!--
-                <checkResolvableHelo> false </checkResolvableHelo>
-                -->
-                
-                <!-- If is set to true helo is only accepted if it is equal the reverse
of the -->
-                <!-- connecting client -->
-                <!--
-                <checkReverseEqualsHelo> false </checkReverseEqualsHelo>
-                -->
-                
-                <!-- If is set to true sender domain will be checked also for clients
that -->
-                <!-- are allowed to relay. Default is false. -->
-                <!--
-                <checkAuthNetworks> false </checkAuthNetworks>
-                -->
-            </handler>
-            <handler command="EHLO" class="org.apache.james.smtpserver.EhloCmdHandler">
-                <!-- If is set to true ehlo is only accepted if it can be resolved -->
-                <!--
-                <checkResolvableEhlo> false </checkResolvableEhlo>
-                -->
-                
-                <!-- If is set to true ehlo is only accepted if it is equal the reverse
of the -->
-                <!-- connecting client -->
-                <!--
-                <checkReverseEqualsEhlo> false </checkReverseEqualsEhlo>
-                -->
-                
-                <!-- If is set to true sender domain will be checked also for clients
that -->
-                <!-- are allowed to relay. Default is false. -->
-                <!--
-                <checkAuthNetworks> false </checkAuthNetworks>
-                -->
-            </handler>
-            <handler command="AUTH" class="org.apache.james.smtpserver.AuthCmdHandler"></handler>
-            <handler command="VRFY" class="org.apache.james.smtpserver.VrfyCmdHandler"></handler>
-            <handler command="EXPN" class="org.apache.james.smtpserver.ExpnCmdHandler"></handler>
-            <handler command="MAIL" class="org.apache.james.smtpserver.MailCmdHandler">
-                <!-- If is set to true mail is only accepted if the sender contains -->
-                <!-- a resolvable domain having a valid MX Record or A Record associated!
-->
-                <!--
-                <checkValidSenderDomain> false </checkValidSenderDomain>
-                -->
-                <!-- If is set to true sender domain from clients that are allowed to
-->
-                <!-- relay will be checked, too. Default is false. -->
-                <!-- 
-                <checkAuthClients> false </checkAuthClients>
-                -->
-            </handler>
-            <handler command="RCPT" class="org.apache.james.smtpserver.RcptCmdHandler">
-                <!-- If is set to a bigger value as 0 you can limit the maximal recipients
-->
-                <!-- per email. Default is set to 0. -->
-                <!-- 
-                <maxRcpt> 0 </maxRcpt>
-                -->
-                
-                <!-- If is set to a bigger value as 0 you can set the recipients after
which -->
-                <!-- tarpitting get activated. -->
-                <!-- Tarpitting is a method to insert a small sleep after each rcpt. For
more -->
-                <!-- infos read this: http://www.palomine.net/qmail/tarpit.html . -->
-                <!-- Default is set to 0 (disabled). -->
-                <!--
-                <tarpitRcptCount> 0 </tarpitRcptCount>
-                -->
-                <!-- See timeout in milliseconds to insert after the rcpt. Only is used
if -->
-                <!-- tarpitting is activated. -->
-                <!--
-                <tarpitSleepTime> 5000 </tarpitSleepTime>
-                -->
-            </handler>
-            <handler command="DATA" class="org.apache.james.smtpserver.DataCmdHandler"></handler>
-            <handler command="RSET" class="org.apache.james.smtpserver.RsetCmdHandler"></handler>
-            <handler command="HELP" class="org.apache.james.smtpserver.HelpCmdHandler"></handler>
-            <handler command="QUIT" class="org.apache.james.smtpserver.QuitCmdHandler"></handler>
-         
+            <handler class="org.apache.james.smtpserver.core.BaseCmdHandler"></handler>
+            
             <!-- The message handler configuration -->
             <!-- 
             <handler class="org.apache.james.smtpserver.SetMimeHeaderHandler">

Added: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/CommandsHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/CommandsHandler.java?rev=418591&view=auto
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/CommandsHandler.java
(added)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/CommandsHandler.java
Sun Jul  2 06:16:43 2006
@@ -0,0 +1,31 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation.                  *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.smtpserver;
+
+import java.util.Map;
+
+public interface CommandsHandler {
+    
+    /**
+     * Return a Map which contains a set of CommandHandlers
+     * 
+     * @return Map
+     */
+    Map getCommands();
+
+}

Modified: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java?rev=418591&r1=418590&r2=418591&view=diff
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java
(original)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java
Sun Jul  2 06:16:43 2006
@@ -37,6 +37,7 @@
 import java.util.Iterator;
 import java.util.List;
 import java.util.Locale;
+import java.util.Map;
 import java.util.Properties;
 
 /**
@@ -106,46 +107,7 @@
                     if(className != null) {
                         //load the handler
                         try {
-                            Object handler = classLoader.loadClass(className).newInstance();
-
-                            //enable logging
-                            ContainerUtil.enableLogging(handler, getLogger());
-                            
-                            ContainerUtil.contextualize(handler,context);
-
-                            //servicing the handler
-                            ContainerUtil.service(handler,serviceManager);
-
-                            //configure the handler
-                            ContainerUtil.configure(handler,children[i]);
-
-                            //if it is a connect handler add it to list of connect handlers
-                            if(handler instanceof ConnectHandler) {
-                                connectHandlers.add((ConnectHandler)handler);
-                                if (getLogger().isInfoEnabled()) {
-                                    getLogger().info("Added ConnectHandler: " + className);
-                                }
-                            }
-
-                            //if it is a command handler add it to the map with key as command
name
-                            if(handler instanceof CommandHandler) {
-                                String commandName = children[i].getAttribute("command");
-                                commandName = commandName.toUpperCase(Locale.US);
-                                addToMap(commandName, (CommandHandler)handler);
-                                if (getLogger().isInfoEnabled()) {
-                                    getLogger().info("Added Commandhandler: " + className);
-                                }
-
-                            }
-
-                            //if it is a message handler add it to list of message handlers
-                            if(handler instanceof MessageHandler) {
-                                messageHandlers.add((MessageHandler)handler);
-                                if (getLogger().isInfoEnabled()) {
-                                    getLogger().info("Added MessageHandler: " + className);
-                                }
-                            }
-
+                            loadClass(classLoader,className,children[i]);
                         } catch (ClassNotFoundException ex) {
                            if (getLogger().isErrorEnabled()) {
                                getLogger().error("Failed to add Commandhandler: " + className,ex);
@@ -224,6 +186,71 @@
         }
     }
 
+    private void loadClass(ClassLoader classLoader, String className,
+            Configuration config) throws ConfigurationException,
+            InstantiationException, IllegalAccessException,
+            ClassNotFoundException, ContextException, ServiceException {
+        Object handler = classLoader.loadClass(className).newInstance();
+
+        // enable logging
+        ContainerUtil.enableLogging(handler, getLogger());
+
+        ContainerUtil.contextualize(handler, context);
+
+        // servicing the handler
+        ContainerUtil.service(handler, serviceManager);
+
+        // configure the handler
+        ContainerUtil.configure(handler, config);
+
+        // if it is a connect handler add it to list of connect handlers
+        if (handler instanceof ConnectHandler) {
+            connectHandlers.add((ConnectHandler) handler);
+            if (getLogger().isInfoEnabled()) {
+                getLogger().info("Added ConnectHandler: " + className);
+            }
+        }
+
+        // if it is a commands handler add it to the map with key as command
+        // name
+        if (handler instanceof CommandsHandler) {
+            Map c = ((CommandsHandler) handler).getCommands();
+
+            Iterator cmdKeys = c.keySet().iterator();
+
+            while (cmdKeys.hasNext()) {
+                String commandName = cmdKeys.next().toString();
+                String cName = c.get(commandName).toString();
+
+                DefaultConfiguration cmdConf = new DefaultConfiguration(
+                        "handler");
+                cmdConf.setAttribute("command", commandName);
+                cmdConf.setAttribute("class", cName);
+
+                loadClass(classLoader, cName, cmdConf);
+            }
+
+        }
+
+        // if it is a command handler add it to the map with key as command name
+        if (handler instanceof CommandHandler) {
+            String commandName = config.getAttribute("command");
+            commandName = commandName.toUpperCase(Locale.US);
+            addToMap(commandName, (CommandHandler) handler);
+            if (getLogger().isInfoEnabled()) {
+                getLogger().info("Added Commandhandler: " + className);
+            }
+
+        }
+
+        // if it is a message handler add it to list of message handlers
+        if (handler instanceof MessageHandler) {
+            messageHandlers.add((MessageHandler) handler);
+            if (getLogger().isInfoEnabled()) {
+                getLogger().info("Added MessageHandler: " + className);
+            }
+        }
+    }
 
     /**
      * Add it to map (key as command name, value is an array list of commandhandlers)

Added: james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/core/BaseCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/core/BaseCmdHandler.java?rev=418591&view=auto
==============================================================================
--- james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/core/BaseCmdHandler.java
(added)
+++ james/server/sandbox/handlerapi/src/java/org/apache/james/smtpserver/core/BaseCmdHandler.java
Sun Jul  2 06:16:43 2006
@@ -0,0 +1,65 @@
+/***********************************************************************
+ * Copyright (c) 2006 The Apache Software Foundation.                  *
+ * All rights reserved.                                                *
+ * ------------------------------------------------------------------- *
+ * Licensed 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.smtpserver.core;
+
+import java.util.HashMap;
+import java.util.Map;
+
+import org.apache.james.smtpserver.CommandsHandler;
+
+/**
+ * This class represent the base command handlers which are shipped with james.
+ */
+public class BaseCmdHandler implements CommandsHandler {
+
+    private final Object AUTHCMDHANDLER = "org.apache.james.smtpserver.AuthCmdHandler";
+    private final Object DATACMDHANDLER = "org.apache.james.smtpserver.DataCmdHandler";
+    private final Object EHLOCMDHANDLER = "org.apache.james.smtpserver.EhloCmdHandler";
+    private final Object EXPNCMDHANDLER = "org.apache.james.smtpserver.ExpnCmdHandler";
+    private final Object HELOCMDHANDLER = "org.apache.james.smtpserver.HeloCmdHandler";
+    private final Object HELPCMDHANDLER = "org.apache.james.smtpserver.HelpCmdHandler";
+    private final Object MAILCMDHANDLER = "org.apache.james.smtpserver.MailCmdHandler";
+    private final Object NOOPCMDHANDLER = "org.apache.james.smtpserver.NoopCmdHandler";
+    private final Object QUITCMDHANDLER = "org.apache.james.smtpserver.QuitCmdHandler";
+    private final Object RCPTCMDHANDLER = "org.apache.james.smtpserver.RcptCmdHandler";
+    private final Object RSETCMDHANDLER = "org.apache.james.smtpserver.RsetCmdHandler";
+    private final Object VRFYCMDHANDLER = "org.apache.james.smtpserver.VrfyCmdHandler";
+   
+    /**
+     * @see org.apache.james.smtpserver.CommandsHandler#getCommands()
+     */
+    public Map getCommands() {
+        Map commands = new HashMap();
+        
+        // Insert the basecommands in the Map
+        commands.put("AUTH", AUTHCMDHANDLER);
+        commands.put("DATA", DATACMDHANDLER);
+        commands.put("EHLO", EHLOCMDHANDLER);
+        commands.put("EXPN", EXPNCMDHANDLER);
+        commands.put("HELO", HELOCMDHANDLER);
+        commands.put("HELP", HELPCMDHANDLER);
+        commands.put("MAIL", MAILCMDHANDLER);
+        commands.put("NOOP", NOOPCMDHANDLER);
+        commands.put("QUIT", QUITCMDHANDLER);
+        commands.put("RCPT", RCPTCMDHANDLER);
+        commands.put("RSET", RSETCMDHANDLER);
+        commands.put("VRFY", VRFYCMDHANDLER);
+        
+        return commands;
+    }
+}



---------------------------------------------------------------------
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