james-server-dev mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From pgoldst...@apache.org
Subject cvs commit: jakarta-james/src/java/org/apache/james/pop3server POP3Handler.java
Date Sat, 02 Nov 2002 09:03:52 GMT
pgoldstein    2002/11/02 01:03:52

  Modified:    src/java/org/apache/james/smtpserver SMTPHandler.java
               src/java/org/apache/james/remotemanager
                        RemoteManagerHandler.java
               src/java/org/apache/james/nntpserver NNTPHandler.java
               src/java/org/apache/james/pop3server POP3Handler.java
  Log:
  Updating the connection timeout mechanism for the handlers.  The handler threads will now
be interrupted upon connection timeout.  This improves recovery from interal hangs.
  Also added some code to the POP3 handler to centralize logging in the same fashion as the
SMTP and NNTP handlers
  
  
  Revision  Changes    Path
  1.35      +19 -0     jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java
  
  Index: SMTPHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/smtpserver/SMTPHandler.java,v
  retrieving revision 1.34
  retrieving revision 1.35
  diff -u -r1.34 -r1.35
  --- SMTPHandler.java	30 Oct 2002 10:34:58 -0000	1.34
  +++ SMTPHandler.java	2 Nov 2002 09:03:51 -0000	1.35
  @@ -148,6 +148,11 @@
       private final static String MAIL_OPTION_SIZE = "SIZE";
   
       /**
  +     * The thread executing this handler 
  +     */
  +    private Thread handlerThread;
  +
  +    /**
        * The TCP/IP socket over which the SMTP 
        * dialogue is occurring.
        */
  @@ -259,6 +264,13 @@
           } catch (Exception e) {
               // ignored
           }
  +
  +        synchronized (this) {
  +            // Interrupt the thread to recover from internal hangs
  +            if (handlerThread != null) {
  +                handlerThread.interrupt();
  +            }
  +        }
       }
   
       /**
  @@ -268,6 +280,9 @@
   
           try {
               this.socket = connection;
  +            synchronized (this) {
  +                handlerThread = Thread.currentThread();
  +            }
               in = new BufferedInputStream(socket.getInputStream(), 1024);
               // An ASCII encoding can be used because all transmissions other
               // that those in the DATA command are guaranteed
  @@ -401,6 +416,10 @@
               }
           } finally {
               socket = null;
  +        }
  +
  +        synchronized (this) {
  +            handlerThread = null;
           }
   
       }
  
  
  
  1.21      +80 -32    jakarta-james/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java
  
  Index: RemoteManagerHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/remotemanager/RemoteManagerHandler.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- RemoteManagerHandler.java	28 Oct 2002 00:26:38 -0000	1.20
  +++ RemoteManagerHandler.java	2 Nov 2002 09:03:52 -0000	1.21
  @@ -150,6 +150,11 @@
       private PrintWriter out;
   
       /**
  +     * The thread executing this handler 
  +     */
  +    private Thread handlerThread;
  +
  +    /**
        * The TCP/IP socket over which the RemoteManager interaction
        * is occurring
        */
  @@ -210,6 +215,16 @@
               }
           } catch (Exception e) {
               // ignored
  +        } finally {
  +            socket = null;
  +        }
  +
  +        synchronized (this) {
  +            // Interrupt the thread to recover from internal hangs
  +            if (handlerThread != null) {
  +                handlerThread.interrupt();
  +                handlerThread = null;
  +            }
           }
       }
   
  @@ -223,6 +238,10 @@
           String remoteIP = socket.getInetAddress().getHostAddress();
           String remoteHost = socket.getInetAddress().getHostName();
   
  +        synchronized (this) {
  +            handlerThread = Thread.currentThread();
  +        }
  +
           try {
               in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "ASCII"),
512);
               out = new PrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()),
512), false);
  @@ -236,21 +255,18 @@
                               .append(")");
                   getLogger().info( infoBuffer.toString() );
               }
  -            out.println( "JAMES Remote Administration Tool " + Constants.SOFTWARE_VERSION
);
  -            out.println("Please enter your login and password");
  +            writeLoggedResponse("JAMES Remote Administration Tool " + Constants.SOFTWARE_VERSION
);
  +            writeLoggedResponse("Please enter your login and password");
               String login = null;
               String password = null;
               do {
                   if (login != null) {
                       final String message = "Login failed for " + login;
  -                    out.println( message );
  -                    getLogger().info( message );
  +                    writeLoggedFlushedResponse(message);
                   }
  -                out.println("Login id:");
  -                out.flush();
  +                writeLoggedFlushedResponse("Login id:");
                   login = in.readLine().trim();
  -                out.println("Password:");
  -                out.flush();
  +                writeLoggedFlushedResponse("Password:");
                   password = in.readLine().trim();
               } while (!password.equals(theConfigData.getAdministrativeAccountData().get(login))
|| password.length() == 0);
   
  @@ -336,6 +352,10 @@
               socket = null;
           }
   
  +        synchronized (this) {
  +            handlerThread = null;
  +        }
  +
           // Reset user repository
           users = theConfigData.getUsersRepository();
           inLocalUsers = true;
  @@ -548,9 +568,9 @@
        * @param argument the argument passed in with the command
        */
       private boolean doLISTUSERS(String argument) {
  -        out.println("Existing accounts " + users.countUsers());
  +        writeLoggedResponse("Existing accounts " + users.countUsers());
           for (Iterator it = users.list(); it.hasNext();) {
  -           out.println("user: " + (String) it.next());
  +           writeLoggedResponse("user: " + (String) it.next());
           }
           out.flush();
           return true;
  @@ -563,8 +583,7 @@
        * @param argument the argument passed in with the command
        */
       private boolean doCOUNTUSERS(String argument) {
  -        out.println("Existing accounts " + users.countUsers());
  -        out.flush();
  +        writeLoggedFlushedResponse("Existing accounts " + users.countUsers());
           return true;
       }
   
  @@ -788,14 +807,13 @@
        */
       private boolean doUNSETFORWARDING(String argument) {
           if ((argument == null) || (argument.equals(""))) {
  -            out.println("Usage: unsetforwarding [username]");
  -            out.flush();
  +            writeLoggedFlushedResponse("Usage: unsetforwarding [username]");
               return true;
           }
           String username = argument;
           JamesUser user = (JamesUser) users.getUserByName(username);
           if (user == null) {
  -            out.println("No such user " + username);
  +            writeLoggedFlushedResponse("No such user " + username);
           } else if (user.getForwarding()){
               user.setForwarding(false);
               users.updateUser(user);
  @@ -805,13 +823,10 @@
                           .append(username)
                           .append(" unset");
               String response = responseBuffer.toString();
  -            out.println(response);
  -            getLogger().info(response);
  +            writeLoggedFlushedResponse(response);
           } else {
  -            out.println("Forwarding not active for" + username);
  -            getLogger().info("Forwarding not active for" + username);
  +            writeLoggedFlushedResponse("Forwarding not active for" + username);
           }
  -        out.flush();
           return true;
       }
   
  @@ -823,14 +838,13 @@
        */
       private boolean doUSER(String argument) {
           if (argument == null || argument.equals("")) {
  -            out.println("Usage: user [repositoryName]");
  -            out.flush();
  +            writeLoggedFlushedResponse("Usage: user [repositoryName]");
               return true;
           }
           String repositoryName = argument.toLowerCase(Locale.US);
           UsersRepository repos = theConfigData.getUserStore().getRepository(repositoryName);
           if ( repos == null ) {
  -            out.println("No such repository: " + repositoryName);
  +            writeLoggedFlushedResponse("No such repository: " + repositoryName);
           } else {
               users = repos;
               StringBuffer responseBuffer =
  @@ -838,14 +852,13 @@
                           .append("Changed to repository '")
                           .append(repositoryName)
                           .append("'.");
  -            out.println(responseBuffer.toString());
  +            writeLoggedFlushedResponse(responseBuffer.toString());
               if ( repositoryName.equals("localusers") ) {
                   inLocalUsers = true;
               } else {
                   inLocalUsers = false;
               }
           }
  -        out.flush();
           return true;
       }
   
  @@ -856,8 +869,7 @@
        * @param argument the argument passed in with the command
        */
       private boolean doQUIT(String argument) {
  -        out.println("Bye");
  -        out.flush();
  +        writeLoggedFlushedResponse("Bye");
           return false;
       }
   
  @@ -868,8 +880,7 @@
        * @param argument the argument passed in with the command
        */
       private boolean doSHUTDOWN(String argument) {
  -        out.println("Shutting down, bye bye");
  -        out.flush();
  +        writeLoggedFlushedResponse("Shutting down, bye bye");
           System.exit(0);
           return false;
       }
  @@ -881,9 +892,46 @@
        * @param argument the unknown command
        */
       private boolean doUnknownCommand(String argument) {
  -        out.println("Unknown command " + argument);
  -        out.flush();
  +        writeLoggedFlushedResponse("Unknown command " + argument);
           return true;
  +    }
  +
  +    /**
  +     * This method logs at a "DEBUG" level the response string that 
  +     * was sent to the RemoteManager client.  The method is provided largely
  +     * as syntactic sugar to neaten up the code base.  It is declared
  +     * private and final to encourage compiler inlining.
  +     *
  +     * @param responseString the response string sent to the client
  +     */
  +    private final void logResponseString(String responseString) {
  +        if (getLogger().isDebugEnabled()) {
  +            getLogger().debug("Sent: " + responseString);
  +        }
  +    }
  +
  +    /**
  +     * Write and flush a response string.  The response is also logged.
  +     * Should be used for the last line of a multi-line response or
  +     * for a single line response.
  +     *
  +     * @param responseString the response string sent to the client
  +     */
  +    final void writeLoggedFlushedResponse(String responseString) {
  +        out.println(responseString);
  +        out.flush();
  +        logResponseString(responseString);
  +    }
  +
  +    /**
  +     * Write a response string.  The response is also logged. 
  +     * Used for multi-line responses.
  +     *
  +     * @param responseString the response string sent to the client
  +     */
  +    final void writeLoggedResponse(String responseString) {
  +        out.println(responseString);
  +        logResponseString(responseString);
       }
   
       /**
  
  
  
  1.25      +22 -0     jakarta-james/src/java/org/apache/james/nntpserver/NNTPHandler.java
  
  Index: NNTPHandler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/nntpserver/NNTPHandler.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- NNTPHandler.java	26 Oct 2002 20:16:30 -0000	1.24
  +++ NNTPHandler.java	2 Nov 2002 09:03:52 -0000	1.25
  @@ -203,6 +203,11 @@
       private final static String AUTHINFO_PARAM_PASS = "PASS";
   
       /**
  +     * The thread executing this handler 
  +     */
  +    private Thread handlerThread;
  +
  +    /**
        * The TCP/IP socket over which the POP3 interaction
        * is occurring
        */
  @@ -301,6 +306,16 @@
               }
           } catch (Exception e) {
               // ignored
  +        } finally {
  +            socket = null;
  +        }
  +
  +        synchronized (this) {
  +            // Interrupt the thread to recover from internal hangs
  +            if (handlerThread != null) {
  +                handlerThread.interrupt();
  +                handlerThread = null;
  +            }
           }
       }
   
  @@ -311,6 +326,9 @@
   
           try {
               this.socket = connection;
  +            synchronized (this) {
  +                handlerThread = Thread.currentThread();
  +            }
               reader = new BufferedReader(new InputStreamReader(socket.getInputStream(),
"ASCII"), 1024);
               writer = new InternetPrintWriter(new BufferedWriter(new OutputStreamWriter(socket.getOutputStream()),
1024), true);
           } catch (Exception e) {
  @@ -387,6 +405,10 @@
               getLogger().warn("NNTPHandler: Unexpected exception occurred while closing
socket: " + ioe);
           } finally {
               socket = null;
  +        }
  +
  +        synchronized (this) {
  +            handlerThread = null;
           }
   
           // Clear the selected group, article info
  
  
  
  1.17      +99 -81    jakarta-james/src/java/org/apache/james/pop3server/POP3Handler.java
  
  Index: POP3Handler.java
  ===================================================================
  RCS file: /home/cvs/jakarta-james/src/java/org/apache/james/pop3server/POP3Handler.java,v
  retrieving revision 1.16
  retrieving revision 1.17
  diff -u -r1.16 -r1.17
  --- POP3Handler.java	26 Oct 2002 19:57:37 -0000	1.16
  +++ POP3Handler.java	2 Nov 2002 09:03:52 -0000	1.17
  @@ -84,6 +84,11 @@
       private MailRepository userInbox;
   
       /**
  +     * The thread executing this handler 
  +     */
  +    private Thread handlerThread;
  +
  +    /**
        * The TCP/IP socket over which the POP3 interaction
        * is occurring
        */
  @@ -176,7 +181,18 @@
               }
           } catch (Exception e) {
               // ignored
  +        } finally {
  +            socket = null;
           }
  +
  +        synchronized (this) {
  +            // Interrupt the thread to recover from internal hangs
  +            if (handlerThread != null) {
  +                handlerThread.interrupt();
  +                handlerThread = null;
  +            }
  +        }
  +
       }
   
       /**
  @@ -190,6 +206,9 @@
   
           try {
               this.socket = connection;
  +            synchronized (this) {
  +                handlerThread = Thread.currentThread();
  +            }
               in = new BufferedReader(new InputStreamReader(socket.getInputStream(), "ASCII"),
512);
               remoteIP = socket.getInetAddress().getHostAddress ();
               remoteHost = socket.getInetAddress().getHostName ();
  @@ -322,6 +341,10 @@
               outs = null;
           }
   
  +        synchronized (this) {
  +            handlerThread = null;
  +        }
  +
           // Clear user data
           user = null;
           userInbox = null;
  @@ -453,9 +476,7 @@
           } else {
               responseString = ERR_RESPONSE;
           }
  -        out.println(responseString);
  -        out.flush();
  -        logResponseString(responseString);
  +        writeLoggedFlushedResponse(responseString);
       }
   
       /**
  @@ -478,20 +499,18 @@
                               .append(user);
                   responseString = responseBuffer.toString();
                   state = TRANSACTION;
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
                   userInbox = theConfigData.getMailServer().getUserInbox(user);
                   stat();
               } else {
                   responseString = ERR_RESPONSE + " Authentication failed.";
                   state = AUTHENTICATION_READY;
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
               }
           } else {
               responseString = ERR_RESPONSE;
  -            out.println(responseString);
  +            writeLoggedFlushedResponse(responseString);
           }
  -        out.flush();
  -        logResponseString(responseString);
       }
   
       /**
  @@ -524,17 +543,15 @@
                               .append(" ")
                               .append(size);
                   responseString = responseBuffer.toString();
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
               } catch (MessagingException me) {
                   responseString = ERR_RESPONSE;
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
               }
           } else {
               responseString = ERR_RESPONSE;
  -            out.println(responseString);
  +            writeLoggedFlushedResponse(responseString);
           }
  -        out.flush();
  -        logResponseString(responseString);
       }
   
       /**
  @@ -569,7 +586,7 @@
                                   .append(" ")
                                   .append(size);
                       responseString = responseBuffer.toString();
  -                    out.println(responseString);
  +                    writeLoggedFlushedResponse(responseString);
                       count = 0;
                       for (Enumeration e = userMailbox.elements(); e.hasMoreElements(); count++)
{
                           MailImpl mc = (MailImpl) e.nextElement();
  @@ -583,9 +600,10 @@
                           }
                       }
                       out.println(".");
  +                    out.flush();
                   } catch (MessagingException me) {
                       responseString = ERR_RESPONSE;
  -                    out.println(responseString);
  +                    writeLoggedFlushedResponse(responseString);
                   }
               } else {
                   int num = 0;
  @@ -601,7 +619,7 @@
                                       .append(" ")
                                       .append(mc.getMessageSize());
                           responseString = responseBuffer.toString();
  -                        out.println(responseString);
  +                        writeLoggedFlushedResponse(responseString);
                       } else {
                           StringBuffer responseBuffer =
                               new StringBuffer(64)
  @@ -610,7 +628,7 @@
                                       .append(num)
                                       .append(") does not exist.");
                           responseString = responseBuffer.toString();
  -                        out.println(responseString);
  +                        writeLoggedFlushedResponse(responseString);
                       }
                   } catch (ArrayIndexOutOfBoundsException npe) {
                       StringBuffer responseBuffer =
  @@ -620,7 +638,7 @@
                                   .append(num)
                                   .append(") does not exist.");
                       responseString = responseBuffer.toString();
  -                    out.println(responseString);
  +                    writeLoggedFlushedResponse(responseString);
                   } catch (NumberFormatException nfe) {
                       StringBuffer responseBuffer =
                           new StringBuffer(64)
  @@ -629,18 +647,16 @@
                                   .append(argument)
                                   .append(" is not a valid number");
                       responseString = responseBuffer.toString();
  -                    out.println(responseString);
  +                    writeLoggedFlushedResponse(responseString);
                   } catch (MessagingException me) {
                       responseString = ERR_RESPONSE;
  -                    out.println(responseString);
  -                }
  +                    writeLoggedFlushedResponse(responseString);
  +               }
               }
           } else {
               responseString = ERR_RESPONSE;
  -            out.println(responseString);
  +            writeLoggedFlushedResponse(responseString);
           }
  -        out.flush();
  -        logResponseString(responseString);
       }
   
       /**
  @@ -656,7 +672,7 @@
           if (state == TRANSACTION) {
               if (argument == null) {
                   responseString = OK_RESPONSE + " unique-id listing follows";
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
                   int count = 0;
                   for (Enumeration e = userMailbox.elements(); e.hasMoreElements(); count++)
{
                       MailImpl mc = (MailImpl) e.nextElement();
  @@ -670,6 +686,7 @@
                       }
                   }
                   out.println(".");
  +                out.flush();
               } else {
                   int num = 0;
                   try {
  @@ -684,7 +701,7 @@
                                       .append(" ")
                                       .append(mc.getName());
                           responseString = responseBuffer.toString();
  -                        out.println(responseString);
  +                        writeLoggedFlushedResponse(responseString);
                       } else {
                           StringBuffer responseBuffer =
                               new StringBuffer(64)
  @@ -693,7 +710,7 @@
                                       .append(num)
                                       .append(") does not exist.");
                           responseString = responseBuffer.toString();
  -                        out.println(responseString);
  +                        writeLoggedFlushedResponse(responseString);
                       }
                   } catch (ArrayIndexOutOfBoundsException npe) {
                       StringBuffer responseBuffer =
  @@ -703,7 +720,7 @@
                                   .append(num)
                                   .append(") does not exist.");
                       responseString = responseBuffer.toString();
  -                    out.println(responseString);
  +                    writeLoggedFlushedResponse(responseString);
                   } catch (NumberFormatException nfe) {
                       StringBuffer responseBuffer =
                           new StringBuffer(64)
  @@ -712,14 +729,12 @@
                                   .append(argument)
                                   .append(" is not a valid number");
                       responseString = responseBuffer.toString();
  -                    out.println(responseString);
  +                    writeLoggedFlushedResponse(responseString);
                   }
               }
           } else {
  -            out.println(ERR_RESPONSE);
  +            writeLoggedFlushedResponse(ERR_RESPONSE);
           }
  -        out.flush();
  -        logResponseString(responseString);
       }
   
       /**
  @@ -738,9 +753,7 @@
           } else {
               responseString = ERR_RESPONSE;
           }
  -        out.println(responseString);
  -        out.flush();
  -        logResponseString(responseString);
  +        writeLoggedFlushedResponse(responseString);
       }
   
       /**
  @@ -760,9 +773,7 @@
                   num = Integer.parseInt(argument);
               } catch (Exception e) {
                   responseString = ERR_RESPONSE + " Usage: DELE [mail number]";
  -                out.println(responseString);
  -                out.flush();
  -                logResponseString(responseString);
  +                writeLoggedFlushedResponse(responseString);
                   return;
               }
               try {
  @@ -775,10 +786,10 @@
                                   .append(num)
                                   .append(") does not exist.");
                       responseString = responseBuffer.toString();
  -                    out.println(responseString);
  +                    writeLoggedFlushedResponse(responseString);
                   } else {
                       userMailbox.setElementAt(DELETED, num);
  -                    out.println(OK_RESPONSE + " Message removed");
  +                    writeLoggedFlushedResponse(OK_RESPONSE + " Message removed");
                   }
               } catch (ArrayIndexOutOfBoundsException iob) {
                   StringBuffer responseBuffer =
  @@ -788,14 +799,12 @@
                               .append(num)
                               .append(") does not exist.");
                   responseString = responseBuffer.toString();
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
               }
           } else {
               responseString = ERR_RESPONSE;
  -            out.println(responseString);
  +            writeLoggedFlushedResponse(responseString);
           }
  -        out.flush();
  -        logResponseString(responseString);
       }
   
       /**
  @@ -810,13 +819,11 @@
           String responseString = null;
           if (state == TRANSACTION) {
               responseString = OK_RESPONSE;
  -            out.println(responseString);
  +            writeLoggedFlushedResponse(responseString);
           } else {
               responseString = ERR_RESPONSE;
  -            out.println(responseString);
  +            writeLoggedFlushedResponse(responseString);
           }
  -        out.flush();
  -        logResponseString(responseString);
       }
   
       /**
  @@ -836,9 +843,7 @@
                   num = Integer.parseInt(argument.trim());
               } catch (Exception e) {
                   responseString = ERR_RESPONSE + " Usage: RETR [mail number]";
  -                out.println(responseString);
  -                logResponseString(responseString);
  -                out.flush();
  +                writeLoggedFlushedResponse(responseString);
                   return;
               }
               //?May be written as
  @@ -847,8 +852,7 @@
                   MailImpl mc = (MailImpl) userMailbox.elementAt(num);
                   if (mc != DELETED) {
                       responseString = OK_RESPONSE + " Message follows";
  -                    out.println(responseString);
  -                    out.flush();
  +                    writeLoggedFlushedResponse(responseString);
                       OutputStream nouts =
                               new ExtraDotOutputStream(outs);
                       nouts = new BytesWrittenResetOutputStream(nouts,
  @@ -857,6 +861,7 @@
                       mc.writeMessageTo(nouts);
                       out.println();
                       out.println(".");
  +                    out.flush();
                   } else {
                       StringBuffer responseBuffer =
                           new StringBuffer(64)
  @@ -865,14 +870,14 @@
                                   .append(num)
                                   .append(") deleted.");
                       responseString = responseBuffer.toString();
  -                    out.println(responseString);
  +                    writeLoggedFlushedResponse(responseString);
                   }
               } catch (IOException ioe) {
                   responseString = ERR_RESPONSE + " Error while retrieving message.";
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
               } catch (MessagingException me) {
                   responseString = ERR_RESPONSE + " Error while retrieving message.";
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
               } catch (ArrayIndexOutOfBoundsException iob) {
                   StringBuffer responseBuffer =
                       new StringBuffer(64)
  @@ -881,15 +886,13 @@
                               .append(num)
                               .append(") does not exist.");
                   responseString = responseBuffer.toString();
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
               }
               // -------------------------------------------?
           } else {
               responseString = ERR_RESPONSE;
  -            out.println(responseString);
  +            writeLoggedFlushedResponse(responseString);
           }
  -        out.flush();
  -        logResponseString(responseString);
       }
   
       /**
  @@ -914,21 +917,18 @@
                   lines = Integer.parseInt(argument1);
               } catch (NumberFormatException nfe) {
                   responseString = ERR_RESPONSE + " Usage: TOP [mail number] [Line number]";
  -                out.println(responseString);
  -                out.flush();
  -                logResponseString(responseString);
  +                writeLoggedFlushedResponse(responseString);
                   return;
               }
               try {
                   MailImpl mc = (MailImpl) userMailbox.elementAt(num);
                   if (mc != DELETED) {
                       responseString = OK_RESPONSE + " Message follows";
  -                    out.println(responseString);
  -                    out.flush();
  +                    writeLoggedFlushedResponse(responseString);
                       for (Enumeration e = mc.getMessage().getAllHeaderLines(); e.hasMoreElements();
) {
                           out.println(e.nextElement());
                       }
  -                    out.println("");
  +                    out.println();
                       OutputStream nouts =
                               new ExtraDotOutputStream(outs);
                       nouts = new BytesWrittenResetOutputStream(nouts,
  @@ -936,6 +936,7 @@
                                                                 theConfigData.getResetLength());
                       mc.writeContentTo(nouts, lines);
                       out.println(".");
  +                    out.flush();
                   } else {
                       StringBuffer responseBuffer =
                           new StringBuffer(64)
  @@ -944,14 +945,14 @@
                                   .append(num)
                                   .append(") already deleted.");
                       responseString = responseBuffer.toString();
  -                    out.println(responseString);
  +                    writeLoggedFlushedResponse(responseString);
                   }
               } catch (IOException ioe) {
                   responseString = ERR_RESPONSE + " Error while retrieving message.";
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
               } catch (MessagingException me) {
                   responseString = ERR_RESPONSE + " Error while retrieving message.";
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
               } catch (ArrayIndexOutOfBoundsException iob) {
                   StringBuffer exceptionBuffer =
                       new StringBuffer(64)
  @@ -960,14 +961,12 @@
                               .append(num)
                               .append(") does not exist.");
                   responseString = exceptionBuffer.toString();
  -                out.println(responseString);
  +                writeLoggedFlushedResponse(responseString);
               }
           } else {
               responseString = ERR_RESPONSE;
  -            out.println(responseString);
  +            writeLoggedFlushedResponse(responseString);
           }
  -        out.flush();
  -        logResponseString(responseString);
       }
   
       /**
  @@ -990,14 +989,12 @@
                   userInbox.remove(mc.getName());
               }
               responseString = OK_RESPONSE + " Apache James POP3 Server signing off.";
  -            out.println(responseString);
  +            writeLoggedFlushedResponse(responseString);
           } catch (Exception ex) {
               responseString = ERR_RESPONSE + " Some deleted messages were not removed";
  -            out.println(responseString);
  +            writeLoggedFlushedResponse(responseString);
               getLogger().error("Some deleted messages were not removed: " + ex.getMessage());
           }
  -        out.flush();
  -        logResponseString(responseString);
       }
   
       /**
  @@ -1009,10 +1006,7 @@
        * @argument1 the second argument parsed by the parseCommand method
        */
       private void doUnknownCmd(String command,String argument,String argument1) {
  -        String responseString = ERR_RESPONSE;
  -        out.println(responseString);
  -        out.flush();
  -        logResponseString(responseString);
  +        writeLoggedFlushedResponse(ERR_RESPONSE);
       }
   
       /**
  @@ -1027,6 +1021,30 @@
           if (getLogger().isDebugEnabled()) {
               getLogger().debug("Sent: " + responseString);
           }
  +    }
  +
  +    /**
  +     * Write and flush a response string.  The response is also logged.
  +     * Should be used for the last line of a multi-line response or
  +     * for a single line response.
  +     *
  +     * @param responseString the response string sent to the client
  +     */
  +    final void writeLoggedFlushedResponse(String responseString) {
  +        out.println(responseString);
  +        out.flush();
  +        logResponseString(responseString);
  +    }
  +
  +    /**
  +     * Write a response string.  The response is also logged. 
  +     * Used for multi-line responses.
  +     *
  +     * @param responseString the response string sent to the client
  +     */
  +    final void writeLoggedResponse(String responseString) {
  +        out.println(responseString);
  +        logResponseString(responseString);
       }
   
       /**
  
  
  

--
To unsubscribe, e-mail:   <mailto:james-dev-unsubscribe@jakarta.apache.org>
For additional commands, e-mail: <mailto:james-dev-help@jakarta.apache.org>


Mime
View raw message