Cliente TCP Spring sem transformador
eu seguiesta exemplo para configurar um cliente TCP no Spring. Abaixo está o meutcpClientServerDemo-context.xml
arquivo onde está o transformador. Alguém pode me ajudar a remover o transformador e enviar os dados como estão, sem modificações? Se eu tentar remover a linhareply-channel='clientBytes2StringChannel'
ou até torná-lo nulo, recebo exceções ao criar o projeto.
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:int="http://www.springframework.org/schema/integration"
xmlns:int-ip="http://www.springframework.org/schema/integration/ip"
xmlns:context="http://www.springframework.org/schema/context"
xsi:schemaLocation="http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsd
http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context.xsd
http://www.springframework.org/schema/integration http://www.springframework.org/schema/integration/spring-integration.xsd
http://www.springframework.org/schema/integration/ip http://www.springframework.org/schema/integration/ip/spring-integration-ip.xsd">
<context:property-placeholder />
<!-- Client side -->
<int:gateway id="gw"
service-interface="hello.SimpleGateway"
default-request-channel="input"/>
<int-ip:tcp-connection-factory id="client"
type="client"
host="192.86.33.61"
serializer="CustomSerializerDeserializer"
deserializer="CustomSerializerDeserializer"
port="${availableServerSocket}"
single-use="true"
so-timeout="10000"/>
<bean id="CustomSerializerDeserializer" class="hello.CustomSerializerDeserializer" />
<int:channel id="input" />
<int-ip:tcp-outbound-gateway id="outGateway"
request-channel="input"
connection-factory="client"
request-timeout="10000"
reply-timeout="10000"/>
<!-- Server side -->
<!-- When creating the socket factory on the server side, we specify both the serializer and deserializer
which deals with both accepting a stream formatted with the Stx-Etx bytes as well as sending a stream
formatted with the Stx-Etx bytes. -->
<int-ip:tcp-connection-factory id="serverConnectionFactory"
type="server"
port="${availableServerSocket}"
single-use="true"
so-linger="10000"
serializer="Custom1SerializerDeserializer"
deserializer="Custom1SerializerDeserializer"/>
<bean id="Custom1SerializerDeserializer" class="hello.CustomSerializerDeserializer1" />
<int-ip:tcp-inbound-gateway id="gatewayCrLf"
connection-factory="serverConnectionFactory"
request-channel="incomingServerChannel"
error-channel="errorChannel"/>
<!-- We leave a message listener off of this channel on purpose because we hook
one up before the test actually runs (see the unit test associated with this
context file) -->
<int:channel id="incomingServerChannel" />
</beans>
EDITAR:
Agora eu posso enviar as mensagens usando um serializador / desserializador personalizado. Infelizmente, porém, não consigo receber as respostas. Aqui está o meu serializador / desserializador:
public class CustomSerializerDeserializer implements Serializer<String>, Deserializer<String> {
protected final Log logger = LogFactory.getLog(this.getClass());
public void serialize(String input, OutputStream outputStream) throws IOException {
logger.info("inside serialize");
outputStream.write(buildSampleMsg(input));
outputStream.flush();
}
public String deserialize(InputStream inputStream) throws IOException {
logger.info("inside deserialize");
final int bufferSize = 1024;
final char[] buffer = new char[bufferSize];
final StringBuilder out = new StringBuilder();
Reader in = new InputStreamReader(inputStream, "UTF-8");
for (;;) {
int rsz = in.read(buffer, 0, buffer.length);
if (rsz < 0) {
break;
}
out.append(buffer, 0, rsz);
}
logger.info(out.toString());
return out.toString();
}
public byte[] buildSampleMsg(String body){
logger.info("inside buildsamplemsg");
......
return hexStringToByteArray(data);
}
Eu tenho alguns logs feitos na primeira linha do serializador / desserializador, mas o log nunca é impresso. O que, por sua vez, significa que não obtemos resposta. Qualquer ajuda será apreciada.