I am trying to use Apache Camel Mina as my socket server to receive byte streams. I am using Apache Camel 2.12.1 and this is my simple route:
<route id="retriever">
<from uri="mina2:tcp://127.0.0.1:5555?sync=false" />
<convertBodyTo type="java.lang.String" />
<to uri="file:temp/out" />
</route>
I can perfectly start the route and send data using telnet. My problem comes when I am using a simple Java test client to send data:
byte[] myData = {0x34, 0x12, 0x25, 0x34};
Socket socket = new Socket("127.0.0.1", 5555);
OutputStream os = socket.getOutputStream();
os.write(myData, 0, myData.length);
os.flush();
socket.close();
When using this client I am not getting any exceptions anywhere but the data does not enter in the camel route. I have been trying to implement my own codec and I check that MINA is receiving the data, but I am not sure if for this simple case I need a special codec. I just want to retrieve the byte array and save it.
So my question is: what I am doing wrong? Why doesn't the default mina2 codec work for my scenario? Am I missing any special option in the mina endpoint to allow this?
Thanks!
If you mean TextLineCodecFactory then you should check the source code. The decoder of this codec uses a delimiter (new line of the OS the the framework is running).
TextLineCodecFactory , TextLineDecoder , LineDelimiter
Check the decoder. In particular check this part
and this part
When it's filling the IoBuffer it uses a new line as the delimiter, so if you don't add one then it will continue to wait for it. Haven't tested this but I'm confident that that is the problem. Just try to send a string with a new line in the end. Convert it into bytes and see what happens.
If you want to transfer data you will have to use some kind of protocol that will set the the rules that the transmitter and the receiver will use in order to set and get the end of communication.