Announcement Announcement Module
Collapse
No announcement yet.
tcp-inbound-gateway error Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • tcp-inbound-gateway error

    I´m trying Spring Integration, but I can´t find important information about it.

    I´m making a inbound/outbound TCP connection, I´m trying with a simple echo server.

    This is my configuration


    Code:
    <ip:tcp-connection-factory id="serverConnection"
    		type="server" port="2003" using-nio="true" />
    
    	<ip:tcp-inbound-gateway id="inGateway" 
    		connection-factory="serverConnection" request-channel="requests" />
    
    	
    	<channel id="requests">
    		<queue capacity="25" />
    	</channel>
    
    	<service-activator id="SA" input-channel="requests" 
    		ref="echoService" method="eco" />
    
    	<beans:bean id="echoService" class="test.EchoService" />
    And this is my EchoService class

    Code:
    public class EchoService {
    
    	
    	public String eco(byte[] bytes) {
    		System.out.println("Llega al server " + new String(bytes));
    		return "echo:" + new String(bytes);
    	}
    }
    When I run the app this receive the input message, but it can´t send the response and I get the next error:

    Code:
    ERROR: org.springframework.integration.ip.tcp.TcpInboundGateway - Failed to send reply
    java.lang.NullPointerException
    	at org.springframework.integration.ip.tcp.connection.TcpMessageMapper.getPayloadAsBytes(TcpMessageMapper.java:76)
    	at org.springframework.integration.ip.tcp.connection.TcpMessageMapper.fromMessage(TcpMessageMapper.java:64)
    	at org.springframework.integration.ip.tcp.connection.TcpNioConnection.send(TcpNioConnection.java:108)
    	at org.springframework.integration.ip.tcp.TcpInboundGateway.onMessage(TcpInboundGateway.java:56)
    	at org.springframework.integration.ip.tcp.connection.TcpNioConnection.sendToChannel(TcpNioConnection.java:235)
    	at org.springframework.integration.ip.tcp.connection.TcpNioConnection.run(TcpNioConnection.java:169)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.runTask(ThreadPoolExecutor.java:885)
    	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:907)
    	at java.lang.Thread.run(Thread.java:619)

    I have tried with a out/reply-channel but it didn´t work.
    This is the new configuration
    Code:
    <ip:tcp-connection-factory id="serverConnection"
    		type="server" port="2003" using-nio="true" />
    
    	<ip:tcp-inbound-gateway id="inGateway" 
    		connection-factory="serverConnection" request-channel="requests" reply-channel="replies"/>
    
    	
    	<channel id="requests">
    		<queue capacity="25" />
    	</channel>
    	
    	<channel id="replies">
    		<queue capacity="25" />
    	</channel>
    
    	<service-activator id="SA" input-channel="requests" output-channel="replies"
    		ref="echoService" method="eco" />
    
    	<beans:bean id="echoService" class="com.reos.messagebroker.services.EchoService" />

    thank you for your help.

  • #2
    @reos

    I am sorry you are having this issue.

    This is essentially the same as the tcl-client-server sample (information about the samples is provided here: http://blog.springsource.com/2010/09...ation-samples/). The only difference I see from your configuration snippet is you are using a QueueChannel whereas the sample uses a DirectChannel (I assume you have a poller somewhere else in your config, not shown here).

    I have made various attempts to reproduce your issue and am having trouble doing so; please can you attach debug level log output from your test case? Alternatively, please provide the complete test case so I can reproduce it myself.

    You may also want to take a look at the sample to see if you can see what (else) is different, but I would like to get to the bottom of this, we certainly shouldn't be throwing an NPE.

    Thanks

    Comment


    • #3
      I was able to reproduce the NPE by returning a null in the service activator.

      https://jira.springsource.org/browse/INT-1529

      This is now fixed, but it doesn't solve your problem in that we need to understand why a null reply is being sent to the gateway.

      Comment


      • #4
        First thank you for reply,

        I downloaded the tcp-client-server sample, but I don´t know what happen.

        When I run the test it works well, after the test it show me an error.

        Code:
        -------------------------------------------------------
         T E S T S
        -------------------------------------------------------
        Running com.reos.spring.ddd.AppTest
        Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.016 sec
        Running org.springframework.integration.samples.tcpclientserver.TcpClientServerDemoTest
        FROM EchoService Hello world!
        echo:Hello world!
        ERROR: org.springframework.integration.ip.tcp.connection.TcpNetConnection - Read exception localhost:4992:16994425 SocketException:null:Connection reset
        Tests run: 1, Failures: 0, Errors: 0, Skipped: 0, Time elapsed: 0.5 sec
        But, when I run the TelnetServer it don´t work, only show me a message "Press Enter/Return in the console to exit", but there isn´t a server listening on any port. I changed the port to 2003, and this is my telnet test

        Code:
        C:\Documents and Settings\rommel>telnet localhost 2003
        Conectándose a localhost...No se puede abrir la conexión al host, en puerto 2003
        : Error en la conexión

        I can run a EchoServer from http://www.javafaq.nu/java-example-code-605.html on the 2003 port while the TelnetServer was running.

        I don´t know if it is my operating system (Windows XP).

        This is the configuration:

        Code:
        <!-- Client side -->
        	
        	<gateway id="gw" 
                service-interface="org.springframework.integration.samples.tcpclientserver.SimpleGateway"
                default-request-channel="input"/>
        
        	<ip:tcp-connection-factory id="client"
        		type="client"
        		host="localhost"
        		port="2003"
        		single-use="true"
        		so-timeout="10000"
                />
        	
        	<channel id="input" />
        	
        	<ip:tcp-outbound-gateway id="outGateway"
        		request-channel="input"
        		connection-factory="client"
        		request-timeout="10000"
        		reply-timeout="10000"
        		/>
        		
        	<!-- Server side -->
        	
        	<ip:tcp-connection-factory id="crLfServer"
        		type="server"
        		port="2003"/>
        			
        	<ip:tcp-inbound-gateway id="gatewayCrLf"
        		connection-factory="crLfServer"
        		request-channel="toSA" />
        		
        	<channel id="toSA" />
        
        	<service-activator input-channel="toSA"
        					   ref="echoService"
        					   method="test"
        	/>
        
        	<beans:bean id="echoService" 
        		  class="org.springframework.integration.samples.tcpclientserver.EchoService" />

        Comment

        Working...
        X