Simple TCP Client - Spring Integration ( Not connecting)
I am trying to simulate following simple tcp client which connect to a socket and reads the data when available and prints.
Code:
public class TestAdapter {
public static void main(String[] args) throws IOException {
Socket socket = null;
PrintWriter out = null;
BufferedReader in = null;
try {
socket = new Socket("localhost ", 11111);
boolean state = socket.isConnected();
if( state)
System.out.println("Successfuly connected ");
in = new BufferedReader(new InputStreamReader(socket.getInputStream()));
} catch (UnknownHostException e) {
System.err.println("Don't know about host: localhost.");
System.exit(1);
} catch (IOException e) {
System.err.println("Couldn't get I/O for " + "the connection to: localhost.");
System.exit(1);
}
String userInput;
while ((userInput = in.readLine()) != null) {
System.out.println("echo: " + userInput);
}
out.close();
in.close();
socket.close();
}
}
With the following configuration, test method on PrintService is not getting invoked when there is some bytes available.
Can anyone help me correct these settings if anything wrong?
Code:
<int:channel id="inputChannel"/>
<ip:tcp-inbound-channel-adapter id="tcpInboundAdapter"
channel="inputChannel"
connection-factory="client"
client-mode="true" />
<ip:tcp-connection-factory id="client"
type="client"
host="localhost"
port="11111"
single-use="false"
using-nio="true"
using-direct-buffers="false"
pool-size="2"
so-keep-alive="true"
so-timeout="0"/>
<int:service-activator id="activator"
input-channel="inputChannel"
ref="printService"
method="test"/>
<bean id="printService" class="com.springintegration.print.PrintService" />
Code:
public class PrintService {
public void test(byte[] bytes) {
System.out.println("Received:" + new String(bytes) );
}
}
from the debug log, connection seems to be established, but the service activator is not invoking test method on PrintService
Code:
01/19 15:25:00,486 DEBUG [main] DefaultLifecycleProcessor} - Successfully started bean 'tcpInboundAdapter'
01/19 15:25:00,586 DEBUG [ThreadPoolTaskScheduler-1] TcpNioClientConnectionFactory} - Opening new socket channel connection to localhost:11111
01/19 15:25:00,622 DEBUG [ThreadPoolTaskScheduler-1] ClientModeConnectionManager} - Connection dell271:11111:79d7e264-d1bb-4b93-8d1b-ffa5c13e9b94 established
01/19 15:25:15,374 DEBUG [pool-1-thread-2] TcpNioConnection} - dell271:11111:79d7e264-d1bb-4b93-8d1b-ffa5c13e9b94 Reading...
01/19 15:25:15,374 DEBUG [pool-1-thread-2] TcpNioConnection} - Read 3251 into raw buffer