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 rd...@apache.org on 2009/09/16 09:23:43 UTC

svn commit: r815640 - in /james/server/trunk: avalon-socket-library/src/main/java/org/apache/james/socket/ imapserver-function/src/main/java/org/apache/james/imapserver/ nntpserver-function/src/main/java/org/apache/james/nntpserver/ pop3server-function...

Author: rdonkin
Date: Wed Sep 16 07:23:41 2009
New Revision: 815640

URL: http://svn.apache.org/viewvc?rev=815640&view=rev
Log:
https://issues.apache.org/jira/browse/JAMES-920 Inject configuration data into handlers. This allows the untyped setter to be removed from the ProtocolHandler API. https://issues.apache.org/jira/browse/JAMES-920

Modified:
    james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java
    james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/DelegatingJamesHandler.java
    james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/ProtocolHandler.java
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapHandler.java
    james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java
    james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java
    james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServer.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java
    james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java
    james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManager.java
    james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java
    james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java

Modified: james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java (original)
+++ james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/AbstractJamesService.java Wed Sep 16 07:23:41 2009
@@ -708,14 +708,11 @@
 
         Watchdog theWatchdog = theWatchdogFactory.getWatchdog(theHandler);
 
-        theHandler.setConfigurationData(getConfigurationData());
         theHandler.setStreamDumpDir(streamDumpDir);
         theHandler.setWatchdog(theWatchdog);
         return theHandler;
     }
 
-    protected abstract Object getConfigurationData();
-
     /**
      * @see org.apache.avalon.cornerstone.services.connection.ConnectionHandlerFactory#releaseConnectionHandler(ConnectionHandler)
      */

Modified: james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/DelegatingJamesHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/DelegatingJamesHandler.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/DelegatingJamesHandler.java (original)
+++ james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/DelegatingJamesHandler.java Wed Sep 16 07:23:41 2009
@@ -416,16 +416,6 @@
     }
     
     /**
-     * This method will be implemented checking for the correct class
-     * type.
-     * 
-     * @param theData Configuration Bean.
-     */
-    public void setConfigurationData(Object theData) {
-        protocolHandler.setConfigurationData(theData);
-    }
-    
-    /**
      * Handle the protocol
      * 
      * @throws IOException get thrown if an IO error is detected

Modified: james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/ProtocolHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/ProtocolHandler.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/ProtocolHandler.java (original)
+++ james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/ProtocolHandler.java Wed Sep 16 07:23:41 2009
@@ -24,14 +24,6 @@
 public interface ProtocolHandler {
 
     /**
-     * This method will be implemented checking for the correct class
-     * type.
-     * 
-     * @param theData Configuration Bean.
-     */
-    public abstract void setConfigurationData(Object theData);
-
-    /**
      * Handle the protocol
      * 
      * @throws IOException get thrown if an IO error is detected

Modified: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapHandler.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapHandler.java (original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapHandler.java Wed Sep 16 07:23:41 2009
@@ -53,11 +53,6 @@
         this.requestHandler = requestHandler;
         this.hello = hello;
     }
-    
-    // TODO: this shouldn't be necessary
-    public void setConfigurationData( Object theData )
-    {
-    }
 
     /**
      * Resets the handler data to a basic state.

Modified: james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java (original)
+++ james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapServer.java Wed Sep 16 07:23:41 2009
@@ -114,11 +114,6 @@
         getLogger().debug("Create handler instance");
         return imapHandler;
     }
-
-    // TODO: 
-    protected Object getConfigurationData() {
-        return null;
-    }
     
     public void post(String url, MimeMessage mail)throws MessagingException {
         final int endOfScheme = url.indexOf(':');

Modified: james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java (original)
+++ james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java Wed Sep 16 07:23:41 2009
@@ -233,7 +233,7 @@
      * Per-service configuration data that applies to all handlers
      * associated with the service.
      */
-    private NNTPHandlerConfigurationData theConfigData;
+    private final NNTPHandlerConfigurationData theConfigData;
 
     /**
      * The user id associated with the NNTP dialogue
@@ -251,17 +251,10 @@
      */
     boolean isAlreadyAuthenticated = false;
 
-    /**
-     * @see org.apache.james.socket.AbstractJamesHandler#setConfigurationData(Object)
-     */
-    public void setConfigurationData(Object theData) {
-        if (theData instanceof NNTPHandlerConfigurationData) {
-            theConfigData = (NNTPHandlerConfigurationData) theData;
-        } else {
-            throw new IllegalArgumentException("Configuration object does not implement NNTPHandlerConfigurationData");
-        }
+    public NNTPHandler(final NNTPHandlerConfigurationData theConfigData) {
+        this.theConfigData = theConfigData;
     }
-
+    
     /**
      * @see org.apache.james.socket.AbstractJamesHandler#handleProtocol()
      */
@@ -320,9 +313,6 @@
         user = null;
         password = null;
         isAlreadyAuthenticated = false;
-
-        // Clear the config data
-        theConfigData = null;
     }
 
     /**

Modified: james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServer.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServer.java (original)
+++ james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPServer.java Wed Sep 16 07:23:41 2009
@@ -135,7 +135,8 @@
      * @see org.apache.james.socket.AbstractJamesService#newProtocolHandlerInstance()
      */
     public ProtocolHandler newProtocolHandlerInstance() {
-        return new NNTPHandler();
+        final NNTPHandler handler = new NNTPHandler(theConfigData);
+        return handler;
     }
 
     /**
@@ -177,11 +178,4 @@
         }
 
     }
-
-    /**
-     * @see org.apache.james.socket.AbstractJamesService#getConfigurationData()
-     */
-    protected Object getConfigurationData() {
-        return theConfigData;
-    }
 }

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java Wed Sep 16 07:23:41 2009
@@ -85,7 +85,7 @@
     /**
      * The per-service configuration data that applies to all handlers
      */
-    private POP3HandlerConfigurationData theConfigData;
+    private final POP3HandlerConfigurationData theConfigData;
 
     /**
      * The mail server's copy of the user's inbox
@@ -127,7 +127,7 @@
     /**
      * The POP3HandlerChain object set by POP3Server
      */
-    POP3HandlerChain handlerChain = null;
+    final POP3HandlerChain handlerChain;
 
     /**
      * The session termination status
@@ -155,17 +155,9 @@
     private byte mode;
     
     
-    /**
-     * Set the configuration data for the handler.
-     *
-     * @param theData the configuration data
-     */
-    public void setConfigurationData(Object theData) {
-        if (theData instanceof POP3HandlerConfigurationData) {
-            theConfigData = (POP3HandlerConfigurationData) theData;
-        } else {
-            throw new IllegalArgumentException("Configuration object does not implement POP3HandlerConfigurationData");
-        }
+    public POP3Handler(final POP3HandlerConfigurationData theConfigData, final POP3HandlerChain handlerChain) {
+        this.theConfigData = theConfigData;
+        this.handlerChain = handlerChain;
     }
     
     /**
@@ -302,9 +294,6 @@
             backupUserMailbox.clear();
             backupUserMailbox = null;
         }
-
-        // Clear config data
-        theConfigData = null;
     }
 
     /**
@@ -414,15 +403,6 @@
     }
 
     /**
-     * Sets the POP3HandlerChain
-     *
-     * @param handlerChain POP3Handler object
-     */
-    public void setHandlerChain(POP3HandlerChain handlerChain) {
-        this.handlerChain = handlerChain;
-    }
-
-    /**
      * @see org.apache.james.pop3server.POP3Session#writeResponse(java.lang.String)
      */
     public void writeResponse(String respString) {

Modified: james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java
URL: http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java (original)
+++ james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Server.java Wed Sep 16 07:23:41 2009
@@ -140,17 +140,15 @@
      * @see org.apache.james.socket.AbstractJamesService#newProtocolHandlerInstance()
      */
     public ProtocolHandler newProtocolHandlerInstance() {
-        POP3Handler protocolHandler = new POP3Handler();
         //pass the handler chain to every POP3handler
-        protocolHandler.setHandlerChain(handlerChain);
+        POP3Handler protocolHandler = new POP3Handler(theConfigData, handlerChain);
         return protocolHandler;
     }
 
     /**
      * A class to provide POP3 handler configuration to the handlers
      */
-    private class POP3HandlerConfigurationDataImpl
-        implements POP3HandlerConfigurationData {
+    private class POP3HandlerConfigurationDataImpl implements POP3HandlerConfigurationData {
 
         /**
          * @see org.apache.james.pop3server.POP3HandlerConfigurationData#getHelloName()
@@ -184,11 +182,4 @@
             return POP3Server.this.users;
         }
     }
-
-    /**
-     * @see org.apache.james.socket.AbstractJamesService#getConfigurationData()
-     */
-    protected Object getConfigurationData() {
-        return theConfigData;
-    }
 }

Modified: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManager.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManager.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManager.java (original)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManager.java Wed Sep 16 07:23:41 2009
@@ -291,7 +291,7 @@
      * @see org.apache.james.socket.AbstractJamesService#newProtocolHandlerInstance()
      */
     public ProtocolHandler newProtocolHandlerInstance() {
-        return new RemoteManagerHandler();
+        return new RemoteManagerHandler(theConfigData);
     }
 
     /**
@@ -393,11 +393,4 @@
             return RemoteManager.this.commands;
         }
     }
-
-    /**
-     * @see org.apache.james.socket.AbstractJamesService#getConfigurationData()
-     */
-    protected Object getConfigurationData() {
-        return theConfigData;
-    }
 }

Modified: james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerHandler.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerHandler.java (original)
+++ james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerHandler.java Wed Sep 16 07:23:41 2009
@@ -108,7 +108,7 @@
     /**
      * The per-service configuration data that applies to all handlers
      */
-    private RemoteManagerHandlerConfigurationData theConfigData;
+    private final RemoteManagerHandlerConfigurationData theConfigData;
 
     /**
      * The current UsersRepository being managed/viewed/modified
@@ -125,23 +125,13 @@
     private final static String REMOVE_MAPPING_ACTION = "REMOVE_MAPPING";
 
     
-    /**
-     * Set the configuration data for the handler.
-     *
-     * @param theData the configuration data
-     */
-    public void setConfigurationData(Object theData) {
-        if (theData instanceof RemoteManagerHandlerConfigurationData) {
-            theConfigData = (RemoteManagerHandlerConfigurationData) theData;
-
-            // Reset the users repository to the default.
-            users = theConfigData.getUsersRepository();
-            
-            Command[] commands = theConfigData.getCommands();
-            commandRegistry = new CommandRegistry(commands);
-        } else {
-            throw new IllegalArgumentException("Configuration object does not implement RemoteManagerHandlerConfigurationData");
-        }
+    public RemoteManagerHandler(RemoteManagerHandlerConfigurationData theConfigData) {
+        this.theConfigData = theConfigData;
+        // Reset the users repository to the default.
+        users = theConfigData.getUsersRepository();
+        
+        Command[] commands = theConfigData.getCommands();
+        commandRegistry = new CommandRegistry(commands);
     }
 
     /**
@@ -229,9 +219,6 @@
     public void resetHandler() {
         // Reset user repository
         users = theConfigData.getUsersRepository();
-
-        // Clear config data
-        theConfigData = null;
     }
 
     /**

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandler.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandler.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandler.java Wed Sep 16 07:23:41 2009
@@ -74,7 +74,7 @@
      */
     private final LinkedList<ConnectHandler> connectHandlers;
 
-	private SMTPConfiguration theConfigData;
+	private final SMTPConfiguration theConfigData;
 
 	private boolean relayingAllowed;
 
@@ -86,24 +86,12 @@
 
 	private String smtpID;
 
-	public SMTPHandler(SMTPHandlerChain handlerChain) {
+	public SMTPHandler(SMTPHandlerChain handlerChain, final SMTPConfiguration theConfigData) {
         this.handlerChain = handlerChain;
         connectHandlers = handlerChain.getHandlers(ConnectHandler.class);
         lineHandlers = handlerChain.getHandlers(LineHandler.class);
+        this.theConfigData = theConfigData;
 	}
-	
-    /**
-     * Set the configuration data for the handler
-     *
-     * @param theData the per-service configuration data for this handler
-     */
-    public void setConfigurationData(Object theData) {
-        if (theData instanceof SMTPConfiguration) {
-            theConfigData = (SMTPConfiguration) theData;
-        } else {
-            throw new IllegalArgumentException("Configuration object does not implement SMTPHandlerConfigurationData");
-        }
-    }
     
     /**
      * @see org.apache.james.socket.ProtocolHandler#handleProtocol()

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPServer.java Wed Sep 16 07:23:41 2009
@@ -361,16 +361,9 @@
 
     }
 
-    /**
-     * @see org.apache.james.core.AbstractJamesService#getConfigurationData()
-     */
-    protected Object getConfigurationData() {
-        return theConfigData;
-    }
-
     @Override
     public ProtocolHandler newProtocolHandlerInstance() {
-        final SMTPHandler theHandler = new SMTPHandler(handlerChain);
+        final SMTPHandler theHandler = new SMTPHandler(handlerChain, theConfigData);
         return theHandler;
     }
 

Modified: james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java?rev=815640&r1=815639&r2=815640&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java (original)
+++ james/server/trunk/smtpserver-function/src/test/java/org/apache/james/smtpserver/TarpitHandlerTest.java Wed Sep 16 07:23:41 2009
@@ -40,7 +40,7 @@
             
             public void sleep(long ms) {
                 // use the real code 
-                (new SMTPHandler(new SMTPHandlerChain())).sleep(ms);
+                (new SMTPHandler(new SMTPHandlerChain(), null)).sleep(ms);
             }
 
         };



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