Author: elecharny
Date: Wed Nov 12 05:39:23 2008
New Revision: 713366

URL: http://svn.apache.org/viewvc?rev=713366&view=rev
Log:
o Fixed the documentation about the 'autoStart' tag
o Define some constant for autoStart
o Removed one handler method
o Minor code refactoring

Modified:
    mina/trunk/core/src/main/java/org/apache/mina/filter/ssl/SslFilter.java

Modified: 
mina/trunk/core/src/main/java/org/apache/mina/filter/ssl/SslFilter.java
URL: 
http://svn.apache.org/viewvc/mina/trunk/core/src/main/java/org/apache/mina/filter/ssl/SslFilter.java?rev=713366&r1=713365&r2=713366&view=diff
==============================================================================
--- mina/trunk/core/src/main/java/org/apache/mina/filter/ssl/SslFilter.java 
(original)
+++ mina/trunk/core/src/main/java/org/apache/mina/filter/ssl/SslFilter.java Wed 
Nov 12 05:39:23 2008
@@ -49,7 +49,7 @@
  * a SSL 'hello' message, so you don't need to call
  * [EMAIL PROTECTED] #startSsl(IoSession)} manually unless you are 
implementing StartTLS
  * (see below).  If you don't want the handshake procedure to start
- * immediately, please specify [EMAIL PROTECTED] true} as [EMAIL PROTECTED] 
autoStart} parameter in
+ * immediately, please specify [EMAIL PROTECTED] false} as [EMAIL PROTECTED] 
autoStart} parameter in
  * the constructor.
  * <p>
  * This filter uses an [EMAIL PROTECTED] SSLEngine} which was introduced in 
Java 5, so
@@ -119,8 +119,7 @@
      * [EMAIL PROTECTED] SSLContext#createSSLEngine(String, int)} to be called 
passing the
      * hostname and port of the [EMAIL PROTECTED] InetSocketAddress} to get an
      * [EMAIL PROTECTED] SSLEngine} instance. If not set [EMAIL PROTECTED] 
SSLContext#createSSLEngine()}
-     * will be called.
-     * .
+     * will be called.<br/>
      * Using this feature [EMAIL PROTECTED] SSLSession} objects may be cached 
and reused
      * when in client mode.
      *
@@ -147,10 +146,14 @@
     private static final AttributeKey NEXT_FILTER = new 
AttributeKey(SslFilter.class, "nextFilter");
     private static final AttributeKey SSL_HANDLER = new 
AttributeKey(SslFilter.class, "handler");
 
-    // SSL Context
+    /** The SslContext used */
     private final SSLContext sslContext;
 
+    /** A flag used to tell the filter to start the handshake immediately */
     private final boolean autoStart;
+    
+    /** A flag used to determinate if the handshake should start immediately */
+    private static final boolean START_HANDSHAKE = true;
 
     private boolean client;
 
@@ -164,13 +167,16 @@
 
     /**
      * Creates a new SSL filter using the specified [EMAIL PROTECTED] 
SSLContext}.
+     * The handshake will start immediately.
      */
     public SslFilter(SSLContext sslContext) {
-        this(sslContext, true);
+        this(sslContext, START_HANDSHAKE);
     }
 
     /**
      * Creates a new SSL filter using the specified [EMAIL PROTECTED] 
SSLContext}.
+     * If the <code>autostart</code> flag is set to <code>true</code>, the
+     * handshake will start immediately.
      */
     public SslFilter(SSLContext sslContext, boolean autoStart) {
         if (sslContext == null) {
@@ -225,7 +231,8 @@
      * is sent and any messages written after then is not goinf to get 
encrypted.
      */
     public boolean isSslStarted(IoSession session) {
-        SslHandler handler = getSslSessionHandler0(session);
+        SslHandler handler = (SslHandler) session.getAttribute(SSL_HANDLER);
+        
         if (handler == null) {
             return false;
         }
@@ -558,7 +565,7 @@
     @Override
     public void filterClose(final NextFilter nextFilter, final IoSession 
session)
             throws SSLException {
-        SslHandler handler = getSslSessionHandler0(session);
+        SslHandler handler = (SslHandler) session.getAttribute(SSL_HANDLER);
         if (handler == null) {
             // The connection might already have closed, or
             // SSL might have not started yet.
@@ -590,9 +597,11 @@
     private void initiateHandshake(NextFilter nextFilter, IoSession session)
             throws SSLException {
         SslHandler handler = getSslSessionHandler(session);
+        
         synchronized (handler) {
             handler.handshake(nextFilter);
         }
+        
         handler.flushScheduledEvents();
     }
 
@@ -647,20 +656,19 @@
     }
 
     private SslHandler getSslSessionHandler(IoSession session) {
-        SslHandler handler = getSslSessionHandler0(session);
+        SslHandler handler = (SslHandler) session.getAttribute(SSL_HANDLER);
+        
         if (handler == null) {
             throw new IllegalStateException();
         }
+        
         if (handler.getParent() != this) {
             throw new IllegalArgumentException("Not managed by this filter.");
         }
+        
         return handler;
     }
 
-    private SslHandler getSslSessionHandler0(IoSession session) {
-        return (SslHandler) session.getAttribute(SSL_HANDLER);
-    }
-
     /**
      * A message that is sent from [EMAIL PROTECTED] SslFilter} when the 
connection became
      * secure or is not secure anymore.


Reply via email to