Search in sources :

Example 11 with ProtocolCodecFilter

use of org.apache.mina.filter.codec.ProtocolCodecFilter 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 12 with ProtocolCodecFilter

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

the class SmtpDetector method onInit.

/**
 * <p>onInit</p>
 */
@Override
protected void onInit() {
    setProtocolCodecFilter(new ProtocolCodecFilter(new MultilineOrientedCodecFactory(StandardCharsets.UTF_8, "-")));
    expectBanner(startsWith("220"));
    send(request("HELO LOCALHOST"), startsWith("250"));
    send(request("QUIT"), startsWith("221"));
}
Also used : MultilineOrientedCodecFactory(org.opennms.netmgt.provision.support.codec.MultilineOrientedCodecFactory) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter)

Example 13 with ProtocolCodecFilter

use of org.apache.mina.filter.codec.ProtocolCodecFilter in project vert.x by eclipse.

the class FakeDNSServer method start.

@Override
public void start() throws IOException {
    UdpTransport transport = new UdpTransport("127.0.0.1", port);
    setTransports(transport);
    acceptor = transport.getAcceptor();
    acceptor.setHandler(new DnsProtocolHandler(this, store) {

        @Override
        public void sessionCreated(IoSession session) throws Exception {
            // Use our own codec to support AAAA testing
            session.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory()));
        }
    });
    // Allow the port to be reused even if the socket is in TIME_WAIT state
    ((DatagramSessionConfig) acceptor.getSessionConfig()).setReuseAddress(true);
    // Start the listener
    acceptor.bind();
}
Also used : UdpTransport(org.apache.directory.server.protocol.shared.transport.UdpTransport) DatagramSessionConfig(org.apache.mina.transport.socket.DatagramSessionConfig) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter) DnsProtocolHandler(org.apache.directory.server.dns.protocol.DnsProtocolHandler) IOException(java.io.IOException) IoSession(org.apache.mina.core.session.IoSession)

Example 14 with ProtocolCodecFilter

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

the class TestDnsServer method start.

@Override
public void start() 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) throws Exception {
            // USe our own codec to support AAAA testing
            session.getFilterChain().addFirst("codec", new ProtocolCodecFilter(new TestDnsProtocolUdpCodecFactory()));
        }
    });
    ((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) DnsException(org.apache.directory.server.dns.DnsException) IOException(java.io.IOException) IoSession(org.apache.mina.core.session.IoSession)

Example 15 with ProtocolCodecFilter

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

the class MultilineHttpDetector method contructDefaults.

private void contructDefaults() {
    setProtocolCodecFilter(new ProtocolCodecFilter(new MultilineHttpProtocolFactory()));
    setUrl(DEFAULT_URL);
    setMaxRetCode(DEFAULT_MAX_RET_CODE);
}
Also used : MultilineHttpProtocolFactory(org.opennms.netmgt.provision.support.codec.MultilineHttpProtocolFactory) ProtocolCodecFilter(org.apache.mina.filter.codec.ProtocolCodecFilter)

Aggregations

ProtocolCodecFilter (org.apache.mina.filter.codec.ProtocolCodecFilter)16 InetSocketAddress (java.net.InetSocketAddress)7 IOException (java.io.IOException)4 NioSocketAcceptor (org.apache.mina.transport.socket.nio.NioSocketAcceptor)4 TextLineCodecFactory (org.apache.mina.filter.codec.textline.TextLineCodecFactory)3 NamedThreadFactory (com.alibaba.dubbo.common.utils.NamedThreadFactory)2 Charset (java.nio.charset.Charset)2 DnsProtocolHandler (org.apache.directory.server.dns.protocol.DnsProtocolHandler)2 UdpTransport (org.apache.directory.server.protocol.shared.transport.UdpTransport)2 DefaultIoFilterChainBuilder (org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder)2 IoSession (org.apache.mina.core.session.IoSession)2 DatagramSessionConfig (org.apache.mina.transport.socket.DatagramSessionConfig)2 SocketAcceptor (org.apache.mina.transport.socket.nio.SocketAcceptor)2 SocketAcceptorConfig (org.apache.mina.transport.socket.nio.SocketAcceptorConfig)2 MultilineOrientedCodecFactory (org.opennms.netmgt.provision.support.codec.MultilineOrientedCodecFactory)2 ThreadFactory (java.util.concurrent.ThreadFactory)1 ThreadPoolExecutor (java.util.concurrent.ThreadPoolExecutor)1 JMException (javax.management.JMException)1 MalformedObjectNameException (javax.management.MalformedObjectNameException)1 DnsException (org.apache.directory.server.dns.DnsException)1