Search in sources :

Example 6 with NioSocketAcceptor

use of org.apache.mina.transport.socket.nio.NioSocketAcceptor in project camel by apache.

the class Mina2ReverserServer method start.

public void start() throws Exception {
    acceptor = new NioSocketAcceptor();
    // Prepare the configuration
    ((NioSocketAcceptor) acceptor).setReuseAddress(true);
    Charset charset = Charset.forName("UTF-8");
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(charset)));
    acceptor.setHandler(new Mina2ReverseProtocolHandler());
    // Bind
    acceptor.bind(new InetSocketAddress(port));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) Charset(java.nio.charset.Charset) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor) TextLineCodecFactory(org.apache.mina.filter.codec.textline.TextLineCodecFactory)

Example 7 with NioSocketAcceptor

use of org.apache.mina.transport.socket.nio.NioSocketAcceptor in project camel by apache.

the class Mina2Consumer method setupSocketProtocol.

protected void setupSocketProtocol(String uri, Mina2Configuration configuration) throws Exception {
    LOG.debug("createSocketEndpoint");
    boolean minaLogger = configuration.isMinaLogger();
    List<IoFilter> filters = configuration.getFilters();
    address = new InetSocketAddress(configuration.getHost(), configuration.getPort());
    final int processorCount = Runtime.getRuntime().availableProcessors() + 1;
    acceptor = new NioSocketAcceptor(processorCount);
    // acceptor connectorConfig
    configureCodecFactory("Mina2Consumer", acceptor, configuration);
    ((NioSocketAcceptor) acceptor).setReuseAddress(true);
    acceptor.setCloseOnDeactivation(true);
    if (configuration.isOrderedThreadPoolExecutor()) {
        workerPool = new OrderedThreadPoolExecutor(configuration.getMaximumPoolSize());
    } else {
        workerPool = new UnorderedThreadPoolExecutor(configuration.getMaximumPoolSize());
    }
    acceptor.getFilterChain().addLast("threadPool", new ExecutorFilter(workerPool));
    if (minaLogger) {
        acceptor.getFilterChain().addLast("logger", new LoggingFilter());
    }
    appendIoFiltersToChain(filters, acceptor.getFilterChain());
    if (configuration.getSslContextParameters() != null) {
        SslFilter filter = new SslFilter(configuration.getSslContextParameters().createSSLContext(getEndpoint().getCamelContext()), configuration.isAutoStartTls());
        filter.setUseClientMode(false);
        acceptor.getFilterChain().addFirst("sslFilter", filter);
    }
}
Also used : SslFilter(org.apache.mina.filter.ssl.SslFilter) UnorderedThreadPoolExecutor(org.apache.mina.filter.executor.UnorderedThreadPoolExecutor) OrderedThreadPoolExecutor(org.apache.mina.filter.executor.OrderedThreadPoolExecutor) InetSocketAddress(java.net.InetSocketAddress) ExecutorFilter(org.apache.mina.filter.executor.ExecutorFilter) LoggingFilter(org.apache.mina.filter.logging.LoggingFilter) IoFilter(org.apache.mina.core.filterchain.IoFilter) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor)

Example 8 with NioSocketAcceptor

use of org.apache.mina.transport.socket.nio.NioSocketAcceptor in project opennms by OpenNMS.

the class AsyncSimpleServer method startServer.

/**
 * <p>startServer</p>
 *
 * @throws java.lang.Exception if any.
 */
public void startServer() throws Exception {
    m_acceptor = new NioSocketAcceptor();
    m_acceptor.getFilterChain().addLast("logger", new LoggingFilter());
    m_acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(StandardCharsets.UTF_8)));
    m_acceptor.setHandler(getServerHandler());
    m_acceptor.getSessionConfig().setReadBufferSize(getBufferSize());
    m_acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, getIdleTime());
    ((NioSocketAcceptor) m_acceptor).setReuseAddress(true);
    m_acceptor.bind(new InetSocketAddress(getPort()));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) LoggingFilter(org.apache.mina.filter.logging.LoggingFilter) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor) TextLineCodecFactory(org.apache.mina.filter.codec.textline.TextLineCodecFactory)

Example 9 with NioSocketAcceptor

use of org.apache.mina.transport.socket.nio.NioSocketAcceptor in project MtgDesktopCompanion by nicho92.

the class ConsoleServer method start.

@Override
public void start() throws IOException {
    acceptor = new NioSocketAcceptor();
    acceptor.getFilterChain().addLast("codec", new ProtocolCodecFilter(new TextLineCodecFactory(Charset.forName(getString("ENCODING")))));
    acceptor.getSessionConfig().setReadBufferSize(Integer.parseInt(getString("BUFFER-SIZE")));
    acceptor.getSessionConfig().setIdleTime(IdleStatus.BOTH_IDLE, Integer.parseInt(getString("IDLE-TIME")));
    acceptor.setHandler(new MTGConsoleHandler());
    acceptor.bind(new InetSocketAddress(Integer.parseInt(getString("SERVER-PORT"))));
    logger.info("Server started on port " + getString("SERVER-PORT"));
}
Also used : InetSocketAddress(java.net.InetSocketAddress) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) NioSocketAcceptor(org.apache.mina.transport.socket.nio.NioSocketAcceptor) TextLineCodecFactory(org.apache.mina.filter.codec.textline.TextLineCodecFactory) MTGConsoleHandler(org.magic.console.MTGConsoleHandler)

Example 10 with NioSocketAcceptor

use of org.apache.mina.transport.socket.nio.NioSocketAcceptor 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

NioSocketAcceptor (org.apache.mina.transport.socket.nio.NioSocketAcceptor)11 InetSocketAddress (java.net.InetSocketAddress)10 ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)9 IOException (java.io.IOException)4 TextLineCodecFactory (org.apache.mina.filter.codec.textline.TextLineCodecFactory)3 IoAcceptor (org.apache.mina.core.service.IoAcceptor)2 ExecutorFilter (org.apache.mina.filter.executor.ExecutorFilter)2 LoggingFilter (org.apache.mina.filter.logging.LoggingFilter)2 SslFilter (org.apache.mina.filter.ssl.SslFilter)2 SocketSessionConfig (org.apache.mina.transport.socket.SocketSessionConfig)2 FileInputStream (java.io.FileInputStream)1 Charset (java.nio.charset.Charset)1 GeneralSecurityException (java.security.GeneralSecurityException)1 Connection (java.sql.Connection)1 PreparedStatement (java.sql.PreparedStatement)1 SQLException (java.sql.SQLException)1 Properties (java.util.Properties)1 MapleServerHandler (net.MapleServerHandler)1 MapleCodecFactory (net.mina.MapleCodecFactory)1 Channel (net.server.channel.Channel)1