Spring TCP Client without Transformer

自古美人都是妖i 提交于 2019-12-02 13:19:37

Removing the reply-channel is correct. You don't give any indication of the error, but the gateway interface method return type must be changed to byte[].

EDIT

Clearly you are doing something wrong if the mainframe is getting junk. You should do the EBCDIC conversion after you convert your "ABCD" to a byte[] (with getBytes()); if you have EBCDIC chars in a String, that won't work. Also, bear in mind the default serializer will add CRLF (ascii) to the output. If that mainframe can determine the end of message from the data itself, you can use a ByteArrayRawSerializer in the serializer attribute. However, you will need a custom deserializer because the framework won't know how to construct a message from the stream; unless the mainframe closes the socket after sending the reply, in which case a ByteArrayRawSerializer will work as the deserializer attribute.

A common technique used to communicate with mainframes (and others) is to use a 1, 2, or 4 byte length header (network byte order). The ByteArrayLengthHeaderSerializer does just that.

If the mainframe is expecting EBCDIC delimiters, you'll need a custom serializer/deserializer - it might make more sense to do the EBCDIC conversion there, separating it from your application logic.

You can read about serializers/deserializers here.

TCP is a streaming protocol; this means that some structure has to be provided to data transported over TCP, so the receiver can demarcate the data into discrete messages. Connection factories are configured to use (de)serializers to convert between the message payload and the bits that are sent over TCP. This is accomplished by providing a deserializer and serializer for inbound and outbound messages respectively. A number of standard (de)serializers are provided.

The ByteArrayCrlfSerializer, converts a byte array to a stream of bytes followed by carriage return and linefeed characters (\r\n). This is the default (de)serializer and can be used with telnet as a client, for example.

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!