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 ba...@apache.org on 2006/12/28 11:43:25 UTC

svn commit: r490693 - in /james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver: ExtensibleHandler.java SMTPCommandDispatcherLineHandler.java SMTPHandler.java SMTPHandlerChain.java WiringException.java

Author: bago
Date: Thu Dec 28 02:43:24 2006
New Revision: 490693

URL: http://svn.apache.org/viewvc?view=rev&rev=490693
Log:
Made SMTPHandlerChain generic (it now doesn't have anymore SMTP knowledge: it is simply an handler container that is able to wire ExtensibleHandlers).
Moved the main LineHandler to its own Class. 
Added a WiringException (to have some degree of control on dependency correctness)
Removed the "commands" configuration support for CmdHandlers (always use all the implemented commands)

Added:
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPCommandDispatcherLineHandler.java   (with props)
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/WiringException.java   (with props)
Modified:
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/ExtensibleHandler.java
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java

Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/ExtensibleHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/ExtensibleHandler.java?view=diff&rev=490693&r1=490692&r2=490693
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/ExtensibleHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/ExtensibleHandler.java Thu Dec 28 02:43:24 2006
@@ -40,6 +40,6 @@
      * @param interfaceName
      * @param extension a list of objects implementing the marker interface
      */
-    void wireExtensions(Class interfaceName, List extension);
+    void wireExtensions(Class interfaceName, List extension) throws WiringException;
     
 }

Added: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPCommandDispatcherLineHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPCommandDispatcherLineHandler.java?view=auto&rev=490693
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPCommandDispatcherLineHandler.java (added)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPCommandDispatcherLineHandler.java Thu Dec 28 02:43:24 2006
@@ -0,0 +1,199 @@
+/****************************************************************
+ * 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.smtpserver;
+
+import org.apache.avalon.framework.logger.AbstractLogEnabled;
+import org.apache.james.smtpserver.core.UnknownCmdHandler;
+import org.apache.james.util.mail.SMTPRetCode;
+
+import java.io.UnsupportedEncodingException;
+import java.util.ArrayList;
+import java.util.Collection;
+import java.util.HashMap;
+import java.util.Iterator;
+import java.util.LinkedList;
+import java.util.List;
+import java.util.Locale;
+
+public class SMTPCommandDispatcherLineHandler extends AbstractLogEnabled implements LineHandler, ExtensibleHandler {
+
+    /**
+     * The list of available command handlers
+     */
+    private HashMap commandHandlerMap = new HashMap();
+
+    private final CommandHandler unknownHandler = new UnknownCmdHandler();
+
+    private final static String[] mandatoryCommands = { "MAIL" , "RCPT", "DATA"};
+
+
+    /**
+     * @see org.apache.james.smtpserver.LineHandler#onLine(org.apache.james.smtpserver.SMTPSession, byte[])
+     */
+    public void onLine(SMTPSession session, byte[] line) {
+        String cmdString;
+        try {
+            cmdString = new String(line, "US-ASCII");
+            if (cmdString != null) {
+                cmdString = cmdString.trim();
+            }
+            
+            String curCommandArgument = null;
+            String curCommandName = null;
+            int spaceIndex = cmdString.indexOf(" ");
+            if (spaceIndex > 0) {
+                curCommandName = cmdString.substring(0, spaceIndex);
+                curCommandArgument = cmdString.substring(spaceIndex + 1);
+            } else {
+                curCommandName = cmdString;
+            }
+            curCommandName = curCommandName.toUpperCase(Locale.US);
+
+            List commandHandlers = getCommandHandlers(curCommandName);
+            //fetch the command handlers registered to the command
+            if(commandHandlers == null) {
+                //end the session
+                SMTPResponse resp = new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Local configuration error: unable to find a command handler.");
+                resp.setEndSession(true);
+                session.writeSMTPResponse(resp);
+            } else {
+                int count = commandHandlers.size();
+                for(int i = 0; i < count; i++) {
+                    SMTPResponse response = ((CommandHandler)commandHandlers.get(i)).onCommand(session, curCommandName, curCommandArgument);
+                    
+                    session.writeSMTPResponse(response);
+                    
+                    //if the response is received, stop processing of command handlers
+                    if(response != null) {
+                        break;
+                    }
+                    
+                    // NOTE we should never hit this line, otherwise we ended the CommandHandlers with
+                    // no responses.
+                    // (The note is valid for i == count-1) 
+                }
+
+            }        
+        } catch (UnsupportedEncodingException e) {
+            // TODO Define what to do
+            e.printStackTrace();
+        }
+    }
+
+    /**
+     * @see org.apache.james.smtpserver.ExtensibleHandler#getMarkerInterfaces()
+     */
+    public List getMarkerInterfaces() {
+        List res = new LinkedList();
+        res.add(CommandHandler.class);
+        return res;
+    }
+
+    /**
+     * @throws WiringException 
+     * @see org.apache.james.smtpserver.ExtensibleHandler#wireExtensions(java.lang.Class, java.util.List)
+     */
+    public void wireExtensions(Class interfaceName, List extension) throws WiringException {
+        this.commandHandlerMap = new HashMap();
+
+        for (Iterator it = extension.iterator(); it.hasNext(); ) {
+            CommandHandler handler = (CommandHandler) it.next();
+            Collection implCmds = handler.getImplCommands();
+    
+            for (Iterator i = implCmds.iterator(); i.hasNext(); ) {
+                String commandName = ((String) i.next()).trim().toUpperCase(Locale.US);
+                if (getLogger().isInfoEnabled()) {
+                    getLogger().info(
+                            "Added Commandhandler: " + handler.getClass() + " for command "+commandName);
+                }
+                addToMap(commandName, (CommandHandler) handler);
+            }
+        }
+
+        addToMap(UnknownCmdHandler.UNKNOWN_COMMAND, unknownHandler);
+
+        if (commandHandlerMap.size() < 2) {
+            if (getLogger().isErrorEnabled()) {
+                getLogger().error("No commandhandlers configured");
+            }
+            throw new WiringException("No commandhandlers configured");
+        } else {
+            boolean found = true;
+            for (int i = 0; i < mandatoryCommands.length; i++) {
+                if (!commandHandlerMap.containsKey(mandatoryCommands[i])) {
+                    if (getLogger().isErrorEnabled()) {
+                        getLogger().error(
+                                "No commandhandlers configured for the command:"
+                                        + mandatoryCommands[i]);
+                    }
+                    found = false;
+                    break;
+                }
+            }
+
+            if (!found) {
+                throw new WiringException(
+                        "No commandhandlers configured for mandatory commands");
+            }
+
+
+        }
+
+    }
+    
+
+    /**
+     * Add it to map (key as command name, value is an array list of commandhandlers)
+     *
+     * @param commandName the command name which will be key
+     * @param cmdHandler The commandhandler object
+     */
+    private void addToMap(String commandName, CommandHandler cmdHandler) {
+        ArrayList handlers = (ArrayList)commandHandlerMap.get(commandName);
+        if(handlers == null) {
+            handlers = new ArrayList();
+            commandHandlerMap.put(commandName, handlers);
+        }
+        handlers.add(cmdHandler);
+    }
+
+
+    /**
+     * Returns all the configured commandhandlers for the specified command
+     *
+     * @param command the command name which will be key
+     * @return List of commandhandlers
+     */
+    List getCommandHandlers(String command) {
+        if (command == null) {
+            return null;
+        }
+        if (getLogger().isDebugEnabled()) {
+            getLogger().debug("Lookup command handler for command: " + command);
+        }
+        List handlers =  (List)commandHandlerMap.get(command);
+        if(handlers == null) {
+            handlers = (List)commandHandlerMap.get(UnknownCmdHandler.UNKNOWN_COMMAND);
+        }
+
+        return handlers;
+    }
+
+}
\ No newline at end of file

Propchange: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPCommandDispatcherLineHandler.java
------------------------------------------------------------------------------
    svn:eol-style = native

Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java?view=diff&rev=490693&r1=490692&r2=490693
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java Thu Dec 28 02:43:24 2006
@@ -23,15 +23,13 @@
 
 import org.apache.james.core.AbstractJamesHandler;
 import org.apache.james.util.CRLFDelimitedByteBuffer;
+import org.apache.james.util.mail.SMTPRetCode;
 
 import java.io.IOException;
-import java.io.UnsupportedEncodingException;
 import java.net.Socket;
 import java.util.Collection;
 import java.util.HashMap;
 import java.util.LinkedList;
-import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Random;
 
@@ -43,7 +41,7 @@
  */
 public class SMTPHandler
     extends AbstractJamesHandler
-    implements SMTPSession, LineHandler {
+    implements SMTPSession {
 
     /**
      * Static Random instance used to generate SMTP ids
@@ -97,11 +95,16 @@
     private LinkedList lineHandlers;
 
     /**
+     * Connect Handlers
+     */
+    private LinkedList connectHandlers;
+
+    /**
      * @see org.apache.james.core.AbstractJamesHandler#initHandler(java.net.Socket)
      */
     protected void initHandler(Socket connection) throws IOException {
         super.initHandler(connection);
-        pushLineHandler(this); 
+        lineHandlers = handlerChain.getHandlers(LineHandler.class);
     }
 
     /**
@@ -155,7 +158,6 @@
         //message will not spooled.
 
         //Session started - RUN all connect handlers
-        List connectHandlers = handlerChain.getConnectHandlers();
         if(connectHandlers != null) {
             int count = connectHandlers.size();
             for(int i = 0; i < count; i++) {
@@ -173,15 +175,19 @@
           try {
               line = readInputLine();
           } catch (CRLFDelimitedByteBuffer.TerminationException e) {
-              writeLoggedFlushedResponse("501 Syntax error at character position " + e.position() + ". CR and LF must be CRLF paired.  See RFC 2821 #2.7.1.");
+              writeSMTPResponse(new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_ARGUMENTS, "Syntax error at character position " + e.position() + ". CR and LF must be CRLF paired.  See RFC 2821 #2.7.1."));
           } catch (CRLFDelimitedByteBuffer.LineLengthExceededException e) {
-              writeLoggedFlushedResponse("500 Line length exceeded. See RFC 2821 #4.5.3.1.");
+              writeSMTPResponse(new SMTPResponse(SMTPRetCode.SYNTAX_ERROR_COMMAND_UNRECOGNIZED, "Line length exceeded. See RFC 2821 #4.5.3.1."));
           }
           if (line == null) {
               break;
           }
 
-          ((LineHandler) lineHandlers.getLast()).onLine(this, line);
+          if (lineHandlers.size() > 0) {
+              ((LineHandler) lineHandlers.getLast()).onLine(this, line);
+          } else {
+              sessionEnded = true;
+          }
           theWatchdog.reset();
           
         }
@@ -190,56 +196,6 @@
     }
 
     /**
-     * @see org.apache.james.smtpserver.LineHandler#onLine(org.apache.james.smtpserver.SMTPSession, byte[])
-     */
-    public void onLine(SMTPSession session, byte[] line) {
-        String cmdString;
-        try {
-            cmdString = new String(line, "US-ASCII");
-            if (cmdString != null) {
-                cmdString = cmdString.trim();
-            }
-            
-            String curCommandArgument = null;
-            String curCommandName = null;
-            int spaceIndex = cmdString.indexOf(" ");
-            if (spaceIndex > 0) {
-                curCommandName = cmdString.substring(0, spaceIndex);
-                curCommandArgument = cmdString.substring(spaceIndex + 1);
-            } else {
-                curCommandName = cmdString;
-            }
-            curCommandName = curCommandName.toUpperCase(Locale.US);
-
-            //fetch the command handlers registered to the command
-            List commandHandlers = handlerChain.getCommandHandlers(curCommandName);
-            if(commandHandlers == null) {
-                //end the session
-                sessionEnded = true;
-            } else {
-                int count = commandHandlers.size();
-                for(int i = 0; i < count; i++) {
-                    SMTPResponse response = ((CommandHandler)commandHandlers.get(i)).onCommand(this, curCommandName, curCommandArgument);
-                    
-                    writeSMTPResponse(response);
-                    
-                    //if the response is received, stop processing of command handlers
-                    if(response != null) {
-                        break;
-                    }
-                    
-                    // NOTE we should never hit this line, otherwise we ended the CommandHandlers with
-                    // no responses.
-                }
-
-            }        
-        } catch (UnsupportedEncodingException e) {
-            // TODO Define what to do
-            e.printStackTrace();
-        }
-    }
-
-    /*
      * @see org.apache.james.smtpserver.SMTPSession#writeSMTPResponse(org.apache.james.smtpserver.SMTPResponse)
      */
     public void writeSMTPResponse(SMTPResponse response) {
@@ -280,8 +236,7 @@
 
         // empty any previous line handler and add self (command dispatcher)
         // as the default.
-        lineHandlers = null;
-        pushLineHandler(this);
+        lineHandlers = handlerChain.getHandlers(LineHandler.class);
 
         authenticatedUser = null;
         smtpID = null;
@@ -295,6 +250,7 @@
      */
     public void setHandlerChain(SMTPHandlerChain handlerChain) {
         this.handlerChain = handlerChain;
+        connectHandlers = handlerChain.getHandlers(ConnectHandler.class);
     }
 
 

Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java?view=diff&rev=490693&r1=490692&r2=490693
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandlerChain.java Thu Dec 28 02:43:24 2006
@@ -32,17 +32,12 @@
 import org.apache.avalon.framework.service.ServiceManager;
 import org.apache.avalon.framework.service.Serviceable;
 import org.apache.james.smtpserver.core.CoreCmdHandlerLoader;
-import org.apache.james.smtpserver.core.UnknownCmdHandler;
 import org.apache.james.smtpserver.core.filter.CoreFilterCmdHandlerLoader;
 
-import java.util.ArrayList;
-import java.util.Collection;
 import java.util.Enumeration;
-import java.util.HashMap;
 import java.util.Iterator;
 import java.util.LinkedList;
 import java.util.List;
-import java.util.Locale;
 import java.util.Map;
 import java.util.Properties;
 
@@ -52,16 +47,10 @@
   */
 public class SMTPHandlerChain extends AbstractLogEnabled implements Configurable, Serviceable, Initializable {
 
-    private HashMap commandHandlerMap = new HashMap();
-    private ArrayList connectHandlers = new ArrayList();
     private List handlers = new LinkedList();
 
-    private final CommandHandler unknownHandler = new UnknownCmdHandler();
     private ServiceManager serviceManager;
-    private boolean messageHandlerFound;
     
-    private final static String[] mandatoryCommands = { "MAIL" , "RCPT", "DATA"};
-
     /**
      * @see org.apache.avalon.framework.service.Serviceable#service(org.apache.avalon.framework.service.ServiceManager)
      */
@@ -71,21 +60,16 @@
 
     /**
      * ExtensibleHandler wiring
+     * @throws WiringException 
      */
-    private void wireExtensibleHandlers() {
+    private void wireExtensibleHandlers() throws WiringException {
         for (Iterator h = handlers.iterator(); h.hasNext(); ) {
             Object handler = h.next();
             if (handler instanceof ExtensibleHandler) {
                 List markerInterfaces = ((ExtensibleHandler) handler).getMarkerInterfaces();
                 for (int i= 0;i < markerInterfaces.size(); i++) {
                     Class markerInterface = (Class) markerInterfaces.get(i);
-                    List extensions = new LinkedList();
-                    for (Iterator c2 = handlers.iterator(); c2.hasNext(); ) {
-                        Object ext = c2.next();
-                        if (markerInterface.isInstance(ext)) {
-                            extensions.add(ext);
-                        }
-                    }
+                    List extensions = getHandlers(markerInterface);
                     ((ExtensibleHandler) handler).wireExtensions(markerInterface,extensions);
                 }
             }
@@ -100,7 +84,6 @@
      */
     public void configure(Configuration configuration)
             throws ConfigurationException {
-        addToMap(UnknownCmdHandler.UNKNOWN_COMMAND, unknownHandler);
         if (configuration == null
                 || configuration.getChildren("handler") == null
                 || configuration.getChildren("handler").length == 0) {
@@ -149,59 +132,21 @@
                         addHandler(null, CoreCmdHandlerLoader.class.getName()));
             }
         }
-
-        // the size must be greater than 1 because we added UnknownCmdHandler to
-        // the map
-
-        if (commandHandlerMap.size() < 2) {
-            if (getLogger().isErrorEnabled()) {
-                getLogger().error("No commandhandlers configured");
-            }
-            throw new ConfigurationException("No commandhandlers configured");
-        } else {
-            boolean found = true;
-            for (int i = 0; i < mandatoryCommands.length; i++) {
-                if (!commandHandlerMap.containsKey(mandatoryCommands[i])) {
-                    if (getLogger().isErrorEnabled()) {
-                        getLogger().error(
-                                "No commandhandlers configured for the command:"
-                                        + mandatoryCommands[i]);
-                    }
-                    found = false;
-                    break;
-                }
-            }
-
-            if (!found) {
-                throw new ConfigurationException(
-                        "No commandhandlers configured for mandatory commands");
-            }
-
-            if (!messageHandlerFound) {
-                if (getLogger().isErrorEnabled()) {
-                    getLogger()
-                            .error(
-                                    "No messageHandler configured. Check that SendMailHandler is configured in the SMTPHandlerChain");
-                }
-                throw new ConfigurationException("No messageHandler configured");
-            }
-
-        }
-
     }
     
     /**
      * @see org.apache.avalon.framework.activity.Initializable#initialize()
      */
     public void initialize() throws Exception {
-        Iterator h = commandHandlerMap.keySet().iterator();
+        SMTPCommandDispatcherLineHandler commandDispatcherLineHandler = new SMTPCommandDispatcherLineHandler();
+        commandDispatcherLineHandler.enableLogging(getLogger());
+        handlers.add(commandDispatcherLineHandler);
+        
+        Iterator h = handlers.iterator();
     
         while(h.hasNext()) {
-            List handlers = (List) commandHandlerMap.get(h.next());
-            Iterator h2 = handlers.iterator();
-            while (h2.hasNext()) {
-                ContainerUtil.initialize(h2.next());
-            }
+            Object next = h.next();
+            ContainerUtil.initialize(next);
         }
         wireExtensibleHandlers();
 
@@ -229,14 +174,6 @@
             // 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) {
@@ -258,40 +195,8 @@
 
             }
 
-            // 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");
-                String cmds[] = commandName.split(",");
-                Collection implCmds = ((CommandHandler) handler).getImplCommands();
-
-                for (int i = 0; i < cmds.length; i++) {
-                    commandName = cmds[i].trim().toUpperCase(Locale.US);
-
-                    // Check if the commandHandler implement the configured command
-                    if (implCmds.contains(commandName)) {
-                        addToMap(commandName, (CommandHandler) handler);
-                        if (getLogger().isInfoEnabled()) {
-                            getLogger().info(
-                                    "Added Commandhandler: " + className);
-                        }
-                    } else {
-                        // The Configured command is not implemented. Throw an exception
-                        throw new ConfigurationException("Commandhandler "
-                                + className + " not implement the command "
-                                + commandName);
-                    }
-
-                }
-
-            }
-
-            // if it is a message handler add it to list of message handlers
-            if (handler instanceof MessageHandler) {
-                messageHandlerFound = true;
-                if (getLogger().isInfoEnabled()) {
-                    getLogger().info("Added MessageHandler: " + className);
-                }
+            if (getLogger().isInfoEnabled()) {
+                getLogger().info("Added Handler: " + className);
             }
             
             // fill the big handler table
@@ -341,50 +246,22 @@
         cmdConf.setAttribute("class",className);
         return cmdConf;
     }
-
-    /**
-     * Add it to map (key as command name, value is an array list of commandhandlers)
-     *
-     * @param commandName the command name which will be key
-     * @param cmdHandler The commandhandler object
-     */
-    private void addToMap(String commandName, CommandHandler cmdHandler) {
-        ArrayList handlers = (ArrayList)commandHandlerMap.get(commandName);
-        if(handlers == null) {
-            handlers = new ArrayList();
-            commandHandlerMap.put(commandName, handlers);
-        }
-        handlers.add(cmdHandler);
-    }
-
+    
     /**
-     * Returns all the configured commandhandlers for the specified command
-     *
-     * @param command the command name which will be key
-     * @return List of commandhandlers
+     * Returns a list of handler of the requested type.
+     * 
+     * @param type the type of handler we're interested in
+     * @return a List of handlers
      */
-    List getCommandHandlers(String command) {
-        if (command == null) {
-            return null;
-        }
-        if (getLogger().isDebugEnabled()) {
-            getLogger().debug("Lookup command handler for command: " + command);
-        }
-        List handlers =  (List)commandHandlerMap.get(command);
-        if(handlers == null) {
-            handlers = (List)commandHandlerMap.get(UnknownCmdHandler.UNKNOWN_COMMAND);
+    public LinkedList getHandlers(Class type) {
+        LinkedList result = new LinkedList();
+        for (Iterator i = handlers.iterator(); i.hasNext(); ) {
+            Object handler = i.next();
+            if (type.isInstance(handler)) {
+                result.add(handler);
+            }
         }
-
-        return handlers;
-    }
-
-    /**
-     * Returns all the configured connect handlers
-     *
-     * @return List of connect handlers
-     */
-    List getConnectHandlers() {
-        return connectHandlers;
+        return result;
     }
 
 }

Added: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/WiringException.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/WiringException.java?view=auto&rev=490693
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/WiringException.java (added)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/WiringException.java Thu Dec 28 02:43:24 2006
@@ -0,0 +1,52 @@
+/****************************************************************
+ * Licensed to the Apache Software Foundation (ASF) under one   *
+ * or more contributor license agreements.  See the NOTICE file *
+ * distributed with this work for additional information        *
+ * regarding copyright ownership.  The ASF licenses this file   *
+ * to you under the Apache License, Version 2.0 (the            *
+ * "License"); you may not use this file except in compliance   *
+ * with the License.  You may obtain a copy of the License at   *
+ *                                                              *
+ *   http://www.apache.org/licenses/LICENSE-2.0                 *
+ *                                                              *
+ * Unless required by applicable law or agreed to in writing,   *
+ * software distributed under the License is distributed on an  *
+ * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY       *
+ * KIND, either express or implied.  See the License for the    *
+ * specific language governing permissions and limitations      *
+ * under the License.                                           *
+ ****************************************************************/
+package org.apache.james.smtpserver;
+
+public class WiringException extends Exception {
+
+    /**
+     * 
+     */
+    public WiringException() {
+        super();
+    }
+
+    /**
+     * @param arg0
+     * @param arg1
+     */
+    public WiringException(String arg0, Throwable arg1) {
+        super(arg0, arg1);
+    }
+
+    /**
+     * @param arg0
+     */
+    public WiringException(String arg0) {
+        super(arg0);
+    }
+
+    /**
+     * @param arg0
+     */
+    public WiringException(Throwable arg0) {
+        super(arg0);
+    }
+
+}

Propchange: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/WiringException.java
------------------------------------------------------------------------------
    svn:eol-style = native



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