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 2006/12/26 10:46:08 UTC

svn commit: r490276 - in /james/server/sandbox/handlerapi-experiment/src: java/org/apache/james/smtpserver/SMTPHandler.java java/org/apache/james/smtpserver/SMTPResponse.java test/org/apache/james/smtpserver/ValidRcptHandlerTest.java

Author: norman
Date: Tue Dec 26 01:46:08 2006
New Revision: 490276

URL: http://svn.apache.org/viewvc?view=rev&rev=490276
Log:
Add javadocs, some refactoring. See JAMES-750

Modified:
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPHandler.java
    james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPResponse.java
    james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/ValidRcptHandlerTest.java

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=490276&r1=490275&r2=490276
==============================================================================
--- 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 Tue Dec 26 01:46:08 2006
@@ -159,6 +159,9 @@
      */
     private LinkedList lineHandlers;
 
+    /**
+     * @see org.apache.james.core.AbstractJamesHandler#initHandler(java.net.Socket)
+     */
     protected void initHandler(Socket connection) throws IOException {
         super.initHandler(connection);
         pushLineHandler(this); 

Modified: james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPResponse.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPResponse.java?view=diff&rev=490276&r1=490275&r2=490276
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPResponse.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/java/org/apache/james/smtpserver/SMTPResponse.java Tue Dec 26 01:46:08 2006
@@ -32,31 +32,61 @@
     private String rawLine = null;
     private boolean endSession = false;
     
+
     public SMTPResponse() {
-        
+        //TODO: Should we remove this constructur to force the developers to specify all needed informations ? 
     }
-    
+       
+    /**
+     * @see #SMTPResponse(String, StringBuffer)
+     */
     public SMTPResponse(String code, String description) {
+        if (code == null) throw new IllegalArgumentException("SMTPResponse code can not be null");
+        if (description == null) new IllegalArgumentException("SMTPResponse description can not be null");
+    
         this.setRetCode(code);
         this.appendLine(description);
+        this.rawLine = code + " " + description;
     }
     
+    /**
+     * Construct a new SMTPResponse. The given code and description can not be null, if null an IllegalArgumentException
+     * get thrown
+     * 
+     * @param code the returnCode
+     * @param description the description 
+     */
     public SMTPResponse(String code, StringBuffer description) {
+        if (code == null) throw new IllegalArgumentException("SMTPResponse code can not be null");
+        if (description == null) new IllegalArgumentException("SMTPResponse description can not be null");
+    
         this.setRetCode(code);
         this.appendLine(description);
+        this.rawLine = code + " " + description.toString();
     }
     
+    /**
+     * Construct a new SMTPResponse. The given rawLine need to be in format [SMTPResponseReturnCode SMTResponseDescription].
+     * If this is not the case an IllegalArgumentException get thrown.
+     * 
+     * @param rawLine the raw SMTPResponse
+     */
     public SMTPResponse(String rawLine) {
-    String args[] = rawLine.split(" ");
-    if (args != null && args.length > 1) {
-        this.setRetCode(args[0]);
-        this.appendLine(new StringBuffer(rawLine.substring(args[0].length()+1)));
-    } else {
-        // TODO: Throw exception ?
-    }
+        String args[] = rawLine.split(" ");
+        if (args != null && args.length > 1) {
+            this.setRetCode(args[0]);
+            this.appendLine(new StringBuffer(rawLine.substring(args[0].length()+1)));
+        } else {
+            throw new IllegalArgumentException("Invalid SMTPResponse format. Format should be [SMTPCode SMTPReply]");
+        }
         this.rawLine = rawLine;
     }
     
+    /**
+     * Append the responseLine to the SMTPResponse
+     * 
+     * @param line the responseLine to append
+     */
     public void appendLine(String line) {
         if (lines == null) {
             lines = new LinkedList();
@@ -64,35 +94,71 @@
         lines.add(line);
     }
     
+    /**
+     * @see #appendLine(String)
+     */
     public void appendLine(StringBuffer line) {
-        if (lines == null) {
-            lines = new LinkedList();
-        }
-        lines.add(line);
+        appendLine(line.toString());
     }
-
+    
+    /**
+     * Return the SMTPCode 
+     * 
+     * @return the SMTPCode
+     */
     public String getRetCode() {
         return retCode;
     }
 
+    /**
+     * Set the SMTPCode
+     *  
+     * @param retCode the SMTPCode
+     */
     public void setRetCode(String retCode) {
         this.retCode = retCode;
     }
 
+    /**
+     * Return a List of all responseLines stored in this SMTPResponse
+     * 
+     * @return all responseLines
+     */
     public List getLines() {
         return lines;
     }
 
+    /**
+     * Return the raw representation of the Stored SMTPResponse
+     * 
+     * @return rawLine the raw SMTPResponse
+     */
     public String getRawLine() {
         return rawLine;
     }
 
+    /**
+     * Return true if the session is ended
+     * 
+     * @return true if session is ended
+     */
     public boolean isEndSession() {
         return endSession;
     }
 
+    /**
+     * Set to true to end the session
+     * 
+     * @param endSession
+     */
     public void setEndSession(boolean endSession) {
         this.endSession = endSession;
     }
 
+    /**
+     * @see java.lang.Object#toString()
+     */
+    public String toString() {
+        return getRetCode() + " " + getLines();
+    }
 }

Modified: james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/ValidRcptHandlerTest.java
URL: http://svn.apache.org/viewvc/james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/ValidRcptHandlerTest.java?view=diff&rev=490276&r1=490275&r2=490276
==============================================================================
--- james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/ValidRcptHandlerTest.java (original)
+++ james/server/sandbox/handlerapi-experiment/src/test/org/apache/james/smtpserver/ValidRcptHandlerTest.java Tue Dec 26 01:46:08 2006
@@ -102,7 +102,7 @@
                 if (user.equals(USER1)) {
                     mappings.add("address@localhost");
                 } else if (user.equals(USER2)) {
-                    throw new ErrorMappingException("BOUNCE!");
+                    throw new ErrorMappingException("554 BOUNCE");
                 }
                 return mappings;
             }



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