Author: norman
Date: Sat Sep 24 19:10:11 2011
New Revision: 1175223

URL: http://svn.apache.org/viewvc?rev=1175223&view=rev
Log:
LineHandler and ConnectHandler now return Response. See PROTOCOLS-34

Modified:
    
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/BasicChannelUpstreamHandler.java
    
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java
    
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java

Modified: 
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/BasicChannelUpstreamHandler.java
URL: 
http://svn.apache.org/viewvc/james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/BasicChannelUpstreamHandler.java?rev=1175223&r1=1175222&r2=1175223&view=diff
==============================================================================
--- 
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/BasicChannelUpstreamHandler.java
 (original)
+++ 
james/protocols/trunk/impl/src/main/java/org/apache/james/protocols/impl/BasicChannelUpstreamHandler.java
 Sat Sep 24 19:10:11 2011
@@ -226,7 +226,6 @@ public class BasicChannelUpstreamHandler
             } else {
                 logger.debug("Unable to process request", e.getCause());
             }
-            e.getCause().printStackTrace();
             cleanup(ctx);            
         }
     }

Modified: 
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java
URL: 
http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java?rev=1175223&r1=1175222&r2=1175223&view=diff
==============================================================================
--- 
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java
 (original)
+++ 
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/ReceivedDataLineFilter.java
 Sat Sep 24 19:10:11 2011
@@ -18,19 +18,21 @@
  ****************************************************************/
 package org.apache.james.protocols.smtp.core;
 
-import java.io.UnsupportedEncodingException;
+import java.nio.charset.Charset;
 import java.util.Collection;
 import java.util.Date;
 import java.util.List;
 
+import org.apache.james.protocols.api.Response;
 import org.apache.james.protocols.api.handler.LineHandler;
-import org.apache.james.protocols.smtp.SMTPResponse;
 import org.apache.james.protocols.smtp.SMTPSession;
 import org.apache.mailet.base.RFC2822Headers;
 import org.apache.mailet.base.RFC822DateFormat;
 
 public class ReceivedDataLineFilter implements DataLineFilter {
 
+    private final static Charset CHARSET = Charset.forName("US-ASCII");
+    
     private final static String SOFTWARE_TYPE = "JAMES SMTP Server ";
 
     // Replace this with something usefull
@@ -47,15 +49,21 @@ public class ReceivedDataLineFilter impl
      * (non-Javadoc)
      * @see 
org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession,
 byte[], org.apache.james.api.protocol.LineHandler)
      */
-    public SMTPResponse onLine(SMTPSession session,  byte[] line, 
LineHandler<SMTPSession> next) {
+    public Response onLine(SMTPSession session,  byte[] line, 
LineHandler<SMTPSession> next) {
         if (session.getState().containsKey(HEADERS_WRITTEN) == false) {
-            addNewReceivedMailHeaders(session, next);
+            Response response = addNewReceivedMailHeaders(session, next);
+
             session.getState().put(HEADERS_WRITTEN, true);
+            
+            if (response != null) {
+                return response;
+            }
         }
-        return (SMTPResponse) next.onLine(session, line);
+        Response resp =  next.onLine(session, line);
+        return resp;
     }
 
-    private void addNewReceivedMailHeaders(SMTPSession session, 
LineHandler<SMTPSession> next) {
+    private Response addNewReceivedMailHeaders(SMTPSession session, 
LineHandler<SMTPSession> next) {
         StringBuilder headerLineBuffer = new StringBuilder();
 
         String heloMode = (String) session.getConnectionState().get(
@@ -74,11 +82,10 @@ public class ReceivedDataLineFilter impl
 
         headerLineBuffer.append(" ([").append(session.getRemoteIPAddress())
                 .append("])").append("\r\n");
-        try {
-            next.onLine(session, 
headerLineBuffer.toString().getBytes("US-ASCII"));
-        } catch (UnsupportedEncodingException e1) {
-            // should never happen
-            e1.printStackTrace();
+            
+        Response response = next.onLine(session, 
headerLineBuffer.toString().getBytes(CHARSET));
+        if (response != null) {
+            return response;
         }
         headerLineBuffer.delete(0, headerLineBuffer.length());
 
@@ -104,38 +111,38 @@ public class ReceivedDataLineFilter impl
         }
 
         headerLineBuffer.append(" ID ").append(session.getSessionID());
-        try {
-
-            if (((Collection) 
session.getState().get(SMTPSession.RCPT_LIST)).size() == 1) {
-                // Only indicate a recipient if they're the only recipient
-                // (prevents email address harvesting and large headers in
-                // bulk email)
-                headerLineBuffer.append("\r\n");
-                next.onLine(session, 
headerLineBuffer.toString().getBytes("US-ASCII"));
-                headerLineBuffer.delete(0, headerLineBuffer.length());
-
-                headerLineBuffer.delete(0, headerLineBuffer.length());
-                headerLineBuffer.append("          for <").append(((List) 
session.getState().get(SMTPSession.RCPT_LIST)).get(0).toString()).append(">;").append("\r\n");
-
-                next.onLine(session, 
headerLineBuffer.toString().getBytes("US-ASCII"));
-                headerLineBuffer.delete(0, headerLineBuffer.length());
 
-                headerLineBuffer.delete(0, headerLineBuffer.length());
-            } else {
-                // Put the ; on the end of the 'by' line
-                headerLineBuffer.append(";");
-                headerLineBuffer.append("\r\n");
-
-                next.onLine(session, 
headerLineBuffer.toString().getBytes("US-ASCII"));
-
-                headerLineBuffer.delete(0, headerLineBuffer.length());
+        if (((Collection) 
session.getState().get(SMTPSession.RCPT_LIST)).size() == 1) {
+            // Only indicate a recipient if they're the only recipient
+            // (prevents email address harvesting and large headers in
+            // bulk email)
+            headerLineBuffer.append("\r\n");  
+            next.onLine(session, 
headerLineBuffer.toString().getBytes(CHARSET));
+            headerLineBuffer.delete(0, headerLineBuffer.length());
+
+            headerLineBuffer.delete(0, headerLineBuffer.length());
+            headerLineBuffer.append("          for <").append(((List) 
session.getState().get(SMTPSession.RCPT_LIST)).get(0).toString()).append(">;").append("\r\n");
+            response = next.onLine(session, 
headerLineBuffer.toString().getBytes(CHARSET));
+           
+            if (response != null) {
+                return response; 
             }
-            headerLineBuffer = null;
-            next.onLine(session, ("          " + rfc822DateFormat.format(new 
Date()) + "\r\n").getBytes("US-ASCII"));
-        } catch (UnsupportedEncodingException e) {
-            // Should never happen
-            e.printStackTrace();
+            headerLineBuffer.delete(0, headerLineBuffer.length());
+            headerLineBuffer.delete(0, headerLineBuffer.length());
             
+        } else {
+            // Put the ; on the end of the 'by' line
+            headerLineBuffer.append(";");
+            headerLineBuffer.append("\r\n");
+
+            response = next.onLine(session, 
headerLineBuffer.toString().getBytes(CHARSET));
+            if (response != null) {
+                return response;
+            }
+            headerLineBuffer.delete(0, headerLineBuffer.length());
         }
+        headerLineBuffer = null;
+        return next.onLine(session, ("          " + 
rfc822DateFormat.format(new Date()) + "\r\n").getBytes(CHARSET));
+
     }
 }

Modified: 
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java
URL: 
http://svn.apache.org/viewvc/james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java?rev=1175223&r1=1175222&r2=1175223&view=diff
==============================================================================
--- 
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java
 (original)
+++ 
james/protocols/trunk/smtp/src/main/java/org/apache/james/protocols/smtp/core/esmtp/MailSizeEsmtpExtension.java
 Sat Sep 24 19:10:11 2011
@@ -138,14 +138,15 @@ public class MailSizeEsmtpExtension impl
      * @see 
org.apache.james.smtpserver.protocol.core.DataLineFilter#onLine(org.apache.james.smtpserver.protocol.SMTPSession,
 byte[], org.apache.james.api.protocol.LineHandler)
      */
     public SMTPResponse onLine(SMTPSession session, byte[] line, 
LineHandler<SMTPSession> next) {
-        Boolean failed = (Boolean) session.getState().get(MESG_FAILED);
+        SMTPResponse response = null;
+       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 {
             if (line.length == 3 && line[0] == 46) {
-                next.onLine(session, line);
+                response = (SMTPResponse) next.onLine(session, line);
             } else {
                 Long currentSize = (Long) 
session.getState().get("CURRENT_SIZE");
                 Long newSize;
@@ -163,15 +164,15 @@ public class MailSizeEsmtpExtension impl
                     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());
+                    response = (SMTPResponse) next.onLine(session, 
".\r\n".getBytes());
                 } else {
-                    next.onLine(session, line);
+                    response = (SMTPResponse) next.onLine(session, line);
                 }
                 
                 session.getState().put("CURRENT_SIZE", newSize);
             }
         }
-        return null;
+        return response;
     }
 
     /**



---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to