java - Spring TCP Client without Transformer -
i followed this example setting tcp client in spring. below tcpclientserverdemo-context.xml
file transformer lies. can me remove transformer , send data without modifications? if try remove line reply-channel='clientbytes2stringchannel'
or make null, exceptions when building project.
<?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 socket factory on server side, specify both serializer , deserializer deals both accepting stream formatted stx-etx bytes sending stream formatted 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"/> <!-- leave message listener off of channel on purpose because hook 1 before test runs (see unit test associated context file) --> <int:channel id="incomingserverchannel" /> </beans>
edit:
now able send messages using custom serializer/deserializer. unfortunately, unable receive responses. here serializer/deserializer:
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"); (;;) { 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); }
i have logging done on first line of serializer/deserializer log never printed. in turn means, don't response. appreciated.
removing reply-channel correct. don't give indication of error, gateway interface method return type must changed byte[].
edit
clearly doing wrong if mainframe getting junk. should ebcdic conversion after convert "abcd" byte[]
(with getbytes()
); if have ebcdic chars in string, won't work. also, bear in mind default serializer add crlf (ascii) output. if mainframe can determine end of message data itself, can use bytearrayrawserializer
in serializer
attribute. however, need custom deserializer
because framework won't know how construct message stream; unless mainframe closes socket after sending reply, in case bytearrayrawserializer
work deserializer
attribute.
a common technique used communicate mainframes (and others) use 1, 2, or 4 byte length header (network byte order). bytearraylengthheaderserializer
that.
if mainframe expecting ebcdic delimiters, you'll need custom serializer/deserializer - might make more sense ebcdic conversion there, separating application logic.
you can read serializers/deserializers here.
tcp streaming protocol; means structure has provided data transported on tcp, receiver can demarcate data discrete messages. connection factories configured use (de)serializers convert between message payload , bits sent on tcp. accomplished providing deserializer , serializer inbound , outbound messages respectively. number of standard (de)serializers provided.
the
bytearraycrlfserializer
, converts byte array stream of bytes followed carriage return , linefeed characters (\r\n
). default (de)serializer , can used telnet client, example.
Comments
Post a Comment