Dear Wiki user, You have subscribed to a wiki page or wiki category on "Directory Wiki" for change notification. The following page has been changed by sishen: http://wiki.apache.org/directory/MinaTutorial ------------------------------------------------------------------------------ session.close(); } - - ---- /!\ '''Edit conflict - other version:''' ---- public void messageReceived( IoSession session, Object message ) - - ---- /!\ '''Edit conflict - your version:''' ---- - public void messageReceived( IoSession session, Object message ) - - ---- /!\ '''End of edit conflict''' ---- { if (!(message instanceof ByteBuffer)) return; @@ -107, +100 @@ You’ve just implemented echo protocol with MINA. Now you need to bind your handler to a server port: {{{ - - ---- /!\ '''Edit conflict - other version:''' ---- import java.net.InetSocketAddress; import org.apache.mina.transport.socket.nio.SocketAcceptor; import org.apache.mina.transport.socket.nio.SocketAcceptorConfig; - ---- /!\ '''Edit conflict - your version:''' ---- - import java.net.InetSocketAddress; - import org.apache.mina.transport.socket.nio.SocketAcceptor; - import org.apache.mina.transport.socket.nio.SocketAcceptorConfig; - - ---- /!\ '''End of edit conflict''' ---- - public class Main { /** Choose your favorite port number. */ @@ -128, +112 @@ public static void main( String[] args ) throws Exception { - - ---- /!\ '''Edit conflict - other version:''' ---- SocketAcceptor acceptor = new SocketAcceptor(); SocketAcceptorConfig defaultConfig = new SocketAcceptorConfig(); defaultConfig.setReuseAddress(true); @@ -137, +119 @@ // Bind acceptor.bind(new InetSocketAddress(PORT), new EchoProtocolHandler(), defaultConfig); - ---- /!\ '''Edit conflict - your version:''' ---- - SocketAcceptor acceptor = new SocketAcceptor(); - SocketAcceptorConfig defaultConfig = new SocketAcceptorConfig(); - defaultConfig.setReuseAddress(true); - - // Bind - acceptor.bind(new InetSocketAddress(PORT), new EchoProtocolHandler(), defaultConfig); - - ---- /!\ '''End of edit conflict''' ---- - System.out.println( "Listening on port " + PORT ); } } @@ -166, +138 @@ Our echo protocol handler doesn’t log any I/O events. We could log them by adding a filter that logs them. MINA, fortunately, provides IoLoggingFilter that provides that functionality. Let’s add a logging filter to ServiceRegistry. {{{ - - ---- /!\ '''Edit conflict - other version:''' ---- .... DefaultIoFilterChainBuilder chain = config.getFilterChain(); addLogger(chain); @@ -177, +147 @@ { chain.addLast( "logger", new LoggingFilter() ); - ---- /!\ '''Edit conflict - your version:''' ---- + System.out.println( "Logging ON" ); + } + }}} + + What about SSL? MINA also provides an SSL filter that works in Java 5 or above. + + {{{ .... DefaultIoFilterChainBuilder chain = config.getFilterChain(); addLogger(chain); .... - private static void addLogger( DefaultIoFilterChainBuilder chain ) throws Exception - { - chain.addLast( "logger", new LoggingFilter() ); - - ---- /!\ '''End of edit conflict''' ---- - System.out.println( "Logging ON" ); - } - }}} - - What about SSL? MINA also provides an SSL filter that works in Java 5 or above. - - {{{ - - ---- /!\ '''Edit conflict - other version:''' ---- - .... - DefaultIoFilterChainBuilder chain = config.getFilterChain(); - addLogger(chain); - .... - private static void addSSLSupport( DefaultIoFilterChainBuilder chain ) throws Exception - - ---- /!\ '''Edit conflict - your version:''' ---- - .... - DefaultIoFilterChainBuilder chain = config.getFilterChain(); - addLogger(chain); - .... - - private static void addSSLSupport( DefaultIoFilterChainBuilder chain ) - throws Exception - - ---- /!\ '''End of edit conflict''' ---- { SSLFilter sslFilter = new SSLFilter( BogusSSLContextFactory.getInstance( true ) ); - ---- /!\ '''Edit conflict - other version:''' ---- chain.addLast( "sslFilter", sslFilter ); - ---- /!\ '''Edit conflict - your version:''' ---- - chain.addLast( "sslFilter", sslFilter ); - - ---- /!\ '''End of edit conflict''' ---- System.out.println( "SSL ON" ); } }}}