hbedi       01/11/27 22:54:56

  Modified:    src/java/org/apache/james/nntpserver NNTPHandler.java
  Log:
  Added system property to debug protocol.
  
  Revision  Changes    Path
  1.6       +22 -5     
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.5
  retrieving revision 1.6
  diff -u -r1.5 -r1.6
  --- NNTPHandler.java  2001/11/23 18:43:06     1.5
  +++ NNTPHandler.java  2001/11/28 06:54:56     1.6
  @@ -36,6 +36,7 @@
   import org.apache.james.nntpserver.repository.NNTPGroup;
   import org.apache.james.nntpserver.repository.NNTPLineReaderImpl;
   import org.apache.james.nntpserver.repository.NNTPRepository;
  +import org.apache.log.Logger;
   
   /**
    * The NNTP protocol is defined by RFC 977.
  @@ -65,6 +66,9 @@
       private NNTPGroup group;
       private NNTPRepository repo;
   
  +    private static final boolean DEBUG_PROTOCOL = 
  +        Boolean.getBoolean("apache.nntpserver.debug");
  +
       public void compose( final ComponentManager componentManager )
           throws ComponentException
       {
  @@ -78,19 +82,32 @@
       }
   
       public void handleConnection( Socket connection ) throws IOException {
  +        final Logger logger = getLogger();
           try {
               this.socket = connection;
  -            reader = new BufferedReader(new 
InputStreamReader(socket.getInputStream()));
  +            reader = new BufferedReader(new 
InputStreamReader(socket.getInputStream())) {
  +                    public String readLine() throws IOException {
  +                        String s = super.readLine();
  +                        if ( DEBUG_PROTOCOL ) 
  +                            logger.debug("C: "+s);
  +                        return s;
  +                    }
  +                };
               writer = new PrintWriter(socket.getOutputStream()) {
                       public void println() {
                           // lines must end with CRLF, irrespective of the OS
                           print("\r\n");
                           flush();
                       }
  +                    public void println(String s) {
  +                        super.println(s);
  +                        if ( DEBUG_PROTOCOL )
  +                            logger.debug("S: "+s);
  +                    }
                   };
  -            getLogger().info( "Connection from " + socket.getInetAddress());
  +            logger.info( "Connection from " + socket.getInetAddress());
           } catch (Exception e) {
  -            getLogger().error( "Cannot open connection from: " + e.getMessage(), e 
);
  +            logger.error( "Cannot open connection from: " + e.getMessage(), e );
           }
   
           try {
  @@ -110,12 +127,12 @@
               writer.close();
               socket.close();
               scheduler.removeTrigger(this.toString());
  -            getLogger().info("Connection closed");
  +            logger.info("Connection closed");
           } catch (Exception e) {
               doQUIT();
               //writer.println("502 Error closing connection.");
               //writer.flush();
  -            getLogger().error( "Exception during connection:" + e.getMessage(), e );
  +            logger.error( "Exception during connection:" + e.getMessage(), e );
               try { socket.close();   } catch (IOException ioe) {  }
           }
       }
  
  
  

--
To unsubscribe, e-mail:   <mailto:[EMAIL PROTECTED]>
For additional commands, e-mail: <mailto:[EMAIL PROTECTED]>

Reply via email to