directory-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From trus...@apache.org
Subject svn commit: r372459 - in /directory/sandbox/trustin/dirmina-158/examples/src: main/java/org/apache/mina/examples/echoserver/ main/java/org/apache/mina/examples/httpserver/ main/java/org/apache/mina/examples/netcat/ main/java/org/apache/mina/examples/re...
Date Thu, 26 Jan 2006 06:38:36 GMT
Author: trustin
Date: Wed Jan 25 22:38:18 2006
New Revision: 372459

URL: http://svn.apache.org/viewcvs?rev=372459&view=rev
Log:
Fixed compilation errors in examples

Modified:
    directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
    directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/echoserver/Main.java
    directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/httpserver/Main.java
    directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/netcat/Main.java
    directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/reverser/Main.java
    directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/sumup/Client.java
    directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/sumup/Server.java
    directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/tennis/Main.java
    directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/AbstractTest.java
    directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/AcceptorTest.java
    directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/ConnectorTest.java

Modified: directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/echoserver/EchoProtocolHandler.java?rev=372459&r1=372458&r2=372459&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
(original)
+++ directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/echoserver/EchoProtocolHandler.java
Wed Jan 25 22:38:18 2006
@@ -23,8 +23,9 @@
 import org.apache.mina.common.IoHandler;
 import org.apache.mina.common.IoHandlerAdapter;
 import org.apache.mina.common.IoSession;
+import org.apache.mina.common.TransportType;
 import org.apache.mina.filter.SSLFilter;
-import org.apache.mina.transport.socket.nio.SocketSession;
+import org.apache.mina.transport.socket.nio.SocketSessionConfig;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
 
@@ -40,9 +41,9 @@
 
     public void sessionCreated( IoSession session )
     {
-        if( session instanceof SocketSession )
+        if( session.getTransportType() == TransportType.SOCKET )
         {
-            ( ( SocketSession ) session ).setSessionReceiveBufferSize( 2048 );
+            ( ( SocketSessionConfig ) session.getConfig() ).setReceiveBufferSize( 2048 );
         }
         
         session.setIdleTime( IdleStatus.BOTH_IDLE, 10 );

Modified: directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/echoserver/Main.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/echoserver/Main.java?rev=372459&r1=372458&r2=372459&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/echoserver/Main.java
(original)
+++ directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/echoserver/Main.java
Wed Jan 25 22:38:18 2006
@@ -18,14 +18,16 @@
  */
 package org.apache.mina.examples.echoserver;
 
+import java.net.InetSocketAddress;
+
+import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.TransportType;
+import org.apache.mina.common.IoAcceptorConfig;
 import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
 import org.apache.mina.filter.LoggingFilter;
 import org.apache.mina.filter.SSLFilter;
-import org.apache.mina.registry.Service;
-import org.apache.mina.registry.ServiceRegistry;
-import org.apache.mina.registry.SimpleServiceRegistry;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
 
 /**
  * (<b>Entry point</b>) Echo server
@@ -43,37 +45,39 @@
 
     public static void main( String[] args ) throws Exception
     {
-        ServiceRegistry registry = new SimpleServiceRegistry();
+        IoAcceptor acceptor = new SocketAcceptor();
+        IoAcceptorConfig config = new SocketAcceptorConfig();
+        DefaultIoFilterChainBuilder chain = config.getFilterChain();
         
         // Add SSL filter if SSL is enabled.
         if( USE_SSL )
         {
-            addSSLSupport( registry );
+            addSSLSupport( chain  );
         }
         
-        addLogger( registry );
+        addLogger( chain );
         
         // Bind
-        Service service = new Service( "echo", TransportType.SOCKET, PORT );
-        registry.bind( service, new EchoProtocolHandler() );
+        acceptor.bind(
+                new InetSocketAddress( PORT ),
+                new EchoProtocolHandler(),
+                config );
 
         System.out.println( "Listening on port " + PORT );
     }
 
-    private static void addSSLSupport( ServiceRegistry registry )
+    private static void addSSLSupport( DefaultIoFilterChainBuilder chain )
         throws Exception
     {
         SSLFilter sslFilter =
             new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
-        IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
-        acceptor.getFilterChain().addLast( "sslFilter", sslFilter );
+        chain.addLast( "sslFilter", sslFilter );
         System.out.println( "SSL ON" );
     }
     
-    private static void addLogger( ServiceRegistry registry ) throws Exception
+    private static void addLogger( DefaultIoFilterChainBuilder chain ) throws Exception
     {
-        IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
-        acceptor.getFilterChain().addLast( "logger", new LoggingFilter() );
+        chain.addLast( "logger", new LoggingFilter() );
         System.out.println( "Logging ON" );
     }
 }

Modified: directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/httpserver/Main.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/httpserver/Main.java?rev=372459&r1=372458&r2=372459&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/httpserver/Main.java
(original)
+++ directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/httpserver/Main.java
Wed Jan 25 22:38:18 2006
@@ -18,13 +18,15 @@
  */
 package org.apache.mina.examples.httpserver;
 
+import java.net.InetSocketAddress;
+
+import org.apache.mina.common.DefaultIoFilterChainBuilder;
 import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.TransportType;
+import org.apache.mina.common.IoAcceptorConfig;
 import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
 import org.apache.mina.filter.SSLFilter;
-import org.apache.mina.registry.Service;
-import org.apache.mina.registry.ServiceRegistry;
-import org.apache.mina.registry.SimpleServiceRegistry;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
 
 /**
  * (<b>Entry point</b>) HTTP server
@@ -41,29 +43,32 @@
 
     public static void main( String[] args ) throws Exception
     {
-        ServiceRegistry registry = new SimpleServiceRegistry();
-        
+        IoAcceptor acceptor = new SocketAcceptor();
+        IoAcceptorConfig config = new SocketAcceptorConfig();
+        DefaultIoFilterChainBuilder chain = config.getFilterChain();
+
         // Add SSL filter if SSL is enabled.
         if( USE_SSL )
         {
-            addSSLSupport( registry );
+            addSSLSupport( chain );
         }
 
         // Bind
-        Service service = new Service( "http", TransportType.SOCKET, PORT );
-        registry.bind( service, new HttpProtocolHandler() );
+        acceptor.bind(
+                new InetSocketAddress( PORT ),
+                new HttpProtocolHandler(),
+                config );
 
         System.out.println( "Listening on port " + PORT );
     }
 
 
-    private static void addSSLSupport( ServiceRegistry registry )
+    private static void addSSLSupport( DefaultIoFilterChainBuilder chain )
         throws Exception
     {
         System.out.println( "SSL is enabled." );
         SSLFilter sslFilter =
             new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
-        IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
-        acceptor.getFilterChain().addLast( "sslFilter", sslFilter );
+        chain.addLast( "sslFilter", sslFilter );
     }
 }

Modified: directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/netcat/Main.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/netcat/Main.java?rev=372459&r1=372458&r2=372459&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/netcat/Main.java
(original)
+++ directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/netcat/Main.java
Wed Jan 25 22:38:18 2006
@@ -20,6 +20,7 @@
 
 import java.net.InetSocketAddress;
 
+import org.apache.mina.common.IoConnectorConfig;
 import org.apache.mina.transport.socket.nio.SocketConnector;
 
 /**
@@ -44,7 +45,7 @@
         SocketConnector connector = new SocketConnector();
 
         // Set connect timeout.
-        connector.setConnectTimeout( 30 );
+        ( ( IoConnectorConfig ) connector.getDefaultConfig()).setConnectTimeout( 30 );
         
         // Start communication.
         connector.connect( 

Modified: directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/reverser/Main.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/reverser/Main.java?rev=372459&r1=372458&r2=372459&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/reverser/Main.java
(original)
+++ directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/reverser/Main.java
Wed Jan 25 22:38:18 2006
@@ -18,10 +18,10 @@
  */
 package org.apache.mina.examples.reverser;
 
-import org.apache.mina.common.TransportType;
-import org.apache.mina.registry.Service;
-import org.apache.mina.registry.ServiceRegistry;
-import org.apache.mina.registry.SimpleServiceRegistry;
+import java.net.InetSocketAddress;
+
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
 
 /**
  * (<b>Entry point</b>) Reverser server which reverses all text lines from
@@ -36,11 +36,12 @@
 
     public static void main( String[] args ) throws Exception
     {
-        ServiceRegistry registry = new SimpleServiceRegistry();
+        IoAcceptor acceptor = new SocketAcceptor();
 
         // Bind
-        Service service = new Service( "reverse", TransportType.SOCKET, PORT );
-        registry.bind( service, new ReverseProtocolHandler() );
+        acceptor.bind(
+                new InetSocketAddress( PORT ),
+                new ReverseProtocolHandler() );
 
         System.out.println( "Listening on port " + PORT );
     }

Modified: directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/sumup/Client.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/sumup/Client.java?rev=372459&r1=372458&r2=372459&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/sumup/Client.java
(original)
+++ directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/sumup/Client.java
Wed Jan 25 22:38:18 2006
@@ -23,6 +23,7 @@
 
 import org.apache.mina.common.ConnectFuture;
 import org.apache.mina.common.IoConnector;
+import org.apache.mina.common.IoConnectorConfig;
 import org.apache.mina.common.IoSession;
 import org.apache.mina.filter.ThreadPoolFilter;
 import org.apache.mina.transport.socket.nio.SocketConnector;
@@ -62,13 +63,13 @@
         ThreadPoolFilter ioThreadPoolFilter = new ThreadPoolFilter();
         ThreadPoolFilter protocolThreadPoolFilter = new ThreadPoolFilter();
         IoConnector connector = new SocketConnector();
-        connector.getFilterChain().addFirst(
+        connector.getDefaultConfig().getFilterChain().addFirst(
                 "ioThreadPool", ioThreadPoolFilter );
-        connector.getFilterChain().addLast(
+        connector.getDefaultConfig().getFilterChain().addLast(
                 "protocolThreadPool", protocolThreadPoolFilter );
 
         // Set connect timeout.
-        connector.setConnectTimeout( CONNECT_TIMEOUT );
+        ( ( IoConnectorConfig ) connector.getDefaultConfig() ).setConnectTimeout( CONNECT_TIMEOUT
);
         
         IoSession session;
         for( ;; )

Modified: directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/sumup/Server.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/sumup/Server.java?rev=372459&r1=372458&r2=372459&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/sumup/Server.java
(original)
+++ directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/sumup/Server.java
Wed Jan 25 22:38:18 2006
@@ -18,10 +18,10 @@
  */
 package org.apache.mina.examples.sumup;
 
-import org.apache.mina.common.TransportType;
-import org.apache.mina.registry.Service;
-import org.apache.mina.registry.ServiceRegistry;
-import org.apache.mina.registry.SimpleServiceRegistry;
+import java.net.InetSocketAddress;
+
+import org.apache.mina.common.IoAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptor;
 
 /**
  * (<strong>Entry Point</strong>) Starts SumUp server.
@@ -38,10 +38,10 @@
     public static void main( String[] args ) throws Throwable
     {
         // Create ServiceRegistry.
-        ServiceRegistry registry = new SimpleServiceRegistry();
+        IoAcceptor acceptor = new SocketAcceptor();
 
-        registry.bind(
-                new Service( "sumUp", TransportType.SOCKET, SERVER_PORT ),
+        acceptor.bind(
+                new InetSocketAddress( SERVER_PORT ),
                 new ServerSessionHandler( USE_CUSTOM_CODEC ) );
 
         System.out.println( "Listening on port " + SERVER_PORT );

Modified: directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/tennis/Main.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/tennis/Main.java?rev=372459&r1=372458&r2=372459&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/tennis/Main.java
(original)
+++ directory/sandbox/trustin/dirmina-158/examples/src/main/java/org/apache/mina/examples/tennis/Main.java
Wed Jan 25 22:38:18 2006
@@ -4,11 +4,9 @@
 package org.apache.mina.examples.tennis;
 
 import org.apache.mina.common.ConnectFuture;
+import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoSession;
-import org.apache.mina.common.TransportType;
-import org.apache.mina.registry.Service;
-import org.apache.mina.registry.ServiceRegistry;
-import org.apache.mina.registry.SimpleServiceRegistry;
+import org.apache.mina.transport.vmpipe.VmPipeAcceptor;
 import org.apache.mina.transport.vmpipe.VmPipeAddress;
 import org.apache.mina.transport.vmpipe.VmPipeConnector;
 
@@ -31,13 +29,11 @@
 
     public static void main( String[] args ) throws Exception
     {
-        ServiceRegistry registry = new SimpleServiceRegistry();
-
+        IoAcceptor acceptor = new VmPipeAcceptor();
         VmPipeAddress address = new VmPipeAddress( 8080 );
 
         // Set up server
-        Service service = new Service( "tennis", TransportType.VM_PIPE, address );
-        registry.bind( service, new TennisPlayer() );
+        acceptor.bind( address, new TennisPlayer() );
 
         // Connect to the server.
         VmPipeConnector connector = new VmPipeConnector();
@@ -52,6 +48,6 @@
         // Wait until the match ends.
         session.getCloseFuture().join();
         
-        registry.unbind( service );
+        acceptor.unbind( address );
     }
 }

Modified: directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/AbstractTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/AbstractTest.java?rev=372459&r1=372458&r2=372459&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/AbstractTest.java
(original)
+++ directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/AbstractTest.java
Wed Jan 25 22:38:18 2006
@@ -19,18 +19,20 @@
 package org.apache.mina.examples.echoserver;
 
 import java.io.IOException;
+import java.net.InetSocketAddress;
+import java.net.SocketAddress;
 
 import junit.framework.TestCase;
 
 import org.apache.mina.common.ByteBuffer;
+import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoSession;
-import org.apache.mina.common.TransportType;
-import org.apache.mina.filter.LoggingFilter;
+import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
 import org.apache.mina.filter.SSLFilter;
-import org.apache.mina.registry.Service;
-import org.apache.mina.registry.ServiceRegistry;
-import org.apache.mina.registry.SimpleServiceRegistry;
+import org.apache.mina.transport.socket.nio.DatagramAcceptor;
+import org.apache.mina.transport.socket.nio.DatagramSessionConfig;
 import org.apache.mina.transport.socket.nio.SocketAcceptor;
+import org.apache.mina.transport.socket.nio.SocketAcceptorConfig;
 import org.apache.mina.util.SessionLog;
 
 /**
@@ -41,9 +43,12 @@
  */
 public abstract class AbstractTest extends TestCase
 {
+    protected boolean useSSL;
     protected int port;
 
-    protected ServiceRegistry registry;
+    protected SocketAddress boundAddress;
+    protected IoAcceptor datagramAcceptor;
+    protected IoAcceptor socketAcceptor;
     
     protected AbstractTest()
     {
@@ -77,30 +82,48 @@
 
     protected void setUp() throws Exception
     {
-        registry = new SimpleServiceRegistry();
+        // Disable SSL by default
+        useSSL = false;
+        final SSLFilter sslFilter =
+            new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
+
+        boundAddress = null;
+        datagramAcceptor = new DatagramAcceptor();
+        socketAcceptor = new SocketAcceptor();
+        
+        ( ( DatagramSessionConfig ) datagramAcceptor.getDefaultConfig().getSessionConfig()
).setReuseAddress( true );
+        ( ( SocketAcceptorConfig ) socketAcceptor.getDefaultConfig() ).setReuseAddress( true
);
+        
 
         // Find an availble test port and bind to it.
         boolean socketBound = false;
         boolean datagramBound = false;
 
-        final SocketAcceptor acceptor = ( SocketAcceptor ) registry.getAcceptor( TransportType.SOCKET
);
-        acceptor.setReuseAddress( true );
-
         // Let's start from port #1 to detect possible resource leak
         // because test will fail in port 1-1023 if user run this test
         // as a normal user.
+        
+        SocketAddress address = null;
+        
         for( port = 1; port <= 65535; port ++ )
         {
             socketBound = false;
             datagramBound = false;
             
-            Service socketService = new Service( "echo", TransportType.SOCKET, port );
-            Service datagramService = new Service( "echo", TransportType.DATAGRAM, port );
+            address = new InetSocketAddress( port );
             
             try
             {
-                registry.bind( socketService, new EchoProtocolHandler()
+                socketAcceptor.bind( address, new EchoProtocolHandler()
                 {
+                    public void sessionCreated( IoSession session )
+                    {
+                        if( useSSL )
+                        {
+                            session.getFilterChain().addFirst( "SSL", sslFilter );
+                        }
+                    }
+
                     // This is for TLS reentrance test
                     public void messageReceived( IoSession session, Object message ) throws
Exception
                     {
@@ -110,10 +133,10 @@
                         }
                         
                         ByteBuffer buf = ( ByteBuffer ) message;
-                        if( buf.remaining() == 1 && buf.get() == ( byte ) '.' )
+                        if( session.getFilterChain().contains( "SSL" ) && buf.remaining()
== 1 && buf.get() == ( byte ) '.' )
                         {
                             SessionLog.info( session, "TLS Reentrance" );
-                            ( ( SSLFilter ) acceptor.getFilterChain().get( "SSL" ) ).startSSL(
session );
+                            ( ( SSLFilter ) session.getFilterChain().get( "SSL" ) ).startSSL(
session );
 
                             // Send a response
                             buf = ByteBuffer.allocate( 1 );
@@ -130,7 +153,7 @@
                 } );
                 socketBound = true;
 
-                registry.bind( datagramService, new EchoProtocolHandler() );
+                datagramAcceptor.bind( address, new EchoProtocolHandler() );
                 datagramBound = true;
 
                 break;
@@ -140,9 +163,13 @@
             }
             finally
             {
-                if( !socketBound || !datagramBound )
+                if( socketBound && !datagramBound )
                 {
-                    registry.unbindAll();
+                    socketAcceptor.unbind( address );
+                }
+                if( datagramBound && !socketBound )
+                {
+                    datagramAcceptor.unbind( address );
                 }
             }
         }
@@ -153,16 +180,16 @@
             throw new IOException( "Cannot bind any test port." );
         }
 
-        registry.getAcceptor( TransportType.SOCKET ).getFilterChain().addLast( "logger",
new LoggingFilter() );
-        registry.getAcceptor( TransportType.DATAGRAM ).getFilterChain().addLast( "logger",
new LoggingFilter() );
-
+        boundAddress = address;
         System.out.println( "Using port " + port + " for testing." );
     }
 
     protected void tearDown() throws Exception
     {
-        registry.unbindAll();
-        registry.getAcceptor( TransportType.SOCKET ).getFilterChain().remove( "logger" );
-        registry.getAcceptor( TransportType.DATAGRAM ).getFilterChain().remove( "logger"
);
+        if( boundAddress != null )
+        {
+            socketAcceptor.unbind( boundAddress );
+            datagramAcceptor.unbind( boundAddress );
+        }
     }
 }

Modified: directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/AcceptorTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/AcceptorTest.java?rev=372459&r1=372458&r2=372459&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/AcceptorTest.java
(original)
+++ directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/AcceptorTest.java
Wed Jan 25 22:38:18 2006
@@ -30,12 +30,8 @@
 
 import org.apache.commons.net.EchoTCPClient;
 import org.apache.commons.net.EchoUDPClient;
-import org.apache.mina.common.IoAcceptor;
-import org.apache.mina.common.TransportType;
-import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
 import org.apache.mina.examples.echoserver.ssl.SSLServerSocketFactory;
 import org.apache.mina.examples.echoserver.ssl.SSLSocketFactory;
-import org.apache.mina.filter.SSLFilter;
 
 /**
  * Tests echo server example.
@@ -58,10 +54,7 @@
     public void testTCPWithSSL() throws Exception
     {
         // Add an SSL filter
-        SSLFilter sslFilter =
-            new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
-        IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
-        acceptor.getFilterChain().addLast( "SSL", sslFilter );
+        useSSL = true;
         
         // Create a commons-net socket factory
         SSLSocketFactory.setSslEnabled(true);

Modified: directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/ConnectorTest.java
URL: http://svn.apache.org/viewcvs/directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/ConnectorTest.java?rev=372459&r1=372458&r2=372459&view=diff
==============================================================================
--- directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/ConnectorTest.java
(original)
+++ directory/sandbox/trustin/dirmina-158/examples/src/test/java/org/apache/mina/examples/echoserver/ConnectorTest.java
Wed Jan 25 22:38:18 2006
@@ -25,14 +25,11 @@
 
 import org.apache.mina.common.ByteBuffer;
 import org.apache.mina.common.ConnectFuture;
-import org.apache.mina.common.IoAcceptor;
 import org.apache.mina.common.IoConnector;
 import org.apache.mina.common.IoHandlerAdapter;
 import org.apache.mina.common.IoSession;
-import org.apache.mina.common.TransportType;
 import org.apache.mina.common.WriteFuture;
 import org.apache.mina.examples.echoserver.ssl.BogusSSLContextFactory;
-import org.apache.mina.filter.LoggingFilter;
 import org.apache.mina.filter.SSLFilter;
 import org.apache.mina.transport.socket.nio.DatagramConnector;
 import org.apache.mina.transport.socket.nio.SocketConnector;
@@ -50,11 +47,21 @@
     private static final int TIMEOUT = 10000; // 10 seconds
     private final int COUNT = 10;
     private final int DATA_SIZE = 16;
+    private SSLFilter connectorSSLFilter;
 
     public ConnectorTest()
     {
     }
 
+    protected void setUp() throws Exception
+    {
+        super.setUp();
+
+        connectorSSLFilter =
+            new SSLFilter( BogusSSLContextFactory.getInstance( false ) );
+        connectorSSLFilter.setUseClientMode( true ); // set client mode
+    }
+
     public void testTCP() throws Exception
     {
         IoConnector connector = new SocketConnector();
@@ -63,21 +70,12 @@
     
     public void testTCPWithSSL() throws Exception
     {
-        // Add an SSL filter to acceptor
-        SSLFilter acceptorSSLFilter =
-            new SSLFilter( BogusSSLContextFactory.getInstance( true ) );
-        IoAcceptor acceptor = registry.getAcceptor( TransportType.SOCKET );
-        acceptor.getFilterChain().addLast( "SSL", acceptorSSLFilter );
-        
+        useSSL = true;
         // Create a connector
         IoConnector connector = new SocketConnector();
         
         // Add an SSL filter to connector
-        SSLFilter connectorSSLFilter =
-            new SSLFilter( BogusSSLContextFactory.getInstance( false ) );
-        connectorSSLFilter.setUseClientMode( true ); // set client mode
-        connector.getFilterChain().addLast( "SSL", connectorSSLFilter );
-
+        connector.getDefaultConfig().getFilterChain().addLast( "SSL", connectorSSLFilter
);
         testConnector( connector );
     }
     
@@ -141,11 +139,9 @@
         testConnector0( session );
         
         // Send closeNotify to test TLS closure if it is TLS connection.
-        SSLFilter sslf = ( SSLFilter ) connector.getFilterChain().get( "SSL" );
-        if( sslf != null )
+        if( useSSL )
         {
-            connector.getFilterChain().addFirst( "log", new LoggingFilter() );
-            sslf.stopSSL( session ).join();
+            connectorSSLFilter.stopSSL( session ).join();
             
             System.out.println( "-------------------------------------------------------------------------------"
);
             // Test again after we finished TLS session.
@@ -169,9 +165,8 @@
             Assert.assertEquals( ( byte ) '.', handler.readBuf.get() );
             
             // Now start TLS connection
-            Assert.assertTrue( sslf.startSSL( session ) );
+            Assert.assertTrue( connectorSSLFilter.startSSL( session ) );
             testConnector0( session );
-            connector.getFilterChain().remove( "log" );
         }
         
         session.close().join();



Mime
View raw message