0

I have a Spring application and I need to implement very simple communication channel with Apache MINA library.

My Spring application is running but MINA server is not running, in netstat is this port not used.

I followed this tutorial: http://mina.apache.org/mina-project/userguide/ch17-spring-integration/ch17-spring-integration.html

What am I doing wrong?

This is a handler class:

public class ServerHandler extends IoHandlerAdapter {

    @Override
    public void exceptionCaught(IoSession session, Throwable cause) throws Exception {
        cause.printStackTrace();
    }

    @Override
    public void messageReceived(IoSession session, Object message) throws Exception {

        String str = message.toString();
        if (str.trim().equalsIgnoreCase("quit")) {
            session.close(true);
            return;
        }
        Date date = new Date();
        session.write(date.toString());
        System.out.println("Message written...");
    }

    @Override
    public void sessionIdle(IoSession session, IdleStatus status) throws Exception {
        System.out.println("IDLE " + session.getIdleCount(status));
    }
}

And this is a XML configuration from applicationContext.xml

<bean id="trapHandler" class="ServerHandler"></bean>

    <bean id="snmpCodecFilter" class="org.apache.mina.filter.codec.ProtocolCodecFilter">
        <constructor-arg>
            <bean class="org.apache.mina.filter.codec.textline.TextLineCodecFactory" />
        </constructor-arg>
    </bean>

    <bean id="loggingFilter" class="org.apache.mina.filter.logging.LoggingFilter" />

    <!-- The filter chain. -->
    <bean id="filterChainBuilder" class="org.apache.mina.core.filterchain.DefaultIoFilterChainBuilder">
        <property name="filters">
            <map>
                <entry key="loggingFilter" value-ref="loggingFilter"/>
                <entry key="codecFilter" value-ref="snmpCodecFilter"/>
            </map>
        </property>
    </bean>

    <bean class="org.springframework.beans.factory.config.CustomEditorConfigurer">
        <property name="customEditors">
            <map>
                <entry key="java.net.SocketAddress">
                    <bean class="org.apache.mina.integration.beans.InetSocketAddressEditor" />
                </entry>
            </map>
        </property>
    </bean>

    <!-- The IoAcceptor which binds to port 161 -->
    <bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioDatagramAcceptor" init-method="bind" destroy-method="unbind">
        <!--<property name="defaultLocalAddress" value="${interface.ip_address}:${interface.communication.port}" />-->
        <property name="defaultLocalAddress" value=":6001" />
        <property name="handler" ref="trapHandler" />
        <property name="filterChainBuilder" ref="filterChainBuilder" />
    </bean>  
user2148736
  • 1,283
  • 4
  • 24
  • 39

1 Answers1

0

Server were running but not on TPC but UDP.

For UDP protocol:

  <bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioDatagramAcceptor" init-method="bind" destroy-method="unbind">
        <property name="defaultLocalAddress" value=":6001" />
        <property name="handler" ref="trapHandler" />
        <property name="filterChainBuilder" ref="filterChainBuilder" />
    </bean> 

For TCP protocol:

  <bean id="ioAcceptor" class="org.apache.mina.transport.socket.nio.NioSocketAcceptor" init-method="bind" destroy-method="unbind">
        <property name="defaultLocalAddress" value=":6001" />
        <property name="handler" ref="trapHandler" />
        <property name="filterChainBuilder" ref="filterChainBuilder" />
    </bean> 

The difference is in type of used Acceptor class.

user2148736
  • 1,283
  • 4
  • 24
  • 39