use of org.apache.mina.filter.logging.MdcInjectionFilter 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;
}
}
Aggregations