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 2010/01/16 19:01:32 UTC

svn commit: r900007 - in /james/server/trunk: smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/ smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/ smtp-protocol-library/src/main/java/org/apache/james/...

Author: norman
Date: Sat Jan 16 18:01:31 2010
New Revision: 900007

URL: http://svn.apache.org/viewvc?rev=900007&view=rev
Log:
use String as parameter for LineHandler
get sure the linehandlers get pushed in the right position when using mina

Modified:
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/LineHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataCmdHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineFilter.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineMessageHookHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/ReceivedDataLineFilter.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SMTPCommandDispatcherLineHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java
    james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/MailSizeEsmtpExtension.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/integration/DataLineJamesMessageHookHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPIoHandler.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/FilterLineHandlerAdapter.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPResponseFilter.java
    james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPValidationFilter.java

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/LineHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/LineHandler.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/LineHandler.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/LineHandler.java Sat Jan 16 18:01:31 2010
@@ -30,6 +30,6 @@
      * @param session not null
      * @param line not null 
      */
-    void onLine(SMTPSession session, byte[] line);
+    void onLine(SMTPSession session, String line);
     
 }

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataCmdHandler.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataCmdHandler.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataCmdHandler.java Sat Jan 16 18:01:31 2010
@@ -45,7 +45,8 @@
         /**
          * @see org.apache.james.smtpserver.protocol.LineHandler#onLine(org.apache.james.smtpserver.protocol.SMTPSession, byte[])
          */
-        public void onLine(SMTPSession session, byte[] line) {
+        public void onLine(SMTPSession session, String rawLine) {
+            byte[] line = rawLine.getBytes();
             // Discard everything until the end of DATA session
             if (line.length == 3 && line[0] == 46) {
                 session.popLineHandler();
@@ -62,7 +63,7 @@
             this.filter = filter;
             this.next = next;
         }
-        public void onLine(SMTPSession session, byte[] line) {
+        public void onLine(SMTPSession session, String line) {
             filter.onLine(session, line, next);
         }
                 

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineFilter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineFilter.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineFilter.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineFilter.java Sat Jan 16 18:01:31 2010
@@ -29,5 +29,5 @@
  * being received.
  */
 public interface DataLineFilter {
-    void onLine(SMTPSession session, byte[] line, LineHandler next);
+    void onLine(SMTPSession session, String line, LineHandler next);
 }
\ No newline at end of file

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineMessageHookHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineMessageHookHandler.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineMessageHookHandler.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/DataLineMessageHookHandler.java Sat Jan 16 18:01:31 2010
@@ -54,13 +54,14 @@
     
     private List rHooks;
     
-    /**
-     * @see org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession, byte[], org.apache.james.smtpserver.protocol.LineHandler)
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession, java.lang.String, org.apache.james.smtpserver.protocol.LineHandler)
      */
-    public void onLine(SMTPSession session, byte[] line, LineHandler next) {
+    public void onLine(SMTPSession session, String rawLine, LineHandler next) {
         MailEnvelopeImpl env = (MailEnvelopeImpl) session.getState().get(DataCmdHandler.MAILENV);
         OutputStream out = env.getMessageOutputStream();
-        
+        byte[] line = rawLine.getBytes();
         try {
             // 46 is "."
             // Stream terminated

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/ReceivedDataLineFilter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/ReceivedDataLineFilter.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/ReceivedDataLineFilter.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/ReceivedDataLineFilter.java Sat Jan 16 18:01:31 2010
@@ -40,11 +40,11 @@
     private final static RFC822DateFormat rfc822DateFormat = new RFC822DateFormat();
     private final static String HEADERS_WRITTEN = "HEADERS_WRITTEN";
 
-    /**
-     * @see org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession,
-     *      byte[], org.apache.james.smtpserver.protocol.LineHandler)
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession, java.lang.String, org.apache.james.smtpserver.protocol.LineHandler)
      */
-    public void onLine(SMTPSession session, byte[] line, LineHandler next) {
+    public void onLine(SMTPSession session,  String line, LineHandler next) {
         if (session.getState().containsKey(HEADERS_WRITTEN) == false) {
             addNewReceivedMailHeaders(session, next);
             session.getState().put(HEADERS_WRITTEN, true);
@@ -71,7 +71,7 @@
 
         headerLineBuffer.append(" ([").append(session.getRemoteIPAddress())
                 .append("])").append("\r\n");
-        next.onLine(session, headerLineBuffer.toString().getBytes());
+        next.onLine(session, headerLineBuffer.toString());
         headerLineBuffer.delete(0, headerLineBuffer.length());
 
         headerLineBuffer.append("          by ").append(session.getHelloName())
@@ -102,7 +102,7 @@
             // (prevents email address harvesting and large headers in
             // bulk email)
             headerLineBuffer.append("\r\n");
-            next.onLine(session, headerLineBuffer.toString().getBytes());
+            next.onLine(session, headerLineBuffer.toString());
             headerLineBuffer.delete(0, headerLineBuffer.length());
 
             headerLineBuffer.delete(0, headerLineBuffer.length());
@@ -110,7 +110,7 @@
                     ((List) session.getState().get(SMTPSession.RCPT_LIST)).get(
                             0).toString()).append(">;").append("\r\n");
 
-            next.onLine(session, headerLineBuffer.toString().getBytes());
+            next.onLine(session, headerLineBuffer.toString());
             headerLineBuffer.delete(0, headerLineBuffer.length());
 
             headerLineBuffer.delete(0, headerLineBuffer.length());
@@ -118,11 +118,11 @@
             // Put the ; on the end of the 'by' line
             headerLineBuffer.append(";");
             headerLineBuffer.append("\r\n");
-            next.onLine(session, headerLineBuffer.toString().getBytes());
+            next.onLine(session, headerLineBuffer.toString());
             headerLineBuffer.delete(0, headerLineBuffer.length());
         }
         headerLineBuffer = null;
         next.onLine(session, ("          "
-                + rfc822DateFormat.format(new Date()) + "\r\n").getBytes());
+                + rfc822DateFormat.format(new Date()) + "\r\n"));
     }
 }

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SMTPCommandDispatcherLineHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SMTPCommandDispatcherLineHandler.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SMTPCommandDispatcherLineHandler.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/SMTPCommandDispatcherLineHandler.java Sat Jan 16 18:01:31 2010
@@ -19,7 +19,6 @@
 
 package org.apache.james.smtpserver.protocol.core;
 
-import java.io.UnsupportedEncodingException;
 import java.util.Arrays;
 import java.util.LinkedList;
 import java.util.List;
@@ -51,60 +50,52 @@
     private final static String[] mandatoryCommands = { "MAIL" , "RCPT", "DATA"};
 
 
-    /**
-     * @see org.apache.james.smtpserver.protocol.LineHandler#onLine(org.apache.james.smtpserver.protocol.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);
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.protocol.LineHandler#onLine(org.apache.james.smtpserver.protocol.SMTPSession, java.lang.String)
+     */
+    public void onLine(SMTPSession session, String cmdString) {
+        if (cmdString != null) {
+            cmdString = cmdString.trim();
+        }
 
-            List<CommandHandler> commandHandlers = getCommandHandlers(curCommandName, session);
-            //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 = commandHandlers.get(i).onCommand(session, new SMTPRequest(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) 
-                }
+        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);
 
-            }        
-        } catch (UnsupportedEncodingException e) {
-            // This should never happen, anyway return a error message and disconnect is prolly the best thing todo here
-            session.getLogger().error("Unable to parse line",e);
-            //end the session
-            SMTPResponse resp = new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unable to parse line.");
+        List<CommandHandler> commandHandlers = getCommandHandlers(curCommandName, session);
+        // 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 = commandHandlers.get(i).onCommand(session, new SMTPRequest(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)
+            }
+
         }
     }
 

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/AuthCmdHandler.java Sat Jan 16 18:01:31 2010
@@ -21,7 +21,6 @@
 
 package org.apache.james.smtpserver.protocol.core.esmtp;
 
-import java.io.UnsupportedEncodingException;
 import java.util.ArrayList;
 import java.util.Collection;
 import java.util.LinkedList;
@@ -59,21 +58,11 @@
 
     private abstract class AbstractSMTPLineHandler implements LineHandler {
 
-        public void onLine(SMTPSession session, byte[] line) {
-            try {
-                String l = new String(line, "US-ASCII");
-                SMTPResponse res = handleCommand(session, l);
-                session.popLineHandler();
-                session.writeSMTPResponse(res);
-            } catch (UnsupportedEncodingException e) {
-                // This should never happen, anyway return a error message and
-                // disconnect is prolly the best thing todo here
-                session.getLogger().error("Unable to parse line", e);
-                // end the session
-                SMTPResponse resp = new SMTPResponse(SMTPRetCode.LOCAL_ERROR, "Unable to parse line.");
-                resp.setEndSession(true);
-                session.writeSMTPResponse(resp);
-            }
+        public void onLine(SMTPSession session, String l) {
+            SMTPResponse res = handleCommand(session, l);
+            session.popLineHandler();
+            session.writeSMTPResponse(res);
+           
         }
 
         private SMTPResponse handleCommand(SMTPSession session, String line) {

Modified: james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/MailSizeEsmtpExtension.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/MailSizeEsmtpExtension.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/MailSizeEsmtpExtension.java (original)
+++ james/server/trunk/smtp-protocol-library/src/main/java/org/apache/james/smtpserver/protocol/core/esmtp/MailSizeEsmtpExtension.java Sat Jan 16 18:01:31 2010
@@ -115,18 +115,20 @@
         return null;
     }
 
-    /**
-     * @see org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession, byte[], org.apache.james.smtpserver.protocol.LineHandler)
+    /*
+     * (non-Javadoc)
+     * @see org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession, java.lang.String, org.apache.james.smtpserver.protocol.LineHandler)
      */
-    public void onLine(SMTPSession session, byte[] line, LineHandler next) {
+    public void onLine(SMTPSession session, String rawline, LineHandler next) {
         Boolean failed = (Boolean) session.getState().get(MESG_FAILED);
         // If we already defined we failed and sent a reply we should simply
         // wait for a CRLF.CRLF to be sent by the client.
         if (failed != null && failed.booleanValue()) {
             // TODO
         } else {
+            byte[] line = rawline.getBytes();
             if (line.length == 3 && line[0] == 46) {
-                next.onLine(session, line);
+                next.onLine(session, rawline);
             } else {
                 Long currentSize = (Long) session.getState().get("CURRENT_SIZE");
                 Long newSize;
@@ -144,9 +146,9 @@
                     session.getState().put(MESG_FAILED, Boolean.TRUE);
                     // then let the client know that the size
                     // limit has been hit.
-                    next.onLine(session, ".\r\n".getBytes());
+                    next.onLine(session, ".\r\n");
                 } else {
-                    next.onLine(session, line);
+                    next.onLine(session, rawline);
                 }
                 
                 session.getState().put("CURRENT_SIZE", newSize);

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=900007&r1=900006&r2=900007&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 Sat Jan 16 18:01:31 2010
@@ -164,7 +164,7 @@
           }
 
           if (lineHandlers.size() > 0) {
-              ((LineHandler) lineHandlers.getLast()).onLine(this, line);
+              ((LineHandler) lineHandlers.getLast()).onLine(this, new String(line,"US-ASCII"));
           } else {
               sessionEnded = true;
           }

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineJamesMessageHookHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineJamesMessageHookHandler.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineJamesMessageHookHandler.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/integration/DataLineJamesMessageHookHandler.java Sat Jan 16 18:01:31 2010
@@ -96,10 +96,11 @@
     /**
      * @see org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession, byte[], org.apache.james.smtpserver.protocol.LineHandler)
      */
-    public void onLine(SMTPSession session, byte[] line, LineHandler next) {
+    public void onLine(SMTPSession session, String rawline, LineHandler next) {
         MimeMessageInputStreamSource mmiss = (MimeMessageInputStreamSource) session.getState().get(JamesDataCmdHandler.DATA_MIMEMESSAGE_STREAMSOURCE);
         OutputStream out = (OutputStream)  session.getState().get(JamesDataCmdHandler.DATA_MIMEMESSAGE_OUTPUTSTREAM);
         try {
+            byte[] line = rawline.getBytes();
             // 46 is "."
             // Stream terminated
             if (line.length == 3 && line[0] == 46) {

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/AsyncSMTPServer.java Sat Jan 16 18:01:31 2010
@@ -328,7 +328,7 @@
         DefaultIoFilterChainBuilder builder = super.createIoFilterChainBuilder();
         
         // response and validation filter to the chain
-        builder.addLast("smtpResponseFilter", new SMTPResponseFilter());
+        builder.addLast(SMTPResponseFilter.NAME, new SMTPResponseFilter());
         builder.addLast("requestValidationFilter", new SMTPValidationFilter(getLogger()));
         return builder;
     }

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPIoHandler.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPIoHandler.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPIoHandler.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPIoHandler.java Sat Jan 16 18:01:31 2010
@@ -27,7 +27,6 @@
 import org.apache.james.smtpserver.protocol.ConnectHandler;
 import org.apache.james.smtpserver.protocol.LineHandler;
 import org.apache.james.smtpserver.protocol.SMTPConfiguration;
-import org.apache.james.smtpserver.protocol.SMTPRequest;
 import org.apache.james.smtpserver.protocol.SMTPSession;
 import org.apache.mina.core.service.IoHandlerAdapter;
 import org.apache.mina.core.session.IdleStatus;
@@ -39,9 +38,7 @@
  * 
  *
  */
-public class SMTPIoHandler extends IoHandlerAdapter{
-    private final static String SMTP_SESSION = "org.apache.james.smtpserver.mina.SMTPIoHandler.SMTP_SESSION";
-    
+public class SMTPIoHandler extends IoHandlerAdapter{    
     private Log logger;
     private ProtocolHandlerChain chain;
     private SMTPConfiguration conf;
@@ -75,13 +72,10 @@
      */
     public void messageReceived(IoSession session, Object message)
             throws Exception {
-        SMTPSession smtpSession = (SMTPSession) session.getAttribute(SMTP_SESSION);
+        SMTPSession smtpSession = (SMTPSession) session.getAttribute(SMTPSessionImpl.SMTP_SESSION);
         LinkedList<LineHandler> lineHandlers = chain.getHandlers(LineHandler.class);
         if (lineHandlers.size() > 0) {
-            // thats not really optimal but it allow us to keep things as generic as possible
-            // Will prolly get refactored later
-            byte[] line = ((SMTPRequest) message).toString().getBytes("US-ASCII");
-            ((LineHandler) lineHandlers.getLast()).onLine(smtpSession, line);
+            ((LineHandler) lineHandlers.getLast()).onLine(smtpSession, (String) message);
         }
     }
 
@@ -109,7 +103,7 @@
         }
         // Add attributes
 
-        session.setAttribute(SMTP_SESSION,smtpSession);
+        session.setAttribute(SMTPSessionImpl.SMTP_SESSION,smtpSession);
     }
 
     /**
@@ -132,7 +126,7 @@
         if (connectHandlers != null) {
             for (int i = 0; i < connectHandlers.size(); i++) {
                 connectHandlers.get(i).onConnect(
-                        (SMTPSession) session.getAttribute(SMTP_SESSION));
+                        (SMTPSession) session.getAttribute(SMTPSessionImpl.SMTP_SESSION));
             }
         }    
     }

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/SMTPSessionImpl.java Sat Jan 16 18:01:31 2010
@@ -28,6 +28,7 @@
 
 import org.apache.commons.logging.Log;
 import org.apache.james.smtpserver.mina.filter.FilterLineHandlerAdapter;
+import org.apache.james.smtpserver.mina.filter.SMTPResponseFilter;
 import org.apache.james.smtpserver.mina.filter.TarpitFilter;
 import org.apache.james.smtpserver.protocol.LineHandler;
 import org.apache.james.smtpserver.protocol.SMTPConfiguration;
@@ -38,6 +39,7 @@
 
 public class SMTPSessionImpl extends AbstractMINASession implements SMTPSession {
 
+        public final static String SMTP_SESSION = "SMTP_SESSION";
         private static Random random = new Random();
 
         private boolean relayingAllowed;
@@ -58,7 +60,6 @@
             smtpID = random.nextInt(1024) + "";
 
             relayingAllowed = theConfigData.isRelayingAllowed(getRemoteIPAddress());
-            session.setAttribute(FilterLineHandlerAdapter.SMTP_SESSION, this);
         }
 
         public SMTPSessionImpl(SMTPConfiguration theConfigData,
@@ -129,7 +130,7 @@
          */
         public void pushLineHandler(LineHandler overrideCommandHandler) {
             lineHandlerCount++;
-            getIoSession().getFilterChain().addAfter("protocolCodecFactory",
+            getIoSession().getFilterChain().addAfter(SMTPResponseFilter.NAME,
                     "lineHandler" + lineHandlerCount,
                     new FilterLineHandlerAdapter(overrideCommandHandler));
         }

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/FilterLineHandlerAdapter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/FilterLineHandlerAdapter.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/FilterLineHandlerAdapter.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/FilterLineHandlerAdapter.java Sat Jan 16 18:01:31 2010
@@ -18,6 +18,7 @@
  ****************************************************************/
 package org.apache.james.smtpserver.mina.filter;
 
+import org.apache.james.smtpserver.mina.SMTPSessionImpl;
 import org.apache.james.smtpserver.protocol.LineHandler;
 import org.apache.james.smtpserver.protocol.SMTPSession;
 import org.apache.mina.core.filterchain.IoFilterAdapter;
@@ -30,8 +31,6 @@
  */
 public final class FilterLineHandlerAdapter extends IoFilterAdapter {
 
-    public final static String SMTP_SESSION = "SMTP_SESSION";
-
     private LineHandler lineHandler;
 
     public FilterLineHandlerAdapter(LineHandler lineHandler) {
@@ -43,7 +42,7 @@
      */
     public void messageReceived(NextFilter arg0, IoSession session, Object arg2)
             throws Exception {
-        lineHandler.onLine((SMTPSession) session.getAttribute(SMTP_SESSION),
-                (((String) arg2) + "\r\n").getBytes());
+        lineHandler.onLine((SMTPSession) session.getAttribute(SMTPSessionImpl.SMTP_SESSION),
+                ((String) arg2) + "\r\n");
     }
 }

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPResponseFilter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPResponseFilter.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPResponseFilter.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPResponseFilter.java Sat Jan 16 18:01:31 2010
@@ -18,9 +18,6 @@
  ****************************************************************/
 package org.apache.james.smtpserver.mina.filter;
 
-import java.util.Locale;
-
-import org.apache.james.smtpserver.protocol.SMTPRequest;
 import org.apache.james.smtpserver.protocol.SMTPResponse;
 import org.apache.james.socket.mina.filter.AbstractResponseFilter;
 import org.apache.mina.core.session.IoSession;
@@ -36,36 +33,7 @@
    
     private static final String SCHEDULE_CLOSE_ATTRIBUTE = SMTPResponseFilter.class.getName() + ".closeAttribute";
 
-    /**
-     * (non-Javadoc)
-     * @see org.apache.mina.core.filterchain.IoFilterAdapter#messageReceived(org.apache.mina.core.filterchain.IoFilter.NextFilter, org.apache.mina.core.session.IoSession, java.lang.Object)
-     */
-    public void messageReceived(NextFilter nextFilter, IoSession session,
-            Object message) throws Exception {
-        if (message instanceof String) {
-            String cmdString = (String) message;
-            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);
-
-            nextFilter.messageReceived(session, new SMTPRequest(curCommandName,
-                    curCommandArgument));
-        } else {
-            super.messageReceived(nextFilter, session, message);
-        }
-    }
-
+    public final static String NAME = "smtpResponseFilter";
 
     /**
      * @see org.apache.mina.core.filterchain.IoFilterAdapter#filterWrite(org.apache.mina.core.filterchain.IoFilter.NextFilter, org.apache.mina.core.session.IoSession, org.apache.mina.core.write.WriteRequest)

Modified: james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPValidationFilter.java
URL: http://svn.apache.org/viewvc/james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPValidationFilter.java?rev=900007&r1=900006&r2=900007&view=diff
==============================================================================
--- james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPValidationFilter.java (original)
+++ james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/mina/filter/SMTPValidationFilter.java Sat Jan 16 18:01:31 2010
@@ -19,7 +19,6 @@
 package org.apache.james.smtpserver.mina.filter;
 
 import org.apache.commons.logging.Log;
-import org.apache.james.smtpserver.protocol.SMTPRequest;
 import org.apache.james.smtpserver.protocol.SMTPResponse;
 import org.apache.james.smtpserver.protocol.SMTPRetCode;
 import org.apache.james.socket.mina.filter.AbstractValidationFilter;
@@ -53,10 +52,7 @@
      * @see org.apache.james.socket.mina.filter.AbstractValidationFilter#isValidRequest(java.lang.Object)
      */
     protected boolean isValidRequest(Object requestObject) {
-        if (requestObject instanceof SMTPRequest) {
-            return true;
-        }
-        return false;
+        return true;
     }
 
     /**



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