0

When I send byte array to response channel I expect to send only that byte-array to the socket. For example, in spring integration ip.

@ServiceActivator(inputChannel = "serviceChannel")
public byte[] service(byte[] byteArray) {
    return new byte[]{0,2,1,0};
}

I expect it to send

00, 02, 01, 00

But! This will also send two additional bytes to the stream

00, 02, 01, 00 , 0D, 0A 

for end of message. I do NOT want to send those bytes, i.e. I'd like to omit them. How can this be achieved?

I suspect this has to do with how sockets interpret messages, but I did not find where this happens, no matter how I tried.

upd: I found the problem: Spring in my configuration uses class ByteArrayCrLfSerializer but I need to use ByteArrayRawSerializer. How can I do this?

Gary Russell
  • 166,535
  • 14
  • 146
  • 179
Andrii Plotnikov
  • 3,022
  • 4
  • 17
  • 37
  • Answerers don't get notifications of edits to the question; you should havew commented on my answer instead. You need to show your connection factory configuration (edit the question). If you are using XML configuration use `serializer="raw"` where `raw` is a `` with class `ByteArrayRawSerializer`. If you are using java configuration, simply set the serializer. – Gary Russell May 30 '17 at 20:33
  • I did not see your answer at that point :) thanks – Andrii Plotnikov May 31 '17 at 12:15
  • @GaryRussell I think that should be added to your answer, then it will be complete and I will be able to accept it, thanks :) – Andrii Plotnikov May 31 '17 at 12:17

1 Answers1

1

See the Spring Integration documentation about serializers/deserializers.

You generally need some way to demarcate multiple messages in the stream. If the data inherently contains such information, you can use the ByteArrayRawSerializer, which will add no characters.

If you are using XML configuration use serializer="raw" where raw is a with class ByteArrayRawSerializer. If you are using java configuration, simply set the serializer in the @Bean.

If you need to decode such messages with Spring Integration (and more than one is sent over the socket), you will need a custom deserializer.

Gary Russell
  • 166,535
  • 14
  • 146
  • 179