directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r165580 - in /directory/network/trunk/src: java/org/apache/mina/io/filter/SSLFilter.java java/org/apache/mina/io/filter/SSLHandler.java test/org/apache/mina/examples/echoserver/AcceptorTest.java test/org/apache/mina/examples/echoserver/ConnectorTest.java
Date Mon, 02 May 2005 04:49:57 GMT
Author: trustin
Date: Sun May  1 21:49:56 2005
New Revision: 165580

URL: http://svn.apache.org/viewcvs?rev=165580&view=rev
Log:
Replace proprietary logging method with standard JDK api.

Modified:
    directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java
    directory/network/trunk/src/java/org/apache/mina/io/filter/SSLHandler.java
    directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
    directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java

Modified: directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java?rev=165580&r1=165579&r2=165580&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/filter/SSLFilter.java Sun May  1 21:49:56
2005
@@ -23,6 +23,8 @@
 import java.util.Date;
 import java.util.IdentityHashMap;
 import java.util.Map;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
@@ -40,12 +42,15 @@
  * This filter uses an {@link SSLEngine} which was introduced in Java 5, so 
  * Java version 5 or above is mandatory to use this filter. And please note that
  * this filter only works for TCP/IP connections.
+ * <p>
+ * This filter logs debug information in {@link Level#FINEST} using {@link Logger}.
  * 
  * @author The Apache Directory Project (dev@directory.apache.org)
  * @version $Rev$, $Date$
  */
 public class SSLFilter extends IoFilterAdapter
 {
+    private static final Logger log = Logger.getLogger( SSLFilter.class.getName() );
     /**
      * A marker which is passed with {@link IoHandler#dataWritten(IoSession, Object)}
      * when <tt>SSLFilter</tt> writes data other then user actually requested.
@@ -64,9 +69,6 @@
     // Map used to map SSLHandler objects per session (key is IoSession)
     private Map sslSessionHandlerMap = new IdentityHashMap();
 
-    /** debug interface */
-    Debug debug = null;
-
     private boolean client;
     private boolean needClientAuth;
     private boolean wantClientAuth;
@@ -184,41 +186,6 @@
         this.enabledProtocols = protocols;
     }
 
-    /**
-     * Sets the debug message auditter.
-     */
-    public void setDebug( Debug debug )
-    {
-        if( debug == null )
-        {
-            throw new NullPointerException( "debug" );
-        }
-
-        if( debug == Debug.OFF )
-        {
-            this.debug = null;
-        }
-        else
-        {
-            this.debug = debug;
-        }
-    }
-
-    /**
-     * Gets the debug message auditter.
-     */
-    public Debug getDebug()
-    {
-        if( debug == null )
-        {
-            return Debug.OFF;
-        }
-        else
-        {
-            return debug;
-        }
-    }
-
     // IoFilter impl.
 
     public void sessionOpened( NextFilter nextFilter, IoSession session )
@@ -231,9 +198,9 @@
     public void sessionClosed( NextFilter nextFilter, IoSession session )
     {
         SSLHandler sslHandler = getSSLSessionHandler( session );
-        if( debug != null )
+        if( log.isLoggable( Level.FINEST ) )
         {
-            debug.print( this, "Closed: " + sslHandler );
+            log.log( Level.FINEST, session + " Closed: " + sslHandler );
         }
         if( sslHandler != null )
         {
@@ -271,9 +238,9 @@
         SSLHandler sslHandler = getSSLSessionHandler( session );
         if( sslHandler != null )
         {
-            if( debug != null )
+            if( log.isLoggable( Level.FINEST ) )
             {
-                debug.print( this, "Data Read: " + sslHandler + " (" + buf+ ')' );
+                log.log( Level.FINEST, session + " Data Read: " + sslHandler + " (" + buf+
')' );
             }
             synchronized( sslHandler )
             {
@@ -287,11 +254,10 @@
 
                     if( sslHandler.isClosed() )
                     {
-                        if( debug != null )
+                        if( log.isLoggable( Level.FINEST ) )
                         {
-                            debug.print(
-                                    this,
-                                    "SSL Session closed. Closing connection.." );
+                            log.log( Level.FINEST,
+                                     session + " SSL Session closed. Closing connection.."
);
                         }
                         session.close();
                     }
@@ -326,9 +292,9 @@
     {
 
         SSLHandler handler = createSSLSessionHandler( session );
-        if( debug != null )
+        if( log.isLoggable( Level.FINEST ) )
         {
-            debug.print( this, "Filtered Write: " + handler );
+            log.log( Level.FINEST, session + " Filtered Write: " + handler );
         }
 
         synchronized( handler )
@@ -336,9 +302,9 @@
             if( handler.isWritingEncryptedData() )
             {
                 // data already encrypted; simply return buffer
-                if( debug != null )
+                if( log.isLoggable( Level.FINEST ) )
                 {
-                    debug.print( this, "  already encrypted: " + buf );
+                    log.log( Level.FINEST, session + "   already encrypted: " + buf );
                 }
                 nextFilter.filterWrite( session, buf, marker );
                 return;
@@ -349,17 +315,17 @@
                 // SSL encrypt
                 try
                 {
-                    if( debug != null )
+                    if( log.isLoggable( Level.FINEST ) )
                     {
-                        debug.print( this, "encrypt: " + buf );
+                        log.log( Level.FINEST, session + " encrypt: " + buf );
                     }
                     handler.encrypt( buf.buf() );
                     ByteBuffer encryptedBuffer = copy( handler
                             .getOutNetBuffer() );
 
-                    if( debug != null )
+                    if( log.isLoggable( Level.FINEST ) )
                     {
-                        debug.print( this, "encrypted buf: " + encryptedBuffer);
+                        log.log( Level.FINEST, session + " encrypted buf: " + encryptedBuffer);
                     }
                     buf.release();
                     nextFilter.filterWrite( session, encryptedBuffer, marker );
@@ -375,16 +341,16 @@
             {
                 if( !session.isConnected() )
                 {
-                    if( debug != null )
+                    if( log.isLoggable( Level.FINEST ) )
                     {
-                        debug.print( this, "Write request on closed session." );
+                        log.log( Level.FINEST, session + " Write request on closed session."
);
                     }
                 }
                 else
                 {
-                    if( debug != null )
+                    if( log.isLoggable( Level.FINEST ) )
                     {
-                        debug.print( this, "Handshaking is not complete yet. Buffering write
request." );
+                        log.log( Level.FINEST, session + " Handshaking is not complete yet.
Buffering write request." );
                     }
                     handler.scheduleWrite( nextFilter, buf, marker );
                 }
@@ -413,17 +379,17 @@
     private void handleAppDataRead( NextFilter nextFilter, IoSession session,
                                    SSLHandler sslHandler )
     {
-        if( debug != null )
+        if( log.isLoggable( Level.FINEST ) )
         {
-            debug.print( this, "appBuffer: " + sslHandler.getAppBuffer() );
+            log.log( Level.FINEST, session + " appBuffer: " + sslHandler.getAppBuffer() );
         }
         if( sslHandler.getAppBuffer().hasRemaining() )
         {
             // forward read app data
             ByteBuffer readBuffer = copy( sslHandler.getAppBuffer() );
-            if( debug != null )
+            if( log.isLoggable( Level.FINEST ) )
             {
-                debug.print( this, "app data read: " + readBuffer + " (" + readBuffer.getHexDump()
+ ')' );
+                log.log( Level.FINEST, session + " app data read: " + readBuffer + " (" +
readBuffer.getHexDump() + ')' );
             }
             nextFilter.dataRead( session, readBuffer );
         }
@@ -450,15 +416,15 @@
 
         try
         {
-            if( debug != null )
+            if( log.isLoggable( Level.FINEST ) )
             {
-                debug.print( this, "write outNetBuffer: " +
+                log.log( Level.FINEST, session + " write outNetBuffer: " +
                                    sslHandler.getOutNetBuffer() );
             }
             ByteBuffer writeBuffer = copy( sslHandler.getOutNetBuffer() );
-            if( debug != null )
+            if( log.isLoggable( Level.FINEST ) )
             {
-                debug.print( this, "session write: " + writeBuffer );
+                log.log( Level.FINEST, session + " session write: " + writeBuffer );
             }
             //debug("outNetBuffer (after copy): {0}", sslHandler.getOutNetBuffer());
             session.write( writeBuffer, SSL_MARKER );
@@ -479,9 +445,9 @@
                 }
                 if( sslHandler.getOutNetBuffer().hasRemaining() )
                 {
-                    if( debug != null )
+                    if( log.isLoggable( Level.FINEST ) )
                     {
-                        debug.print( this, "write outNetBuffer2: " +
+                        log.log( Level.FINEST, session + " write outNetBuffer2: " +
                                            sslHandler.getOutNetBuffer() );
                     }
                     ByteBuffer writeBuffer2 = copy( sslHandler

Modified: directory/network/trunk/src/java/org/apache/mina/io/filter/SSLHandler.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/java/org/apache/mina/io/filter/SSLHandler.java?rev=165580&r1=165579&r2=165580&view=diff
==============================================================================
--- directory/network/trunk/src/java/org/apache/mina/io/filter/SSLHandler.java (original)
+++ directory/network/trunk/src/java/org/apache/mina/io/filter/SSLHandler.java Sun May  1
21:49:56 2005
@@ -19,6 +19,8 @@
 package org.apache.mina.io.filter;
 
 import java.nio.ByteBuffer;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 import javax.net.ssl.SSLContext;
 import javax.net.ssl.SSLEngine;
@@ -43,6 +45,8 @@
  */
 class SSLHandler
 {
+    private static final Logger log = Logger.getLogger( SSLFilter.class.getName() );
+
     private final SSLFilter parent;
 
     private final IoSession session;
@@ -191,9 +195,9 @@
         
         while( ( scheduledBuf = ( org.apache.mina.common.ByteBuffer ) writeBufferQueue.pop()
) != null )
         {
-            if( parent.debug != null )
+            if( log.isLoggable( Level.FINEST ) )
             {
-                parent.debug.print( parent, "Flushing buffered write request: " + scheduledBuf
);
+                log.log( Level.FINEST, session + " Flushing buffered write request: " + scheduledBuf
);
             }
             nextFilter = ( NextFilter ) nextFilterQueue.pop();
             scheduledMarker = writeMarkerQueue.pop();
@@ -219,12 +223,12 @@
             appBuffer = SSLByteBufferPool.expandBuffer( appBuffer, inNetBuffer.capacity()
* 2);
             appBuffer.position( 0 );
             appBuffer.limit( 0 );
-            if( parent.debug != null )
+            if( log.isLoggable( Level.FINEST ) )
             {
-                parent.debug.print( parent,
-                                    "expanded inNetBuffer:" + inNetBuffer );
-                parent.debug.print( parent, 
-                                    "expanded appBuffer:" + appBuffer );
+                log.log( Level.FINEST, session + 
+                                    " expanded inNetBuffer:" + inNetBuffer );
+                log.log( Level.FINEST, session + 
+                                    " expanded appBuffer:" + appBuffer );
             }
         }
 
@@ -247,9 +251,9 @@
      */
     public void continueHandshake() throws SSLException
     {
-        if( parent.debug != null )
+        if( log.isLoggable( Level.FINEST ) )
         {
-            parent.debug.print( parent, "continueHandshake()" );
+            log.log( Level.FINEST, session + " continueHandshake()" );
         }
         doHandshake();
     }
@@ -323,8 +327,8 @@
 
         if( appBuffer.hasRemaining() )
         {
-             if ( parent.debug != null ) {
-                 parent.debug.print( parent, "Error: appBuffer not empty!" );
+             if ( log.isLoggable( Level.FINEST ) ) {
+                 log.log( Level.FINEST, session + " Error: appBuffer not empty!" );
              }
             //still app data in buffer!?
             throw new IllegalStateException();
@@ -372,14 +376,14 @@
                 // Note: there is no way to know the exact size required, but enrypted data
                 // shouln't need to be larger than twice the source data size?
                 outNetBuffer = SSLByteBufferPool.expandBuffer( outNetBuffer, src.capacity()
* 2 );
-                if ( parent.debug != null ) {
-                    parent.debug.print( parent, "expanded outNetBuffer:" + outNetBuffer );
+                if ( log.isLoggable( Level.FINEST ) ) {
+                    log.log( Level.FINEST, session + " expanded outNetBuffer:" + outNetBuffer
);
                 }
             }
 
             result = sslEngine.wrap( src, outNetBuffer );
-            if ( parent.debug != null ) {
-                parent.debug.print( parent, "Wrap res:" + result );
+            if ( log.isLoggable( Level.FINEST ) ) {
+                log.log( Level.FINEST, session + " Wrap res:" + result );
             }
 
             if ( result.getStatus() == SSLEngineResult.Status.OK ) {
@@ -402,40 +406,39 @@
     synchronized void doHandshake() throws SSLException
     {
 
-        if( parent.debug != null )
+        if( log.isLoggable( Level.FINEST ) )
         {
-            parent.debug.print( parent, "doHandshake()" );
+            log.log( Level.FINEST, session + " doHandshake()" );
         }
 
         while( !initialHandshakeComplete )
         {
             if( initialHandshakeStatus == SSLEngineResult.HandshakeStatus.FINISHED )
             {
-                if( parent.debug != null )
+                if( log.isLoggable( Level.FINEST ) )
                 {
                     SSLSession sslSession = sslEngine.getSession();
-                    parent.debug.print( parent, " initialHandshakeStatus=FINISHED" );
-                    parent.debug.print( parent, " sslSession CipherSuite used " + sslSession.getCipherSuite());
+                    log.log( Level.FINEST, session + "  initialHandshakeStatus=FINISHED"
);
+                    log.log( Level.FINEST, session + "  sslSession CipherSuite used " + sslSession.getCipherSuite());
                 }
                 initialHandshakeComplete = true;
                 return;
             }
             else if( initialHandshakeStatus == SSLEngineResult.HandshakeStatus.NEED_TASK
)
             {
-                if( parent.debug != null )
+                if( log.isLoggable( Level.FINEST ) )
                 {
-                    parent.debug.print( parent, " initialHandshakeStatus=NEED_TASK" );
+                    log.log( Level.FINEST, session + "  initialHandshakeStatus=NEED_TASK"
);
                 }
                 initialHandshakeStatus = doTasks();
             }
             else if( initialHandshakeStatus == SSLEngineResult.HandshakeStatus.NEED_UNWRAP
)
             {
                 // we need more data read
-                if( parent.debug != null )
+                if( log.isLoggable( Level.FINEST ) )
                 {
-                    parent.debug.print(
-                            parent,
-                            " initialHandshakeStatus=NEED_UNWRAP" );
+                    log.log( Level.FINEST, session +
+                             "  initialHandshakeStatus=NEED_UNWRAP" );
                 }
                 SSLEngineResult.Status status = unwrapHandshake();
                 if( ( initialHandshakeStatus != SSLEngineResult.HandshakeStatus.FINISHED

@@ -448,25 +451,25 @@
             }
             else if( initialHandshakeStatus == SSLEngineResult.HandshakeStatus.NEED_WRAP
)
             {
-                if( parent.debug != null )
+                if( log.isLoggable( Level.FINEST ) )
                 {
-                    parent.debug.print( parent, " initialHandshakeStatus=NEED_WRAP" );
+                    log.log( Level.FINEST, session + "  initialHandshakeStatus=NEED_WRAP"
);
                 }
                 // First make sure that the out buffer is completely empty. Since we
                 // cannot call wrap with data left on the buffer
                 if( outNetBuffer.hasRemaining() )
                 {
-                    if( parent.debug != null )
+                    if( log.isLoggable( Level.FINEST ) )
                     {
-                        parent.debug.print( parent, " Still data in out buffer!" );
+                        log.log( Level.FINEST, session + "  Still data in out buffer!" );
                     }
                     return;
                 }
                 outNetBuffer.clear();
                 SSLEngineResult result = sslEngine.wrap( hsBB, outNetBuffer );
-                if( parent.debug != null )
+                if( log.isLoggable( Level.FINEST ) )
                 {
-                    parent.debug.print( parent, "Wrap res:" + result );
+                    log.log( Level.FINEST, session + " Wrap res:" + result );
                 }
 
                 outNetBuffer.flip();
@@ -485,9 +488,9 @@
 
     SSLEngineResult.Status unwrap() throws SSLException
     {
-        if( parent.debug != null )
+        if( log.isLoggable( Level.FINEST ) )
         {
-            parent.debug.print( parent, "unwrap()" );
+            log.log( Level.FINEST, session + " unwrap()" );
         }
         // Prepare the application buffer to receive decrypted data
         appBuffer.clear();
@@ -498,15 +501,15 @@
         SSLEngineResult res;
         do
         {
-            if( parent.debug != null )
+            if( log.isLoggable( Level.FINEST ) )
             {
-                parent.debug.print( parent, "  inNetBuffer: " + inNetBuffer );
-                parent.debug.print( parent, "  appBuffer: " + appBuffer );
+                log.log( Level.FINEST, session + "   inNetBuffer: " + inNetBuffer );
+                log.log( Level.FINEST, session + "   appBuffer: " + appBuffer );
             }
             res = sslEngine.unwrap( inNetBuffer, appBuffer );
-            if( parent.debug != null )
+            if( log.isLoggable( Level.FINEST ) )
             {
-                parent.debug.print( parent, "Unwrap res:" + res );
+                log.log( Level.FINEST, session + " Unwrap res:" + res );
             }
         }
         while( res.getStatus() == SSLEngineResult.Status.OK );
@@ -535,9 +538,9 @@
 
     private SSLEngineResult.Status unwrapHandshake() throws SSLException
     {
-        if( parent.debug != null )
+        if( log.isLoggable( Level.FINEST ) )
         {
-            parent.debug.print( parent, "unwrapHandshake()" );
+            log.log( Level.FINEST, session + " unwrapHandshake()" );
         }
         // Prepare the application buffer to receive decrypted data
         appBuffer.clear();
@@ -548,15 +551,15 @@
         SSLEngineResult res;
         do
         {
-            if( parent.debug != null )
+            if( log.isLoggable( Level.FINEST ) )
             {
-                parent.debug.print( parent, "  inNetBuffer: " + inNetBuffer );
-                parent.debug.print( parent, "  appBuffer: " + appBuffer );
+                log.log( Level.FINEST, session + "   inNetBuffer: " + inNetBuffer );
+                log.log( Level.FINEST, session + "   appBuffer: " + appBuffer );
             }
             res = sslEngine.unwrap( inNetBuffer, appBuffer );
-            if( parent.debug != null )
+            if( log.isLoggable( Level.FINEST ) )
             {
-                parent.debug.print( parent, "Unwrap res:" + res );
+                log.log( Level.FINEST, session + " Unwrap res:" + res );
             }
 
         }
@@ -572,14 +575,14 @@
 				&& res.getStatus() == SSLEngineResult.Status.OK
 				&& inNetBuffer.hasRemaining()) {
 			do {
-				if (parent.debug != null) {
-					parent.debug.print(parent, " extra handshake unwrap");
-					parent.debug.print(parent, "  inNetBuffer: " + inNetBuffer);
-					parent.debug.print(parent, "  appBuffer: " + appBuffer);
+				if (log.isLoggable( Level.FINEST )) {
+					log.log( Level.FINEST, session + "  extra handshake unwrap" );
+                    log.log( Level.FINEST, session + "   inNetBuffer: " + inNetBuffer );
+                    log.log( Level.FINEST, session + "   appBuffer: " + appBuffer );
 				}
 				res = sslEngine.unwrap(inNetBuffer, appBuffer);
-				if (parent.debug != null) {
-					parent.debug.print(parent, "Unwrap res:" + res);
+				if (log.isLoggable( Level.FINEST )) {
+                    log.log( Level.FINEST, session + " Unwrap res:" + res );
 				}
 			} while (res.getStatus() == SSLEngineResult.Status.OK);
 		}
@@ -613,9 +616,9 @@
      */
     private SSLEngineResult.HandshakeStatus doTasks()
     {
-        if( parent.debug != null )
+        if( log.isLoggable( Level.FINEST ) )
         {
-            parent.debug.print( parent, "  doTasks()" );
+            log.log( Level.FINEST, session + "   doTasks()" );
         }
 
         /*
@@ -625,15 +628,15 @@
         Runnable runnable;
         while( ( runnable = sslEngine.getDelegatedTask() ) != null )
         {
-            if( parent.debug != null )
+            if( log.isLoggable( Level.FINEST ) )
             {
-                parent.debug.print( parent, "   doTask: " + runnable );
+                log.log( Level.FINEST, session + "    doTask: " + runnable );
             }
             runnable.run();
         }
-        if( parent.debug != null )
+        if( log.isLoggable( Level.FINEST ) )
         {
-            parent.debug.print( parent, "  doTasks(): "
+            log.log( Level.FINEST, session + "   doTasks(): "
                     + sslEngine.getHandshakeStatus() );
         }
         return sslEngine.getHandshakeStatus();

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java?rev=165580&r1=165579&r2=165580&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/AcceptorTest.java
Sun May  1 21:49:56 2005
@@ -61,7 +61,6 @@
         // Add an SSL filter
         SSLFilter sslFilter =
             new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
-        //sslFilter.setDebug( SSLFilter.Debug.ON );
         IoAcceptor acceptor = registry.getIoAcceptor( TransportType.SOCKET );
         acceptor.getFilterChain().addLast( "SSL", sslFilter );
         

Modified: directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
URL: http://svn.apache.org/viewcvs/directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java?rev=165580&r1=165579&r2=165580&view=diff
==============================================================================
--- directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
(original)
+++ directory/network/trunk/src/test/org/apache/mina/examples/echoserver/ConnectorTest.java
Sun May  1 21:49:56 2005
@@ -76,7 +76,6 @@
         // Add an SSL filter to acceptor
         SSLFilter acceptorSSLFilter =
             new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
-        //acceptorSSLFilter.setDebug( SSLFilter.Debug.ON );
         IoAcceptor acceptor = registry.getIoAcceptor( TransportType.SOCKET );
         acceptor.getFilterChain().addLast( "SSL", acceptorSSLFilter );
 
@@ -87,7 +86,6 @@
         SSLFilter connectorSSLFilter =
             new SSLFilter( BogusSSLContextFactory.getInstance( false ) );
         connectorSSLFilter.setUseClientMode( true ); // set client mode
-        //connectorSSLFilter.setDebug( SSLFilter.Debug.ON );
         connector.getFilterChain().addLast( "SSL", connectorSSLFilter );
 
         testConnector( connector );



Mime
View raw message