Author: rdonkin
Date: Wed Sep 16 10:56:30 2009
New Revision: 815718

URL: http://svn.apache.org/viewvc?rev=815718&view=rev
Log:
JAMES-920 Add context to method signature and replace use of helper field with 
passed in context. https://issues.apache.org/jira/browse/JAMES-920

Modified:
    
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/JamesConnectionBridge.java
    
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/ProtocolHandler.java
    
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapHandler.java
    
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java
    
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java
    
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerHandler.java
    
james/server/trunk/smtpserver-function/src/main/java/org/apache/james/smtpserver/SMTPHandler.java

Modified: 
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/JamesConnectionBridge.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/JamesConnectionBridge.java?rev=815718&r1=815717&r2=815718&view=diff
==============================================================================
--- 
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/JamesConnectionBridge.java
 (original)
+++ 
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/JamesConnectionBridge.java
 Wed Sep 16 10:56:30 2009
@@ -435,7 +435,7 @@
      * @throws IOException get thrown if an IO error is detected
      */
     public void handleProtocol() throws IOException {
-        protocolHandler.handleProtocol();
+        protocolHandler.handleProtocol(this);
     }
 
    /**

Modified: 
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/ProtocolHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/ProtocolHandler.java?rev=815718&r1=815717&r2=815718&view=diff
==============================================================================
--- 
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/ProtocolHandler.java
 (original)
+++ 
james/server/trunk/avalon-socket-library/src/main/java/org/apache/james/socket/ProtocolHandler.java
 Wed Sep 16 10:56:30 2009
@@ -25,10 +25,11 @@
 
     /**
      * Handle the protocol
+     * @param context not null
      * 
      * @throws IOException get thrown if an IO error is detected
      */
-    public abstract void handleProtocol() throws IOException;
+    public abstract void handleProtocol(ProtocolContext context) throws 
IOException;
 
     /**
      * Resets the handler data to a basic state.

Modified: 
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapHandler.java?rev=815718&r1=815717&r2=815718&view=diff
==============================================================================
--- 
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapHandler.java
 (original)
+++ 
james/server/trunk/imapserver-function/src/main/java/org/apache/james/imapserver/ImapHandler.java
 Wed Sep 16 10:56:30 2009
@@ -20,9 +20,7 @@
 package org.apache.james.imapserver;
 
 import java.io.IOException;
-import java.net.Socket;
 
-import org.apache.avalon.cornerstone.services.connection.ConnectionHandler;
 import org.apache.commons.logging.Log;
 import org.apache.james.imap.api.process.ImapSession;
 import org.apache.james.imap.encode.ImapResponseComposer;
@@ -30,8 +28,8 @@
 import org.apache.james.imap.main.ImapRequestHandler;
 import org.apache.james.imap.main.ImapSessionImpl;
 import org.apache.james.imap.main.OutputStreamImapResponseWriter;
-import org.apache.james.socket.ProtocolHandler;
 import org.apache.james.socket.ProtocolContext;
+import org.apache.james.socket.ProtocolHandler;
 
 /**
  * Handles IMAP connections.
@@ -72,46 +70,47 @@
     }
 
     /**
-     * @see ConnectionHandler#handleConnection(Socket)
+     * @see ProtocolHandler#handleProtocol(ProtocolContext)
      */
-    public void handleProtocol() throws IOException {
+    public void handleProtocol(final ProtocolContext context) throws 
IOException {
             getLogger().debug(
-                "Connection from " + helper.getRemoteHost() + " (" + 
helper.getRemoteIP()
+                "Connection from " + context.getRemoteHost() + " (" + 
context.getRemoteIP()
                         + ") opened.");
-            final OutputStreamImapResponseWriter writer = new 
OutputStreamImapResponseWriter( helper.getOutputStream() );
+            final OutputStreamImapResponseWriter writer = new 
OutputStreamImapResponseWriter( context.getOutputStream() );
             ImapResponseComposer response = new ImapResponseComposerImpl( 
writer);
 
             // Write welcome message
                  
             response.hello(hello);
 
-            setUpSession();
+            setUpSession(context);
             
-            helper.getWatchdog().start();
-            while ( handleRequest() ) {
-                helper.getWatchdog().reset();
+            context.getWatchdog().start();
+            while ( handleRequest(context) ) {
+                context.getWatchdog().reset();
             }
-            helper.getWatchdog().stop();
+            context.getWatchdog().stop();
             if (session != null) {
                 session.logout();
             }
             
             getLogger().info(
-                    "Connection from " + helper.getRemoteHost() + " (" + 
helper.getRemoteIP()
+                    "Connection from " + context.getRemoteHost() + " (" + 
context.getRemoteIP()
                             + ") closed.");
     }
 
     /**
      * Sets up a session.
+     * @param context not null
      */
-    private void setUpSession() {
+    private void setUpSession(ProtocolContext context) {
         final ImapSessionImpl session = new ImapSessionImpl();
-        session.setLog(helper.getLogger());
+        session.setLog(context.getLogger());
         this.session = session;
     }
 
-    private boolean handleRequest() {
-        final boolean result = requestHandler.handleRequest( 
helper.getInputStream(), helper.getOutputStream(), session );
+    private boolean handleRequest(ProtocolContext context) {
+        final boolean result = requestHandler.handleRequest( 
context.getInputStream(), context.getOutputStream(), session );
         return result;
     }
     

Modified: 
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java?rev=815718&r1=815717&r2=815718&view=diff
==============================================================================
--- 
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java
 (original)
+++ 
james/server/trunk/nntpserver-function/src/main/java/org/apache/james/nntpserver/NNTPHandler.java
 Wed Sep 16 10:56:30 2009
@@ -256,9 +256,9 @@
     }
     
     /**
-     * @see org.apache.james.socket.AbstractJamesHandler#handleProtocol()
+     * @see 
org.apache.james.socket.ProtocolHandler#handleProtocol(ProtocolContext)
      */
-    public void handleProtocol() throws IOException {
+    public void handleProtocol(ProtocolContext context) throws IOException {
         // section 7.1
         if ( theConfigData.getNNTPRepository().isReadOnly() ) {
             StringBuilder respBuffer =
@@ -266,27 +266,27 @@
                     .append("201 ")
                     .append(theConfigData.getHelloName())
                     .append(" NNTP Service Ready, posting prohibited");
-            helper.writeLoggedFlushedResponse(respBuffer.toString());
+            context.writeLoggedFlushedResponse(respBuffer.toString());
         } else {
             StringBuilder respBuffer =
                 new StringBuilder(128)
                         .append("200 ")
                         .append(theConfigData.getHelloName())
                         .append(" NNTP Service Ready, posting permitted");
-            helper.writeLoggedFlushedResponse(respBuffer.toString());
+            context.writeLoggedFlushedResponse(respBuffer.toString());
         }
 
-        helper.getWatchdog().start();
-        while (parseCommand(helper.getInputReader().readLine())) {
-            helper.getWatchdog().reset();
+        context.getWatchdog().start();
+        while (parseCommand(context.getInputReader().readLine())) {
+            context.getWatchdog().reset();
         }
-        helper.getWatchdog().stop();
+        context.getWatchdog().stop();
 
-        helper.getLogger().info("Connection closed");
+        context.getLogger().info("Connection closed");
     }
     
     /**
-     * @see 
org.apache.james.socket.AbstractJamesHandler#fatalFailure(java.lang.RuntimeException,
 ProtocolContext)
+     * @see 
org.apache.james.socket.ProtocolHandler#fatalFailure(java.lang.RuntimeException,
 ProtocolContext)
      */
     public void fatalFailure(final RuntimeException e, final ProtocolContext 
context) {
         // If the connection has been idled out, the

Modified: 
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java?rev=815718&r1=815717&r2=815718&view=diff
==============================================================================
--- 
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java
 (original)
+++ 
james/server/trunk/pop3server-function/src/main/java/org/apache/james/pop3server/POP3Handler.java
 Wed Sep 16 10:56:30 2009
@@ -161,9 +161,9 @@
     }
     
     /**
-     * @see org.apache.james.socket.AbstractJamesHandler#handleProtocol()
+     * @see 
org.apache.james.socket.AbstractJamesHandler#handleProtocol(ProtocolContext)
      */
-    public void handleProtocol() throws IOException {
+    public void handleProtocol(ProtocolContext context) throws IOException {
         handlerState = AUTHENTICATION_READY;
         authenticatedUser = "unknown";
 
@@ -179,7 +179,7 @@
                     .append(POP3Handler.softwaretype)
                     .append(") ready ");
         String responseString = clearResponseBuffer();
-        helper.writeLoggedFlushedResponse(responseString);
+        context.writeLoggedFlushedResponse(responseString);
 
         //Session started - RUN all connect handlers
         List connectHandlers = handlerChain.getConnectHandlers();
@@ -194,7 +194,7 @@
         }
 
         
-        helper.getWatchdog().start();
+        context.getWatchdog().start();
         while(!sessionEnded) {
           //Reset the current command values
           curCommandName = null;
@@ -215,12 +215,12 @@
           }
           curCommandName = curCommandName.toUpperCase(Locale.US);
 
-          if (helper.getLogger().isDebugEnabled()) {
+          if (context.getLogger().isDebugEnabled()) {
               // Don't display password in logger
               if (!curCommandName.equals("PASS")) {
-                  helper.getLogger().debug("Command received: " + cmdString);
+                  context.getLogger().debug("Command received: " + cmdString);
               } else {
-                  helper.getLogger().debug("Command received: PASS <password 
omitted>");
+                  context.getLogger().debug("Command received: PASS <password 
omitted>");
               }
           }
 
@@ -233,7 +233,7 @@
               int count = commandHandlers.size();
               for(int i = 0; i < count; i++) {
                   ((CommandHandler)commandHandlers.get(i)).onCommand(this);
-                  helper.getWatchdog().reset();
+                  context.getWatchdog().reset();
                   //if the response is received, stop processing of command 
handlers
                   if(mode != COMMAND_MODE) {
                       break;
@@ -242,18 +242,18 @@
 
           }
         }
-        helper.getWatchdog().stop();
-        if (helper.getLogger().isInfoEnabled()) {
+        context.getWatchdog().stop();
+        if (context.getLogger().isInfoEnabled()) {
             StringBuilder logBuffer =
                 new StringBuilder(128)
                     .append("Connection for ")
                     .append(getUser())
                     .append(" from ")
-                    .append(helper.getRemoteHost())
+                    .append(context.getRemoteHost())
                     .append(" (")
-                    .append(helper.getRemoteIP())
+                    .append(context.getRemoteIP())
                     .append(") closed.");
-            helper.getLogger().info(logBuffer.toString());
+            context.getLogger().info(logBuffer.toString());
         }
     }
     

Modified: 
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerHandler.java
URL: 
http://svn.apache.org/viewvc/james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerHandler.java?rev=815718&r1=815717&r2=815718&view=diff
==============================================================================
--- 
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerHandler.java
 (original)
+++ 
james/server/trunk/remotemanager-function/src/main/java/org/apache/james/remotemanager/RemoteManagerHandler.java
 Wed Sep 16 10:56:30 2009
@@ -137,20 +137,20 @@
     /**
      * @see 
org.apache.avalon.cornerstone.services.connection.ConnectionHandler#handleConnection(Socket)
      */
-    public void handleProtocol() throws IOException {
-        helper.writeLoggedResponse("JAMES Remote Administration Tool " + 
Constants.SOFTWARE_VERSION );
-        helper.writeLoggedResponse("Please enter your login and password");
+    public void handleProtocol(ProtocolContext context) throws IOException {
+        context.writeLoggedResponse("JAMES Remote Administration Tool " + 
Constants.SOFTWARE_VERSION );
+        context.writeLoggedResponse("Please enter your login and password");
         String login = null;
         String password = null;
         do {
             if (login != null) {
                 final String message = "Login failed for " + login;
-                helper.writeLoggedFlushedResponse(message);
+                context.writeLoggedFlushedResponse(message);
             }
-            helper.writeLoggedFlushedResponse("Login id:");
-            login = helper.getInputReader().readLine().trim();
-            helper.writeLoggedFlushedResponse("Password:");
-            password = helper.getInputReader().readLine().trim();
+            context.writeLoggedFlushedResponse("Login id:");
+            login = context.getInputReader().readLine().trim();
+            context.writeLoggedFlushedResponse("Password:");
+            password = context.getInputReader().readLine().trim();
         } while 
(!password.equals(theConfigData.getAdministrativeAccountData().get(login)) || 
password.length() == 0);
 
         StringBuilder messageBuffer =
@@ -158,39 +158,39 @@
                     .append("Welcome ")
                     .append(login)
                     .append(". HELP for a list of commands");
-        helper.getOutputWriter().println( messageBuffer.toString() );
-        helper.getOutputWriter().flush();
-        if (helper.getLogger().isInfoEnabled()) {
+        context.getOutputWriter().println( messageBuffer.toString() );
+        context.getOutputWriter().flush();
+        if (context.getLogger().isInfoEnabled()) {
             StringBuilder infoBuffer =
                 new StringBuilder(128)
                         .append("Login for ")
                         .append(login)
                         .append(" successful");
-            helper.getLogger().info(infoBuffer.toString());
+            context.getLogger().info(infoBuffer.toString());
         }
 
         try {
-            helper.getOutputWriter().print(theConfigData.getPrompt());
-            helper.getOutputWriter().flush();
-            helper.getWatchdog().start();
-            while (parseCommand(helper.getInputReader().readLine())) {
-                helper.getWatchdog().reset();
-                helper.getOutputWriter().print(theConfigData.getPrompt());
-                helper.getOutputWriter().flush();
+            context.getOutputWriter().print(theConfigData.getPrompt());
+            context.getOutputWriter().flush();
+            context.getWatchdog().start();
+            while (parseCommand(context.getInputReader().readLine())) {
+                context.getWatchdog().reset();
+                context.getOutputWriter().print(theConfigData.getPrompt());
+                context.getOutputWriter().flush();
             }
-            helper.getWatchdog().stop();
+            context.getWatchdog().stop();
         } catch (IOException ioe) {
             //We can cleanly ignore this as it's probably a socket timeout
         } catch (Throwable thr) {
             System.out.println("Exception: " + thr.getMessage());
-            helper.getLogger().error("Encountered exception in handling the 
remote manager connection.", thr);
+            context.getLogger().error("Encountered exception in handling the 
remote manager connection.", thr);
         }
         StringBuilder infoBuffer =
             new StringBuilder(64)
                     .append("Logout for ")
                     .append(login)
                     .append(".");
-        helper.getLogger().info(infoBuffer.toString());
+        context.getLogger().info(infoBuffer.toString());
 
     }
 

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=815718&r1=815717&r2=815718&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
 Wed Sep 16 10:56:30 2009
@@ -94,12 +94,12 @@
        }
     
     /**
-     * @see org.apache.james.socket.ProtocolHandler#handleProtocol()
+     * @see 
org.apache.james.socket.ProtocolHandler#handleProtocol(ProtocolContext)
      */
-    public void handleProtocol() throws IOException {
+    public void handleProtocol(ProtocolContext context) throws IOException {
         smtpID = Integer.toString(random.nextInt(1024));
-        relayingAllowed = 
theConfigData.isRelayingAllowed(helper.getRemoteIP());
-        authSupported = theConfigData.isAuthRequired(helper.getRemoteIP());
+        relayingAllowed = 
theConfigData.isRelayingAllowed(context.getRemoteIP());
+        authSupported = theConfigData.isAuthRequired(context.getRemoteIP());
 
         // Both called in resetHandler, we don't need to call them again here.
         // sessionEnded = false;
@@ -142,8 +142,8 @@
             }
         }
 
-        CRLFDelimitedByteBuffer bytebufferHandler = new 
CRLFDelimitedByteBuffer(helper.getInputStream());
-        helper.getWatchdog().start();
+        CRLFDelimitedByteBuffer bytebufferHandler = new 
CRLFDelimitedByteBuffer(context.getInputStream());
+        context.getWatchdog().start();
         while(!sessionEnded) {
           //parse the command
           byte[] line =  null;
@@ -163,11 +163,11 @@
           } else {
               sessionEnded = true;
           }
-          helper.getWatchdog().reset();
+          context.getWatchdog().reset();
           
         }
-        helper.getWatchdog().stop();
-        helper.getLogger().debug("Closing socket.");
+        context.getWatchdog().stop();
+        context.getLogger().debug("Closing socket.");
     }
 
     /**



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

Reply via email to