Search in sources :

Example 26 with ProtocolCodecFilter

use of org.apache.mina.filter.codec.ProtocolCodecFilter in project netty by netty.

the class TestDnsServer method start.

/**
 * Start the {@link TestDnsServer} but drop all {@code AAAA} queries and not send any response to these at all.
 */
public void start(final boolean dropAAAAQueries) throws IOException {
    InetSocketAddress address = new InetSocketAddress(NetUtil.LOCALHOST4, 0);
    UdpTransport transport = new UdpTransport(address.getHostName(), address.getPort());
    setTransports(transport);
    DatagramAcceptor acceptor = transport.getAcceptor();
    acceptor.setHandler(new DnsProtocolHandler(this, store) {

        @Override
        public void sessionCreated(IoSession session) {
            // USe our own codec to support AAAA testing
            session.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory(dropAAAAQueries)));
        }
    });
    ((DatagramSessionConfig) acceptor.getSessionConfig()).setReuseAddress(true);
    // Start the listener
    acceptor.bind();
}
Also used : UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) DatagramAcceptor(org.apache.mina.transport.socket.DatagramAcceptor) InetSocketAddress(java.net.InetSocketAddress) DatagramSessionConfig(org.apache.mina.transport.socket.DatagramSessionConfig) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) DnsProtocolHandler(org.apache.directory.server.dns.protocol.DnsProtocolHandler) IoSession(org.apache.mina.core.session.IoSession)

Example 27 with ProtocolCodecFilter

use of org.apache.mina.filter.codec.ProtocolCodecFilter in project lobcder by skoulouzis.

the class MiltonListener method start.

/**
 * @see Listener#start(FtpServerContext)
 */
public synchronized void start(FtpServerContext context) {
    try {
        this.context = context;
        acceptor = new NioSocketAcceptor(Runtime.getRuntime().availableProcessors());
        if (getServerAddress() != null) {
            address = new InetSocketAddress(getServerAddress(), getPort());
        } else {
            address = new InetSocketAddress(getPort());
        }
        acceptor.setReuseAddress(true);
        acceptor.getSessionConfig().setReadBufferSize(2048);
        acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, getIdleTimeout());
        // Decrease the default receiver buffer size
        ((SocketSessionConfig) acceptor.getSessionConfig()).setReceiveBufferSize(512);
        MdcInjectionFilter mdcFilter = new MdcInjectionFilter();
        acceptor.getFilterChain().addLast("mdcFilter", mdcFilter);
        // add and update the blacklist filter
        acceptor.getFilterChain().addLast("ipFilter", new BlacklistFilter());
        updateBlacklistFilter();
        acceptor.getFilterChain().addLast("threadPool", new ExecutorFilter(filterExecutor));
        acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new FtpServerProtocolCodecFactory()));
        acceptor.getFilterChain().addLast("mdcFilter2", mdcFilter);
        acceptor.getFilterChain().addLast("logger", new FtpLoggingFilter());
        if (isImplicitSsl()) {
            SslConfiguration ssl = getSslConfiguration();
            SslFilter sslFilter;
            try {
                sslFilter = new SslFilter(ssl.getSSLContext());
            } catch (GeneralSecurityException e) {
                throw new FtpServerConfigurationException("SSL could not be initialized, check configuration");
            }
            if (ssl.getClientAuth() == ClientAuth.NEED) {
                sslFilter.setNeedClientAuth(true);
            } else if (ssl.getClientAuth() == ClientAuth.WANT) {
                sslFilter.setWantClientAuth(true);
            }
            if (ssl.getEnabledCipherSuites() != null) {
                sslFilter.setEnabledCipherSuites(ssl.getEnabledCipherSuites());
            }
            acceptor.getFilterChain().addFirst("sslFilter", sslFilter);
        }
        handler.init(context, this);
        // ////////////////////////////////////////
        // Here's the hack. Instead of instantiating a defaultftphandler
        // we use the one supplied in the constructor
        // ////////////////////////////////////////
        acceptor.setHandler(new FtpHandlerAdapter(context, handler));
        try {
            acceptor.bind(address);
        } catch (IOException e) {
            throw new FtpServerConfigurationException("Failed to bind to address " + address + ", check configuration", e);
        }
        updatePort();
    } catch (RuntimeException e) {
        // clean up if we fail to start
        stop();
        throw e;
    }
}
Also used : SslFilter(org.apache.mina.filter.ssl.SslFilter) MdcInjectionFilter(org.apache.mina.filter.logging.MdcInjectionFilter) FtpLoggingFilter(org.apache.ftpserver.listener.nio.FtpLoggingFilter) InetSocketAddress(java.net.InetSocketAddress) FtpHandlerAdapter(org.apache.ftpserver.listener.nio.FtpHandlerAdapter) GeneralSecurityException(java.security.GeneralSecurityException) ExecutorFilter(org.apache.mina.filter.executor.ExecutorFilter) IOException(java.io.IOException) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor) SocketSessionConfig(org.apache.mina.transport.socket.SocketSessionConfig) FtpServerProtocolCodecFactory(org.apache.ftpserver.listener.nio.FtpServerProtocolCodecFactory) BlacklistFilter(org.apache.mina.filter.firewall.BlacklistFilter) SslConfiguration(org.apache.ftpserver.ssl.SslConfiguration) FtpServerConfigurationException(org.apache.ftpserver.FtpServerConfigurationException)

Aggregations

ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)27 InetSocketAddress (java.net.InetSocketAddress)15 NioSocketAcceptor (org.apache.mina.transport.socket.nio.NioSocketAcceptor)9 IOException (java.io.IOException)6 IoSession (org.apache.mina.core.session.IoSession)4 TextLineCodecFactory (org.apache.mina.filter.codec.textline.TextLineCodecFactory)4 DnsProtocolHandler (org.apache.directory.server.dns.protocol.DnsProtocolHandler)3 UdpTransport (org.apache.directory.server.protocol.shared.transport.UdpTransport)3 ObjectSerializationCodecFactory (org.apache.mina.filter.codec.serialization.ObjectSerializationCodecFactory)3 DatagramSessionConfig (org.apache.mina.transport.socket.DatagramSessionConfig)3 SocketAcceptor (org.apache.mina.transport.socket.nio.SocketAcceptor)3 SocketAcceptorConfig (org.apache.mina.transport.socket.nio.SocketAcceptorConfig)3 NamedThreadFactory (com.alibaba.dubbo.common.utils.NamedThreadFactory)2 Charset (java.nio.charset.Charset)2 DnsException (org.apache.directory.server.dns.DnsException)2 NamedThreadFactory (org.apache.dubbo.common.utils.NamedThreadFactory)2 DefaultIoFilterChainBuilder (org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder)2 ConnectFuture (org.apache.mina.core.future.ConnectFuture)2 IoAcceptor (org.apache.mina.core.service.IoAcceptor)2 IoConnector (org.apache.mina.core.service.IoConnector)2