Package org.apache.mina.common

Examples of org.apache.mina.common.IoSession


            throw new IllegalArgumentException("Unknown localAddress: "
                    + localAddress);
        }

        RegistrationRequest req = (RegistrationRequest) key.attachment();
        IoSession session;
        IoSessionRecycler sessionRecycler = getSessionRecycler(req);
        synchronized (sessionRecycler) {
            session = sessionRecycler.recycle(localAddress, remoteAddress);
            if (session != null) {
                return session;
View Full Code Here


   
    private void testConnector( IoConnector connector, boolean useLocalAddress ) throws Exception
    {
        EchoConnectorHandler handler = new EchoConnectorHandler();
       
        IoSession session = null;
        if( !useLocalAddress )
        {
            ConnectFuture future = connector.connect(
                    new InetSocketAddress( "localhost", port ),
                    handler );
            future.join();
            session = future.getSession();
        }
        else
        {
            int clientPort = port;
            for( int i = 0; i < 65536; i ++ )
            {
                clientPort = AvailablePortFinder.getNextAvailable( clientPort + 1 );
                try
                {
                    ConnectFuture future = connector.connect(
                            new InetSocketAddress( "localhost", port ),
                            new InetSocketAddress( clientPort ),
                            handler );
                    future.join();
                    session = future.getSession();
                    break;
                }
                catch( RuntimeIOException e )
                {
                    // Try again until we succeed to bind.
                }
            }

            if( session == null )
            {
                Assert.fail( "Failed to find out an appropriate local address." );
            }
        }
       
        // Run a basic connector test.
        testConnector0( session );
       
        // Send closeNotify to test TLS closure if it is TLS connection.
        if( useSSL )
        {
            connectorSSLFilter.stopSSL( session ).join();
           
            System.out.println( "-------------------------------------------------------------------------------" );
            // Test again after we finished TLS session.
            testConnector0( session );
           
            System.out.println( "-------------------------------------------------------------------------------" );
           
            // Test if we can enter TLS mode again.
            //// Send StartTLS request.
            handler.readBuf.clear();
            ByteBuffer buf = ByteBuffer.allocate( 1 );
            buf.put( ( byte ) '.' );
            buf.flip();
            session.write( buf ).join();
           
            //// Wait for StartTLS response.
            waitForResponse( handler, 1 );

            handler.readBuf.flip();
            Assert.assertEquals( 1, handler.readBuf.remaining() );
            Assert.assertEquals( ( byte ) '.', handler.readBuf.get() );
           
            // Now start TLS connection
            Assert.assertTrue( connectorSSLFilter.startSSL( session ) );
            testConnector0( session );
        }
       
        session.close().join();
    }
View Full Code Here

            throw new IllegalArgumentException("Unknown localAddress: "
                    + localAddress);
        }

        RegistrationRequest req = (RegistrationRequest) key.attachment();
        IoSession session;
        IoSessionRecycler sessionRecycler = getSessionRecycler(req);
        synchronized (sessionRecycler) {
            session = sessionRecycler.recycle(localAddress, remoteAddress);
            if (session != null) {
                return session;
View Full Code Here

        if (parent.contains(SSLFilter.class)) {
            throw new IllegalStateException(
                    "A filter chain cannot contain more than one SSLFilter.");
        }

        IoSession session = parent.getSession();
        session.setAttribute(NEXT_FILTER, nextFilter);

        // Create an SSL handler and start handshake.
        SSLHandler handler = new SSLHandler(this, sslContext, session);
        session.setAttribute(SSL_HANDLER, handler);
    }
View Full Code Here

        handler.flushScheduledEvents();
    }

    public void onPreRemove(IoFilterChain parent, String name,
            NextFilter nextFilter) throws SSLException {
        IoSession session = parent.getSession();
        stopSSL(session);
        session.removeAttribute(NEXT_FILTER);
        session.removeAttribute(SSL_HANDLER);
    }
View Full Code Here

        // handle app. data read (if any)
        handleAppDataRead(nextFilter, handler);
    }

    private void handleAppDataRead(NextFilter nextFilter, SSLHandler handler) {
        IoSession session = handler.getSession();
        if (!handler.getAppBuffer().hasRemaining()) {
            return;
        }

        if (SessionLog.isDebugEnabled(session)) {
View Full Code Here

        exchange.getIn().setBody("Hello World");
        producer.process(exchange);

        Field field = producer.getClass().getDeclaredField("session");
        field.setAccessible(true);
        IoSession session = (IoSession) field.get(producer);
        assertTrue("There should be a test filter", session.getFilterChain().contains(TestFilter.class.getCanonicalName()));

        assertTrue("The filter should have been called twice (producer and consumer)", TestFilter.called == 2);

        producer.stop();
View Full Code Here

*/
public class ObjectSerializationTest extends TestCase {
    public void testEncoder() throws Exception {
        final String expected = "1234";

        IoSession session = new MockIoSession();
        SimpleProtocolEncoderOutput out = new SimpleProtocolEncoderOutput() {
            protected WriteFuture doFlush(ByteBuffer buf) {
                return null;
            }
        };
View Full Code Here

        assertEquals(expected, actual);

        // Test ProtocolDecoder
        ProtocolDecoder decoder = new ObjectSerializationDecoder();
        MockProtocolDecoderOutput decoderOut = new MockProtocolDecoderOutput();
        IoSession session = new MockIoSession();
        decoder.decode(session, in.duplicate(), decoderOut);

        Assert.assertEquals(expected, decoderOut.result.get(0));
        Assert.assertEquals(1, decoderOut.result.size());
    }
View Full Code Here

            throw new IllegalArgumentException("Unknown localAddress: "
                    + localAddress);
        }

        RegistrationRequest req = (RegistrationRequest) key.attachment();
        IoSession session;
        IoSessionRecycler sessionRecycler = getSessionRecycler(req);
        synchronized (sessionRecycler) {
            session = sessionRecycler.recycle(localAddress, remoteAddress);
            if (session != null) {
                return session;
View Full Code Here

TOP

Related Classes of org.apache.mina.common.IoSession

Copyright © 2018 www.massapicom. All rights reserved.
All source code are property of their respective owners. Java is a trademark of Sun Microsystems, Inc and owned by ORACLE Inc. Contact coftware#gmail.com.